1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. The forum software that supports hummy.tv will be upgraded on Sunday to XenForo 2.0 and so will be unavailable for periods during the day. This is a major upgrade which changes the look and feel of the forum somewhat but brings a host of improvements too. Please bear with us, there will doubtless be further style changes required following this work.

Mod: helper script for network shares

Discussion in 'HD/HDR-FOX T2 Customised Firmware' started by Drutt, Oct 22, 2011.

  1. Drutt

    Drutt Active Member

    I have knocked up a script that attempts to simplify nfs / smb setup by allowing shares to be configured on the box, using folder names in a special "settings" directory to add and configure shares. It runs in the background, pinging the host(s) and mounting / unmounting the share when applicable. This should solve the problem of the Humax locking up if the computer goes to sleep. Its a bit rough and ready at the moment, and only tested on an HD. I'd appreciate any feedback / improvements / HDR testing, and then I can put it into a nice package :)

    Put the script in a file called /mod/sbin/scanMounts, and create a startup script in /mod/etc/init.d to kick it off (with an "&" after to run in the background). When a new directory is created in smb or nfs, after a few seconds it should create template "options" within it for you to fill in.

        host=$(ls "$name" | grep -e "^host" | cut -d'=' -f2 | sed -e 's/_/./g') #convert "_"s to "."s in host
        folder=$(ls "$name" | grep -e "^folder" | cut -d'=' -f2 | sed -e 's/_/\//g') #convert "_"s to "/"s in folder name
        ping -c 3 $host > /dev/null
        if [ $? != 0 ]; then                # mount or unmount?
            echo "$host not found.."
            # unmount if mounted
            if [ -d "/media/$name" ]; then
                echo "umount "/TEMP/$name""
                umount "/media/$name" -l
                rmdir "/media/$name"
            if [ ! -d "/media/$name" ]; then
                echo "$host is on-line - attempting to mount"
                mkdir "/media/$name"        # and in My Videos?
                if [ $type = "smb" ]; then
                    user=$(ls "$name" | grep -e "^user")        # keep the [user|password etc]=... for these as they go into mount int that format
                    password=$(ls "$name" | grep -e "^password")
                    domain=$(ls "$name" | grep -e "^domain")
                    echo "mount -t cifs "//$host/$folder" "/media/$name" -o $user,$password,$domain,$workgroup"
                    mount -t cifs "//$host/$folder" "/media/$name" -o $user,$password,$domain,$workgroup
                elif [ $type = "nfs" ]; then
                    echo "mount -o soft "$host:/$folder" "/media/$name""
                    mount -o soft "$host:/$folder" "/media/$name"
                if [ $? != 0 ]; then                # failed
                    echo "Mount failed..."
                    rmdir "/media/$name"
        mkdir "$name/host=10_0_1_XX"
        mkdir "$name/folder=ShareFolder (use _ for slash)"
        if [ $type = "smb" ]; then
            mkdir "$name/user=User"
            mkdir "$name/password=Password"
            mkdir "$name/*workgroup=Workgroup (Optional - remove *)"
            mkdir "$name/*domain=Domain (Optional - remove *)"
    exec >/tmp/scanmounts.log 2>&1
    cd /mod/settings
    # create some help 1st time
    if [ ! -d smb ]; then
        mkdir -p "smb/*Create folder with mount name (opt+)"
        mkdir -p "smb/*Then edit options in folder"
    if [ ! -d nfs ]; then
        mkdir -p "nfs/*Create folder with mount name (opt+)"
        mkdir -p "nfs/*Then edit options in folder"
    # set up links to where we can get at the settings folder (a bit messy due to HDR / HD differences)
    if [ -d "/media/My Video" ]; then                # HDR - add link to settings here as it can't get to /mod
        mkdir -p "/media/My Video/*modSettings/smb"
        mkdir -p "/media/My Video/*modSettings/nfs"
        mount /mod/settings/smb "/media/My Video/*modSettings/smb"
        mount /mod/settings/nfs "/media/My Video/*modSettings/nfs"
    if [ -d "/media/drive1/*ModSettings" ]; then    # HD with *modsettings on root- add link to settings here
        mkdir -p "/media/drive1/*ModSettings/smb"
        mkdir -p "/media/drive1/*ModSettings/nfs"
        mount /mod/settings/smb "/media/drive1/*ModSettings/smb"
        mount /mod/settings/nfs "/media/drive1/*ModSettings/nfs"
    # loop checking the mounts
    while [ 1 ]
        for type in smb nfs; do
            if [ -d $type ]; then
                cd $type
                for mountname in [!*]*; do                                        #ignore "comments" starting with *
                    if [ -d "$mountname" ]; then
                        echo "Checking $mountname"
                        if [ "$(ls -A "$mountname")" != "" ]; then
                            TryMount $type "$mountname"
                            CreateExample $type "$mountname"                    #Empty dir - create examples
                cd ..        # back up to settings
        sleep 9
  2. Kev_w

    Kev_w Member

    This looks very usefull! I'll have a go at this tonight on my HDR if I have time. Thanks.
  3. Trevor Jasper

    Trevor Jasper Member

    Well done Steve.

    Just need this integrated into the webif and do it all graphically :) - tongue in cheek, but great work none-the-less.

    Haven't got round to this yet, but thinking it ought to be something I do.