18876Srgrimes#!/bin/sh 24Srgrimes# auto-unmount floppy/cd directory before ejecting device 34Srgrimes# script taken from Debian Linux's amd 44Srgrimes# 58876Srgrimes# Package: am-utils-6.x 64Srgrimes# (Additional) author: Erez Zadok <ezk@cs.columbia.edu> 74Srgrimes 84Srgrimes# set path 94Srgrimesprefix=@prefix@ 104Srgrimesexec_prefix=@exec_prefix@ 118876SrgrimesPATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH} 128876Srgrimesexport PATH 134Srgrimes 144Srgrimesif [ $# -ne 1 ]; then 158876Srgrimes echo "Usage: $0 cd|cdrom|fd|floppy" 164Srgrimes exit 2 178876Srgrimesfi 184Srgrimes 194Srgrimes# determine toplevel mount point of amd 204Srgrimesfs=`amq | grep ' toplvl ' | cut -d' ' -f1` 214Srgrimesif [ "$fs" = "" ]; then 228876Srgrimes echo "Cannot determine amd toplevel directory" 234Srgrimes exit 2 244Srgrimesfi 254Srgrimes 2624840Sjoerg# append name of medium 274Srgrimescase "$1" in 28623Srgrimes cd|fd) fs=$fs/$1;; 294Srgrimes *) echo "Usage: $0 cd|cdrom|fd|floppy"; exit 2;; 304Srgrimesesac 314Srgrimes 324Srgrimes# is the medium mounted? 334Srgrimesif amq | grep -q "^$fs" >/dev/null 2>&1; then 342056Swollman # if yes, try to unmount it 3517495Sjoerg sync 362056Swollman amq -u $fs 3712734Sbde sleep 2 3812734Sbde if amq | grep -q "^$fs" >/dev/null 2>&1; then 3912734Sbde # failed, bail out 402056Swollman echo -n "Cannot unmount $fs; in use by:" 412056Swollman fuser -uv -m $fs 424Srgrimes echo "" 434Srgrimes exit 1 444Srgrimes fi 454Srgrimeselse 464Srgrimes echo "$fs not mounted" 474Srgrimesfi 484Srgrimes 494Srgrimescase $1 in 504Srgrimes cd|cdrom) eject cdrom || eject ;; # eject CD-ROM 514Srgrimes fd|floppy) eject floppy || eject 5212720Sphk echo "Ok to remove disk" ;; 5312720Sphkesac 5412720Sphk