#!/bin/bash #+ # NAME: # goto # PURPOSE: # Mounting/unmounting of removable disks (floppy,cdrom,zip) # CALLING SEQUENCE # goto 'drive' # RESTRICTIONS: # 'drive' must be listed in /etc/fstab # PROCEDURE: # > After checking /etc/fstab, the mount command is piped # through grep searching for 'drive'. If present the # drive is mounted. # > When bash is the default shell aliases can be defined as: # alias floppy=". goto floppy" # alias cdrom=". goto cdrom" # alias zip=". goto zip" # (i.e. the script is sourced) # In other shells (e.g. csh) the aliases need to be defined as # alias floppy "$COM/goto floppy" # > If 'drive' is not mounted yet then it is mounted, and # a 'cd' is made to the root directory 'drive' # > If 'drive' is mounted, then it is umounted. If the # current directory is on 'drive' then a 'cd' is made # to the previous working directory $OLDPWD. If this fails # then a 'cd' to the user home directory follows. # MODIFICATION HISTORY: # FEB-2001, Paul Hick (UCSD/CASS) # FEB-2003, Paul Hick (UCSD/CASS) # Fixed problem detecting non-existing mount points # FEB-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) # Instead of testing for "drive" test for "drive ". # The added space should avoid problems when e.g. # cdrom and cdrom1 exist. #- thing=$1 if [ "$thing" != "" ]; then # Check the mount points for entry containing $thing dir_thing=$(gawk /"$thing "/'{print $2}' /etc/fstab) dir_thing=$(echo $dir_thing | gawk '{print $1}') if [ -z "$dir_thing" ]; then echo "No mount point found for "$thing" in /etc/fstab" else dev_thing=$(gawk /$thing/'{print $1}' /etc/fstab) dev_thing=$(echo $dev_thing | gawk '{print $1}') mount | grep $dir_thing > /dev/null if [ $? = 0 ]; then echo $PWD | grep $dir_thing > /dev/null if [ $? = 0 ]; then cd $OLDPWD echo $PWD | grep $dir_thing > /dev/null if [ $? = 0 ]; then cd fi fi echo ....... unmounting $dev_thing from $dir_thing umount $dir_thing else echo ....... mounting $dev_thing at $dir_thing mount $dir_thing if [ $? = 0 ]; then cd $dir_thing fi fi fi fi # Probably redundant. echo $0 | grep "/goto" > /dev/null if [ $? = 0 ]; then exit 0 fi