Monday, October 6, 2008

Auto Mount/Unmout Disk Images

Here are two scripts to automatically mount and unmout image files in Linux.

Console Script:
/usr/local/bin/isomnt
#!/bin/bash
if [ -e "$*" ]; then
if [ -d /media/"$*" ]; then
echo "Unmounting '$*'..."
sudo umount -d /media/"$*"
sudo rmdir /media/"$*"
else
echo "Mounting '$*'..."
sudo mkdir /media/"$*"
sudo mount -o loop "$*" /media/"$*"
fi
else
echo "No image found to mount."
fi

Nautilus Script:
~/.gnome2/nautilus-scripts/(Un)Mount ISO
#!/bin/bash
if [ -d /media/"$*" ]; then
gksudo ls /media
sudo umount -d /media/"$*"
sudo rmdir /media/"$*"
else
gksudo mkdir /media/"$*"
wd=${NAUTILUS_SCRIPT_CURRENT_URI#file://}
sudo mount -o loop "$wd/$*" /media/"$*"
fi

No comments: