Results 1 to 7 of 7

Thread: mount/unmount script for iso and img files

Threaded View

  1. #1
    Join Date
    Sep 2007
    Beans
    471
    Distro
    Ubuntu 11.04 Natty Narwhal

    mount/unmount script for iso and img files

    I created a script that is able to mount .iso and .img files, it also unmount if used on a already mounted file. I know there is a script to mount .iso files but I haven't found any script that can mount both .iso and .img files. Simply save it in ~/.gnome2/nautilus-scripts/ and make the file executable.

    PHP Code:
    #!/bin/bash
    #
    # nautilus-file-mounter

    gksudo -u root -/bin/echo "Enter your password for root terminal access"

    # Determine if file is ISO,IMG (UDF) or neither
    TYPE="$(file -b "$*" | cut -c 3-5)"
    if [ $TYPE 'ISO' ]
        
    then
        BASENAME
    =`basename $* .iso`
    elif $TYPE 'UDF' ]
        
    then
        BASENAME
    =`basename $* .img`
    else
        
    zenity --error --title "File Mounter" --text "File not recognized!"
        
    exit 1
    fi
    #Check if the intended mount point already exist,
    #in that case ask if the user wish to unmount this AND remove the map
    if [ -/media/"$BASENAME
    then
        
    #Confirm to unmount
        
    if zenity --question --title "File Mounter" --text "Unmount $BASENAME at /media/$BASENAME?"
        
    then
            
    if sudo umount /media/$BASENAME
            then
                zenity 
    --info --text "Successfully unmounted /media/$BASENAME"
                
    sudo rmdir "/media/$BASENAME"
                
    exit 0
            
    else
                
    zenity --error --text "Failed to unmount /media/$BASENAME"
                
    exit 1
            fi
        
    else
            exit 
    1
        fi
    #Try to mount
    else
        
    #ISO
        
    if [ $TYPE 'ISO' ]
        
    then
            sudo mkdir 
    "/media/$BASENAME"
            
    if sudo mount -o loop -t iso9660 $* /media/"$BASENAME"
                
    then
                zenity 
    --info --title "File Mounter" --text "$BASENAME.iso Successfully Mounted."
                
    exit 0
            
    else
                
    sudo rmdir "/media/$BASENAME"
                
    zenity --error --title "File Mounter" --text "Cannot mount $BASENAME.iso!"
                
    exit 1
            fi
        
    #UDF IMG
        
    else
            
    sudo mkdir "/media/$BASENAME"
            
    if sudo mount -t udf -o loop $* "/media/$BASENAME
            
    then
                zenity 
    --info --title "File Mounter" --text "$BASENAME.img Successfully Mounted."
                
    exit 0
            
    else
                
    sudo rmdir "/media/$BASENAME"
                
    zenity --error --title "File Mounter" --text "Cannot mount $BASENAME.img!"
                
    exit 1
            fi
        fi
    fi 
    Sources:
    http://ubuntuforums.org/showpost.php...20&postcount=2
    http://www.ubuntugeek.com/mount-isos...-nautilus.html
    http://www.ubuntugeek.com/mount-and-...ning-them.html
    http://ubuntuforums.org/showthread.php?t=87369
    http://ubuntuforums.org/showthread.php?t=1483438
    Last edited by SpinningAround; May 17th, 2010 at 05:43 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •