Script for mounting DVD ISO-files on Linux

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
roelvdh
Newbie
Newbie
Posts: 24
Joined: January 29th, 2010, 12:13 pm

Script for mounting DVD ISO-files on Linux

Post by roelvdh »

Hello all,

I have been using SABnzbd for a month now and I am very satisfied with it. I have installed it on my Linux server. All downloaded files end up in the "complete" dropbox for further redirection. This is a little drawback if your downloaded file is an ISO and you want to convert it first. A web-based program mounting ISO-files from the "complete"-dropbox would be a nice feature, certainly on a Linux server without a graphical (drag and drop) interface like mine.
So, I tried to write a script doing just that. Being rather new on writing scripts it took me a few hours to understand that this would be tricky. A Linux script will open a new process for each command in the command shell. So, for instance a cd command does not seem to work, as it was opened in a new process environment which is lost when control reverts to the parent process.
After a lot of thinking I came up with following scripts which may be useful. If anybody can improve the scripts I would be interested to learn how.

I assume there is a PuTTY terminal logged in on the Linux server as root. In the root directory there are 2 scripts, mountDVD and umountDVD. Only the locations of the parent directory for the "complete" dropbox (which will be called /parent) and the mount directory need to be adapted. This involves 2 parameters clearly identified.
mountDVD calls another script, called mountFile located in subdirectory /parent/aux. No need to modify this script.
This script will go down  1 or 2 levels from /parent/complete and then list the ISO and iso files that are found in the lowest level present. The last file of the list will be mounted as a loop device /dev/loop0.
I assume that non-iso/ISO files have alreay been redirected so that in /parent/complete there are only ISO/iso files left. The script will only mount the last ISO/iso file, so after mounting you need to move the mounted file, umountDVD and run the script again for the next ISO/iso file, if any.

The scripts have worked well for me. Here they are:

1. mountDVD on /root (Modify params PRNTDIR and MNTDIR)
  • # Script for mounting ISO-files
    # Roel vdH 26-02-2010
    #
    # Specify parent directory of directory "complete"
    # Specify directory where iso/ISO-file will be mounted
    #
    PRNTDIR="/home/roel/comms/downloads"
    MNTDIR="/home/roel/comms/mountDVD"
    #
    rm -f mnt1
    cat $PRNTDIR/aux/mountFile > mnt1
    source mnt1
2. umountDVD on /root (change mount directory)
  • # Script for unmounting ISO-files
    # Roel vdH 26-02-2010
    #
    # Change mount directory
    #
    rm -f mnt1
    echo 'umount /home/roel/comms/mountDVD ' > mnt1
    source mnt1


3.  mountFile on /parent/aux
  • # Script for mounting ISO-files
    # Roel vdH 26-02-2010
    #
    # Called from and returns to root directory ~
    # Will go down 1 or 2 levels from parent directory of directory "complete"
    # Looking for files *.ISO and *.iso
    # Will select last subdirectory in list
    # Will select last line with either ISO or iso in list
    #
    rm -f $PRNTDIR/aux/aux*
    #
    echo
    echo -- mountDVD - Step 1: listing files and directories level -1
    echo
    ls $PRNTDIR/complete > $PRNTDIR/aux/aux1
    cat $PRNTDIR/aux/aux1
    echo
    echo -n 'cd "$PRNTDIR/complete/' > $PRNTDIR/aux/aux2
    cat $PRNTDIR/aux/aux1 | tail -1 >> $PRNTDIR/aux/aux2
    cat $PRNTDIR/aux/aux2 | tr -d "\n" > $PRNTDIR/aux/aux3
    echo '"' >> $PRNTDIR/aux/aux3
    # chmod 700 $PRNTDIR/aux/aux3
    source $PRNTDIR/aux/aux3
    echo -- mountDVD - Step 2: listing files and directories level -2
    echo
    ls > $PRNTDIR/aux/aux4
    cat $PRNTDIR/aux/aux4
    echo
    echo -n 'cd "' > $PRNTDIR/aux/aux5
    cat $PRNTDIR/aux/aux4 | tail -1 >> $PRNTDIR/aux/aux5
    cat $PRNTDIR/aux/aux5 | tr -d "\n" > $PRNTDIR/aux/aux6
    echo '"' >> $PRNTDIR/aux/aux6
    # chmod 700 $PRNTDIR/aux/aux6
    source $PRNTDIR/aux/aux6
    echo -n '-- mountDVD - Step 3: iso and ISO-files in directory ' ; pwd
    echo
    ls | grep ISO > $PRNTDIR/aux/aux7
    ls | grep iso >> $PRNTDIR/aux/aux7
    cat $PRNTDIR/aux/aux7
    echo
    echo -n '-- mountDVD - Step 4: Mount file ' ; cat $PRNTDIR/aux/aux7 | tail -1
    echo
    echo -n 'mount -t iso9660 -o ro,loop=/dev/loop0 ' > $PRNTDIR/aux/aux8
    cat $PRNTDIR/aux/aux7 | tail -1 >> $PRNTDIR/aux/aux8
    cat $PRNTDIR/aux/aux8 | tr -d "\n" > $PRNTDIR/aux/aux9
    echo -n ' ' >> $PRNTDIR/aux/aux9
    echo $MNTDIR >> $PRNTDIR/aux/aux9
    source $PRNTDIR/aux/aux9
    echo -n '-- mountDVD - In absence of error messages : Successfully mounted on '
    echo $MNTDIR
    echo
    cd /root
I hope this will be helpful. It certainly is to me though far from perfect still.
The script is only valid for DVD iso files using the iso9660 filesystem which is the standard filesystem for DVD. Very easy to change for other iso variants.
Good luck!
roelvdh
Newbie
Newbie
Posts: 24
Joined: January 29th, 2010, 12:13 pm

Re: Script for mounting DVD ISO-files on Linux server -- Improved version

Post by roelvdh »

I made a much improved version of the script for mounting iso-files als DVD, on a Linux server.

Please note: This is intended for people using SABnzbd on a (remote) Linux server, connecting to the server via a (PuTTY) terminal. The script will automate the mounting process for all iso and ISO files in the .../complete dropbox and its subdirs.
The former version is deprecated. Unmounting is now done in the script, so umountDVD is no longer necessary.

Usage:
1. Copy the script to a file mountDVD in the (home or root) directory where you normally login
2. Modify 2 lines (7 and 8 ) according to your own situation
3. chmod 755 mountDVD
4. Connect a (PuTTY) terminal, login and type ./mountDVD

The script will sequentially mount all iso and ISO files, wait after mounting each separate file for you to do proper postprocessing, and unmount the files when done. The script does not delete any files in your .../complete directory, not does it do any postprocessing like moving files. Deleting files has to be done manually after inspecting the postprocessing results. Currently the script will only  mount iso9660 filesystems, which is the DVD standard anyway, but changing that is an apparant modification.

Script:
  • #! /bin/bash
    #
    # Script for mounting iso files as DVD (on Linux server via terminal)
    # Roel van der Heide 12-03-2010
    #
    # Please modify next 2 lines appropriately
    COMPLDIR=/home/roel/comms/downloads/complete  # auxfile_1
    wc -l auxfile_1 | sed 's/ auxfile_1//g'  > auxfile_2
    read NUMFILES auxfile_2
        read ISOFILE /dev/null 1>&2
        echo "mounting file $ISOFILE on $MOUNTDIR"
        echo "mount -t iso9660 -o ro,loop=/dev/loop0 $ISOFILE $MOUNTDIR" > auxfile_2
        . auxfile_2
        echo -n "Type done (d) or quit (q) when finished postprocessing: ... "
        read ISDONE

          case $ISDONE in
            done | d) sed -n '$!p' auxfile_1 > auxfile_2
                      if test -s auxfile_2
                        then
                        mv -f auxfile_2 auxfile_1
                      else
                        echo
                        echo "Ready"
                        break
                      fi
                      ;;
            quit | q) echo "Mounting process aborted"
                      break
                      ;;
            *) echo "----> Try again: Type done or quit"
          esac

          echo
        done

    else
    echo "No iso files in .../complete or subdirs"
    echo "----------"
    break
    fi

    umount $MOUNTDIR 2> /dev/null 1>&2
    echo
    echo "All iso files still exist in $COMPLDIR"
    echo "  -- delete files manually after checking postprocessing --"
    echo "-------------------------------------------------------------"

    # End of script
.
Post Reply