Mount/Unmount ISO images in nautilus

Hey,

I figured out that nautilus, the file browser of GNOME, has a nice feature of adding scripts to the context menu (right click).
For instance, you can place the following two scripts in ~/.gnome2/nautilus-scripts/ and make them executable (chmod +x).
Then you will be able to do a right-click on iso-images for (un)mounting them.

mount.sh:

#!/bin/bash
# mount
 
gksudo -k /bin/echo "got r00t?"
BASENAME=`basename $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS`
MOUNTPOINT="/media/$BASENAME"
 
if [ ! -d "$MOUNTPOINT" ] ; then
	sudo mkdir "$MOUNTPOINT"
fi
 
ret=`sudo mount -o loop,uid=$UID,gid=$GROUPS $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS "$MOUNTPOINT"`
if [ $? ] ; then
	zenity --info --title "ISO Mounter" --text "$BASENAME Successfully Mounted."
	exit 0
else
	zenity --error --title "ISO Mounter" --text "Could not mount $BASENAME!\nReason: $ret"
	sudo rmdir "$MOUNTPOINT"
	exit 1
fi

unmount.sh:

#!/bin/bash
# unmount
 
gksudo -k /bin/echo "got r00t?"
BASENAME=`basename $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS`
MP="/media/$BASENAME"
 
ret=`sudo umount "$MP"`
if [ $? ] ; then
	zenity --info --title "ISO Mounter" --text "Successfully unmounted $MP"
	sudo rmdir "$MP"
	exit 0
else
	zenity --error --title "ISO Mounter" --text "Could not
	unmount $MP\nReason: $ret"
fi

Posted

in

by

Tags: