Mount/dismount ISO images

In order to mount and dismount ISO image files I use this script:

#!/bin/bash 

if  -z $1 ]; then
  kdialog --error "Usage: $0 filename.iso"
  exit 1;
fi

DIRNAME="$HOME/mnt/"`basename "$1" | sed s/.]^.]*//`

MOUNTLINE=`mount |grep $DIRNAME`
DEVICE=`echo $MOUNTLINE | gawk -F ' ' '{ print $1 }'`
DIRECTORY=`echo $MOUNTLINE | gawk -F ' ' '{ print $3 }'`

if  ! -z $DEVICE ]; then
  kdialog --title "Unmounting $DEVICE" --yesno "Do you wish to unmount $DEVICE on $DIRECTORY?"
  if  $? -eq 0 ]; then
    kdesu -c umount\ $DEVICE || { kdialog --error "Failed to unmount $DEVICE on $DIRECTORY ($?)"; exit 2; }
    kdialog --msgbox "Unmounted"
  fi
else
  test -f $1 || { kdialog --error "File <$1> does not exist!"; exit 2; }
  test -d $DIRNAME || mkdir -p $DIRNAME
  /usr/bin/kdesu -c "/bin/mount -t iso9660 -o loop,ro,user $1 $DIRNAME" || { kdialog --error "Failed to mount $1 to $DIRNAME"; exit 3; }

  /usr/bin/dolphin $DIRNAME
  kdialog --msgbox "Loop devices: $(mount|grep loop)"
fi

If you connect this script to MIME type application/x-cd-image with KDE utility systemsettings you will be able to mount and dismount ISO images by double clicking the files.

Seems interesting. Thanks for the script. I’ll keep it under my sleeve. :wink:

Very nice there sunders and thanks for posting your script, you did a very good job.

Thank You,