44#
55# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7- # Last Modified: 2024-Dec-28
7+ # Last Modified: 2024-Jan-01
88# ##################################################################
99set -u
1010
@@ -37,8 +37,13 @@ readonly CL_URL_3006="${FW_SFURL_BASE}/Documentation/Changelog-3006.txt/download
3737
3838readonly high_risk_terms=" factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended"
3939
40+ # #----------------------------------------##
41+ # # Modified by Martinski W. [2024-Dec-31] ##
42+ # #----------------------------------------##
4043# For new script version updates from source repository #
4144DLRepoVersion=" "
45+ DLRepoVersionNum=" "
46+ ScriptVersionNum=" "
4247scriptUpdateNotify=0
4348
4449# #------------------------------------------##
@@ -475,9 +480,9 @@ Toggle_LEDs_PID=""
475480FW_UpdateCheckState=" TBD"
476481FW_UpdateCheckScript=" /usr/sbin/webs_update.sh"
477482
478- # #-------------------------------------- ##
479- # # Added by Martinski W. [22023 -Nov-24] ##
480- # #-------------------------------------- ##
483+ # #-------------------------------------##
484+ # # Added by Martinski W. [2023 -Nov-24] ##
485+ # #-------------------------------------##
481486# ---------------------------------------------------------#
482487# The USB-attached drives can have multiple partitions
483488# with different file systems (NTFS, ext3, ext4, etc.),
@@ -1834,59 +1839,104 @@ _Config_FromSettings_(){
18341839 return 0
18351840}
18361841
1837- # #------------------------------------------##
1838- # # Modified by ExtremeFiretop [2024-Dec-21] ##
1839- # #------------------------------------------##
1842+ # #-------------------------------------##
1843+ # # Added by Martinski W. [2024-Dec-31] ##
1844+ # #-------------------------------------##
1845+ newGUIversionNum=" $( _ScriptVersionStrToNum_ ' 1.4.0' ) "
1846+ # Temporary code used to migrate to future new script version #
1847+ _CheckForNewGUIVersionUpdate_ ()
1848+ {
1849+ local retCode theScriptVerNum urlScriptVerNum
1850+ if [ $# -lt 2 ] || [ -z " $1 " ] || [ -z " $2 " ]
1851+ then
1852+ theScriptVerNum=" $ScriptVersionNum "
1853+ urlScriptVerNum=" $DLRepoVersionNum "
1854+ else
1855+ theScriptVerNum=" $( _ScriptVersionStrToNum_ " $1 " ) "
1856+ urlScriptVerNum=" $( _ScriptVersionStrToNum_ " $2 " ) "
1857+ fi
1858+ if [ " $theScriptVerNum " -lt " $newGUIversionNum " ] && \
1859+ [ " $urlScriptVerNum " -ge " $newGUIversionNum " ]
1860+ then retCode=0
1861+ else retCode=1
1862+ fi
1863+ return " $retCode "
1864+ }
1865+
1866+ # #-------------------------------------##
1867+ # # Added by Martinski W. [2025-Jan-01] ##
1868+ # #-------------------------------------##
1869+ _CurlFileDownload_ ()
1870+ {
1871+ if [ $# -lt 2 ] || [ -z " $1 " ] || [ -z " $2 " ]
1872+ then return 1 ; fi
1873+ local retCode tempFilePathDL=" ${2} .DL.TMP"
1874+
1875+ curl -LSs --retry 4 --retry-delay 5 --retry-connrefused \
1876+ " $1 " -o " $tempFilePathDL "
1877+ if [ $? -ne 0 ] && [ ! -s " $tempFilePathDL " ] || \
1878+ grep -iq " ^404: Not Found" " $tempFilePathDL "
1879+ then rm -f " $tempFilePathDL " ; retCode=1
1880+ else mv -f " $tempFilePathDL " " $2 " ; retCode=0
1881+ fi
1882+ return " $retCode "
1883+ }
1884+
1885+ # #----------------------------------------##
1886+ # # Modified by Martinski W. [2024-Dec-31] ##
1887+ # #----------------------------------------##
18401888_SCRIPTUPDATE_ ()
18411889{
1842- local scriptVers ScriptFileDL= " ${ScriptFilePath} .DL "
1890+ local urlScriptVers theScriptVers extraParam= " "
18431891
18441892 _DownloadScriptFiles_ ()
18451893 {
18461894 local retCode
1847-
1848- curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /version.txt" -o " $SCRIPTVERPATH "
1849- curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /${SCRIPT_NAME} .sh" -o " $ScriptFileDL "
1850- curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /${SCRIPT_NAME} .asp" -o " $SETTINGS_DIR "
1851-
1852- if [ $? -eq 0 ] && [ -s " $ScriptFileDL " ]
1895+ if _CurlFileDownload_ " ${SCRIPT_URL_REPO} /version.txt" " $SCRIPTVERPATH "
18531896 then
1854- mv -f " $ScriptFileDL " " $ScriptFilePath "
1855- chmod 755 " $ScriptFilePath "
1856- retCode=0
1897+ retCode=0 ; chmod 664 " $SCRIPTVERPATH "
18571898 else
1858- rm -f " $ScriptFileDL "
1859- printf " \n${REDct} Download failed.${NOct} \n"
18601899 retCode=1
1900+ Say " ${REDct} **ERROR**${NOct} : Unable to download latest version file for $SCRIPT_NAME ."
1901+ fi
1902+ if _CurlFileDownload_ " ${SCRIPT_URL_REPO} /${SCRIPT_NAME} .sh" " $ScriptFilePath "
1903+ then
1904+ retCode=0 ; chmod 755 " $ScriptFilePath "
1905+ else
1906+ retCode=1
1907+ Say " ${REDct} **ERROR**${NOct} : Unable to download latest script file for $SCRIPT_NAME ."
18611908 fi
18621909 return " $retCode "
18631910 }
18641911
18651912 if [ $# -gt 0 ] && [ " $1 " = " force" ]
18661913 then
1867- echo -e " ${CYANct} Force downloading latest version...${NOct} "
1868- scriptVers=" $( /usr/sbin/curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /version.txt" ) "
1869- echo -e " ${CYANct} Downloading latest version ($scriptVers ) of ${SCRIPT_NAME}${NOct} "
1914+ printf " \n${CYANct} Force downloading latest script version...${NOct} \n"
1915+ theScriptVers=" $SCRIPT_VERSION "
1916+ [ -s " $SCRIPTVERPATH " ] && theScriptVers=" $( cat " $SCRIPTVERPATH " ) "
1917+ urlScriptVers=" $( /usr/sbin/curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /version.txt" ) "
1918+ printf " ${CYANct} Downloading latest version ($urlScriptVers ) of ${SCRIPT_NAME}${NOct} \n"
18701919
18711920 if _DownloadScriptFiles_
18721921 then
1873- if " $inRouterSWmode "
1874- then
1875- _Set_Version_SharedSettings_ add " $SCRIPT_VERSION "
1876- _Create_Symlinks_
1877- fi
1878- echo -e " ${CYANct} $SCRIPT_NAME successfully updated. ${NOct} "
1922+ printf " ${CYANct} $SCRIPT_NAME was successfully updated. ${NOct} \n\n "
1923+ sleep 1
1924+ [ -s " $SCRIPTVERPATH " ] && urlScriptVers= " $( cat " $SCRIPTVERPATH " ) "
1925+ if [ $# -gt 1 ] && [ " $2 " = " newgui " ] && \
1926+ _CheckForNewGUIVersionUpdate_ " $theScriptVers " " $urlScriptVers "
1927+ then extraParam= " forceupdate " ; fi
18791928 _ReleaseLock_
1880- chmod 755 " $ScriptFilePath "
1881- exec " $ScriptFilePath "
1929+ exec " $ScriptFilePath " $extraParam
1930+ exit 0
18821931 fi
1883- return
1932+ return 0
18841933 fi
18851934
1886- _CheckForNewScriptUpdates_
1935+ ! _CheckForNewScriptUpdates_ && return 1
18871936
18881937 clear
18891938 logo
1939+
18901940 printf " \n${YLWct} Script Update Utility${NOct} \n\n"
18911941 printf " ${CYANct} Version Currently Installed: ${YLWct}${SCRIPT_VERSION}${NOct} \n"
18921942 printf " ${CYANct} Update Version Available Now: ${YLWct}${DLRepoVersion}${NOct} \n\n"
@@ -1897,8 +1947,7 @@ _SCRIPTUPDATE_()
18971947 echo -e " ${CYANct} This will overwrite your currently installed version.${NOct} "
18981948 if _WaitForYESorNO_
18991949 then
1900- printf " \n\n"
1901- echo -e " ${CYANct} Downloading $SCRIPT_NAME ${CYANct} v${DLRepoVersion}${NOct} "
1950+ printf " \n\n${CYANct} Downloading $SCRIPT_NAME ${CYANct} v${DLRepoVersion}${NOct} \n"
19021951
19031952 if _DownloadScriptFiles_
19041953 then
@@ -1909,15 +1958,14 @@ _SCRIPTUPDATE_()
19091958 fi
19101959 chmod 755 " $ScriptFilePath "
19111960 echo
1912- echo -e " ${CYANct} Download successful!${NOct} "
1913- echo -e " $( date ) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v $DLRepoVersion "
1961+ printf " \n ${CYANct} Download successful!${NOct} \n "
1962+ printf " \n\n ${CYANct} Downloading $SCRIPT_NAME $DLRepoVersion version. ${NOct} \n "
19141963 echo
19151964 fi
19161965 _WaitForEnterKey_
19171966 return
19181967 else
1919- printf " \n\n"
1920- echo -e " ${GRNct} Exiting Script Update Utility...${NOct} "
1968+ printf " \n\n${GRNct} Exiting Script Update Utility...${NOct} \n"
19211969 sleep 1
19221970 return
19231971 fi
@@ -1927,48 +1975,53 @@ _SCRIPTUPDATE_()
19271975 if _WaitForYESorNO_
19281976 then
19291977 printf " \n\n"
1930- echo -e " ${CYANct} Downloading $SCRIPT_NAME ${CYANct} v ${ DLRepoVersion} ${NOct}"
1978+ printf " \n\n ${CYANct} Downloading $SCRIPT_NAME $DLRepoVersion version. ${NOct} \n "
19311979
19321980 if _DownloadScriptFiles_
19331981 then
1934- echo
1935- echo -e " $( date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion "
1936- echo -e " ${CYANct} Update successful! Restarting script...${NOct} "
19371982 if " $inRouterSWmode "
19381983 then
19391984 _Set_Version_SharedSettings_ add " $DLRepoVersion "
19401985 _Create_Symlinks_
19411986 fi
1987+ printf " \n$( date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v${DLRepoVersion} \n"
1988+ printf " ${CYANct} Update successful! Restarting script...${NOct} \n"
1989+ sleep 1
1990+ _CheckForNewGUIVersionUpdate_ && extraParam=" forceupdate"
19421991 _ReleaseLock_
1943- chmod 755 " $ScriptFilePath "
1944- exec " $ScriptFilePath " # Re-execute the updated script #
1945- exit 0 # This line will not be executed due to above exec #
1992+ exec " $ScriptFilePath " $extraParam
1993+ exit 0
19461994 else
19471995 _WaitForEnterKey_
19481996 return
19491997 fi
19501998 else
1951- printf " \n\n"
1952- echo -e " ${GRNct} Exiting Script Update Utility...${NOct} "
1999+ printf " \n\n${GRNct} Exiting Script Update Utility...${NOct} \n"
19532000 sleep 1
19542001 return
19552002 fi
19562003 fi
19572004}
19582005
1959- # #------------------------------------------ ##
1960- # # Modified by ExtremeFiretop [2024-Nov-18 ] ##
1961- # #------------------------------------------ ##
2006+ # #----------------------------------------##
2007+ # # Modified by Martinski W. [2025-Jan-01 ] ##
2008+ # #----------------------------------------##
19622009_CheckForNewScriptUpdates_ ()
19632010{
1964- local DLRepoVersionNum ScriptVersionNum
2011+ local extraParam= " "
19652012
1966- echo " "
2013+ echo
2014+ DLRepoVersion=" $SCRIPT_VERSION "
19672015 [ -s " $SCRIPTVERPATH " ] && DLRepoVersion=" $( cat " $SCRIPTVERPATH " ) "
19682016 rm -f " $SCRIPTVERPATH "
19692017
19702018 # Download the latest version file from the source repository
1971- curl -LSs --retry 4 --retry-delay 5 " ${SCRIPT_URL_REPO} /version.txt" -o " $SCRIPTVERPATH "
2019+ if ! _CurlFileDownload_ " ${SCRIPT_URL_REPO} /version.txt" " $SCRIPTVERPATH "
2020+ then
2021+ Say " ${REDct} **ERROR**${NOct} : Unable to download latest version file for $SCRIPT_NAME ."
2022+ scriptUpdateNotify=0
2023+ return 1
2024+ fi
19722025
19732026 if [ $? -ne 0 ] || [ ! -s " $SCRIPTVERPATH " ]
19742027 then scriptUpdateNotify=0 ; return 1 ; fi
@@ -1977,27 +2030,28 @@ _CheckForNewScriptUpdates_()
19772030 DLRepoVersion=" $( cat " $SCRIPTVERPATH " ) "
19782031 if [ -z " $DLRepoVersion " ]
19792032 then
1980- echo " Variable for downloaded version is empty."
2033+ Say " ${REDct} **ERROR** ${NOct} : Variable for downloaded version is empty."
19812034 scriptUpdateNotify=0
19822035 return 1
19832036 fi
19842037
19852038 DLRepoVersionNum=" $( _ScriptVersionStrToNum_ " $DLRepoVersion " ) "
19862039 ScriptVersionNum=" $( _ScriptVersionStrToNum_ " $SCRIPT_VERSION " ) "
19872040
1988- # Version comparison
19892041 if [ " $DLRepoVersionNum " -gt " $ScriptVersionNum " ]
19902042 then
1991- scriptUpdateNotify=" New script update available.
2043+ scriptUpdateNotify=" New script update available.
19922044${REDct} v${SCRIPT_VERSION}${NOct} --> ${GRNct} v${DLRepoVersion}${NOct} "
1993- Say " $( date +' %b %d %Y %X' ) $myLAN_HostName ${ScriptFNameTag} _[$$ ] - INFO: A new script update (v$DLRepoVersion ) is available to download."
1994- if [ " $ScriptAutoUpdateSetting " = " ENABLED" ]
1995- then
1996- _SCRIPTUPDATE_ force
1997- fi
2045+ Say " $myLAN_HostName - A new script version update (v$DLRepoVersion ) is available to download."
2046+ if [ " $ScriptAutoUpdateSetting " = " ENABLED" ]
2047+ then
2048+ _CheckForNewGUIVersionUpdate_ && extraParam=" newgui"
2049+ _SCRIPTUPDATE_ force $extraParam
2050+ fi
19982051 else
1999- scriptUpdateNotify=0
2052+ scriptUpdateNotify=0
20002053 fi
2054+ return 0
20012055}
20022056
20032057# #----------------------------------------------##
@@ -3454,7 +3508,7 @@ _GetNodeInfo_()
34543508 return 1
34553509 fi
34563510
3457- # Perform login request
3511+ # Perform login request #
34583512 curl -s -k " ${NodeURLstr} /login.cgi" \
34593513 --referer " ${NodeURLstr} /Main_Login.asp" \
34603514 --user-agent ' Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' \
@@ -3472,7 +3526,7 @@ _GetNodeInfo_()
34723526 return 1
34733527 fi
34743528
3475- # Run the curl command to retrieve the HTML content
3529+ # Retrieve the HTML content #
34763530 htmlContent=" $( curl -s -k " ${NodeURLstr} /appGet.cgi?hook=nvram_get(productid)%3bnvram_get(asus_device_list)%3bnvram_get(cfg_device_list)%3bnvram_get(firmver)%3bnvram_get(buildno)%3bnvram_get(extendno)%3bnvram_get(webs_state_flag)%3bnvram_get(odmpid)%3bnvram_get(wps_modelnum)%3bnvram_get(model)%3bnvram_get(build_name)%3bnvram_get(lan_hostname)%3bnvram_get(webs_state_info)%3bnvram_get(label_mac)" \
34773531 -H ' User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' \
34783532 -H ' Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
@@ -3512,7 +3566,7 @@ _GetNodeInfo_()
35123566 # Combine extracted information into one string #
35133567 Node_combinedVer=" ${node_firmver} .${node_buildno} .$node_extendno "
35143568
3515- # Perform logout request
3569+ # Perform logout request #
35163570 curl -s -k " ${NodeURLstr} /Logout.asp" \
35173571 -H ' User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' \
35183572 -H ' Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
@@ -7438,9 +7492,9 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
74387492 fi
74397493 fi
74407494
7441- # Extracting the F/W Update codebase number to use in the curl #
7495+ # Extracting the F/W Update codebase number #
74427496 fwUpdateBaseNum=" $( echo " $release_version " | cut -d' .' -f1) "
7443- # Inserting dots between each number
7497+ # Inserting dots between each number #
74447498 dottedVersion=" $( echo " $fwUpdateBaseNum " | sed ' s/./&./g' | sed ' s/.$//' ) "
74457499
74467500 # # Check for Login Credentials ##
@@ -8584,13 +8638,13 @@ _ConfirmCronJobEntry_()
85848638 fi
85858639}
85868640
8587- # #------------------------------------------ ##
8588- # # Modified by ExtremeFiretop [2024-Dec-21 ] ##
8589- # #------------------------------------------ ##
8590- if [ $# -gt 0 ]
8641+ # #----------------------------------------##
8642+ # # Modified by Martinski W. [2024-Dec-31 ] ##
8643+ # #----------------------------------------##
8644+ if [ $# -gt 0 ] && [ -n " $1 " ]
85918645then
85928646 inMenuMode=false
8593- case $1 in
8647+ case " $1 " in
85948648 run_now) _RunFirmwareUpdateNow_
85958649 ;;
85968650 processNodes) _ProcessMeshNodes_ 0
@@ -8609,7 +8663,7 @@ then
86098663 ;;
86108664 checkupdates) _CheckForNewScriptUpdates_
86118665 ;;
8612- forceupdate) _SCRIPTUPDATE_ force
8666+ forceupdate) _SCRIPTUPDATE_ force " $( [ $# -gt 1 ] && echo " $2 " || echo ) "
86138667 ;;
86148668 develop) _ChangeToDev_
86158669 ;;
0 commit comments