1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Restore Script

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

  1. Dark_Shadow

    Dark_Shadow Addicted to LI Member

    As stated before I only know enough about Linux to make me dangerous and did not write this script. Original credit goes to frater.

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

    I am using the backup settings script by Austin Saint Aubin
    Also using the Tutorial by ray123 Make syslog go to a disk or another computer

    If your not worried about logging then the ray's script is not needed and the sleep line can be removed.

    Also, I think 60 might be a little extreme of a sleep time, I will play around with it later to see exactly what is needed.

    Working Code:
    filename: 75-factdefault.autorun (placed in root dir of sd card)

    Code:
    #!/bin/sh
    NAME=factdefault.sh
    CUR_DIR="/mnt/DRIVENAME"
    restflag="${CUR_DIR}/just_restored"
     
    wl0_ssid=`nvram get wl0_ssid`
    lan_ipaddr=`nvram get lan_ipaddr`
     
    if [ ! -f "${restflag}" ] && [ "${lan_ipaddr}" = '192.168.1.1' ] && [ "${wl0_ssid}" = 'Tomato24' ] ; then
      sleep 60
      logger -s -t $NAME "Detected a firmware reset"
      lastbackup="`ls -1t /tmp/mnt/DRIVE/PATH/TO/lastbackup_*.sh | head -n1`"
      touch "${restflag}"
     
      if [ -z "${lastbackup}" ] ; then
        logger -s -t $NAME "Unable to find a backup, will restore some handpicked settings"
        nvram set "nvramvar=nvramsetting"
        nvram commit
      else
        logger -s -t $NAME "Restore settings using ${lastbackup}"
        ${lastbackup}
      fi
      logger -s -t $NAME "Reboot"
      reboot
    else
      rm -f "${restflag}" 2>/dev/null
    fi
    At this point, I know it works when external storage is enabled or you use shibby's 95 AIO or higher, which has USB and SD function enabled by default.

    <s>The problem I am having is no logging is recorded.</s> No longer a problem

    for reference here is fraters script untouch that works flawlessly in DD-WRT
    Code:
    #!/bin/sh
    NAME=factconfig
    NAME="$0"
    [ -h "${NAME}" ] && NAME="`readlink "${NAME}"`"
    CUR_DIR="`dirname "${NAME}"`"
    restflag="${CUR_DIR}/just_restored"
     
    wl_ssid=`nvram get wl_ssid`
    lan_ipaddr=`nvram get lan_ipaddr`
     
    if [ ! -f "${restflag}" ] && [ "${lan_ipaddr}" = '192.168.1.1' ] && [ "${wl_ssid}" = 'dd-wrt' ] ; then
      optlog $NAME "Detected a firmware reset"
      lastbackup="`ls -1t /opt/var/backups/*.essential.sh | head -n1`"
      touch "${restflag}"
     
      if [ -z "${lastbackup}" ] ; then
        optlog $NAME "Unable to find a backup, will restore some handpicked settings"
        nvram set "nvramvar=nvramsetting"
     
        nvram commit
      else
        optlog $NAME "Restore settings using ${lastbackup}"
        ${lastbackup}
      fi
      optlog $NAME "Reboot"
      reboot
    else
      rm -f "${restflag}" 2>/dev/null
    fi
    DS
     
  2. Dark_Shadow

    Dark_Shadow Addicted to LI Member

    Does the syslog survive a reboot?
     
  3. Dark_Shadow

    Dark_Shadow Addicted to LI Member

    Ok,I have been through the logger man page, nothing helps. Am i asking such a stupid question that I should know the answer and am just overlooking it?
     
  4. mstombs

    mstombs Network Guru Member

  5. Dark_Shadow

    Dark_Shadow Addicted to LI Member

    Did the tutorial, Now i was seeing that it created a separate log file for 1970-01-01-0100 but wasn't being populated. So i placed a "sleep 60" in the script and began moving it around until it gave enough time to log. will update first post.
     

Share This Page