1#!/bin/sh 2# auto-unmount floppy/cd directory before ejecting device 3# script taken from Debian Linux's amd 4# 5# Package: am-utils-6.x 6# (Additional) author: Erez Zadok <ezk@cs.columbia.edu> 7 8# set path 9prefix=@prefix@ 10exec_prefix=@exec_prefix@ 11PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH} 12export PATH 13 14if [ $# -ne 1 ]; then 15 echo "Usage: $0 cd|cdrom|fd|floppy" 16 exit 2 17fi 18 19# determine toplevel mount point of amd 20fs=`amq | grep ' toplvl ' | cut -d' ' -f1` 21if [ "$fs" = "" ]; then 22 echo "Cannot determine amd toplevel directory" 23 exit 2 24fi 25 26# append name of medium 27case "$1" in 28 cd|fd) fs=$fs/$1;; 29 *) echo "Usage: $0 cd|cdrom|fd|floppy"; exit 2;; 30esac 31 32# is the medium mounted? 33if amq | grep -q "^$fs" >/dev/null 2>&1; then 34 # if yes, try to unmount it 35 sync 36 amq -u $fs 37 sleep 2 38 if amq | grep -q "^$fs" >/dev/null 2>&1; then 39 # failed, bail out 40 echo -n "Cannot unmount $fs; in use by:" 41 fuser -uv -m $fs 42 echo "" 43 exit 1 44 fi 45else 46 echo "$fs not mounted" 47fi 48 49case $1 in 50 cd|cdrom) eject cdrom || eject ;; # eject CD-ROM 51 fd|floppy) eject floppy || eject 52 echo "Ok to remove disk" ;; 53esac 54