#! /bin/sh #---------------------------------------------------------------------------- # system-devices-umount-usb - umount usb device # # Creation : 2003-11-14 fm # Last Update: $Id$ # # Copyright (c) 2001-2009 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" echo } #---------------------------------------------------------------------------- # 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 -n "Umount of " mecho -n "'${_usb_dev}' " mecho -info "successful." _usb_retval=0 else mecho -error -n "Umount " mecho -n "'${_usb_dev}' " mecho -error "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}/" | LANG=C 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=`grep -c . ${tmpfile}` 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 echo maxnum=`expr ${idx} - 1` /var/install/bin/ask "Select" "" "1-${maxnum}" "a=All" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? devnbr="`cat /tmp/ask.$$`" rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then devnbr=0 fi echo case ${devnbr} in '' ) # quit program u_exit=0 ;; 0 ) # exit program rm -f ${tmpfile}* exit 127 ;; a|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 ;; * ) # 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 ;; esac else mecho -info "No mounted USB drives found!" u_exit=0 anykey fi done rm -f ${tmpfile} exit 0 #============================================================================ # end #============================================================================