Merge from vendor branch LESS:
[dragonfly.git] / contrib / amd / scripts / am-eject.in
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.0
6 # (Additional) author:  Erez Zadok <ezk@cs.columbia.edu>
7
8 # set path
9 prefix=@prefix@
10 exec_prefix=@exec_prefix@
11 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
12 export PATH
13
14 if [ $# -ne 1 ]; then
15         echo "Usage: $0 cd|fd"
16         exit 2
17 fi
18
19 # determine toplevel mount point of amd
20 fs=`amq | grep ' toplvl ' | cut -d' ' -f1`
21 if [ "$fs" = "" ]; then
22         echo "Cannot determine amd toplevel directory"
23         exit 2
24 fi
25
26 # append name of medium
27 case "$1" in
28   cd|fd) fs=$fs/$1;;
29   *)     echo "Usage: $0 cd|fd"; exit 2;;
30 esac
31
32 # is the medium mounted?
33 if 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
45 else
46         echo "$fs not mounted"
47 fi
48
49 case $1 in
50   cd)   eject;; # eject CD-ROM
51   fd)   echo "Ok to remove disk";;
52 esac