FAQ  •  Register  •  Login

How do I install Serviio on a Zyxel NSA-310 ?

<<

Dangerousp

Serviio newbie

Posts: 7

Joined: Tue Nov 29, 2011 8:22 pm

Post Tue Dec 06, 2011 8:45 am

Re: How do I install Serviio on a Zyxel NSA-310 ?

I did get FFP to work properly. Did you enable sshd and then maybe disable telnet? If so try to start it again in sshd with /ffp/start/telnetd.sh start

I've been away from for a few days and my internet connection is really poor the past few weeks. I'll try it this evening again.
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Tue Dec 06, 2011 12:57 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Dangerousp wrote:I did get FFP to work properly. Did you enable sshd and then maybe disable telnet? If so try to start it again in sshd with /ffp/start/telnetd.sh start

I've been away from for a few days and my internet connection is really poor the past few weeks. I'll try it this evening again.


How do I do this ? I cannot telnet to my NSA-310 after the reboot. My NSA-310 seems to have booted normally and busybox is running.

The only way I got to telnet to my NSA-310 was to use the Zyxel backdoor.

When FFP is working, should I still get the Zyxel WebUI ?

Thanks.
<<

Dangerousp

Serviio newbie

Posts: 7

Joined: Tue Nov 29, 2011 8:22 pm

Post Tue Dec 06, 2011 1:41 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

harpoon wrote:
Dangerousp wrote:I did get FFP to work properly. Did you enable sshd and then maybe disable telnet? If so try to start it again in sshd with /ffp/start/telnetd.sh start

I've been away from for a few days and my internet connection is really poor the past few weeks. I'll try it this evening again.


How do I do this ? I cannot telnet to my NSA-310 after the reboot. My NSA-310 seems to have booted normally and busybox is running.

The only way I got to telnet to my NSA-310 was to use the Zyxel backdoor.

When FFP is working, should I still get the Zyxel WebUI ?

Thanks.


Well, I just did what was on the site http://zyxel.nas-central.org/wiki/FFP-stick

Yes, when ffp is working all the functions of the Zyxel are still working as normal.

I allready tried to do what's in this thread, but I get stuck on the readme file in the zip file. I've got two volumes instead of one, so I don't know exactly where the files should be pasted. Also making the requested folders is not possible for me, putty says nothing and I can't see the paths on my stick. In other directories it does work, but the one in the readme doesn't.

I will try the more complex method when I have time!
<<

Dangerousp

Serviio newbie

Posts: 7

Joined: Tue Nov 29, 2011 8:22 pm

Post Tue Dec 06, 2011 5:55 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

to be more specific:

In the readme it says: Download files:
http://www.inreto.de/dns323/fun-plug/0.5/fun_plug
http://www.inreto.de/dns323/fun-plug/0.5/fun_plug.tgz
and put them to \\DNS-device\Volume_1 where "DNS-device" is the IP address of your DNS device ;-)

But I've got two volumes with FFP where volume 1 is only the bootlog etc. and volume 2 I can go to /ffproot/
I put it on the volume 1?

Edit the fun_plug from /mnt/HD_a2 to /mnt/HD/HD_a2, I assume it's the one I just downloaded? and if it says, is that correct?:

FFP_LOG=/mnt/HD_a2/ffp.log
#FFP_LOG=/dev/null
exec

to
FFP_LOG=/mnt/HD/HD_a2/ffp.log
#FFP_LOG=/dev/null
exec

Step 2) I can't put them on volume 1, because that one is to small. I do have a volume 2, but I don't know where to put it. I also can't make the /mnt/HD/HD_a2/tsqueeze folder.. so I'm a bit stuck at this point.
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Tue Dec 06, 2011 9:53 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Dangerousp wrote:
harpoon wrote:
Dangerousp wrote:I did get FFP to work properly. Did you enable sshd and then maybe disable telnet? If so try to start it again in sshd with /ffp/start/telnetd.sh start

I've been away from for a few days and my internet connection is really poor the past few weeks. I'll try it this evening again.


How do I do this ? I cannot telnet to my NSA-310 after the reboot. My NSA-310 seems to have booted normally and busybox is running.

The only way I got to telnet to my NSA-310 was to use the Zyxel backdoor.

When FFP is working, should I still get the Zyxel WebUI ?

Thanks.


Well, I just did what was on the site http://zyxel.nas-central.org/wiki/FFP-stick

Yes, when ffp is working all the functions of the Zyxel are still working as normal.

I allready tried to do what's in this thread, but I get stuck on the readme file in the zip file. I've got two volumes instead of one, so I don't know exactly where the files should be pasted. Also making the requested folders is not possible for me, putty says nothing and I can't see the paths on my stick. In other directories it does work, but the one in the readme doesn't.

I will try the more complex method when I have time!


FFP now working ... my bad for using an old version of FFPstick !

now on to the next step ...
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Wed Dec 07, 2011 10:05 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Dangerousp wrote:to be more specific:

Step 2) I can't put them on volume 1, because that one is to small. I do have a volume 2, but I don't know where to put it. I also can't make the /mnt/HD/HD_a2/tsqueeze folder.. so I'm a bit stuck at this point.


I think I may be getting the idea of what is going on.

Fonz released the original fun_plug script ... but this was modified by Mijzelf to get it working on the NSA-310.

To do this, he needed some serious surgical work ... needless to say the modification of the mount point
/mnt/HD/HD_a2 should be done in the "after_booting.sh" file in the FFPStick-2011-07-15.zip archive posted by Mijzelf.

Note that Mijzelf downloads the fun_plug.tgz in his script, so Step 1 is not needed ... except maybe for the /mnt/HD_a2 renaming (which I do not understand and could not get to work).

... However ... if this is renamed in the "after_booting.sh" file, then somehow the link is broken.

I don't know why this needs to point to a different location ... so I have left it alone and gone to Step 2.

The next thing is to do is to copy and unpack tsqueeze. To do this, I copied tihob's tsqueeze.tar.gz to the public folder of my Zyxel (using Windows).
i.e. copy tsqueeze.tar.gz to \\nsa_310_ip_address\public\tsqueeze.tar.gz

Then using telnet, do the following :-
cd /mnt/HD_a2
mkdir tsqueeze
cd /mnt/HD_a2/tsqueeze
cp ../public/tsqueeze.tar.gz
gunzip tsqueeze.tar.gz .
tar -xf tsqueeze.tar

this will extract the package to the tsqueeze folder in /mnt/HD_a2/tsqueeze.

Finally I need to figure out how fun_plug.debian can be launched from within the Mijzelf Fun_Plug scripts ...

[tihob] Do you have any pointers on how to modify your fun_plug.debian for the Zyxel NSA-310 ? Anyone ?

Thank you in advance ...
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Wed Dec 07, 2011 11:32 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Here is the fun_plug.sh used by Mijzelf
  Code:
#!/bin/sh
# ============================================================================
#
# This file is part of the 'FFP-stick for ZyXEL NSA-nnn'
# http://zyxel.nas-central.org/wiki/FFP-stick
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Author: Mijzelf <Mijzelf@live.com>
#
# ============================================================================
#
# This script is supposed to be started by usb_key_func.sh, or by itself
#
# Run without params for a brief help

SCRIPTVERSION="20110712"
LOGFILE="ffpboot.log"
WHILEBOOTING="while_booting.sh"
AFTERBOOTING="after_booting.sh"
TMPSTICK="/tmp/.ffpstick"
TMPROOT="/tmp/ffproot"

FATFILES="${WHILEBOOTING} \
      usb_key_func.sh \
      nsa210_check_file md5sum \
      nsa220_check_file \
          NSA221_check_file salted_md5sum \
      nsa310_check_file_C0 salted_md5sum_3x0 "
EXT3FILES="${AFTERBOOTING} rootfs.tgz fun_plug.tgz"

# ======================
# Filled in by commandline params
USBDEVICE=
NASTYPE=
FIRMWARE=
USELOGFILE=""
PARNERKEY_MP=""
# ======================

# ===================================================
# function SplitPath
# split path in first parameter in path and filename
SPLITTEDPATH="" # Output path
SPLITTEDFILE="" # Output file
# ===================================================
SplitPath()
{
    SPLITTEDPATH=""
    SPLITTEDFILE=""
    IFSBACKUP=${IFS};    IFS=/
    for chunk in $1
    do
        newpath=""
        if [ "${SPLITTEDPATH}" = "" ] ; then
       newpath="${chunk}"
   else
       newpath="${SPLITTEDPATH}/${chunk}"
   fi
   if [ "${newpath}" = "$1" ] ; then
       SPLITTEDFILE="${chunk}"
   elif [ "/${newpath}" = "$1" ] ; then
       SPLITTEDPATH="/${SPLITTEDPATH}"
       SPLITTEDFILE="${chunk}"
   else
       SPLITTEDPATH="${newpath}"
   fi
    done
    IFS=${IFSBACKUP}
    if [ "" = "${SPLITTEDPATH}" ] || [ "." = "${SPLITTEDPATH}" ]; then
   SPLITTEDPATH=` pwd `
    fi
}

# ===================================================
# function GetNasType
# Try to find out the NAS type, and FW
NASTYPE="" # output NAS type
FIRMWARE="" # output FW
# Actually from the viewpoint of the FFP stick there are only 2 types:
# - NSA220 firmware 2.20 or lower, which has a different mountpoint
# - All other NASsen/firmwares
# ===================================================
GetNasType()
{
   if [ -x /zyxel/sbin/mrd_model ]; then
      model=` /zyxel/sbin/mrd_model -p `
   
      case ${model} in
         D401)
            NASTYPE="NSA210"
            ;;
         D501)
            NASTYPE="NSA220"
            ;;
         DA01)
            NASTYPE="NSA310"
            ;;
         DC01)
            NASTYPE="NSA221"
            ;;
         DD01)
            NASTYPE="NSA320"
            ;;
      esac
   fi

   if [ "" = "${NASTYPE}" ]; then
      case ` uname -r ` in
         2.6.18.6*)
            NASTYPE="NSA220"
            ;;
         2.6.24.4*)
            NASTYPE="NSA210"
            ;;
         *)
            NASTYPE="Unknown-${model}"
            ;;
      esac
   fi
   
   if [ -r /zyxel/mnt/info/fwversion ] ; then
      FIRMWARE=` cat /zyxel/mnt/info/fwversion `
   elif [ -r /etc/fwversion ]; then
      FIRMWARE=` cat /etc/fwversion ` 
   fi
   
   if [ "" = "${FIRMWARE}" ]; then
      FIRMWARE="Undetermined"
   fi
}

# =======================================
# function JumpToRepartition
# copies all needed files to ramdisk,
# and passes execution to script there
# =======================================
JumpToRepartition()
{
    echo Copy files to ramdisk...
   
    mkdir -p ${TMPSTICK}

    filelist=${FATFILES}
    local copied=""
    local notcopied=""
    for loop in 1 2 3
    do
   for file in ${filelist}
   do
       if [ -r ${SPLITTEDPATH}/${file} ] ; then
      if cp ${SPLITTEDPATH}/${file} ${TMPSTICK}/${file}; then
          copied="${copied} ${file}"
      else
          rm ${TMPSTICK}/${file}
          notcopied="${notcopied} ${file}"
      fi
       fi
   done
   if [ 1 -eq ${loop} ]; then
       filelist=${EXT3FILES}
   else
       filelist=${SPLITTEDFILE}
   fi
    done

    echo "Copied${copied}"
    if [ "" != "${notcopied}" ]; then
   echo "*Not* copied${notcopied}"
    fi

    if [ "" != "${USELOGFILE}" ]; then
   exec >/dev/null 2>&1
   cp -a ${SPLITTEDPATH}/${USELOGFILE} ${TMPSTICK}/${USELOGFILE}
        exec >>${TMPSTICK}/${USELOGFILE} 2>&1
        sync
    fi

    exec ${TMPSTICK}/${SPLITTEDFILE} Repartition -m ${PARNERKEY_MP} -d ${USBDEVICE} -l
}

# =========================================
# function FirstCall
# This is the original call of the script
# =========================================
FirstCall()
{
    echo ffpstick started at ` date `
    echo -ne Try to determine NAS type...
    GetNasType
    echo type ${NASTYPE}, fw ${FIRMWARE}
   
    PARNERKEY_MP="/mnt/parnerkey"
    if [ "${NASTYPE}" = "NSA220" ]; then
   if cat ${SPLITTEDPATH}/nsa220_check_file | grep -v parnerkey >/dev/null ; then
      PARNERKEY_MP="/mnt"
   fi
    fi

    if [ "${PARNERKEY_MP}" != "${SPLITTEDPATH}" ]; then
   echo FATAL Wrong mountpoint ${SPLITTEDPATH}, should have been ${PARNERKEY_MP}
   echo Cowardly refusing to install/start FFP in an unknown environment
   exit 1
    fi

    if [ -e /tmp/${SPLITTEDFILE} ]; then
   echo For some reason this script is called multiple times
   exit 1
    fi

    echo -ne Find the current usb device...
    usbdev=`cat /proc/mounts | grep ${SPLITTEDPATH} | grep -v ram | tail -n 1 | awk '{print $1}'`
    if [ "${usbdev}" = "" ]; then
   echo FATAL Usbdevice not found
   exit 1
    fi
    echo -ne usb device is ${usbdev}
    USBDEVICE=` echo ${usbdev} | sed 's/[0-9]*//g' `
    if [ "${USBDEVICE}" = "${usbdev}" ] ; then
   echo
    else
   echo " on device ${USBDEVICE}"
    fi
   
    if [ -x ${SPLITTEDPATH}/${AFTERBOOTING} ]; then
   echo -ne "Check for filesystem..."
   filesystem=`cat /proc/mounts | grep ${SPLITTEDPATH} | grep -v ram | tail -n 1 | awk '{print $3}'`
   echo Filesystem is ${filesystem}
   if [ "${filesystem}" = "vfat" ] ; then
       if [ "${USBDEVICE}" = "${usbdev}" ]; then
      echo ${usbdev} is not partitioned. Will have to partition it
      JumpToRepartition
       else
      echo -ne "Check ${USBDEVICE} for number of partitions..."
           partition_num=`fdisk -l ${USBDEVICE} | grep "^"${USBDEVICE} | wc -l `
      echo ${USBDEVICE} has ${partition_num} partitions
      if [ ${partition_num} -eq 1 ] ; then
          echo Will have to repartition
          JumpToRepartition
      fi
       fi
   fi
    else
   echo No ${AFTERBOOTING} in the root of the ffpstick found
   echo This is not the first run, or FFP is supposed to run from a different place
    fi

    # Execute an eventual '${WHILEBOOTING}' script
    if [ "${WHILEBOOTING}" != "" ] && [ -x ${SPLITTEDPATH}/${WHILEBOOTING} ]; then
   echo Executing ${WHILEBOOTING}...
   cd ${SPLITTEDPATH}
   ${SPLITTEDPATH}/${WHILEBOOTING} ${usbdev} ${SPLITTEDPATH} ${NASTYPE} "${FIRMWARE}"
    fi

    echo -ne Copy myself to /tmp...
    mkdir -p ${TMPSTICK}
    cp -pf ${SPLITTEDPATH}/${SPLITTEDFILE} ${TMPSTICK}/${SPLITTEDFILE}

    if ! [ -x ${TMPSTICK}/${SPLITTEDFILE} ]; then
   echo FATAL Failed to copy!
   exit 1
    fi

    COMMAND="${TMPSTICK}/${SPLITTEDFILE} BackgroundPolling -d ${USBDEVICE} -n ${NASTYPE} -f \"${FIRMWARE}\" -l"
    echo And execute...
    echo "${COMMAND} &"

    if [ "" != "${USELOGFILE}" ]; then
   cp -a ${SPLITTEDPATH}/${USELOGFILE} ${TMPSTICK}/${USELOGFILE}
   # Close logfile, maybe it will disturb the unmounting hereafter
        exec >/dev/null 2>&1
        sync
    fi
    cd /tmp
   
    ${COMMAND} &
    exit 1
}

# ==========================================================================
# function ReopenLogfile
# Arguments: device mountpoint copy/movecommand
# Mounts device on mountpoint, moves/copies current logfile to mountpoint
# and redirects output
# ==========================================================================
ReopenLogfile()
{
    if [ "" = "${USELOGFILE}" ] ; then
   return 0
    fi

    if ! [ -d $2 ]; then
        mkdir -p $2
    fi
    if ! mount $1 $2 ; then
   return 1
    fi
    $3 ${TMPSTICK}/${USELOGFILE} $2/${USELOGFILE}
    exec >>$2/${USELOGFILE} 2>&1
}

# ================================================
# function ProbeMountPoints
# Check all mountpoints for the existence of
# - usb_key_func.sh (this file) being the ffpstick
# - ffproot/after_booting.sh being the ffproot
# Outputs:
MP_FFPSTICK=""
MP_FFPROOT=""
#=================================================
ProbeMountPoints()
{
    echo Probe all mount points $1 seconds...

    mountpoints=`cat /proc/mounts | awk '{print $2}'`

    for mp in ${mountpoints}
    do
   # count number of / in string. We're only interested with 2 or more
   slashes=` echo ${mp} | tr -cd / `
   if [ ${#slashes} -gt 1 ]; then
       echo probe ${mp}...

       if [ "" != "${USELOGFILE}" ] && [ "" = "${MP_FFPSTICK}"  ] ; then
      if cat /proc/mounts | grep ${mp} | grep ${USBDEVICE}1 >/dev/null ; then
          MP_FFPSTICK=${mp}
          echo "found ffpstick on ${MP_FFPSTICK}, moving logfile"
          mv ${SPLITTEDPATH}/${USELOGFILE} ${MP_FFPSTICK}/${USELOGFILE}
          exec >>${MP_FFPSTICK}/${USELOGFILE} 2>&1
      fi
       fi

       if [ "" = "${MP_FFPROOT}" ] && [ -x ${mp}/ffproot/${AFTERBOOTING} ] ; then
      MP_FFPROOT=${mp}/ffproot
      echo found ffproot on ${MP_FFPROOT}
      local device=`cat /proc/mounts | grep ${mp} | awk '{print $1}'`
      if [ "${device}" = "${USBDEVICE}2" ] ; then
          # This is the USB stick. Try to remount it relatime
          if ! mount ${device} ${mp} -t ext3 -o remount,relatime 2>/dev/null ; then
         # or, if relatime is not supported, noatime
         mount ${device} ${mp} -t ext3 -o remount,noatime
          fi
      fi
       fi
   fi
    done


    if [ "" = "${MP_FFPROOT}" ]; then
        echo No /anymountpoint/ffproot/${AFTERBOOTING} found
        return 1
    fi

    return 0
}

# ===========================================
# function BackgroundPolling
# function waits until NAS is booted, and has
# mounted the stick partition, and then starts ffp
# ===========================================
BackgroundPolling()
{
    echo Wait for the stick to be mounted again by the firmware...
    sleep 30

    if [ -r ${SPLITTEDPATH}/${SPLITTEDFILE} ]; then
   rm ${SPLITTEDPATH}/${SPLITTEDFILE}
    fi
   
    local loopteller=0
    local waitforstick=0
    while [ 900 -gt ${loopteller} ]
    do
        ProbeMountPoints ${loopteller}
       
   if [ "" != "${MP_FFPROOT}" ] ; then
       if [ 3 -gt ${waitforstick} ] && [ "" = "${MP_FFPSTICK}" ] ; then
      waitforstick=`expr ${waitforstick} + 1`
       else
      cd ${MP_FFPROOT}
      # telnetd -l /bin/sh
      exec ${MP_FFPROOT}/${AFTERBOOTING} ${MP_FFPROOT} ${NASTYPE} "${FIRMWARE}"
           exit 0
           fi
   else
           if [ "" = "${MP_FFPSTICK}" ] ; then
      waitforstick=0
       else
          if [ 3 -eq ${waitforstick} ] ; then
              # Have a look if we can mount the 2nd partition ourselfs
          echo "30 seconds should be enough for anybody ;)"
          echo Will try to mount ffproot myself
          mkdir -p ${TMPROOT}
          mount ${USBDEVICE}2 ${TMPROOT}
          fi
          waitforstick=`expr ${waitforstick} + 1`
           fi
   fi
   loopteller=`expr ${loopteller} + 10`
   sleep 10
    done

    # Have a look if we can mount the 2nd partition ourselfs
    ReopenLogile ${USBDEVICE}1 ${TMPSTICK} mv
    echo Final attempt to mount the stick myself
    mkdir -p ${TMPROOT}
    if mount ${USBDEVICE}2 ${TMPROOT} ; then
   MP_FFPROOT=${TMPROOT}/ffproot
   if [ -x ${MP_FFPROOT}/${AFTERBOOTING} ] ; then
       cd ${MP_FFPROOT}
       exec ${MP_FFPROOT}/${AFTERBOOTING} ${MP_FFPROOT} ${NASTYPE} "${FIRMWARE}"
       exit 0
   fi

   echo FATAL No ${MP_FFPROOT}/${AFTERBOOTING} found
   exit 0
    fi
   
    echo FATAL Mounting failed
    echo "FATAL Timeout & Giving up"
    ReopenLogfile ${USBDEVICE}1 ${TMPSTICK} mv
    exit 0
}

# ================================================
# function FatalErrorInRepartitioning
# Is called when repartitioning failed.
# It will try to put the logfile back on the stick
# and collect more info
# ================================================
FatalErrorInRepartitioning()
{
    echo FATAL $1
   
    # Try to get the logfile back on the stick
    if ! ReopenLogfile ${USBDEVICE}1  ${PARNERKEY_MP} mv ; then
       ReopenLogfile ${USBDEVICE}  ${PARNERKEY_MP} mv
    fi
    for dmp in mounts filesystems partitions
    do
   echo =================
   echo cat /proc/${dmp}
   cat /proc/${dmp}
    done
    echo ================
    echo dmesg:
    dmesg
    exec >/dev/null 2>&1
    exit 1
}

TryToMount()
{
    echo -ne Mount $1 on $2...
    local counter=0
    mount $1 $2 -t $3
    while [ 0 -ne $? ];
    do
   echo
   counter=` expr ${counter} + 1 `
   if [ ${counter} -gt 5 ]; then
      FatalErrorInRepartitioning "Mount $1 on $2 failed"
   fi
   echo -ne Couldn\'t mount $1 on $2. Will retry in 5 seconds...
   sleep 5
   mount $1 $2 -t $3
    done
    echo done
}

Repartition()
{
    echo Repartition ${USBDEVICE}
    echo -ne unmount ${PARNERKEY_MP}...
    umount ${PARNERKEY_MP}
    echo done

    # Clear dmesg, just in case we get a fatal error.
    dmesg -c >/dev/null 2>&1

    echo Repartitioning...
    echo -e "o\nn\np\n1\n\n+16M\nn\np\n2\n\n\nt\n1\n4\nw\n" | fdisk ${USBDEVICE}
    if [ "0" != "$?" ]; then
        FatalErrorInRepartitioning "Partitioning failed"
    fi

    echo Done. Creating and mounting filesystems...

    echo Create ext3 filesystem on ${USBDEVICE}2 and mount...
    if ! mke2fs -L FFPROOT -j ${USBDEVICE}2 ; then
   FatalErrorInRepartitioning "Couldn\'t create ext3 fs on ${USBDEVICE}2"
    fi
    sync

    TryToMount ${USBDEVICE}2 ${PARNERKEY_MP} ext3

    echo -ne Move files...
    mkdir -p ${PARNERKEY_MP}/ffproot
    for file in ${EXT3FILES}
    do
   if [ -r ${TMPSTICK}/${file} ]; then
       echo -ne ${file}...
       mv ${TMPSTICK}/${file} ${PARNERKEY_MP}/ffproot/
   fi
    done
    chmod 700 ${PARNERKEY_MP}/ffproot/${AFTERBOOTING}
    echo done

    echo -ne Create dummy symlinks...
    cat >${PARNERKEY_MP}/.readme <<_EOF_
zyshd runs "rm \` find /mountpoint/of/stick -type l \`"
after mounting any external device.
This removes all symlinks from the device, rendering FFP useless.
The bunch of symlinks here are added to overflow the commandline,
making rm fail with an "Argument list too long"
instead of deleting all symlinks
_EOF_

    # Generate long name (128 characters)
    local counter=0
    longname=LongName
    while [ ${counter} -le 3 ] ; do
   longname=${longname}${longname}
   counter=` expr ${counter} + 1 `
    done
   
    # Generate 512 symlinks (total filename length = 64k)
    counter=0
    while [ ${counter} -le 512 ]
    do
   ln -s ".readme" ${PARNERKEY_MP}/.${counter}${longname}
   counter=` expr ${counter} + 1 `
    done
    echo done

    echo -ne Unmount ${USBDEVICE}2...
    umount ${PARNERKEY_MP}
    echo done

    echo -ne Create FAT filesystem on ${USBDEVICE}1 and mount...
    if ! mkdosfs -n FFPBOOT ${USBDEVICE}1 ; then
   FatalErrorInRepartitioning "Couldn\'t create vfat fs on ${USBDEVICE}1"
    fi
    sync

    TryToMount ${USBDEVICE}1 ${PARNERKEY_MP} vfat

    echo -ne Move files...
    for file in ${FATFILES}
    do
   if [ -r ${TMPSTICK}/${file} ]; then
       echo -ne ${file}...
       mv ${TMPSTICK}/${file} ${PARNERKEY_MP}/
   fi
    done
    echo -ne ${SPLITTEDFILE}...
    cp ${SPLITTEDPATH}/${SPLITTEDFILE} ${PARNERKEY_MP}/
    echo done

    if [ "" != "${USELOGFILE}" ]; then
   exec >/dev/null 2>&1
   mv ${TMPSTICK}/${USELOGFILE} ${PARNERKEY_MP}/${USELOGFILE}
        exec >>${PARNERKEY_MP}/${USELOGFILE} 2>&1
        sync
    fi

    exec ${PARNERKEY_MP}/${SPLITTEDFILE} FirstCall -l
}

OpenLogfile()
{
   if [ "" = "${LOGFILE}" ]; then
      return 0
   fi
   
   USELOGFILE=${LOGFILE}
   
   logfile=${SPLITTEDPATH}/${USELOGFILE}
   if [ "$1" = "extended" ] ; then
      templog=${SPLITTEDPATH}/templog.log
      exec >>${templog} 2>&1
      # Try to save older bootlogs
      echo Some logfile administration...
      oldlog=${logfile}.9.gz
      if [ -r ${oldlog} ] ; then
         echo rm ${oldlog}
         rm ${oldlog}
      fi
      for nr in 8 7 6 5 4 3 2 1
      do
         oldlog=${logfile}.${nr}.gz
         if [ -r ${oldlog} ] ; then
            newnr=`expr $nr + 1`
            newlog=${logfile}.${newnr}.gz
            echo mv ${oldlog} ${newlog}
            mv ${oldlog} ${newlog}
         fi
      done
      if [ -r ${logfile} ] ; then
         echo "cat ${logfile} | gzip -c >${oldlog}"
         cat ${logfile} | gzip -c >${oldlog}
         rm ${logfile}
      fi
      exec >/dev/null 2>&1
      mv ${templog} ${logfile}
   fi

   exec >>${logfile} 2>&1
}

PrintHelp()
{
    echo Usage: ${SPLITTEDFILE} command arguments
    echo "   command is one of:"
    echo "       FirstCall"
    echo "       Repartition"
    echo "       BackgroundPolling"
    echo "       Help"
    echo "   arguments:"
    echo "       -f <firmware>"
    echo "       -n <nastype>"
    echo "       -d <usbdevice>"
    echo "       -m <mountpoint> (normally /mnt/parnerkey)"
    echo "       -l redirect output to logfile"
    echo "       -ll shift logfiles and redirect output"
}

ReadParams()
{
    shift
    while [ "$1" != "" ] ; do
   case $1 in
       -f)
      FIRMWARE=$2
      shift
      ;;
       -n)
      NASTYPE=$2
      shift
      ;;
       -d)
      USBDEVICE=$2
      shift
      ;;
       -m)
      PARNERKEY_MP=$2
      shift
      ;;
       -h)
      PrintHelp
      ;;
       -l)
      OpenLogfile
      ;;
       -ll)
      OpenLogfile extended
      ;;
       *)
      echo Unknown option $1
      ;;
   esac
   shift
    done
}

# Entrypoint of the script
# Find filename and path
SplitPath $0
# Read the command
COMMAND=$1
# Read params
if [ $# -gt 1 ]; then
    ReadParams $@
fi

echo Script ${SPLITTEDFILE} version ${SCRIPTVERSION} running from ${SPLITTEDPATH}

case ${COMMAND} in
   FirstCall)
      FirstCall
      exit 1
      ;;
   Repartition)
      Repartition
      ;;
   BackgroundPolling)
      BackgroundPolling
      ;;
   Help)
      PrintHelp
      ;;
   NSA221Finish)
      umount /mnt/parnerkey
      rmdir /mnt/parnerkey
      if [ -x /tmp/NSA221Finish.sh ]; then
          exec /tmp/NSA221Finish.sh
      fi
      ;;
   *)
      PrintHelp
      ;;
esac


and after_booting.sh

  Code:
#!/bin/sh
# ============================================================================
#
# This file is part of the 'FFP-stick for ZyXEL NSA-nnn'
# http://zyxel.nas-central.org/wiki/FFP-stick
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Author: Mijzelf <Mijzelf@live.com>
#
# ============================================================================
#
# This script has multiple functions.
# - Download, unpack and start ffp
# - Stop ffp
# - Execute any function outside the ffp chroot
#
# It is supposed to be started by usb_key_func.sh/fun_plug.sh or by itself.
#
# Execute the script without params for a brief help

# ===========================================
# Options
# ===========================================
# Uncomment next line if you want a /ffp symlink
# FFPSYMLINK=1
#
# Uncomment next line if you don't want to chroot (you'll need the /ffp symlink too).
# NOCHROOT=1
# (The script will chroot anyway if the root is read only, or if you
# didn't enable the /ffp symlink
#
# Uncomment next line if you want the rootpassword changed, when not chrooting
# CHANGEROOTPASSWORD=1
# Edit the function ChangePasswords() to add your users/passwords/hashes
#
# ===========================================
# End of options
# ===========================================


SCRIPTVERSION="20110712"
FFPROOT=
NASTYPE=
FIRMWARE=
CHROOTDIR=

HELPERDIR=/tmp/.ffpstick/
HELPERFILE=helper.inc

# ===================================================
# function SplitPath
# split path in first parameter in path and filename
SPLITTEDPATH="" # Output path
SPLITTEDFILE="" # Output file
# environment: current directory changes
# ===================================================
SplitPath()
{
        SPLITTEDPATH=""
        SPLITTEDFILE=""
        IFSBACKUP=${IFS};   IFS=/                       
                   
        for chunk in $1; do
          newpath=""
                if [ "${SPLITTEDPATH}" = "" ] ; then
                  newpath="${chunk}"
                else       
                  newpath="${SPLITTEDPATH}/${chunk}"
                fi         
          if [ "${newpath}" = "$1" ] ; then
                  SPLITTEDFILE="${chunk}"
                elif [ "/${newpath}" = "$1" ] ; then
                  SPLITTEDPATH="/${SPLITTEDPATH}"
                  SPLITTEDFILE="${chunk}"
                else       
                  SPLITTEDPATH="${newpath}"
           fi         
        done                                           
   IFS=${IFSBACKUP}   
   if [ "" != "${SPLITTEDPATH}" ]; then
       cd ${SPLITTEDPATH}
   fi                 
   SPLITTEDPATH=` pwd `
}                           

# =============================================================
# function CleanUp
# Delete some unneeded (and possibly dangerous) DNS-323 scripts
# =============================================================
CleanUp()
{
    echo -ne Delete some DNS-323 specific stuff...
    for file in start/passwd.sh start/rcS.sh start/shells.sh sbin/store-passwd.sh
    do
   rm -f ffp/${file}
    done
    echo done
}

# =============================================================
# function Unpack_fun_plug
# Unpack fonz' base package
# 1st argument: filename
# =============================================================
Unpack_fun_plug()
{
    echo Unpack ${FFPROOT}/$1...
    cd ffp
    tar -xzf ../$1
    cd ..
    rm $1
    echo Done
    CleanUp
}

# =============================================================
# function CheckForFfpTarball
# Check for a user-provided ffp base package either in /path/to/ffproot
# or it's parent (the ext3 partition of the ffp-stick)
# =============================================================
CheckForFfpTarball()
{
    # find ffp tarball
    for file in fun_plug.tgz ../fun_plug.tgz
    do
   if [ -r ${file} ]; then
       Unpack_fun_plug ${file}
   fi
    done
}

# =============================================================
# function TryToDownload
# Downloads ffp base package from inreto.de
# =============================================================
TryToDownload()
{
    if ! [ -x wget ]; then
   echo No wget found
   return 0
    fi

    echo Will try to download fun_plug.tgz
    echo If the script stops here, downloading the tarball from inreto.de failed.
    echo You can try to get internet access for the ${NASTYPE},
    echo "or copy fun_plug.tgz (case sensitive!) to the share containing ffproot."
    echo It should be recognized and installed.
    echo It is possible that you have to reboot the box before this share shows up.
    echo ping www.inreto.de...
    while ! [ -r ffp/bin/busybox ] && ! ping -c 1 www.inreto.de >/dev/null ; do
   sleep 10
   CheckForFfpTarball
    done 

    if ! [ -r ffp/bin/busybox ]; then
   echo www.inreto.de found. Downloading fun_plug.tgz...
   cd ffp
   ../wget -qO- http://www.inreto.de/dns323/fun-plug/0.5/fun_plug.tgz | tar -xz
   if [ "$?" != "0" ] ; then
           echo Download failed.
   else
       echo fun_plug.tgz is downloaded
       CleanUp
   fi
       cd ..
    fi
   
    # Say hello to the author of this script. This doesn't do anything, (the file doesn't exist, so you'll get
    # a 404), except generating a logline on my webserver. (When it's online), Then I know that yet another
    # FFP-stick is created. I like that. ;)
    # If you want to opt-out, just remove the line below
    ./wget -qO- http://mijzelf.hopto.org/hello_author.php?nas=${NASTYPE}\&firmware=${FIRMWARE} >/dev/null 2>&1
    rm ./wget
}

#####################
# Function added 20101217 to solve the problem that the /i-data/md0
# symlink was not copied right on the NSA-320
#####################
CopySymlink()
{
    echo CopySymlink $1 $2
    target=` ls -l $1 | awk -F\  '{print $NF}' `   
    echo ln -s $target $2
    ln -s $target $2
}

# ===========================================================
# function CopyTree
# Helper function for the NSA3x0.
# ===========================================================
CopyTree()
{
    echo CopyTree $1 $2 $3
   
    if [ -h $2 ] ; then
   # Directory turns out to be a symlink. Just copy it
   CopySymlink $2 $3
   return 0
    fi
   
    mkdir $3
    if mountpoint $2 ; then
   # Directory is a mountpoint
   mount --bind $2 $3
   if [ "0" != "$?" ] ; then
       return 1
   fi
   return 0
    fi
   
    for file in ` ls $2 `
    do
   if [ -d $2/${file} ] ; then
   # File is a directory
       CopyTree $1 $2/${file} $3/${file}
       if [ "0" != "$?" ] ; then
           return 1
       fi
   #########################################
   # Added 2011-03-08; Changed 2011-03-23;
   # The NSA-320 has a symlink /etc/exports,
   # which points to a non-existing file
   # as long as the nfs packet is not installed.
   # This frustrated this copy script
   elif [ -h $2/${file} ] ; then
       # File is a symlink. Just copy it
       CopySymlink $2/${file} $3/${file}
   #########################################
   else
       case $1 in
      ln)
          ln $2/${file} $3/${file}
          ;;
      cp)
          cp -p $2/${file} $3/${file}
          ;;
       esac
       if [ "0" != "$?" ] ; then
      return 1
       fi
   fi
    done
    return 0
}
        
# ===================================================================
# function NSA320BindAll
# Helper function for the NSA320. Because the firmware directories cannot
# be bind-mounted on the FFP-stick directories, we'll inverse it.
# Basically the rootfs is doubled using hardlinks, and the 2nd copy is
# chrooted, with the FFP-stick bindmounted on /2ndcopy/ffp
# ===================================================================
NSA320BindAll()
{
    chdir=/tmp/bindroot
   
    mkdir ${chdir}
    for dir in bin sbin lib usr i-data e-data dev mnt
    do
   CopyTree ln /${dir} ${chdir}/${dir}
   if [ "0" != "$?" ]; then
       echo Failed to CopyTree /${dir}
       return 1
   fi
    done

    mkdir ${chdir}/tmp
    mount -t tmpfs tmfs ${chdir}/tmp
    if [ "0" != "$?" ]; then
   echo Failed to mount tmpfs on ${chdir}/tmp
        return 1
    fi

    echo ` date ` Waiting for fadd to show up...
    while ! ps | grep /sbin/fadd >/dev/null ; do
   sleep 10
    done
    echo ` date ` Hello fadd!

    CopyTree cp /etc ${chdir}/tmp/.etc
    if [ "0" != "$?" ]; then
   echo Failed to CopyTree /etc
        return 1
    fi

    # Because the files in /etc are bound to be changed by the firmware, we can't just make hardlinks to
    # it. We'll just hijack the map...
    mount --bind ${chdir}/tmp/.etc /etc
    if [ "0" != "$?" ]; then
   echo Failed to bind ${chdir}/tmp/.etc on /etc
        return 1
    fi
   
    ##################
    # Added 20101221 to solve the problem that the 'default' shares were not
    # exported, only the user made ones. The mount mtd4 on /etc/zyxel was lost.
    echo mount --bind ${chdir}/tmp/.etc/zyxel /etc/zyxel
    mount --bind ${chdir}/tmp/.etc/zyxel /etc/zyxel
    ##################
   
    ln -s ${FFPROOT}/ffp ${chdir}/ffp
    ln -s ${FFPROOT}/ffp/etc ${chdir}/etc
    ln -s ${FFPROOT}/after_booting.sh ${chdir}/after_booting.sh
   
    mount --bind ${chdir}/tmp/.etc ${chdir}${FFPROOT}/ffp/etc/original
    mount --bind ${chdir}/tmp/.etc/zyxel ${chdir}${FFPROOT}/ffp/etc/zyxel

    # We'll hijack /var/log to, for the same reason...
    ln -s ${FFPROOT}/var ${chdir}/var
    CopyTree cp /var/log ${chdir}/tmp/.log
    mount --bind ${chdir}/tmp/.log /var/log
    mount --bind ${chdir}/tmp/.log ${chdir}${FFPROOT}/var/log

    if ! [ -d ${chdir}/dev/pts ]; then
   mkdir ${chdir}/dev/pts
    fi

    mount -t devpts devpts ${chdir}/dev/pts
    mkdir ${chdir}/proc
    mount -t proc proc ${chdir}/proc
    mkdir ${chdir}/sys
    mount -t sysfs sys ${chdir}/sys

    mkdir ${chdir}/home
    mount --bind ${FFPROOT}/home ${chdir}/home

    # Restart Samba because it has gone mad about the etc exchange
    /etc/init.d/samba.sh restart

    CHROOTDIR=${chdir}
    return 0
}

# ========================================================
# function ClassicBindAll
# All firmware root directories are bind mounted on ffproot
# ========================================================
ClassicBindAll()
{
    # mount directories for chroot
    tomount="e-data i-data"
    for arg in rbind bind
    do
   for tm in ${tomount}
   do
       mount --${arg} /${tm} ${tm}
       if [ "$?" != "0" ] ; then
      return 1
       fi
   done
   tomount="dev var tmp bin sbin lib usr"
    done

    mount --bind /etc ffp/etc/original
    mount --bind /etc/zyxel ffp/etc/zyxel
    mount -t proc none proc
    mount -t sysfs none sys
    CHROOTDIR=${FFPROOT}
    return 0
}

# ================================================
# function FinalBindAll
# 'poor man's chroot'
# FFP is chrooted with hardly any connection to the firmware
# ================================================
FinalBindAll()
{
    CopyTree cp /dev ${FFPROOT}/dev
    if ! [ -d ${FFPROOT}/dev/pts ] ; then
        mkdir ${FFPROOT}/dev/pts
    fi
    mount -t devpts devpts ${FFPROOT}/dev/pts
    for dir in i-data e-data
    do
   mkdir ${FFPROOT}/${dir}
   CopyTree cp /${dir} ${FFPROOT}/${dir}
    done
    mount -t proc proc proc
    mount -t sysfs sys sys
    CHROOTDIR=${FFPROOT}
}

WriteParams()
{
    echo NASTYPE=${NASTYPE} >$1
    echo FIRMWARE=${FIRMWARE} >>$1
    echo FFPROOT=${FFPROOT} >>$1
    echo CHROOTDIR=${CHROOTDIR} >>$1
}

# ==========================================================
# function ChangePasswords()
# Changes the default password for root (the default is 'disabled')
# and adds users and password if you like
# ==========================================================
ChangePasswords()
{
    echo -ne Adding/changing passwords...
   
    # You can add your own users here:
    for name in user root
   
    do
        if ! cat /etc/passwd | grep ^${name} ; then
       # User doesn't exist yet, so add it
       adduser -G nobody -s /ffp/bin/sh ${name}
   fi
   # Delete password, so the shadow entry starts with name::
   passwd -d ${name}
   old=${name}::

   hash=""
   password=""
   # You can specify the password per user, or specify the hash value,
   # which is safer. Don't forget to escape your $
   case ${name} in
       user)
           password=user
           ;;
       root)
           # password=root
      hash=\$1\$\$oCLuEVgI1iAqOA8pwkzAg1
           ;;
       *)
      password=${name}
      ;;
   esac
         
   if [ "" = "${hash}" ]; then
       # If hash is empty, create it:
       tempfile=/tmp/$$` date +%s `.tmp
       makepwd ${password} | sed -e 's/\//\\\//g' >${tempfile}
       hash=` cat ${tempfile} `
            rm ${tempfile}
        fi
   
   new=${name}:${hash}:
        mv /etc/shadow /tmp/shadow.bak
        sed 's|'${old}'|'${new}'|' </tmp/shadow.bak >/etc/shadow
        rm /tmp/shadow.bak
    done
    echo done
}

# ===========================================
# function StartFFP()
# main function. Will download ffp if necessary
# create an environment for chrooting,
# chroot ffp
# ===========================================
StartFFP()
{
    # create rootdirectory
    if [ -r rootfs.tgz ]; then
   echo -ne Extract rootfs.tgz...
        tar -xzf rootfs.tgz
   rm rootfs.tgz
   echo Done
    fi

    CheckForFfpTarball
   
    if ! [ -r ffp/bin/busybox ] ; then
   TryToDownload
    fi

    if ! [ -r ffp/bin/busybox ] ; then
   echo Could not download fun_plug.tgz for some reason
   echo Will start polling for the existance forever in the share containing ffproot...
   while ! [ -r ffp/bin/busybox ]; do
       sleep 10
       CheckForFfpTarball
   done
    fi

    if [ "${FFPSYMLINK:-notset}" != "notset" ] ; then
   echo -ne Try to create a /ffp symlink...
   ln -s ${FFPROOT}/ffp /ffp
   if [ -x /ffp/bin/busybox ]; then
       echo done
   else
       echo "Failed. (Read only rootfs?)"
   fi
    fi
   
   
   
    if [ "${NOCHROOT:-notset}" != "notset" ] ; then
   if [ -x /ffp/bin/busybox ] ; then
       NOCHROOT=1   
       if [ "${CHANGEROOTPASSWORD:-notset}" != "notset" ] ; then
      ChangePasswords
       fi
   else
       echo Cannot answer to the 'nochroot' request. There is no /ffp symlink
       NOCHROOT=0
   fi
    else
   NOCHROOT=0
    fi

    if [ ${NOCHROOT} -eq 0 ] ; then
        ClassicBindAll
   if [ "$?" != "0" ]; then
           echo "Bummer! Cannot bind directories. Will try the NSA320 hack to get it going"
       NSA320BindAll
           if [ "$?" != "0" ]; then
      echo "The NSA320 hack doesn't work either. Will do the best I can to get it working"
      echo Possibilities are limited.
      FinalBindAll
       fi
   fi

        echo Will chroot ffp on ${CHROOTDIR}
    else
   CHROOTDIR=""
    fi
   
    # Generate helper file
    hf=${CHROOTDIR}${HELPERDIR}
    echo -ne Generate helper file ${hf}...
    mkdir -p ${hf}
    chmod 755 ${hf}
    WriteParams ${hf}${HELPERFILE}
    echo done

    if [ ${NOCHROOT} -eq 0 ] ; then
        # start helper
   echo Start execute_outside_chroot Helper...
   $0 InvokeHelper -c ${CHROOTDIR} &
   sleep 1
   echo done

   # Copy /i-data/md0 symlink to /mnt/HD_a2 to make the ZyXEL more compatible with the DNS-323
   if [ -h /i-data/md0 ] ; then
       CopySymlink /i-data/md0 ${CHROOTDIR}/mnt/HD_a2
   fi

        # run fun_plug local, if present
   if [ -x ${CHROOTDIR}/ffp/etc/fun_plug.local ]; then
       chroot ${CHROOTDIR} /ffp/etc/fun_plug.local
   fi
 
   # start services
   if [ -x ${CHROOTDIR}/ffp/etc/rc ]; then
       exec chroot ${CHROOTDIR} /ffp/etc/rc
   fi
    else
   # Copy /i-data/md0 symlink to /mnt/HD_a2 to make the ZyXEL more compatible with the DNS-323
   if [ -h /i-data/md0 ] ; then
       CopySymlink /i-data/md0 /mnt/HD_a2
   fi

        # run fun_plug local, if present
   if [ -x /ffp/etc/fun_plug.local ]; then
       /ffp/etc/fun_plug.local
   fi
 
   # start services
   if [ -x /ffp/etc/rc ]; then
       exec /ffp/etc/rc
   fi
    fi

    exit 0
}

# ============================================
# function StopFFP()
# terminates all ffp processes,
# unmounts all ffp mounts
# ============================================
StopFFP()
{
    if [ "${CHROOTDIR}" = "" ]; then
   if [ -x ${CHROOTDIR}/ffp/etc/rc ]; then
       echo /ffp/etc/rc stop
       /ffp/etc/rc stop
   fi
    else
        cd /
   # stop services
   if [ -x ${CHROOTDIR}/ffp/etc/rc ]; then
       echo /ffp/etc/rc stop
       chroot ${CHROOTDIR} /ffp/etc/rc stop
   fi
    fi
    sleep 1

    message="Try to kill all remaining chrooted processes"
    for killtype in SIGTERM SIGKILL
    do   
   # List of all programs pid
   tokill=` ps | awk '{print $1}' `
   for pf in $tokill
   do
       if [ -f /proc/$pf/maps ]; then
      if grep ${CHROOTDIR}/ffp/lib /proc/$pf/maps >/dev/null ; then                   
          # Program has some chrooted libraries loaded
          if [ "${message}" != "" ] ; then
         echo ${message} ; message=""
          fi
                   echo "      " ` cat /proc/$pf/cmdline `
                   kill -${killtype} $pf
           fi 
           fi         
   done               
        sleep 1
   message="Try a bit harder"
    done

    if [ "${CHROOTDIR}" = "" ] ; then
   exit 0
    fi

    echo Unmount all FFP mounts...
    tounmount=` cat /proc/mounts | grep ${CHROOTDIR} | awk '{print $2}' 2>/dev/null `
    while [ "${tounmount}" != "" ]; do
   # While loop because mounts are nested.
   for unmount in ${tounmount} ; do
       if umount $unmount 2>/dev/null ; then
           echo "      " $unmount
       fi 
   done       
   tounmount=` cat /proc/mounts | grep ${CHROOTDIR} | awk '{print $2}' 2>/dev/null `
    done
    echo done       
    exit 0
}

# ==================================================
# function InvokeHelper()
# Helperfunction to be able to run programs outside the chroot.
# It will sleep until it's woken up by a SIGCONT,
# then in will execute scripts in HELPERDIR
# ==================================================
InvokeHelper()
{
    hd=${FFPROOT}${HELPERDIR}
    hf=${hd}${HELPERFILE}

    mv ${hf} ${hf}.tmp
    cat ${hf}.tmp | grep -v HELPERPID >${hf}
    rm ${hf}.tmp

    if [ "$1" = "stop" ]; then
   exit 0
    fi

    echo HELPERPID=$$ >>${hf}
   
    while [ true ]; do
        trap "InvokeHelper stop" SIGTERM
   if [ ! -d ${hd} ] ; then
       trap "echo Helper terminated" SIGTERM
       exit 0
   fi
   
   local scripts=` ls ${hd} | grep helper | grep .sh `
   if [ "${scripts}" != "" ] ; then
       trap "echo Helper terminated" SIGTERM

       for script in ${scripts}
       do
      tmpfile=/tmp/$$` date +%s `
      mv ${hd}${script} ${tmpfile}
      chmod a+x ${tmpfile}
      ${tmpfile}
          rm ${tmpfile}
       done
   else
       kill -SIGSTOP $$
   fi
    done
}

