#!/bin/sh # Umount USB Flash drive # BSD License. Copyright (C) by Rashid N. "CityCat" Achilov # $Id: umflash,v 1.1.1.1 2008/01/20 21:10:58 shelton Exp $ if [ $# -eq 0 ]; then mpoint="/mnt/umass" else mpoint=$1 fi # Check on user id. Only root allow to umount flash myid=`id -u` if [ $myid -ne 0 ]; then echo Only root can umount flashdrives exit fi # Memorize device, mounted into this mount point mpdev=`mount | grep -e "$mpoint " | awk '{print substr($1,6,3)}'` # Do umount umount $mpoint # Do search installed device and take info umdrive=`camcontrol devlist | grep -e "($mpdev"` # When we couldn't search drive, try to find ",da" (device number as second arg) if [ ${#umdrive} -eq 0 ]; then umdrive=`camcontrol devlist | grep -e ",$mpdev"` fi # Search bus (search "scbusX", than select X from string) umbus=`echo $umdrive | awk '{print substr($0,index($0,"scbus"),6)}'` umdig=`echo $umbus | awk '{print substr($1,6)}'` # Similar way search target umtarget=`echo $umdrive | awk '{print substr($0,index($0,"target") + 7,1)}'` umlun=`echo $umdrive | awk '{print substr($0,index($0,"lun") + 4,1)}'` camcontrol eject $umdig:$umtarget:$umlun