Put this script in your ~/bin directory as 'whatson':
Code:
#!/bin/bash
sdir=${1:-cdrom}
if [ $sdir == cdimg ]; then
if [ `id -u` != '0' ]; then
export WHATSON_CDIMG_FILE=$2
echo "You must become root to mount an image"
exec su -c "$0 cdimg"
fi
file=$2
[ -z $file ] && file=$WHATSON_CDIMG_FILE
dir=/mnt/tmp-whatson-$$
mkdir $dir
mount="mount -t iso9660 -o loop $file $dir"
remove=1
else
dir=/mnt/$sdir
eject=1
mount="mount $dir"
fi
echo "$mount"
if [ x$TERM == xxterm ]; then
PROMPT_COMMAND='echo -ne "\033]0;[whatson '$sdir'] ${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
export PROMPT_COMMAND
fi
[ -z $eject ] || eject -t $dir &> /dev/null
if $mount; then
cd $dir
echo 'Contents:'
ls --color=tty -Fhp
echo 'Starting subshell...'
bash
cd ~
umount $dir
fi
[ -z $eject ] || eject $dir &> /dev/null
[ -z $remove ] || rm -rf $dir
This is a script I first wrote a long time ago to help me sort out a bunch of unlabeled CDRs I had laying around.
To use it for physical media (cds, floppies, etc.), run it as 'whatson [directory]' where directory is the subdirectory of /mnt where the medium is mounted (e.g. floppy for /mnt/floppy, cdrom for /mnt/cdrom). If the directory is omitted, it defaults to 'cdrom'. It will automatically close the tray (on cdroms and dvdroms), mount it, start a shell, and will unmount and eject on exit.
For images, use the command 'whatson cdimg image-file' where image-file is the file name of the image to be mounted. If you are not running as root, the script will prompt you for the password before mounting. It will then run the same as for physical media (except it cannot eject or close the tray).
Example:
Code:
$ whatson
mount /mnt/cdrom
Contents:
ANNOUNCE.9_0 CHECKSUMS.md5 COPYRIGHT.TXT FILELIST.TXT kernels/ RELEASE_NOTES SPEAK_INSTALL.TXT
BOOTING.TXT CHECKSUMS.md5.asc CRYPTO_NOTICE.TXT GPG-KEY PACKAGES.TXT slackware/ SPEAKUP_DOCS.TXT
ChangeLog.txt COPYING FAQ.TXT isolinux/ README90.TXT Slackware-HOWTO UPGRADE.TXT
Starting subshell...
$ exit
$ whatson dvd
mount /mnt/dvd
Contents:
AUIDO_TS/ VIDEO_TS/
$ exit
$ whatson cdimg tmp.iso
You must become root to mount an image
Password:
mount -t iso9660 -o loop tmp.iso /mnt/tmp-whatson-2042
Contents:
foo/ bar/
# exit