PrintHelp()
{
    echo Usage: $0 command arguments
    echo "   command is one of:"
    echo "       StartFFP"
    echo "       StopFFP"
    echo "       InvokeHelper"
    echo "       Help"
    echo "   arguments:"
    echo "       -f firmware"
    echo "       -n nastype"
    echo "       -r ffproot"
    echo "       -c chrootdir"
}

ReadParams()
{
    shift
    while [ "$1" != "" ] ; do
   case $1 in
       -f)
      FIRMWARE=$2
      shift
      ;;
       -n)
      NASTYPE=$2
      shift
      ;;
       -h)
      PrintHelp
      shift
      ;;
       -r)
      FFPROOT=$2
      shift
      ;;
       -c)
      CHROOTDIR=$2
      shift
      ;;
       *)
      echo Unknown option $1
      ;;
   esac
   shift
    done

    if [ "" = "${CHROOTDIR}" ]; then
   CHROOTDIR=${FFPROOT}
    fi

    hf=${CHROOTDIR}${HELPERDIR}${HELPERFILE}
    if [ -r ${hf}  ]; then
        . ${hf}
    fi
}

# ================================================
# Entrypoint of the script
# ================================================
echo Starting $0 version ${SCRIPTVERSION} at ` date `...
SplitPath $0
FFPROOT=${SPLITTEDPATH}

if [ $# -eq 0 ]; then
    PrintHelp
    exit 0
fi

case $1 in
   StartFFP)
      ReadParams $@
      StartFFP
      ;;
   StopFFP)
      ReadParams $@
      StopFFP
      ;;
   InvokeHelper)
      ReadParams $@
      InvokeHelper
      ;;
   Test)
      ReadParams $@
      tmpfile=/tmp/` date +%s%N `
      WriteParams ${tmpfile}
      cat ${tmpfile}
      rm ${tmpfile}
      ;;
   *)
      if [ $# -eq 3 ]; then   
         # Assume this is an 'old style' call
         FFPROOT=$1
         NASTYPE=$2
         FIRMWARE=$3
         StartFFP
      else
         PrintHelp
      fi
      ;;
esac


How do I modify it based on tihob's fun_plug.debian ?
  Code:
#!/bin/sh
# Root DISK1
export DISK1=/mnt/HD/HD_a2
export DISTDIR=tsqueeze

cd $DISK1

mount --bind $DISK1 $DISTDIR$DISK1
mount --bind / $DISTDIR/mnt/root
mount --bind /dev $DISTDIR/dev
mount --bind /sys  $DISTDIR/sys
mount --bind /proc $DISTDIR/proc

cp -f /proc/mounts $DISTDIR/etc/mtab
rm -f $DISTDIR/etc/fstab
touch $DISTDIR/etc/fstab
cp -f /etc/resolv.conf $DISTDIR/etc
hostname >$DISTDIR/etc/hostname
cp -f /etc/hosts $DISTDIR/etc
$DISK1/$DISTDIR/boot/chroot $DISK1/$DISTDIR /boot/linuxrc


Any help is greatly appreciated ...
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Mon Dec 12, 2011 2:42 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

tihob wrote:Hi,
I'll try to help since I have already some experience on how to install "serviio" on processors ARM5 :geek:

First, have you root access ?
if Yes, Zip is right, the first things to do, is to check if java is installed, or if you can install it.
if not, find a way to become root :?

I don't know this linux version is a debian ? Do you have aptitude ?
What is your knowledge of Linux environments ?


After trying the FFP route, I got stuck with modifying the FFP stick to run debian squeeze. (tihob any pointers ?)

I contacted Zyxel about installing other packages and they came up with the following guide. Can anyone help make sense of what I need to do ?

Thanks again in advance ...
Attachments
ZyXEL_User_Made_package_installation_guide.pdf
(143.5 KiB) Downloaded 1379 times
<<

Dangerousp

Serviio newbie

Posts: 7

Joined: Tue Nov 29, 2011 8:22 pm

Post Mon Dec 12, 2011 5:56 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

the link ftp://opensource.zyxel.com/NSA-220%20PL ... kit.tar.gz is not working, I did find it over here: ftp://opensource.zyxel.com/NSA-220%20PL ... kit.tar.gz it's really slow though, but I will try the manual after that.
<<

tihob

Streaming enthusiast

Posts: 38

Joined: Tue Feb 08, 2011 8:30 pm

Location: France

Post Sat Dec 17, 2011 3:00 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Have you tried thhat : http://zyxel.nas-central.org/wiki/Debia ... d_to_flash
It's for NSA-220, but does it work with your nas ?
It will be easier than changing the ffp script...
<<

Dangerousp

Serviio newbie

Posts: 7

Joined: Tue Nov 29, 2011 8:22 pm

Post Wed Jan 04, 2012 8:36 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

I can't get it to extract.. when I reboot, nothing happens.
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Sat Jan 07, 2012 7:08 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Dangerousp wrote:I can't get it to extract.. when I reboot, nothing happens.


maybe the latest firmware does not support it ?

dangerousp : did you try the montevista toolkit ?
<<

marght

Serviio newbie

Posts: 1

Joined: Thu Jun 07, 2012 7:28 am

Post Thu Jun 07, 2012 7:39 am

Re: How do I install Serviio on a Zyxel NSA-310 ?

Hi.

I suggest to try this: http://openrouter.info/forum/viewtopic. ... 790#p15790

It works perfectly, but topic is in polish. I use is for 1 month without any problems.

First, you have to upgrade your NSA310 firmware to v. 4.40, next get 2 files: nsa310-ali.zip from http://www.2shared.com/file/fEXqAAxM/nsa310-ali.html and linux.tgz from http://www.2shared.com/file/sIHKCw8M/linux.html.
First file has to be extracted to flashdrive (with FAT filesystem !!!), then and copy second file to flashdrive as it is.
Reboot nas with flashdrive installed, after several minutes nas will turn off. Remove flashdrive and turn it on.
Debian will start with sshd, ip address from DHCP, user/pass: root/root
<<

harpoon

Serviio newbie

Posts: 17

Joined: Mon Nov 28, 2011 10:30 pm

Post Thu Jul 05, 2012 10:19 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

marght wrote:Hi.

I suggest to try this: http://openrouter.info/forum/viewtopic. ... 790#p15790

It works perfectly, but topic is in polish. I use is for 1 month without any problems.

First, you have to upgrade your NSA310 firmware to v. 4.40, next get 2 files: nsa310-ali.zip from http://www.2shared.com/file/fEXqAAxM/nsa310-ali.html and linux.tgz from http://www.2shared.com/file/sIHKCw8M/linux.html.
First file has to be extracted to flashdrive (with FAT filesystem !!!), then and copy second file to flashdrive as it is.
Reboot nas with flashdrive installed, after several minutes nas will turn off. Remove flashdrive and turn it on.
Debian will start with sshd, ip address from DHCP, user/pass: root/root


Hi Marght,

The linux.tgz cannot be found. can you upload it somewhere else ?

Do you have serviio installed on a NSA-310 ?

Thanks.
<<

antl

Serviio newbie

Posts: 15

Joined: Tue May 29, 2012 7:02 pm

Post Sun Dec 16, 2012 12:52 pm

Re: How do I install Serviio on a Zyxel NSA-310 ?

Any one get this working?
Previous

Return to NAS installation

Who is online

Users browsing this forum: No registered users and 8 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.