diff --git a/MerlinAU.sh b/MerlinAU.sh index 40851141..fd3bc317 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,15 +4,15 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2025-Jun-17 +# Last Modified: 2025-Jul-03 ################################################################### set -u ## Set version for each Production Release ## -readonly SCRIPT_VERSION=1.4.9 +readonly SCRIPT_VERSION=1.5.0 readonly SCRIPT_NAME="MerlinAU" ## Set to "master" for Production Releases ## -SCRIPT_BRANCH="master" +SCRIPT_BRANCH="dev" ##----------------------------------------## ## Modified by Martinski W. [2024-Jul-03] ## @@ -775,7 +775,7 @@ _GetFirmwareVariantFromRouter_() ##FOR TESTING/DEBUG ONLY## if false # Change to true for forcing GNUton flag # - then hasGNUtonFW=true ; return 0 ; fi + then echo "true" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## # Check if installed F/W NVRAM vars contain "gnuton" # @@ -3136,34 +3136,32 @@ _CreateEMailContent_() ;; STOP_FW_UPDATE_APPROVAL) emailBodyTitle="WARNING" - high_risk_regex=$(printf '%s\n' "$high_risk_terms" | sed 's/ /[[:space:]]+/g') + high_risk_regex="$(printf '%s\n' "$high_risk_terms" | sed 's/ /[[:space:]]+/g')" if "$isEMailFormatHTML" then # Highlight high-risk terms using HTML with a yellow background # highlighted_changelog_contents="$( - printf '%s\n' "$changelog_contents" | + printf '%s\n' "$changelog_contents" | \ sed -E ":a;N;\$!ba; \ - s/(${high_risk_regex})/\\1<\\/span>/Ig" - )" + s/(${high_risk_regex})/\\1<\\/span>/Ig")" else - # Step 1: Enclose matched terms with unique markers that don't conflict with '>' and '<' + # Step 1: Enclose matched terms with unique markers that don't conflict with '>' and '<' # highlighted_changelog_contents="$( - printf '%s\n' "$changelog_contents" | + printf '%s\n' "$changelog_contents" | \ awk -v regex="$high_risk_regex" ' BEGIN { IGNORECASE = 1 } - { buf = buf $0 ORS } # slurp into buf + { buf = buf $0 ORS } # slurp into buf # END { out = "" while (match(buf, regex)) { pre = substr(buf, 1, RSTART - 1) hit = substr(buf, RSTART, RLENGTH) - buf = substr(buf, RSTART + RLENGTH) # delete hit + prefix - out = out pre ">" toupper(hit) "<" # grow output + buf = substr(buf, RSTART + RLENGTH) # delete hit + prefix # + out = out pre ">" toupper(hit) "<" # grow output # } - out = out buf # tail with no more matches + out = out buf # tail with no more matches # printf "%s", out - }' - )" + }')" fi { echo "Found high-risk phrases in the changelog file while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." @@ -3700,16 +3698,41 @@ _GetFreeRAM_KB_() ##FOR DEBUG ONLY## echo 1000 } +##-------------------------------------## +## Added by Martinski W. [2024-Jun-29] ## +##-------------------------------------## +_GetFileSizeBytes_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] || [ ! -s "$1" ] + then echo 0 ; return 1 ; fi + echo "$(ls -1l "$1" | awk -F ' ' '{print $3}')" +} + ##----------------------------------------## -## Modified by Martinski W. [2025-Jun-01] ## +## Modified by Martinski W. [2025-Jun-29] ## ##----------------------------------------## -theZIP_FileSizeKB=0 -theZIP_FileSizeBytes=0 - +theTargetFileSizeKB=0 +theTargetFileSizeBytes=0 +#-------------------------------------------- +# ARG1: "URL=https://link/to/file/..." OR +# "FPATH=/the/local/file/path/..." +#-------------------------------------------- _GetRequiredRAM_KB_() { - local theURL="$1" thePhase overhead_percentage - local overhead_KB total_required_KB + if [ $# -eq 0 ] || [ -z "$1" ] || \ + ! echo "$1" | grep -qE "^(URL=|FPATH=).+" + then echo 0 ; return 1 ; fi + + local theURLstr="" theBINpath="" thePhase + local overhead_KB total_required_KB overhead_percentage + + if echo "$1" | grep -qE "^URL=.+" + then + theURLstr="${1#*=}" + elif echo "$1" | grep -qE "^FPATH=.+" + then + theBINpath="${1#*=}" + fi if [ $# -lt 2 ] || [ -z "$2" ] || \ ! echo "$2" | grep -qE "^phase#[1-9]$" @@ -3718,24 +3741,30 @@ _GetRequiredRAM_KB_() fi overhead_percentage="$(_GetAvailableRAM_PercentOverheadNum_ "$thePhase")" - if [ -z "$theZIP_FileSizeBytes" ] || \ - [ "$theZIP_FileSizeBytes" = "0" ] || \ - ! echo "$theZIP_FileSizeBytes" | grep -qE "^[0-9]+$" + if [ -z "$theTargetFileSizeBytes" ] || \ + [ "$theTargetFileSizeBytes" -eq 0 ] || \ + ! echo "$theTargetFileSizeBytes" | grep -qE "^[0-9]+$" then - theZIP_FileSizeBytes="$(curl -LsI --retry 4 --retry-delay 5 "$theURL" | grep -i Content-Length | tail -1 | awk '{print $2}')" + if [ -n "$theBINpath" ] + then + theTargetFileSizeBytes="$(_GetFileSizeBytes_ "$theBINpath")" + elif [ -n "$theURLstr" ] + then + theTargetFileSizeBytes="$(curl -LsI --retry 4 --retry-delay 5 "$theURLstr" | grep -i Content-Length | tail -1 | awk '{print $2}')" + fi fi - if [ -n "$theZIP_FileSizeBytes" ] && \ - [ "$theZIP_FileSizeBytes" -gt 0 ] && \ - [ "$theZIP_FileSizeKB" -eq 0 ] + if [ -n "$theTargetFileSizeBytes" ] && \ + [ "$theTargetFileSizeBytes" -gt 0 ] && \ + [ "$theTargetFileSizeKB" -eq 0 ] then - theZIP_FileSizeKB="$((theZIP_FileSizeBytes / 1024))" + theTargetFileSizeKB="$((theTargetFileSizeBytes / 1024))" fi # Calculate overhead based on the percentage # - overhead_KB="$((theZIP_FileSizeKB * overhead_percentage / 100))" + overhead_KB="$((theTargetFileSizeKB * overhead_percentage / 100))" - total_required_KB="$((theZIP_FileSizeKB + overhead_KB))" + total_required_KB="$((theTargetFileSizeKB + overhead_KB))" echo "$total_required_KB" } @@ -4642,32 +4671,31 @@ _GetLoginCredentials_() ##-------------------------------------------## _GetNodeIPv4List_() { - local NODE_ROLE="2" # keep only nodes whose last field == 2 - local device_list ip_addresses + local NODE_ROLE="2" # keep only nodes whose last field == 2 # + local device_list ip_addresses device_list="$(nvram get asus_device_list)" - if [ -z "$device_list" ]; then + if [ -z "$device_list" ] + then Say "NVRAM asus_device_list is NOT populated. No Mesh Nodes were found." return 1 fi ip_addresses="$( - printf '%s\n' "$device_list" | - tr '<' '\n' | + printf '%s\n' "$device_list" | tr '<' '\n' | \ awk -F'>' \ -v role="$NODE_ROLE" \ -v exclude="$mainLAN_IPaddr" ' - NF >= 4 && $3 != exclude && $NF == role { print $3 } - ' - )" + NF >= 4 && $3 != exclude && $NF == role { print $3 }')" - if [ -n "$ip_addresses" ]; then + if [ -n "$ip_addresses" ] + then printf '%s\n' "$ip_addresses" return 0 fi - # nothing matched + # nothing matched # return 1 } @@ -4742,7 +4770,7 @@ _GetNodeURL_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2025-June-08] ## +## Modified by ExtremeFiretop [2025-Jun-08] ## ##------------------------------------------## _GetNodeInfo_() { @@ -4922,13 +4950,14 @@ _GetLatestFWUpdateVersionFromWebsite_() ##------------------------------------------## _GetLatestFWUpdateVersionFromGitHub_() { - local routerVersion + local routerVersion search_type release_data local gitURL="$1" # GitHub URL for the latest release # local firmware_type="$2" # "tuf", "rog" or "pure" # + local grep_pattern downloadURLs theURL urlVersion - local search_type="$firmware_type" # Default to the input firmware_type # + search_type="$firmware_type" # Default to the input firmware_type # - # If firmware_type is "pure", set search_type to include "squashfs" as well + # If firmware_type is "pure", set search_type to include "squashfs" as well # if [ "$firmware_type" = "pure" ] then search_type="pure\|squashfs\|ubi" @@ -4947,13 +4976,13 @@ _GetLatestFWUpdateVersionFromGitHub_() fi # Fetch the latest release data from GitHub # - local release_data="$(curl -s "$gitURL")" + release_data="$(curl -s "$gitURL")" # Construct the grep pattern based on search_type # - local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\"" + grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\"" # Extract all matched download URLs # - local downloadURLs="$(echo "$release_data" | \ + downloadURLs="$(echo "$release_data" | \ grep -o "$grep_pattern" | \ grep -o "https://[^ ]*\.\(w\|pkgtb\)")" @@ -4962,7 +4991,6 @@ _GetLatestFWUpdateVersionFromGitHub_() echo "**ERROR** **NO_GITHUB_URL**" return 1 else - local theURL urlVersion for theURL in $downloadURLs do # Extract the version portion from the URL # @@ -8224,40 +8252,54 @@ _EntwareServicesHandler_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Nov-15] ## +## Modified by ExtremeFiretop [2025-Jun-28] ## ##------------------------------------------## _GetOfflineFirmwareVersion_() { local zip_file="$1" - local extract_version_regex='[0-9]+_[0-9]+\.[0-9]+_[0-9a-zA-Z]+' - local validate_version_regex='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(_[0-9a-zA-Z]+)?' + local extract_version_regex='[0-9]+_[0-9]+\.[0-9]+_[0-9a-zA-Z]+(-gnuton[0-9a-zA-Z_]+)?' + local validate_version_regex='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+([_-][0-9a-zA-Z_]+)?' local fwVersionFormat firmware_version formatted_version # Extract the version number using regex # firmware_version="$(echo "$zip_file" | grep -oE "$extract_version_regex")" + firmware_version="${firmware_version%_ubi*}" if [ -n "$firmware_version" ] then if echo "$firmware_version" | grep -qE '^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+)$' then - # Numeric patch version + # Numeric patch (Merlin) # formatted_version="$(echo "$firmware_version" | sed -E 's/^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+)/\1.\2.\3.\4/')" + + elif echo "$firmware_version" | grep -qE '^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+)-gnuton[0-9]+$' + then + # Stable Gnuton build – drop the "-gnutonN" tail # + formatted_version="$(echo "$firmware_version" | sed -E 's/^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+)-gnuton[0-9]+$/\1.\2.\3.\4/')" + + elif echo "$firmware_version" | grep -qE '^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+-gnuton[0-9]+_(alpha|beta)[0-9a-zA-Z]*)$' + then + # Gnuton beta/alpha – keep the "-gnuton…_beta/alpha" suffix # + formatted_version="$(echo "$firmware_version" | sed -E 's/^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9]+-gnuton[0-9]+_[a-zA-Z]+[0-9a-zA-Z]*)/\1.\2.\3.\4/')" + elif echo "$firmware_version" | grep -qE '^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9a-zA-Z]+)$' then - # Alphanumeric suffix + # Alphanumeric suffix (Merlin "_beta3", "_alpha1", etc.) # formatted_version="$(echo "$firmware_version" | sed -E 's/^([0-9]+)_([0-9]+)\.([0-9]+)_([0-9a-zA-Z]+)/\1.\2.\3.0_\4/')" else printf "\nFailed to parse firmware version from the ZIP file name.\n" firmware_version="" + formatted_version="UNKNOWN" fi printf "\nIdentified firmware version: ${GRNct}$formatted_version${NOct}\n" printf "\n---------------------------------------------------\n" - # Ask the user to confirm the detected firmware version - if _WaitForYESorNO_ "\nIs this firmware version correct?"; then + # Ask the user to confirm the detected firmware version # + if _WaitForYESorNO_ "\nIs this firmware version correct?" + then printf "\n---------------------------------------------------\n" else - # Set firmware_version to empty to trigger manual entry + # Set firmware_version to empty to trigger manual entry # firmware_version="" fi fi @@ -8274,18 +8316,29 @@ _GetOfflineFirmwareVersion_() printf "\nFailed to identify firmware version from the ZIP file name." fi printf "\nPlease enter the firmware version number in the format ${fwVersionFormat}\n" - printf "\n(Examples: 3004.388.8.0 or 3004.388.8.0_beta1). Enter 'e' to exit: " + if "$isGNUtonFW" + then + printf "\n(Examples: 3004.388.8.0 or 3004.388.8.0-gnuton0_beta3). Enter 'e' to exit: " + else + printf "\n(Examples: 3004.388.8.0 or 3004.388.8.0_beta1). Enter 'e' to exit: " + fi read -r formatted_version # Validate user input # while ! echo "$formatted_version" | grep -qE "^${validate_version_regex}$" do - if echo "$formatted_version" | grep -qE "^(e|E|exit|Exit)$"; then + if echo "$formatted_version" | grep -qE "^(e|E|exit|Exit)$" + then return 1 fi printf "\n${REDct}**WARNING**${NOct} Invalid format detected!\n" printf "\nPlease enter the firmware version number in the format ${fwVersionFormat}\n" - printf "\n(i.e 3004.388.8.0 or 3004.388.8.0_beta1). Enter 'e' to exit: " + if "$isGNUtonFW" + then + printf "\n(Examples: 3004.388.8.0 or 3004.388.8.0-gnuton0_beta3). Enter 'e' to exit: " + else + printf "\n(Examples: 3004.388.8.0 or 3004.388.8.0_beta1). Enter 'e' to exit: " + fi read -r formatted_version done printf "\nThe user-provided firmware version: ${GRNct}$formatted_version${NOct}\n" @@ -8576,9 +8629,9 @@ _RunBackupmon_() return 0 } -##----------------------------------------## -## Modified by Martinski W. [2025-Feb-15] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2025-Jun-30] ## +##------------------------------------------## _RunOfflineUpdateNow_() { local retCode @@ -8685,27 +8738,13 @@ _RunOfflineUpdateNow_() extension="${sanitized_filename##*.}" FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" _GnutonBuildSelection_ - set -- $(_GetLatestFWUpdateVersionFromGitHub_ "$FW_GITURL_RELEASE" "$firmware_choice") - retCode="$?" - else - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - retCode="$?" fi - if [ "$retCode" -eq 0 ] && [ $# -eq 2 ] && \ - [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] + if _AcquireLock_ cliFileLock then - release_link="$2" - if _AcquireLock_ cliFileLock - then - _RunFirmwareUpdateNow_ - _ReleaseLock_ cliFileLock - fi - _ClearOfflineUpdateState_ - else - Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$MODEL_ID] router model." - _ClearOfflineUpdateState_ 1 - return 1 + _RunFirmwareUpdateNow_ + _ReleaseLock_ cliFileLock fi + _ClearOfflineUpdateState_ else _ClearOfflineUpdateState_ 1 return 1 @@ -8899,11 +8938,18 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or return 1 fi - ##----------------------------------------## - ## Modified by Martinski W. [2025-Jun-01] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2025-Jun-30] ## + ##------------------------------------------## # Get the required memory for the firmware download and extraction - requiredRAM_kb="$(_GetRequiredRAM_KB_ "$release_link" 'phase#1')" + if ! "$offlineUpdateTrigger" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "URL=$release_link" 'phase#1')" + else + if "$isGNUtonFW" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_DL_FPATH" 'phase#1')" + else requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_ZIP_FPATH" 'phase#1')" + fi + fi if ! _HasRouterMoreThan256MBtotalRAM_ && [ "$requiredRAM_kb" -gt 51200 ] then if ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 @@ -8971,12 +9017,19 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or fi fi - ##----------------------------------------## - ## Modified by Martinski W. [2025-Jun-01] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2025-Jun-30] ## + ##------------------------------------------## freeRAM_kb="$(_GetFreeRAM_KB_)" availableRAM_kb="$(_GetAvailableRAM_KB_)" - requiredRAM_kb="$(_GetRequiredRAM_KB_ "$release_link" 'phase#2')" + if ! "$offlineUpdateTrigger" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "URL=$release_link" 'phase#2')" + else + if "$isGNUtonFW" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_DL_FPATH" 'phase#2')" + else requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_ZIP_FPATH" 'phase#2')" + fi + fi Say "Required RAM: ${requiredRAM_kb} KB - RAM Free: ${freeRAM_kb} KB - RAM Available: ${availableRAM_kb} KB" check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" @@ -9000,7 +9053,14 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or freeRAM_kb="$(_GetFreeRAM_KB_)" availableRAM_kb="$(_GetAvailableRAM_KB_)" - requiredRAM_kb="$(_GetRequiredRAM_KB_ "$release_link" 'phase#3')" + if ! "$offlineUpdateTrigger" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "URL=$release_link" 'phase#3')" + else + if "$isGNUtonFW" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_DL_FPATH" 'phase#3')" + else requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_ZIP_FPATH" 'phase#3')" + fi + fi Say "Required RAM: ${requiredRAM_kb} KB - RAM Free: ${freeRAM_kb} KB - RAM Available: ${availableRAM_kb} KB" check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" @@ -9022,7 +9082,14 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or freeRAM_kb="$(_GetFreeRAM_KB_)" availableRAM_kb="$(_GetAvailableRAM_KB_)" - requiredRAM_kb="$(_GetRequiredRAM_KB_ "$release_link" 'phase#4')" + if ! "$offlineUpdateTrigger" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "URL=$release_link" 'phase#4')" + else + if "$isGNUtonFW" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_DL_FPATH" 'phase#4')" + else requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_ZIP_FPATH" 'phase#4')" + fi + fi Say "Required RAM: ${requiredRAM_kb} KB - RAM Free: ${freeRAM_kb} KB - RAM Available: ${availableRAM_kb} KB" check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" @@ -9108,12 +9175,19 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or return 1 fi - ##----------------------------------------## - ## Modified by Martinski W. [2025-Jun-01] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2025-Jun-30] ## + ##------------------------------------------## freeRAM_kb="$(_GetFreeRAM_KB_)" availableRAM_kb="$(_GetAvailableRAM_KB_)" - requiredRAM_kb="$(_GetRequiredRAM_KB_ "$release_link" 'phase#5')" + if ! "$offlineUpdateTrigger" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "URL=$release_link" 'phase#5')" + else + if "$isGNUtonFW" + then requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_DL_FPATH" 'phase#5')" + else requiredRAM_kb="$(_GetRequiredRAM_KB_ "FPATH=$FW_ZIP_FPATH" 'phase#5')" + fi + fi Say "Required RAM: ${requiredRAM_kb} KB - RAM Free: ${freeRAM_kb} KB - RAM Available: ${availableRAM_kb} KB" check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" @@ -11094,6 +11168,50 @@ _DoInitializationStartup_() _SetDefaultBuildType_ } +##-------------------------------------## +## Added by Martinski W. [2025-Jul-03] ## +##-------------------------------------## +####################################################################### +# TEMPORARY hack to check if the Gnuton F/W built-in 'webs_update.sh' +# script is the most recent version that includes required fixes. +# If not, we temporarily set up a local version so that MerlinAU +# can continue to work by detecting available F/W version updates. +# NOTE: +# The 'webs_update.sh' MUST have "SCRIPT_VERSTAG" variable defined. +####################################################################### +_Gnuton_Check_Webs_Update_Script_() +{ + if ! "$isGNUtonFW" || \ + ! "$checkWebsUpdateScriptForGnuton" || \ + grep -qE 'SCRIPT_VERSTAG="[0-9]+"' "$FW_UpdateCheckScript" + then + checkWebsUpdateScriptForGnuton=false + return 0 + fi + + local theWebsUpdateFile="webs_update.sh" + local fixedWebsUpdateFilePath="${SETTINGS_DIR}/$theWebsUpdateFile" + + ## Get the fixed version of the script targeted for Gnuton F/W ## + if _CurlFileDownload_ "gnuton_webs_update.sh" "$fixedWebsUpdateFilePath" + then + chmod 755 "$fixedWebsUpdateFilePath" + else + return 1 #NOT available so do nothing# + fi + + if ! diff "$FW_UpdateCheckScript" "$fixedWebsUpdateFilePath" >/dev/null 2>&1 + then + umount "$FW_UpdateCheckScript" 2>/dev/null + mount -o bind "$fixedWebsUpdateFilePath" "$FW_UpdateCheckScript" + Say "${YLWct}Set up a fixed version of the \"${theWebsUpdateFile}\" script file.${NOct}" + fi +} + +## Set variable to 'false' to stop the check ## +checkWebsUpdateScriptForGnuton="$isGNUtonFW" +_Gnuton_Check_Webs_Update_Script_ + FW_InstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" FW_InstalledVerStr="${GRNct}${FW_InstalledVersion}${NOct}" FW_NewUpdateVerInit=TBD diff --git a/README.md b/README.md index b8919528..6993eefb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MerlinAU - AsusWRT-Merlin Firmware Auto Updater -## v1.4.9 -## 2025-Jun-19 +## v1.5.0 +## 2025-Jul-06 ## WebUI: ![image](https://github.com/user-attachments/assets/9c1dff99-9c13-491b-a7fa-aff924d5f02e) diff --git a/gnuton_webs_update.sh b/gnuton_webs_update.sh new file mode 100644 index 00000000..1e1fcc6a --- /dev/null +++ b/gnuton_webs_update.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +readonly SCRIPT_VERSTAG="25070312" + +wget_options="-q -t 2 -T 30" + +fwsite="https://raw.githubusercontent.com/gnuton/asuswrt-merlin.ng/master/updates" + +nvram set webs_state_update=0 # INITIALIZING +nvram set webs_state_flag=0 # 0: Don't do upgrade 1: Do upgrade +nvram set webs_state_error=0 +nvram set webs_state_url="" + +#openssl support rsa check +IS_SUPPORT_NOTIFICATION_CENTER=$(nvram get rc_support|grep -i nt_center) +if [ "$IS_SUPPORT_NOTIFICATION_CENTER" != "" ]; then +. /tmp/nc/event.conf +fi +# current firmware information +current_base=$(nvram get firmver | sed "s/\.//g") +current_firm=$(nvram get buildno | cut -d. -f1) +current_buildno=$(nvram get buildno | cut -d. -f2) +#Extract extendno, subtract value by 1 if it contains "alpha/beta", remove all other values such as "_rog" or "-g*" +current_extendno="$(nvram get extendno | awk -F'[_-]' '{n=$1} /[aA]lpha|[bB]eta/{n--} END{print n}')" + +# get firmware information +model=$(nvram get productid) +model="$model#" + +if [ "$current_base" = "3006" ]; then + manifest_file="manifest_3006.txt" +else + manifest_file="manifest2.txt" +fi + +echo "---- update real normal----" > /tmp/webs_upgrade.log +/usr/sbin/wget $wget_options "$fwsite/$manifest_file" -O /tmp/wlan_update.txt + +if [ "$?" != "0" ]; then + nvram set webs_state_error=1 +else + + fullver="$(grep "$model" /tmp/wlan_update.txt | tail -n1 | sed 's/.*#FW//')" + fullver=$(echo $fullver | sed s/#.*//;) + firmbase=$(echo $fullver | cut -d. -f1) + firmver=$(echo $fullver | cut -d. -f2) + buildno=$(echo $fullver | cut -d. -f3) + + extendno="$(grep "$model" /tmp/wlan_update.txt | tail -n1 | sed 's/.*#EXT//')" + extendno=$(echo $extendno | sed s/#.*//;) + lextendno=$(echo $extendno | sed s/-g.*//;) + + nvram set webs_state_info=${firmbase}_${firmver}_${buildno}_${extendno} + + rm -f /tmp/wlan_update.* +fi + +echo "---- Have ${current_base}.${current_firm}.${current_buildno}_${current_extendno}----" >> /tmp/webs_upgrade.log +echo "---- Stable available ${firmbase}.${firmver}.${buildno}_${extendno}----" >> /tmp/webs_upgrade.log + +update_webs_state_info=$(nvram get webs_state_info) +last_webs_state_info=$(nvram get webs_last_info) +if [ "$firmbase" == "" ] || [ "$firmver" == "" ] || [ "$buildno" == "" ] || [ "$lextendno" == "" ]; then + nvram set webs_state_error=1 # exist no Info +else + + if [ "$current_base" -lt "$firmbase" ]; then + newfirm=1 + elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -lt "$firmver" ]; then + newfirm=1 + elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -lt "$buildno" ]; then + newfirm=1 + elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -eq "$buildno" ] && [ "$current_extendno" -lt "$lextendno" ]; then + newfirm=1 + else + newfirm=0 + fi + + if [ "$newfirm" -eq "1" ]; then + echo "---- Update available" >> /tmp/webs_upgrade.log + nvram set webs_state_flag=1 # Do upgrade + if [ "$IS_SUPPORT_NOTIFICATION_CENTER" != "" ]; then + if [ "$last_webs_state_info" != "$update_webs_state_info" ]; then + Notify_Event2NC "$SYS_FW_NWE_VERSION_AVAILABLE_EVENT" "{\"fw_ver\":\"$update_webs_state_info\"}" + nvram set webs_last_info="$update_webs_state_info" + fi + fi + fi +fi +# download releasee note +webs_state_flag=$(nvram get webs_state_flag) + +if [ "$webs_state_flag" -eq "1" ]; then + releasenote_file0=$(nvram get webs_state_info)_note.txt + releasenote_path0="/tmp/release_note0.txt" + echo "---- download real release note ----" >> /tmp/webs_upgrade.log + /usr/sbin/wget $wget_options $fwsite/$releasenote_file0 -O $releasenote_path0 + + if [ "$?" != "0" ]; then + echo "---- download $fwsite/$releasenote_file0 failed ----" >> /tmp/webs_upgrade.log + nvram set webs_state_error=1 + else + echo "---- $fwsite/$releasenote_file0 ----" >> /tmp/webs_upgrade.log + fi +fi + +nvram set webs_state_update=1 diff --git a/version.txt b/version.txt index 4ea2b1f4..bc80560f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.4.9 +1.5.0