Script Converting

Discussion in 'Tomato Firmware' started by Dark_Shadow, Jun 13, 2012.

  1. Dark_Shadow

    Dark_Shadow LI Guru Member

    I know enough about linux to make me dangerous, I can figure out a few things here and there, so I thought I would throw this out and get others perspectives.

    Router = Asus RT-N66U
    Firmware = Shibby 94.1 AIO test build
    External Storage = 2GB MicroSD card in onboard slot.

    I am using the backup settings script by Austin Saint Aubin

    The following script was written by frater for DD-WRT. I would like to convert any DD_WRT specific code to Tomato. It will reside in /opt/etc/config (Which opt is mounted already to a dir on the sd card) so as to get run on reboot. Now obviously I am going to have to change the location of the backup files.

    Note: Even though I have the /opt folder mounted, I do not have opt installed.

    Working Code

    wl0_ssid=`nvram get wl0_ssid`
    lan_ipaddr=`nvram get lan_ipaddr`
    if [ ! -f "${restflag}" ] && [ "${lan_ipaddr}" = '' ] && [ "${wl0_ssid}" = 'Tomato24' ] ; then
      logger $NAME "Detected a firmware reset"
      lastbackup="`ls -1t /tmp/mnt/MSD2GB/Tomato/Backups/lastbackup_*.sh | head -n1`"
      touch "${restflag}"
      if [ -z "${lastbackup}" ] ; then
        logger $NAME "Unable to find a backup, will restore some handpicked settings"
          nvram set "dhcpd_endip="
          nvram commit
        logger $NAME "Restore settings using ${lastbackup}"
      logger $NAME "Reboot"
      rm -f "${restflag}" 2>/dev/null
      logger " has nothing to do"
    I also added lines to Austins script to also place a copy of the filtered nvram file in the root of the backup dir.

        backThisUp "NVRam Full List (Quote Filtered)" nvram quote "/tmp//mnt/MSD2GB/Tomato/Backups" "lastbackup" sh $NumOfBackupsToKeep "NC|clkfreq|ddnsx|dhcpd|dnsmasq_|ftp|http|lan_hostname|lan_ipaddr|lan_netmask|lan_proto|log|ntp|portforward|ppp|qos|rstats|sch|script|sesx|smbd|snmp|sshd|telnetd|tm|usb|vpn_server_|vpn_server1|wan_dns|wan_hostname|wan_proto|web|wl0_|wl1_" "Remove-NOTHING"
        chmod 755 /tmp//mnt/MSD2GB/Tomato/Backups/*.sh
  2. mstombs

    mstombs Network Guru Member

    Haven't tried this, but by inspection:-

    Tomato versions I know don't have "readlink", but I'm sure you can just manually set NAME and/or CUR_DIR to the fixed location you use (note factconfig is replaced by the command used to run the script)

    Not sure about wl_ssid, I think the primary ssid is wl0_ssid - is the default "wireless"?

    Replace "optlog" with "logger"
  3. Dark_Shadow

    Dark_Shadow LI Guru Member

    So, remove the line [ -h "${NAME}" ] && NAME="`readlink "${NAME}"`" and set CUR_DIR="`path of factconfig script"`" ?

    If i wanted to type "sh" then "NAME=factdefault,sh"?
  4. Dark_Shadow

    Dark_Shadow LI Guru Member

    Ok this is what I got and it appears to do nothing, I first had CUR_DIR="`/mnt/MSD2GB/Scripts"`" but got line 4 permission denied so I changed it to line 4 below. Nothing in the syslog ether.

    See first post for current codeset
    EDIT: ok I added logger " has nothing to do" after rm -f "${restflag}" 2>/dev/null and it showed Jun 14 22:25:18 RT-N66U user.notice root: has nothing to do. So thus far seems to be working. Now to tweak a bit further.
  5. mstombs

    mstombs Network Guru Member

    I try not to use the back-tick `do it` to execute commands because it is difficult to read/ differentiate from strong quotes 'do it', $(do it) seems easier, but then on BusyBox ash at least you do not need the curly brackets in ${lan_ipaddr}, $lan_ipaddr works just as well (there are some constructs that do need the {}). You are still looking for a default ssid of 'dd-wrt'.

    For script testing from console I should have advised "logger -s" which outputs messages to the console as well as into the message log.
  6. Dark_Shadow

    Dark_Shadow LI Guru Member

    I have updated the first post to reflect my current code. So should I remove all the back-tick's and curly brackets? I have found that shibby's default for wl0_ssid is Tomato24. I have also added the -s to logger so I don't have to keep opening the syslog.
  7. mstombs

    mstombs Network Guru Member

    if it works leave it, there are may ways to peel the tomato!
  8. Dark_Shadow

    Dark_Shadow LI Guru Member

    It works as soon as USB and SD are enabled, I have a request into shibby to enable them by default and I need to tweak the line of Austin's script that filters the settings.

    Code in fist post is updated, should I change the title of the thread to something more relevant?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice