Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- VER="v01.05"
- #======================================================================================================= © 2016-2017 Martineau, v01.05
- #
- # Refresh custom /www i.e. adding custom TAB (such as Kvic's NTP Daemon) to say Tools Menu in the GUI
- #
- # Each time a NEW firmware is installed, then this script should be run (in case there are any undisclosed GUI tweaks by ASUS or RMerlin! ;-)
- #
- # NOTE: In say '/jffs/scripts/post-mount' you could automate the process.
- #
- # e.g. /jffs/scripts/post-mount
- #
- # Check if the firmware has changed, if so, we need to refresh '/www' just in case there are any subtle (undisclosed) tweaks by Asus or RMerlin!
- # FIRMWARE=$(nvram get buildno | awk 'BEGIN { FS = "." } {print $1$2}')
- # if [ -f "/tmp/mnt/$MYROUTER/Firmware_ver.txt" ];then
- # FIRMWARE_PREV=$(cat /tmp/mnt/$MYROUTER/Firmware_ver.txt)
- # else
- # FIRMWARE_PREV="N/A"
- # fi
- #
- # if [ "$FIRMWARE" != "$FIRMWARE_PREV" ];then
- # logger -st "($(basename $0))" $$ "Firmware v'"$FIRMWARE"' changed from previous v'"$FIRMWARE_PREV"'; requesting 'RefreshWWW.sh'....."
- # /jffs/scripts/RefreshWWW.sh
- # echo $FIRMWARE >/tmp/mnt/$MYROUTER/Firmware_ver.txt # Update/create the Firmware tracking file on USB
- # else
- # logger -st "($(basename $0))" $$ "Mounting '/www'
- # 'NTP Daemon' on Tools TAB"
- # mount -a # NTP Daemon - mounts /opt/var/www to /www (see cp /jffs/configs/fstab /etc)
- # service restart_httpd # NTP Daemon new tab added to tools page ? etc.
- # fi
- # Print between line beginning with'#==' to first blank line inclusive
- ShowHelp() {
- awk '/^#==/{f=1} f{print; if (!NF) exit}' $0
- }
- ANSIColours () {
- cRESET="\e[0m";cBLA="\e[30m";cRED="\e[31m";cGRE="\e[32m";cYEL="\e[33m";cBLU="\e[34m";cMAG="\e[35m";cCYA="\e[36m";cGRA="\e[37m"
- cBGRA="\e[90m";cBRED="\e[91m";cBGRE="\e[92m";cBYEL="\e[93m";cBBLU="\e[94m";cBMAG="\e[95m";cBCYA="\e[96m";cBWHT="\e[97m"
- aBOLD="\e[1m";aDIM="\e[2m";aUNDER="\e[4m";aBLINK="\e[5m";aREVERSE="\e[7m"
- cRED_="\e[41m";cGRE_="\e[42m"
- }
- # For >380.68 customisiation has now changed:
- # /www/require/modules/menuTree.js
- #==============================================Main==================================================================================
- ANSIColours
- if [ "$1" = "-h" ] || [ "$1" = "help" ]; then
- echo -en $cBWHT
- ShowHelp # Show help
- echo -e $cRESET
- exit 0
- fi
- logger -st "($(basename $0))" $$ $VER "© 2016-2017 Martineau, Refresh '/www' requested....."
- # Stop the active HTTPD
- echo -e $cBCYA"\n\tStopping HTTPD....."$cBGRE
- service stop_httpd
- echo -e $cBRED
- umount /www
- # Ensure the old copy of /www is deleted
- echo -e $cBCYA"\tErasing '/opt/var/www* .....\n"$cBRED
- rm -rf /opt/var/www
- #rmdir /opt/var/www
- if [ -d /opt/var/www ];then
- echo -e "\a\n"$cRED_"\t***Cannot delete directory '/opt/var/www'"$cRESET
- echo -e $cBCYA"\n\tRestarting HTTPD"$cBGRE
- service restart_httpd
- echo -e $cRESET
- exit 97
- fi
- # Clone HTTP to /www
- echo -e $cBCYA"\tCloning '/www' to '/opt/var/www' may take upto 30 secs.....\n"$cBMAG
- sleep 10
- start=`date +%s`
- tar cf - /www | tar -C /opt/var -xvf - 2> /dev/null
- end=`date +%s`
- difftime=$((end-start))
- echo -e $cBYEL"\n\tCloning '/www' to '/opt/var/www' took $(($difftime % 60)) seconds\n"
- # Reload /www and use it!
- echo -e $cBCYA"\tMounting /www"$cBRED
- mount -a
- if [ -z "$(df | grep "/www")" ];then
- df
- logger -t "($(basename $0))" $$ "Warning /www not mounted?"
- echo -e $cRED_"\a\n\t**Warning /www not mounted?"$cRESET
- fi
- if [ -f /opt/var/spool/ntp/Tools_NtpdStats.asp ];then
- # Customise the Tools TAB
- echo -e $cBCYA"\n\tCustomising Kvic NTPD Tools TAB.....\n"$cBRED
- cp /opt/var/spool/ntp/Tools_NtpdStats.asp /www
- # v380.68 redesigned the menu structure
- FIRMWARE=`echo $(nvram get buildno) | awk 'BEGIN { FS = "." } {print $1$2}'`
- if [ $FIRMWARE -lt 38068 ];then
- FN="/www/state.js"
- sed -i 's/Other Settings");/Other Settings", "NTP Daemon");/' $FN
- sed -i 's/therSettings.asp");/therSettings.asp", "Tools_NtpdStats.asp");/' $FN
- else
- FN="/www/require/modules/menuTree.js"
- # {
- # menuName: "Tools",
- # index: "menu_Tools",
- # tab: [
- # {url: "Tools_Sysinfo.asp", tabName: "Sysinfo"},
- # {url: "Tools_OtherSettings.asp", tabName: "Other Settings"},
- # {url: "Tools_NtpdStats.asp", tabName: "NTP Daemon"}, <<== insert this line
- # {url: "NULL", tabName: "__INHERIT__"}
- # ]
- # },
- sed -i '/"Tools_OtherSettings.asp", tabName: "Other Settings"/a {url: "Tools_NtpdStats.asp", tabName: "NTP Daemon"},' $FN
- fi
- logger -t "($(basename $0))" $$ "NTP Daemon TAB added '"$FN"'....."
- echo -e $cBMAG"\t\tNTP Daemon TAB added '"$FN"'.....\n"$cBRED
- else
- logger -t "($(basename $0))" $$ "Refresh skipped - Kvic mod '/opt/var/spool/ntp/Tools_NtpdStats.asp' not found?"
- echo -e $cRED_"\n\tRefresh skipped - Kvic mod '/opt/var/spool/ntp/Tools_NtpdStats.asp' not found?"$cRESET
- umount /www
- fi
- echo -e $cBCYA"\n\tRestarting HTTPD"$cBGRE
- service restart_httpd
- echo -e $cRESET
- logger -st "($(basename $0))" $$ "Refresh '/www' request complete."
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement