#!/bin/bash # # Adrian's ISO Mounter MNT_POINT=/media/isoimage TITLE="ISO Mounter" if ! gksudo -u root -k -m "ISO Mounter is preparing to mount or unmount an ISO. Please enter your password." /bin/echo "Attained root access" then zenity --error --title "$TITLE" --text "Unable to mount or unmount without superuser privileges. Please contact your system administrator." exit 1 fi #check first if it's mounted right now MNT_INFO=$(mount | grep "on $MNT_POINT") if [ "$MNT_INFO" == "" ]; then #we're mounting it #make the directory we're going to mount to if [ -d $MNT_POINT ]; then #if the media directory exists already if zenity --question --title "$TITLE" --text "The $MNT_POINT directory exists, but is not mounted to anything. Would you like to try to delete it?" then if sudo rmdir "$MNT_POINT" then echo "Good removal" else zenity --error --title "$TITLE" --text "Could not delete the $MNT_POINT folder. Possibly it contains files; please try to delete the folder manually." exit 1 fi else zenity --error --title "$TITLE" --text "Failed to mount to $MNT_POINT: The folder already exists." exit 1 fi fi #the directory now does not exist, and we are clear to create afresh and mount. sudo mkdir /media/isoimage if sudo mount -o loop -t iso9660 "$*" "$MNT_POINT" then if zenity --question --title "$TITLE" --text "$* Successfully Mounted. Open Volume?" then nautilus $MNT_POINT --no-desktop fi exit 0 else sudo rmdir "$MNT_POINT" zenity --error --title "$TITLE" --text "Could not mount $*!" exit 1 fi else #currently mounted already if zenity --question --title "$TITLE" --text "Something is already mounted to the $MNT_POINT directory. Unmount?" then if sudo umount $MNT_POINT then sudo rmdir "$MNT_POINT" zenity --info --title "$TITLE" --text "Successfully unmounted $MNT_POINT" exit 0 else zenity --error --title "$TITLE" --text "Could not unmount from $MNT_POINT!" exit 1 fi fi fi