#! /bin/sh #---------------------------------------------------------------------------- # system-devices-umount-usb - umount usb device # # Creation : 14.11.2003 fm # Last Update: $Id$ # # Copyright (c) 2003-2008 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # print header #---------------------------------------------------------------------------- print_header () { clrhome mecho -info "Umount USB device" mecho } #---------------------------------------------------------------------------- # umount USB device # input : $1 - device name # output: 0 - umount successful # 1 - umount unsuccessful #---------------------------------------------------------------------------- function umount_usb_drive () { _usb_dev=$1 _usb_retval=1 /bin/umount ${_usb_dev} sleep 1 if [ $? -eq 0 ] then mecho -info "Umount of ${_usb_dev} successful." _usb_retval=0 else mecho -error "Umount ${_usb_dev} failed." fi return ${_usb_retval} } #============================================================================ # main #============================================================================ . /var/install/include/eislib #exec 2>./umount-usb-drive-$$.log #set -x echo mountpath=/usb tmpfile=/tmp/system-devices-umount-usb.$$ mecho "Looking up mounted drives ..." # get list if mounted drives mount | grep "${mountpath}/" | sort > ${tmpfile} u_exit=1 while [ ${u_exit} -eq 1 ] do print_header if [ -s ${tmpfile} ] then # mounted drives found, go on ... techo begin 2 3r 2 10 2 30 2 23 techo "" -info "Nr" "" -info "Device" "" -info "Description" "" -info "Status" maxnum=`cat ${tmpfile} | wc -l` idx=1 while [ ${idx} -le ${maxnum} ] do eval "dev_${idx}_name=`sed -n "${idx}p" ${tmpfile} | cut -d' ' -f1`" eval devname="\$dev_${idx}_name" eval "dev_${idx}_desc=\"`sed -n "${idx}p" ${tmpfile} | cut -d' ' -f2-`\"" eval devdesc="\$dev_${idx}_desc" eval devstat="\$dev_${idx}_stat" if [ "${devstat}" = "" ] then devstat='mounted' eval "dev_${idx}_stat='${devstat}'" fi if [ "${devstat}" = "mounted" ] then techo row "" "${idx}" "" "${devname}" "" "${devdesc}" "" "${devstat}" else techo row "" "${idx}" "" "${devname}" "" "${devdesc}" "" -warn "${devstat}" fi idx=`expr ${idx} + 1` done techo end mecho maxnum=`expr ${idx} - 1` /var/install/bin/ask "Select" "" "1-${maxnum}" "a=All" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? devnbr="`cat /tmp/ask.$$|sed 's/\/$//'`" rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then exit 1 fi mecho case ${devnbr} in '' ) # quit program u_exit=0 ;; 0 ) # exit program u_exit=127 ;; a ) # umount all drives idx=1 while [ ${idx} -le ${maxnum} ] do eval dev="\$dev_${idx}_name" eval stat="\$dev_${idx}_stat" if [ "${stat}" = 'not mounted' ] then # not mounted mecho -error "Device cannot be unmounted!" else umount_usb_drive ${dev} if [ $? -eq 0 ] then devstat='not mounted' eval "dev_${idx}_stat='${devstat}'" fi fi idx=`expr ${idx} + 1` done sleep 2 ;; * ) # numeric value, umount single drive if [ ${devnbr} -lt 1 -o ${devnbr} -gt ${maxnum} ] then # error mecho -error "Value out of range!" anykey else # umount device eval dev="\$dev_${devnbr}_name" eval stat="\$dev_${devnbr}_stat" if [ "${stat}" = 'not mounted' ] then # not mounted mecho -error "Device cannot be unmounted!" else umount_usb_drive ${dev} if [ $? -eq 0 ] then devstat='not mounted' eval "dev_${devnbr}_stat='${devstat}'" fi fi sleep 2 fi ;; esac else mecho -info "No mounted USB drives found!" u_exit=0 fi done rm -f ${tmpfile} anykey exit 0 #============================================================================ # end #============================================================================