NAS326, auto execute command at startup

Hi all,
I would like my NAS326 to execute some (simple) commands at startup, but I would prefere to keep NAS' software untouched; in other words, I would prefere not to install Tweaks/Random Tools. "Since those packages exist, the standard f/w already provides a way to execute something at startup", I guess. Assuming I'm right: which is the "magic file" (...or the "magic trick") to get the job done...?
Thank you in advance for your help!
Regards

Accepted Solution

  • Mijzelf
    Mijzelf Posts: 2,598  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Answer ✓
    The magic trick used by Tweaks and RandomTools is that they are zypgs, installed in the normal way (apart from the MetaRepository injector), and so they are started regularly by the firmware package manager.

    Fortunately for you there is another way. The packages are started by /etc/init.d/zypkg_controller.sh, and this script contains this snippet:

    [code]
    ZYPKG_PKG_SRC_PATH="/i-data/.system/zy-pkgs"
    <snip>
    USRPKG_DEPS_START="${ZYPKG_PKG_SRC_PATH}/USRPKG_DEPS_START"
    <snip>
    case "$1" in
    "start" )

    <snip>
        # - start to startup packages according to ${USRPKG_DEPS_START}
        while read zypkg; do
            bname=`basename ${zypkg}`
            zypkg=${ZYPKG_PKG_SRC_PATH}/${bname}
            Processed_Packages=${Processed_Packages}:${bname}
            write_log "- starting package \"${bname}\" ..."
            #ckeck ZYPKG_DEPS format
            CHKVERSION=`grep "/i-data/" ${zypkg}`
            if [ "$?" != "0" ]; then
                PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
                zypkg=${PKGVOLPATH}/etc/init.d/${bname}
            fi
            if [ ! -x ${zypkg} ]; then
                write_log "---> Error: start-up program \"${zypkg}\" is not existed or not excutable"
            else
                ${zypkg} startup
                if [ "$?" == "0" ]; then
                    write_log "---> start \"${bname}\" successfully."
                else
                    write_log "---> start \"${bname}\" failed."
                fi
            fi
        done < ${USRPKG_DEPS_START}
    [/code]

    So basically it reads the file /i-data/.system/zy-pkgs/USRPKG_DEPS_START line by line, each line is considered to be a filename, the directory is stripped, and /i-data/.system/zy-pkgs/ put in front. If the resulting filename is executable, it is executed with 'startup' as argument.

    So create an executable script in /i-data/.system/zy-pkgs/, and put it's name in /i-data/.system/zy-pkgs/USRPKG_DEPS_START (which doesn't exist by default).

    You can also use /i-data/.system/zy-pkgs/USRPKG_DEPS_SHUTDOWN to shutdown your stuff cleanly on nas shutdown.

All Replies

  • Mijzelf
    Mijzelf Posts: 2,598  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Answer ✓
    The magic trick used by Tweaks and RandomTools is that they are zypgs, installed in the normal way (apart from the MetaRepository injector), and so they are started regularly by the firmware package manager.

    Fortunately for you there is another way. The packages are started by /etc/init.d/zypkg_controller.sh, and this script contains this snippet:

    [code]
    ZYPKG_PKG_SRC_PATH="/i-data/.system/zy-pkgs"
    <snip>
    USRPKG_DEPS_START="${ZYPKG_PKG_SRC_PATH}/USRPKG_DEPS_START"
    <snip>
    case "$1" in
    "start" )

    <snip>
        # - start to startup packages according to ${USRPKG_DEPS_START}
        while read zypkg; do
            bname=`basename ${zypkg}`
            zypkg=${ZYPKG_PKG_SRC_PATH}/${bname}
            Processed_Packages=${Processed_Packages}:${bname}
            write_log "- starting package \"${bname}\" ..."
            #ckeck ZYPKG_DEPS format
            CHKVERSION=`grep "/i-data/" ${zypkg}`
            if [ "$?" != "0" ]; then
                PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
                zypkg=${PKGVOLPATH}/etc/init.d/${bname}
            fi
            if [ ! -x ${zypkg} ]; then
                write_log "---> Error: start-up program \"${zypkg}\" is not existed or not excutable"
            else
                ${zypkg} startup
                if [ "$?" == "0" ]; then
                    write_log "---> start \"${bname}\" successfully."
                else
                    write_log "---> start \"${bname}\" failed."
                fi
            fi
        done < ${USRPKG_DEPS_START}
    [/code]

    So basically it reads the file /i-data/.system/zy-pkgs/USRPKG_DEPS_START line by line, each line is considered to be a filename, the directory is stripped, and /i-data/.system/zy-pkgs/ put in front. If the resulting filename is executable, it is executed with 'startup' as argument.

    So create an executable script in /i-data/.system/zy-pkgs/, and put it's name in /i-data/.system/zy-pkgs/USRPKG_DEPS_START (which doesn't exist by default).

    You can also use /i-data/.system/zy-pkgs/USRPKG_DEPS_SHUTDOWN to shutdown your stuff cleanly on nas shutdown.

  • P13r0
    P13r0 Posts: 3
    Thank you so much! :)
    I'll try, and let you know the result

    Regards
  • P13r0
    P13r0 Posts: 3
    ...It works, thank you again!

    Just a note, for non expert users (...like me):

    [code]

    #ckeck ZYPKG_DEPS format
            CHKVERSION=`grep "/i-data/" ${zypkg}`
            if [ "$?" != "0" ]; then
                PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
                zypkg=${PKGVOLPATH}/etc/init.d/${bname}

    [/code]


    The executable file (i.e. /i-data/.system/zy-pkgs/your_script.sh) MUST contain the string "/i-data/", otherwise the NAS will try to execute a file (tipically /etc/init.d/your_script.sh)... that doesn't exist.
    A simple remark (something like: # /i-data/) is OK too.

    Regards

Consumer Product Help Center