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