From dd665c25087f6e58ee40eb24fc755fa8415ef4a9 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 7 Apr 2024 02:20:38 -0400 Subject: [PATCH 001/185] Update MerlinAU.sh --- MerlinAU.sh | 266 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 213 insertions(+), 53 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index fa006ae8..9748fe4e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -19,8 +19,9 @@ readonly SCRIPT_BRANCH="master" readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router/$SCRIPT_BRANCH" # Firmware URL Info # -readonly FW_URL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" -readonly FW_URL_RELEASE_SUFFIX="Release" +readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" +readonly FW_SFURL_RELEASE_SUFFIX="Release" +readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.ng/releases/latest" # For new script version updates from source repository # UpdateNotify=0 @@ -29,6 +30,7 @@ DLRepoVersion="" # For supported version and model checks # MinFirmwareCheckFailed=0 ModelCheckFailed=0 +GnutonFlag="" readonly ScriptFileName="${0##*/}" readonly ScriptFNameTag="${ScriptFileName%%.*}" @@ -467,8 +469,9 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" +#DEBUGONLY#readonly PRODUCT_ID="RT-AX92U" readonly FW_FileName="${PRODUCT_ID}_firmware" -readonly FW_URL_RELEASE="${FW_URL_BASE}/${PRODUCT_ID}/${FW_URL_RELEASE_SUFFIX}/" +readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-01] ## @@ -1976,7 +1979,7 @@ check_version_support() { check_model_support() { # List of unsupported models as a space-separated string - local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900" + local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900 DSL-AC68U" # Get the current model local current_model="$(_GetRouterProductID_)" @@ -2470,6 +2473,51 @@ _GetLatestFWUpdateVersionFromWebsite_() return 0 } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Feb-23] ## +##---------------------------------------## +_GetLatestFWUpdateVersionFromGithub_() +{ + local url="$1" + + # Use curl to fetch the latest release data from GitHub + local release_data=$(curl -s "$1") + + # Parse the release data to find the download URL of the asset that matches the model number + local download_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\"" | grep -o "https://[^ ]*\.w" | head -1) + + if [ -z "$download_url" ] + then + echo "**ERROR** **NO_GITHUB_URL**" ; + return 1 + else + # Extract version from the download URL or release data + local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") + echo "$version" + echo "$download_url" + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-05] ## +##---------------------------------------## +GetLatestFirmwareMD5Url() { + local url="$1" # GitHub API URL for the latest release + + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + + # Parse the release data to find the download URL of the .md5 file that matches the model number + local md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\.md5\"" | grep -o "https://[^ ]*\.md5" | head -1) + + if [ -z "$md5_url" ]; then + echo "**ERROR** **NO_MD5_FILE_URL_FOUND**" + return 1 + else + echo "$md5_url" + fi +} + ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -3420,9 +3468,38 @@ Please manually update to version $minimum_supported_version or higher to use th fi # Use set to read the output of the function into variables - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") - release_version="$1" - release_link="$2" + # Attempt to fetch release information from the website + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + website_release_version="$1" + website_release_link="$2" + + # Check if website fetch resulted in an error + if [ "$website_release_version" = "**ERROR**" ]; then + # Attempt to fetch release information from GitHub due to error from website + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") + github_release_version="$1" + github_release_link="$2" + + md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") + + # Use release information from GitHub if available + if [ -n "$github_release_link" ]; then + release_version="$github_release_version" + release_link="$github_release_link" + Say "Using release information for Gnuton" + GnutonFlag="true" + checkChangeLogSetting="DISABLED" + Update_Custom_Settings "CheckChangeLog" "DISABLED" + else + Say "No valid release information found from GitHub." + # Implement failure handling logic here + fi + else + # No error from website fetch, use its release information + release_version="$website_release_version" + release_link="$website_release_link" + Say "Using release information for Merlin" + fi if [ "$release_version" = "**ERROR**" ] && [ "$release_link" = "**NO_URL**" ] then @@ -3561,14 +3638,40 @@ Please manually update to version $minimum_supported_version or higher to use th wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - wget -O "$FW_ZIP_FPATH" "$release_link" - fi - - if [ ! -f "$FW_ZIP_FPATH" ] - then - Say "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_ZIP_FPATH] was not downloaded." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if [ "$GnutonFlag" = "true" ]; then + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + # Extract the file extension + extension="${sanitized_filename##*.}" + # Combine path, custom file name, and extension before download + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" + wget -O "$FW_DL_FPATH" "$release_link" + wget -O "$FW_MD5_GITHUB" "$md5_url" + else + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + # Extract the filename from the URL + original_filename="${effective_url##*/}" + # Sanitize filename by removing problematic characters (if necessary) + sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + # Extract the file extension + extension="${sanitized_filename##*.}" + # Combine path, custom file name, and extension before download + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + wget -O "$FW_DL_FPATH" "$release_link" + + if [ ! -f "$FW_ZIP_FPATH" ] + then + ay "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_ZIP_FPATH] was not downloaded." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi + fi fi ##------------------------------------------## @@ -3582,25 +3685,57 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Mar-19] ## ##------------------------------------------## + if [ ! "$GnutonFlag" = "true" ]; then Say "-----------------------------------------------------------" # List & log the contents of the ZIP file # unzip -l "$FW_ZIP_FPATH" 2>&1 | \ while IFS= read -r uzLINE ; do Say "$uzLINE" ; done Say "-----------------------------------------------------------" - # Extracting the firmware binary image # - if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ - while IFS= read -r line ; do Say "$line" ; done - then - Say "-----------------------------------------------------------" - #---------------------------------------------------------------# - # Check if ZIP file was downloaded to a USB-attached drive. - # Take into account special case for Entware "/opt/" paths. - #---------------------------------------------------------------# - if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + # Extracting the firmware binary image # + if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ + while IFS= read -r line ; do Say "$line" ; done then - # It's not on a USB drive, so it's safe to delete it # + Say "-----------------------------------------------------------" + #---------------------------------------------------------------# + # Check if ZIP file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# + if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # It's not on a USB drive, so it's safe to delete it # + rm -f "$FW_ZIP_FPATH" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + #-------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + "$inMenuMode" && _WaitForEnterKey_ + # Consider how to handle this error. For now, we'll not delete the ZIP file. + else + keepZIPfile=1 + fi + else + #------------------------------------------------------------# + # Remove ZIP file here because it may have been corrupted. + # Better to download it again and start all over, instead + # of trying to figure out why uncompressing it failed. + #------------------------------------------------------------# rm -f "$FW_ZIP_FPATH" + _SendEMailNotification_ FAILED_FW_UNZIP_STATUS + Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi + else + if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" + cp "$FW_DL_FPATH" "$FW_BIN_DIR" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then #-------------------------------------------------------------# @@ -3613,19 +3748,8 @@ Please manually update to version $minimum_supported_version or higher to use th "$inMenuMode" && _WaitForEnterKey_ # Consider how to handle this error. For now, we'll not delete the ZIP file. else - keepZIPfile=1 + echo fi - else - #------------------------------------------------------------# - # Remove ZIP file here because it may have been corrupted. - # Better to download it again and start all over, instead - # of trying to figure out why uncompressing it failed. - #------------------------------------------------------------# - rm -f "$FW_ZIP_FPATH" - _SendEMailNotification_ FAILED_FW_UNZIP_STATUS - Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 fi freeRAM_kb="$(_GetFreeRAM_KB_)" @@ -3759,30 +3883,66 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-03] ## ##------------------------------------------## - if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then - fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" - if [ "$fw_sig" != "$dl_sig" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" + if [ ! "$GnutonFlag" = "true" ]; then + if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then + fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" + dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" + if [ "$fw_sig" != "$dl_sig" ]; then + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi + fi + else + Say "${REDct}**ERROR**${NOct}: SHA256 signature file not found!" _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 + # Assume non-interactive mode; perform exit. + _DoExit_ 1 fi fi else - Say "${REDct}**ERROR**${NOct}: SHA256 signature file not found!" - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if [ -f "$FW_MD5_GITHUB" ] && [ -f "$firmware_file" ]; then + # Extract the MD5 checksum from the downloaded .md5 file + # Assuming the .md5 file contains a single line with the checksum followed by the filename + md5_expected=$(cut -d' ' -f1 "$FW_MD5_GITHUB") + + # Calculate the MD5 checksum of the firmware file + md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) + + if [ "$md5_actual" != "$md5_expected" ]; then + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi + else + Say "Firmware MD5 checksum verified successfully." + fi else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 + Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi fi fi From 2f77b89ba11ed740b6947598ead40e409753ff45 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 7 Apr 2024 02:26:06 -0400 Subject: [PATCH 002/185] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 59e9e604..524cb552 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.11 +1.1.1 From ae899f4ab76346a97f0d0f5b68cfbc508e803456 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 7 Apr 2024 02:26:22 -0400 Subject: [PATCH 003/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9748fe4e..ce99e5e5 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -8,7 +8,7 @@ ################################################################### set -u -readonly SCRIPT_VERSION=1.1.0 +readonly SCRIPT_VERSION=1.1.1 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## From 35e8e6ae67d80604db4fa00cf3c0e9d36027911d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 14 Apr 2024 00:01:01 -0400 Subject: [PATCH 004/185] Update MerlinAU.sh --- MerlinAU.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 0a2d8dd5..b62423c8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -8,7 +8,7 @@ ################################################################### set -u -readonly SCRIPT_VERSION=1.1.1 +readonly SCRIPT_VERSION=1.1.2 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -3056,7 +3056,7 @@ _Set_FW_UpdateCronSchedule_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jan-26] ## +## Modified by ExtremeFiretop [2024-Apr-13] ## ##------------------------------------------## _CheckNewUpdateFirmwareNotification_() { @@ -3091,7 +3091,10 @@ _CheckNewUpdateFirmwareNotification_() fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Vers "$fwNewUpdateNotificationVers" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" - _SendEMailNotification_ NEW_FW_UPDATE_STATUS + if "$inRouterSWmode" + then + _SendEMailNotification_ NEW_FW_UPDATE_STATUS + fi fi fi @@ -3100,7 +3103,10 @@ _CheckNewUpdateFirmwareNotification_() then fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" - _SendEMailNotification_ NEW_FW_UPDATE_STATUS + if "$inRouterSWmode" + then + _SendEMailNotification_ NEW_FW_UPDATE_STATUS + fi fi return 0 } From e65e5b125ddc4fa637a4a39726bc7a7c530f4c0f Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 14 Apr 2024 14:10:40 -0400 Subject: [PATCH 005/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index b62423c8..3c2a24ec 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1689,7 +1689,7 @@ _GetCurrentFWInstalledLongVersion_() _GetCurrentFWInstalledShortVersion_() { ##FOR TESTING/DEBUG ONLY## -if false ; then echo "388.5.0" ; return 0 ; fi +if true ; then echo "388.5.0" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum From 9509aa52666a87bca2df763e816a484bacb96f9f Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 15 Apr 2024 10:35:34 -0400 Subject: [PATCH 006/185] Update MerlinAU.sh --- MerlinAU.sh | 83 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 3c2a24ec..f1f78b66 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Apr-07 +# Last Modified: 2024-Apr-15 ################################################################### set -u @@ -2042,7 +2042,7 @@ _TestLoginCredentials_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Mar-03] ## +## Modified by Martinski W. [2024-Apr-15] ## ##----------------------------------------## _GetPasswordInput_() { @@ -2050,7 +2050,7 @@ _GetPasswordInput_() local PSWDstring PSWDtmpStr PSWDprompt local retCode charNum pswdLength showPSWD # Added for TAB keypress debounce # - local lastTabTime=0 currentTime timeDiff + local lastTabTime=0 currentTime if [ $# -eq 0 ] || [ -z "$1" ] then @@ -2068,7 +2068,15 @@ _GetPasswordInput_() stty "$savedSettings" } - _showPSWDPrompt_() + _ShowAsterisks_() + { + if [ $# -eq 0 ] || [ "$1" -eq 0 ] + then echo "" + else printf "%*s" "$1" ' ' | tr ' ' '*' + fi + } + + _ShowPSWDPrompt_() { local pswdTemp LENct LENwd [ "$showPSWD" = "1" ] && pswdTemp="$PSWDstring" || pswdTemp="$PSWDtmpStr" @@ -2083,11 +2091,8 @@ _GetPasswordInput_() charNum="" PSWDstring="$pswdString" pswdLength="${#PSWDstring}" - if [ -z "$PSWDstring" ] - then PSWDtmpStr="" - else PSWDtmpStr="$(printf "%*s" "$pswdLength" " " | tr ' ' '*')" - fi - echo ; _showPSWDPrompt_ + PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" + echo ; _ShowPSWDPrompt_ while IFS='' theChar="$(_GetKeypress_)" do @@ -2122,12 +2127,11 @@ _GetPasswordInput_() if [ "$charNum" -eq 9 ] then currentTime="$(date +%s)" - timeDiff="$((currentTime - lastTabTime))" - if [ "$timeDiff" -gt 0 ] + if [ "$((currentTime - lastTabTime))" -gt 0 ] then showPSWD="$((! showPSWD))" - lastTabTime="$currentTime" # Update last TAB press time # - _showPSWDPrompt_ + lastTabTime="$currentTime" # Update TAB keypress time # + _ShowPSWDPrompt_ fi continue fi @@ -2137,10 +2141,10 @@ _GetPasswordInput_() then if [ "$pswdLength" -gt 0 ] then - PSWDtmpStr="${PSWDtmpStr%?}" PSWDstring="${PSWDstring%?}" - pswdLength="$((pswdLength - 1))" - _showPSWDPrompt_ + pswdLength="${#PSWDstring}" + PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" + _ShowPSWDPrompt_ continue fi fi @@ -2150,11 +2154,12 @@ _GetPasswordInput_() then if [ "$pswdLength" -le "$PSWDstrLenMAX" ] then - PSWDtmpStr="${PSWDtmpStr}*" - pswdLength="$((pswdLength + 1))" PSWDstring="${PSWDstring}${theChar}" + pswdLength="${#PSWDstring}" + PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" + _ShowPSWDPrompt_ + continue fi - _showPSWDPrompt_ fi done @@ -2456,7 +2461,11 @@ _GetLatestFWUpdateVersionFromWebsite_() awk -F'[_\.]' '{print $3"."$4"."$5" "$0}' | sort -t. -k1,1n -k2,2n -k3,3n)" if [ -z "$links_and_versions" ] - then echo "**ERROR** **NO_URL**" ; return 1 ; fi + then + echo "**ERROR**" + echo "**NO_URL**" + return 1 + fi local latest="$(echo "$links_and_versions" | tail -n 1)" local linkStr="$(echo "$latest" | cut -d' ' -f2-)" @@ -2472,7 +2481,11 @@ _GetLatestFWUpdateVersionFromWebsite_() local correct_link="$(echo "$linkStr" | sed 's|^/|https://sourceforge.net/|')" if [ -z "$versionStr" ] || [ -z "$correct_link" ] - then echo "**ERROR** **NO_URL**" ; return 1 ; fi + then + echo "**ERROR**" + echo "**NO_URL**" + return 1 + fi echo "$versionStr" echo "$correct_link" @@ -2494,13 +2507,15 @@ _GetLatestFWUpdateVersionFromGithub_() if [ -z "$download_url" ] then - echo "**ERROR** **NO_GITHUB_URL**" ; + echo "**ERROR**" + echo "**NO_URL**" return 1 else # Extract version from the download URL or release data local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") echo "$version" echo "$download_url" + return 0 fi } @@ -3479,16 +3494,30 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi - # Use set to read the output of the function into variables + # Use set to read the SFoutput of the function into variables # Attempt to fetch release information from the website - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + SFoutput=$(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + SFexit_status=$? + set -- $SFoutput + if [ "$#" -ne 2 ] && [ "$SFexit_status" -ne 0 ]; then + # Handle error: insufficient SFoutput from the function + Say "Error: Invalid SFOutput from website check" + _DoExit_ 1 + fi website_release_version="$1" website_release_link="$2" # Check if website fetch resulted in an error if [ "$website_release_version" = "**ERROR**" ]; then # Attempt to fetch release information from GitHub due to error from website - set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") + GIToutput=$(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") + GITexit_status=$? + set -- $GIToutput + if [ "$#" -ne 2 ] && [ "$GITexit_status" -ne 0 ]; then + # Handle error: insufficient GIToutput from the function + Say "Error: Invalid GIToutput from website check" + _DoExit_ 1 + fi github_release_version="$1" github_release_link="$2" @@ -3496,9 +3525,9 @@ Please manually update to version $minimum_supported_version or higher to use th # Use release information from GitHub if available if [ -n "$github_release_link" ]; then + Say "Using release information for Gnuton" release_version="$github_release_version" release_link="$github_release_link" - Say "Using release information for Gnuton" GnutonFlag="true" checkChangeLogSetting="DISABLED" Update_Custom_Settings "CheckChangeLog" "DISABLED" @@ -3507,10 +3536,10 @@ Please manually update to version $minimum_supported_version or higher to use th # Implement failure handling logic here fi else + Say "Using release information for Merlin" # No error from website fetch, use its release information release_version="$website_release_version" release_link="$website_release_link" - Say "Using release information for Merlin" fi if [ "$release_version" = "**ERROR**" ] && [ "$release_link" = "**NO_URL**" ] From 3a1b9976d78b850df4c98fc4003d83b615650d26 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 15 Apr 2024 10:40:33 -0400 Subject: [PATCH 007/185] Update MerlinAU.sh --- MerlinAU.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f1f78b66..9a916949 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2515,7 +2515,7 @@ _GetLatestFWUpdateVersionFromGithub_() local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") echo "$version" echo "$download_url" - return 0 + return 0 fi } @@ -3498,10 +3498,10 @@ Please manually update to version $minimum_supported_version or higher to use th # Attempt to fetch release information from the website SFoutput=$(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") SFexit_status=$? - set -- $SFoutput + set -- "$SFoutput" if [ "$#" -ne 2 ] && [ "$SFexit_status" -ne 0 ]; then # Handle error: insufficient SFoutput from the function - Say "Error: Invalid SFOutput from website check" + Say "Error: Invalid SFOutput from website check, exit status $SFexit_status" _DoExit_ 1 fi website_release_version="$1" @@ -3512,10 +3512,10 @@ Please manually update to version $minimum_supported_version or higher to use th # Attempt to fetch release information from GitHub due to error from website GIToutput=$(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") GITexit_status=$? - set -- $GIToutput + set -- "$GIToutput" if [ "$#" -ne 2 ] && [ "$GITexit_status" -ne 0 ]; then # Handle error: insufficient GIToutput from the function - Say "Error: Invalid GIToutput from website check" + Say "Error: Invalid GIToutput from website check, exit status $GITexit_status" _DoExit_ 1 fi github_release_version="$1" @@ -3528,7 +3528,7 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Using release information for Gnuton" release_version="$github_release_version" release_link="$github_release_link" - GnutonFlag="true" + GnutonFlag="true" checkChangeLogSetting="DISABLED" Update_Custom_Settings "CheckChangeLog" "DISABLED" else From 089208fa41b39d23948273895e3696af21b6e200 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 15 Apr 2024 10:42:24 -0400 Subject: [PATCH 008/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9a916949..8571c012 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3502,7 +3502,7 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$#" -ne 2 ] && [ "$SFexit_status" -ne 0 ]; then # Handle error: insufficient SFoutput from the function Say "Error: Invalid SFOutput from website check, exit status $SFexit_status" - _DoExit_ 1 + return 1 fi website_release_version="$1" website_release_link="$2" @@ -3516,7 +3516,7 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$#" -ne 2 ] && [ "$GITexit_status" -ne 0 ]; then # Handle error: insufficient GIToutput from the function Say "Error: Invalid GIToutput from website check, exit status $GITexit_status" - _DoExit_ 1 + return 1 fi github_release_version="$1" github_release_link="$2" From 18796b726ed3f3545b194ef461014d7c2d633fe6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 15 Apr 2024 10:56:40 -0400 Subject: [PATCH 009/185] Update MerlinAU.sh --- MerlinAU.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8571c012..47460898 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4924,13 +4924,8 @@ _ProcessMeshNodes_() else if [ "$includeExtraLogic" -eq 1 ]; then printf "\n${padStr}${padStr}${padStr}${REDct}No AiMesh Node(s)${NOct}" - else - Say "No AiMesh Node(s). Disabling AiMesh verification." fi fi - else - # Else statement for when not running on primary router # - Say "Not running on Primary Router. Skipping AiMesh verification." fi } From d307d7a634fb0fc10e8213fd11dc1ce254da90dd Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 15 Apr 2024 11:49:34 -0400 Subject: [PATCH 010/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 47460898..e83b550f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3498,7 +3498,7 @@ Please manually update to version $minimum_supported_version or higher to use th # Attempt to fetch release information from the website SFoutput=$(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") SFexit_status=$? - set -- "$SFoutput" + set -- $SFoutput if [ "$#" -ne 2 ] && [ "$SFexit_status" -ne 0 ]; then # Handle error: insufficient SFoutput from the function Say "Error: Invalid SFOutput from website check, exit status $SFexit_status" @@ -3512,7 +3512,7 @@ Please manually update to version $minimum_supported_version or higher to use th # Attempt to fetch release information from GitHub due to error from website GIToutput=$(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") GITexit_status=$? - set -- "$GIToutput" + set -- $GIToutput if [ "$#" -ne 2 ] && [ "$GITexit_status" -ne 0 ]; then # Handle error: insufficient GIToutput from the function Say "Error: Invalid GIToutput from website check, exit status $GITexit_status" From e3db8ad4cd166f132fac867e95883bf5843df55b Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 16 Apr 2024 00:49:06 -0400 Subject: [PATCH 011/185] Update MerlinAU.sh --- MerlinAU.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e83b550f..37914edf 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2461,11 +2461,7 @@ _GetLatestFWUpdateVersionFromWebsite_() awk -F'[_\.]' '{print $3"."$4"."$5" "$0}' | sort -t. -k1,1n -k2,2n -k3,3n)" if [ -z "$links_and_versions" ] - then - echo "**ERROR**" - echo "**NO_URL**" - return 1 - fi + then echo "**ERROR** **NO_URL**" ; return 1 ; fi local latest="$(echo "$links_and_versions" | tail -n 1)" local linkStr="$(echo "$latest" | cut -d' ' -f2-)" @@ -2481,11 +2477,7 @@ _GetLatestFWUpdateVersionFromWebsite_() local correct_link="$(echo "$linkStr" | sed 's|^/|https://sourceforge.net/|')" if [ -z "$versionStr" ] || [ -z "$correct_link" ] - then - echo "**ERROR**" - echo "**NO_URL**" - return 1 - fi + then echo "**ERROR** **NO_URL**" ; return 1 ; fi echo "$versionStr" echo "$correct_link" @@ -2506,10 +2498,8 @@ _GetLatestFWUpdateVersionFromGithub_() local download_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\"" | grep -o "https://[^ ]*\.w" | head -1) if [ -z "$download_url" ] - then - echo "**ERROR**" - echo "**NO_URL**" - return 1 + then echo "**ERROR** **NO_URL**" ; return 1 ; fi + else # Extract version from the download URL or release data local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") From 5db6c31d8efcbf4b85143431f83be9e26e82c29d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 16 Apr 2024 02:11:20 -0400 Subject: [PATCH 012/185] Update MerlinAU.sh --- MerlinAU.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index 37914edf..5e0c8fb9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2094,6 +2094,7 @@ _GetPasswordInput_() PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" echo ; _ShowPSWDPrompt_ + local savedIFS="$IFS" while IFS='' theChar="$(_GetKeypress_)" do charNum="$(printf "%d" "'$theChar")" @@ -2162,6 +2163,7 @@ _GetPasswordInput_() fi fi done + IFS="$savedIFS" pswdString="$PSWDstring" return "$retCode" From 9b1a709e76eb438453a64bb5d93ac5fd3c542753 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 16 Apr 2024 02:13:53 -0400 Subject: [PATCH 013/185] Update MerlinAU.sh --- MerlinAU.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5e0c8fb9..102c630c 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2500,8 +2500,9 @@ _GetLatestFWUpdateVersionFromGithub_() local download_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\"" | grep -o "https://[^ ]*\.w" | head -1) if [ -z "$download_url" ] - then echo "**ERROR** **NO_URL**" ; return 1 ; fi - + then + echo "**ERROR** **NO_GITHUB_URL**" ; + return 1 else # Extract version from the download URL or release data local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") From 64d0e06610d6efb814b75054c454ee57de60a479 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 16 Apr 2024 08:30:09 -0400 Subject: [PATCH 014/185] Update MerlinAU.sh --- MerlinAU.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 102c630c..e40b5501 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5036,15 +5036,14 @@ _ShowNodesMenuOptions_() # Main Menu loop inMenuMode=true HIDE_ROUTER_SECTION=false +if ! node_list="$(_GetNodeIPv4List_)" +then node_list="" ; fi while true do # Check if the directory exists again before attempting to navigate to it [ -d "$FW_BIN_DIR" ] && cd "$FW_BIN_DIR" - if ! node_list="$(_GetNodeIPv4List_)" - then node_list="" ; fi - _ShowMainMenu_ printf "Enter selection: " ; read -r userChoice echo From 4a27b959a411e3ec9bd39baa0047cb91656d83d4 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 16 Apr 2024 08:43:25 -0400 Subject: [PATCH 015/185] Update MerlinAU.sh --- MerlinAU.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d541d81d..e40b5501 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3537,9 +3537,6 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$release_version" = "**ERROR**" ] && [ "$release_link" = "**NO_URL**" ] then - release_version="$1" - release_link="$2" - else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 From 072cae2202dfc67ee7c1a4415f65d7151dfd9114 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 17 Apr 2024 22:31:26 -0400 Subject: [PATCH 016/185] Update MerlinAU.sh --- MerlinAU.sh | 111 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 33 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e40b5501..9db73a28 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2532,6 +2532,28 @@ GetLatestFirmwareMD5Url() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-17] ## +##---------------------------------------## +GetLatestChangelogUrl() { + local url="$1" # GitHub API URL for the latest release + + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + + # Parse the release data to find the download URL of the CHANGELOG file + # Directly find the URL without matching a specific model number + local changelog_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*CHANGELOG.*\"" | grep -o "https://[^ ]*\"" | tr -d '"' | head -1) + + # Check if the URL has been found + if [ -z "$changelog_url" ]; then + echo "**ERROR** **NO_CHANGELOG_FILE_URL_FOUND**" + return 1 + else + echo "$changelog_url" + fi +} + ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -3515,21 +3537,20 @@ Please manually update to version $minimum_supported_version or higher to use th github_release_link="$2" md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") # Use release information from GitHub if available if [ -n "$github_release_link" ]; then - Say "Using release information for Gnuton" + Say "Using release information for Gnuton Firmware." release_version="$github_release_version" release_link="$github_release_link" GnutonFlag="true" - checkChangeLogSetting="DISABLED" - Update_Custom_Settings "CheckChangeLog" "DISABLED" else Say "No valid release information found from GitHub." # Implement failure handling logic here fi else - Say "Using release information for Merlin" + Say "Using release information for Merlin Firmware." # No error from website fetch, use its release information release_version="$website_release_version" release_link="$website_release_link" @@ -3684,8 +3705,14 @@ Please manually update to version $minimum_supported_version or higher to use th # Combine path, custom file name, and extension before download FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" + FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" wget -O "$FW_DL_FPATH" "$release_link" + Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" + echo wget -O "$FW_MD5_GITHUB" "$md5_url" + Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" + echo + wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" else # Follow redirects and capture the effective URL local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") @@ -3768,8 +3795,15 @@ Please manually update to version $minimum_supported_version or higher to use th else if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" then - cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" - cp "$FW_DL_FPATH" "$FW_BIN_DIR" + if [ "$FW_DL_FPATH" != "$FW_BIN_DIR" ]; then + cp "$FW_DL_FPATH" "$FW_BIN_DIR" + fi + if [ "$FW_MD5_GITHUB" != "$FW_BIN_DIR" ]; then + cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" + fi + if [ "$FW_Changelog_GITHUB" != "$FW_BIN_DIR" ]; then + cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" + fi elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then #-------------------------------------------------------------# @@ -3801,9 +3835,14 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$checkChangeLogSetting" = "ENABLED" ] then - # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" - changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" + # Check if the GnutonFlag is set to true, if so, use the special changelog file + if [ "$GnutonFlag" = "true" ]; then + changeLogFile="$FW_Changelog_GITHUB" + else + # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" + fi if [ ! -f "$changeLogFile" ] then @@ -3832,34 +3871,40 @@ Please manually update to version $minimum_supported_version or higher to use th release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - # Check if the current version is present in the changelog - if ! grep -Eq "$current_version_regex" "$changeLogFile"; then - Say "Current version not found in change-log. Bypassing change-log verification for this run." + ## Check if the current version is present in the changelog + if [ "$GnutonFlag" = "true" ]; then + # For Gnuton, the whole file is relevant as it only contains the current version + changelog_contents="$(cat "$changeLogFile")" else - # Extract log contents between two firmware versions - changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" - # Define high-risk terms as a single string separated by '|' - high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" - - # Search for high-risk terms in the extracted log contents - if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then - if [ "$inMenuMode" = true ]; then - printf "\n ${REDct}Warning: Found high-risk phrases in the change-log.${NOct}" - printf "\n ${REDct}Would you like to continue anyways?${NOct}" - if ! _WaitForYESorNO_ ; then - Say "Exiting for change-log review." - _DoCleanUp_ 1 ; return 1 - fi - else - Say "Warning: Found high-risk phrases in the change-log." - Say "Please run script interactively to approve the upgrade." - _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL - _DoCleanUp_ 1 - _DoExit_ 1 + if ! grep -Eq "$current_version_regex" "$changeLogFile"; then + Say "Current version not found in change-log. Bypassing change-log verification for this run." + return 1 + else + # Extract log contents between two firmware versions for non-Gnuton changelogs + changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" + fi + fi + + high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" + + # Search for high-risk terms in the extracted log contents + if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then + if [ "$inMenuMode" = true ]; then + printf "\n ${REDct}Warning: Found high-risk phrases in the change-log.${NOct}" + printf "\n ${REDct}Would you like to continue anyways?${NOct}" + if ! _WaitForYESorNO_ ; then + Say "Exiting for change-log review." + _DoCleanUp_ 1 ; return 1 fi else - Say "No high-risk phrases found in the change-log." + Say "Warning: Found high-risk phrases in the change-log." + Say "Please run script interactively to approve the upgrade." + _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL + _DoCleanUp_ 1 + _DoExit_ 1 fi + else + Say "No high-risk phrases found in the change-log." fi fi else From f8474184adb0cc2371e77a494f18e377b57859a6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 12:50:52 -0400 Subject: [PATCH 017/185] Update MerlinAU.sh --- MerlinAU.sh | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9db73a28..243546aa 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -30,7 +30,6 @@ DLRepoVersion="" # For supported version and model checks # MinFirmwareCheckFailed=0 ModelCheckFailed=0 -GnutonFlag="" readonly ScriptFileName="${0##*/}" readonly ScriptFNameTag="${ScriptFileName%%.*}" @@ -477,7 +476,6 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -#DEBUGONLY#readonly PRODUCT_ID="RT-AX92U" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1217,6 +1215,33 @@ _GetLatestFWUpdateVersionFromRouter_() echo "$newVersionStr" ; return "$retCode" } +_GetFirmwareVariantFromRouter_() +{ + local retCode=0 newVersionStr + + newVersionStr="$(nvram get webs_state_info | sed 's/_/./g')" + if [ $# -eq 0 ] || [ -z "$1" ] + then + newVersionStr="$(echo "$newVersionStr" | awk -F '-' '{print $1}')" + fi + + ##FOR TESTING/DEBUG ONLY## + if false # Change to true for forcing GNUton flag + then + isGNUtonFW=true + else + # Check if the version string contains "gnuton" + if echo "$newVersionStr" | grep -iq "gnuton"; then + isGNUtonFW=true + else + isGNUtonFW=false + fi + fi + + [ -z "$isGNUtonFW" ] && retCode=1 + echo "$isGNUtonFW" ; return "$retCode" +} + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Apr-02] ## ##------------------------------------------## @@ -1690,7 +1715,6 @@ _GetCurrentFWInstalledShortVersion_() { ##FOR TESTING/DEBUG ONLY## if true ; then echo "388.5.0" ; return 0 ; fi -##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum @@ -3544,7 +3568,6 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Using release information for Gnuton Firmware." release_version="$github_release_version" release_link="$github_release_link" - GnutonFlag="true" else Say "No valid release information found from GitHub." # Implement failure handling logic here @@ -3693,7 +3716,7 @@ Please manually update to version $minimum_supported_version or higher to use th wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - if [ "$GnutonFlag" = "true" ]; then + if [ "$isGNUtonFW" = "true" ]; then # Follow redirects and capture the effective URL local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") # Use the effective URL to capture the Content-Disposition header @@ -3746,7 +3769,7 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Mar-19] ## ##------------------------------------------## - if [ ! "$GnutonFlag" = "true" ]; then + if [ ! "$isGNUtonFW" = "true" ]; then Say "-----------------------------------------------------------" # List & log the contents of the ZIP file # unzip -l "$FW_ZIP_FPATH" 2>&1 | \ @@ -3835,8 +3858,8 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$checkChangeLogSetting" = "ENABLED" ] then - # Check if the GnutonFlag is set to true, if so, use the special changelog file - if [ "$GnutonFlag" = "true" ]; then + # Check if the isGNUtonFW is set to true, if so, use the special changelog file + if [ "$isGNUtonFW" = "true" ]; then changeLogFile="$FW_Changelog_GITHUB" else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # @@ -3872,7 +3895,7 @@ Please manually update to version $minimum_supported_version or higher to use th current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" ## Check if the current version is present in the changelog - if [ "$GnutonFlag" = "true" ]; then + if [ "$isGNUtonFW" = "true" ]; then # For Gnuton, the whole file is relevant as it only contains the current version changelog_contents="$(cat "$changeLogFile")" else @@ -3962,7 +3985,7 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-03] ## ##------------------------------------------## - if [ ! "$GnutonFlag" = "true" ]; then + if [ ! "$isGNUtonFW" = "true" ]; then if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" @@ -4738,6 +4761,13 @@ _ShowMainMenu_() then notificationStr="${REDct}NOT SET${NOct}" else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}" fi + isGNUtonFW=$(_GetFirmwareVariantFromRouter_) + # Use the global variable + if [ "$isGNUtonFW" = "true" ]; then + FirmwareFlavor="${GRNct}GNUton${NOct}" + else + FirmwareFlavor="${GRNct}Merlin${NOct}" + fi ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Mar-27] ## @@ -4750,6 +4780,7 @@ _ShowMainMenu_() else FW_NewUpdateVersion="${GRNct}${FW_NewUpdateVersion}${NOct}$arrowStr" fi printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(H)ide" + printf "\n${padStr}F/W Variant Detected: $FirmwareFlavor" printf "\n${padStr}F/W Update Available: $FW_NewUpdateVersion" printf "\n${padStr}F/W Version Installed: $FW_InstalledVersion" printf "\n${padStr}USB Storage Connected: $USBConnected" From ff4b69e5a9f1fc06e3e60d8a92f23c46bfc7a73f Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 13:39:13 -0400 Subject: [PATCH 018/185] Update MerlinAU.sh --- MerlinAU.sh | 68 ++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 243546aa..077d6dc8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,6 +476,7 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" +#DEBUGONLY# readonly PRODUCT_ID="RT-AX92U" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -3533,58 +3534,29 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi - # Use set to read the SFoutput of the function into variables - # Attempt to fetch release information from the website - SFoutput=$(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - SFexit_status=$? - set -- $SFoutput - if [ "$#" -ne 2 ] && [ "$SFexit_status" -ne 0 ]; then - # Handle error: insufficient SFoutput from the function - Say "Error: Invalid SFOutput from website check, exit status $SFexit_status" - return 1 - fi - website_release_version="$1" - website_release_link="$2" - - # Check if website fetch resulted in an error - if [ "$website_release_version" = "**ERROR**" ]; then - # Attempt to fetch release information from GitHub due to error from website - GIToutput=$(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") - GITexit_status=$? - set -- $GIToutput - if [ "$#" -ne 2 ] && [ "$GITexit_status" -ne 0 ]; then - # Handle error: insufficient GIToutput from the function - Say "Error: Invalid GIToutput from website check, exit status $GITexit_status" - return 1 - fi - github_release_version="$1" - github_release_link="$2" - - md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - - # Use release information from GitHub if available - if [ -n "$github_release_link" ]; then - Say "Using release information for Gnuton Firmware." - release_version="$github_release_version" - release_link="$github_release_link" - else - Say "No valid release information found from GitHub." - # Implement failure handling logic here - fi - else - Say "Using release information for Merlin Firmware." - # No error from website fetch, use its release information - release_version="$website_release_version" - release_link="$website_release_link" - fi + if "$isGNUtonFW" + then + Say "Using release information for Gnuton Firmware." + md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") + rectCode="$?" + else + Say "Using release information for Merlin Firmware." + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + rectCode="$?" + fi - if [ "$release_version" = "**ERROR**" ] && [ "$release_link" = "**NO_URL**" ] - then + if [ "$rectCode" -eq 0 ] && [ "$#" -eq 2 ] && \ + [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] + then + release_version="$1" + release_link="$2" + else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 - fi + fi # Extracting the first octet to use in the curl firstOctet="$(echo "$release_version" | cut -d'.' -f1)" From 5a059f27e5aeb92e2a21a12fc1325847054f002a Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 13:44:28 -0400 Subject: [PATCH 019/185] Update MerlinAU.sh --- MerlinAU.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 077d6dc8..117935dc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4735,7 +4735,8 @@ _ShowMainMenu_() fi isGNUtonFW=$(_GetFirmwareVariantFromRouter_) # Use the global variable - if [ "$isGNUtonFW" = "true" ]; then + if "$isGNUtonFW" + then FirmwareFlavor="${GRNct}GNUton${NOct}" else FirmwareFlavor="${GRNct}Merlin${NOct}" From 7e3d0bbaa99b8fe67185bb82441bbc2c9dc0a3de Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 14:03:04 -0400 Subject: [PATCH 020/185] Update MerlinAU.sh --- MerlinAU.sh | 132 ++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 71 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 117935dc..83244fe3 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2579,6 +2579,63 @@ GetLatestChangelogUrl() { fi } +_UnzipMerlin_() { + Say "-----------------------------------------------------------" + # List & log the contents of the ZIP file + unzip -l "$FW_ZIP_FPATH" 2>&1 | \ + while IFS= read -r uzLINE ; do Say "$uzLINE" ; done + Say "-----------------------------------------------------------" + + # Extracting the firmware binary image + if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ + while IFS= read -r line ; do Say "$line" ; done + then + Say "-----------------------------------------------------------" + # Check if ZIP file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # It's not on a USB drive, so it's safe to delete it + rm -f "$FW_ZIP_FPATH" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + "$inMenuMode" && _WaitForEnterKey_ + # Consider how to handle this error. For now, we'll not delete the ZIP file. + else + keepZIPfile=1 + fi + else + # Remove ZIP file here because it may have been corrupted. + # Better to download it again and start all over, instead + # of trying to figure out why uncompressing it failed. + rm -f "$FW_ZIP_FPATH" + _SendEMailNotification_ FAILED_FW_UNZIP_STATUS + Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi +} + +_CopyGnutonFiles_() { + # Check if the download path is on a USB-attached drive or specific directories + if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # Copy the firmware and associated files to the binary directory + cp "$FW_DL_FPATH" "$FW_BIN_DIR" + cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" + cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + # Report error if the USB mount point is not valid + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + "$inMenuMode" && _WaitForEnterKey_ + # Additional handling could be added here based on your application's needs + fi +} + ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -3741,78 +3798,11 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Mar-19] ## ##------------------------------------------## - if [ ! "$isGNUtonFW" = "true" ]; then - Say "-----------------------------------------------------------" - # List & log the contents of the ZIP file # - unzip -l "$FW_ZIP_FPATH" 2>&1 | \ - while IFS= read -r uzLINE ; do Say "$uzLINE" ; done - Say "-----------------------------------------------------------" - - # Extracting the firmware binary image # - if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ - while IFS= read -r line ; do Say "$line" ; done - then - Say "-----------------------------------------------------------" - #---------------------------------------------------------------# - # Check if ZIP file was downloaded to a USB-attached drive. - # Take into account special case for Entware "/opt/" paths. - #---------------------------------------------------------------# - if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" - then - # It's not on a USB drive, so it's safe to delete it # - rm -f "$FW_ZIP_FPATH" - elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 - then - #-------------------------------------------------------------# - # This should not happen because we already checked for it - # at the very beginning of this function, but just in case - # it does (drive going bad suddenly?) we'll report it here. - #-------------------------------------------------------------# - Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." - Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ - # Consider how to handle this error. For now, we'll not delete the ZIP file. - else - keepZIPfile=1 - fi - else - #------------------------------------------------------------# - # Remove ZIP file here because it may have been corrupted. - # Better to download it again and start all over, instead - # of trying to figure out why uncompressing it failed. - #------------------------------------------------------------# - rm -f "$FW_ZIP_FPATH" - _SendEMailNotification_ FAILED_FW_UNZIP_STATUS - Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - fi + if "$isGNUtonFW" + then + _CopyGnutonFiles_ else - if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" - then - if [ "$FW_DL_FPATH" != "$FW_BIN_DIR" ]; then - cp "$FW_DL_FPATH" "$FW_BIN_DIR" - fi - if [ "$FW_MD5_GITHUB" != "$FW_BIN_DIR" ]; then - cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" - fi - if [ "$FW_Changelog_GITHUB" != "$FW_BIN_DIR" ]; then - cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" - fi - elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 - then - #-------------------------------------------------------------# - # This should not happen because we already checked for it - # at the very beginning of this function, but just in case - # it does (drive going bad suddenly?) we'll report it here. - #-------------------------------------------------------------# - Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." - Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ - # Consider how to handle this error. For now, we'll not delete the ZIP file. - else - echo - fi + _UnzipMerlin_ fi freeRAM_kb="$(_GetFreeRAM_KB_)" From 84537af8d697b576921e83187c61f702004fccb2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 14:07:01 -0400 Subject: [PATCH 021/185] Update MerlinAU.sh --- MerlinAU.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 83244fe3..8cf40da8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2591,14 +2591,21 @@ _UnzipMerlin_() { while IFS= read -r line ; do Say "$line" ; done then Say "-----------------------------------------------------------" + #---------------------------------------------------------------# # Check if ZIP file was downloaded to a USB-attached drive. # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" then # It's not on a USB drive, so it's safe to delete it rm -f "$FW_ZIP_FPATH" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then + -------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." "$inMenuMode" && _WaitForEnterKey_ @@ -2607,9 +2614,11 @@ _UnzipMerlin_() { keepZIPfile=1 fi else + #------------------------------------------------------------# # Remove ZIP file here because it may have been corrupted. # Better to download it again and start all over, instead # of trying to figure out why uncompressing it failed. + #------------------------------------------------------------# rm -f "$FW_ZIP_FPATH" _SendEMailNotification_ FAILED_FW_UNZIP_STATUS Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." @@ -2628,11 +2637,14 @@ _CopyGnutonFiles_() { cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then - # Report error if the USB mount point is not valid + #-------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." "$inMenuMode" && _WaitForEnterKey_ - # Additional handling could be added here based on your application's needs fi } From c6a9befad8989a0564f7113290495c58b5a76095 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 22:24:47 -0400 Subject: [PATCH 022/185] Update MerlinAU.sh --- MerlinAU.sh | 251 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 147 insertions(+), 104 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8cf40da8..8f440bb4 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,7 +476,7 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -#DEBUGONLY# readonly PRODUCT_ID="RT-AX92U" +#DEBUGONLY#readonly PRODUCT_ID="RT-AX92U" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -2579,6 +2579,67 @@ GetLatestChangelogUrl() { fi } +_DownloadForGnuton_() { + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + # Extract the file extension + local extension="${sanitized_filename##*.}" + + # Combine path, custom file name, and extension before download + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" + FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + + # Download the firmware using the release link + wget -O "$FW_DL_FPATH" "$release_link" + + Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" + # Download the latest MD5 checksum + wget -O "$FW_MD5_GITHUB" "$md5_url" + + Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" + # Download the latest changelog + wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" +} + +_DownloadForMerlin_() { + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + + # Extract the filename from the URL + local original_filename="${effective_url##*/}" + + # Sanitize filename by removing problematic characters (if necessary) + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + # Extract the file extension + local extension="${sanitized_filename##*.}" + + # Combine path, custom file name, and extension before download + local FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + + # Download the file using the release link + wget -O "$FW_DL_FPATH" "$release_link" + + # Check if the file was downloaded successfully + if [ ! -f "$FW_DL_FPATH" ]; then + Say "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_DL_FPATH] was not downloaded." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + fi + return 1 + fi +} + _UnzipMerlin_() { Say "-----------------------------------------------------------" # List & log the contents of the ZIP file @@ -2648,6 +2709,78 @@ _CopyGnutonFiles_() { fi } +_CheckFirmwareSHA256_() { + # Check if both the SHA256 signature file and the firmware file exist + if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then + # Extract the SHA256 signature from the firmware file + local fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" + # Extract the recorded SHA256 signature from the checksum file + local dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" + + # Compare the extracted signature and the recorded signature + if [ "$fw_sig" != "$dl_sig" ]; then + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Non-interactive mode; perform an exit. + _DoExit_ 1 + fi + fi + else + Say "${REDct}**ERROR**${NOct}: SHA256 signature file or firmware file not found!" + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Non-interactive mode; perform an exit. + _DoExit_ 1 + fi + fi +} + +_CheckFirmwareMD5_() { + # Check if both the MD5 checksum file and the firmware file exist + if [ -f "$FW_MD5_GITHUB" ] && [ -f "$firmware_file" ]; then + # Extract the MD5 checksum from the downloaded .md5 file + # Assuming the .md5 file contains a single line with the checksum followed by the filename + local md5_expected=$(cut -d' ' -f1 "$FW_MD5_GITHUB") + + # Calculate the MD5 checksum of the firmware file + local md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) + + # Compare the calculated MD5 checksum with the expected MD5 checksum + if [ "$md5_actual" != "$md5_expected" ]; then + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Non-interactive mode; perform exit. + _DoExit_ 1 + fi + else + Say "Firmware MD5 checksum verified successfully." + fi + else + Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Non-interactive mode; perform exit. + _DoExit_ 1 + fi + fi +} + ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -3757,46 +3890,12 @@ Please manually update to version $minimum_supported_version or higher to use th wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - if [ "$isGNUtonFW" = "true" ]; then - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") - # Use the effective URL to capture the Content-Disposition header - local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') - # Sanitize filename by removing problematic characters - local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - # Extract the file extension - extension="${sanitized_filename##*.}" - # Combine path, custom file name, and extension before download - FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" - FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" - FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" - wget -O "$FW_DL_FPATH" "$release_link" - Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" - echo - wget -O "$FW_MD5_GITHUB" "$md5_url" - Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" - echo - wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + if "$isGNUtonFW" + then + _DownloadForGnuton_ else - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") - # Extract the filename from the URL - original_filename="${effective_url##*/}" - # Sanitize filename by removing problematic characters (if necessary) - sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - # Extract the file extension - extension="${sanitized_filename##*.}" - # Combine path, custom file name, and extension before download - FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" - wget -O "$FW_DL_FPATH" "$release_link" - - if [ ! -f "$FW_ZIP_FPATH" ] - then - ay "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_ZIP_FPATH] was not downloaded." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - fi - fi + _DownloadForMerlin_ + fi fi ##------------------------------------------## @@ -3832,8 +3931,8 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$checkChangeLogSetting" = "ENABLED" ] then - # Check if the isGNUtonFW is set to true, if so, use the special changelog file - if [ "$isGNUtonFW" = "true" ]; then + if "$isGNUtonFW" + then changeLogFile="$FW_Changelog_GITHUB" else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # @@ -3868,8 +3967,8 @@ Please manually update to version $minimum_supported_version or higher to use th release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - ## Check if the current version is present in the changelog - if [ "$isGNUtonFW" = "true" ]; then + if "$isGNUtonFW" + then # For Gnuton, the whole file is relevant as it only contains the current version changelog_contents="$(cat "$changeLogFile")" else @@ -3959,67 +4058,11 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-03] ## ##------------------------------------------## - if [ ! "$isGNUtonFW" = "true" ]; then - if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then - fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" - if [ "$fw_sig" != "$dl_sig" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" - _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - fi - else - Say "${REDct}**ERROR**${NOct}: SHA256 signature file not found!" - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - fi + if "$isGNUtonFW" + then + _CheckFirmwareMD5_ else - if [ -f "$FW_MD5_GITHUB" ] && [ -f "$firmware_file" ]; then - # Extract the MD5 checksum from the downloaded .md5 file - # Assuming the .md5 file contains a single line with the checksum followed by the filename - md5_expected=$(cut -d' ' -f1 "$FW_MD5_GITHUB") - - # Calculate the MD5 checksum of the firmware file - md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) - - if [ "$md5_actual" != "$md5_expected" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" - _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - else - Say "Firmware MD5 checksum verified successfully." - fi - else - Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - fi + _CheckFirmwareSHA256_ fi ##----------------------------------------## From 4e172c33ce87434fba62d02555e67d2ea70fc585 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 22:33:45 -0400 Subject: [PATCH 023/185] Update MerlinAU.sh --- MerlinAU.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8f440bb4..c52a6e5f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2581,9 +2581,6 @@ GetLatestChangelogUrl() { _DownloadForGnuton_() { - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") - # Use the effective URL to capture the Content-Disposition header local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') @@ -2600,20 +2597,38 @@ _DownloadForGnuton_() { # Download the firmware using the release link wget -O "$FW_DL_FPATH" "$release_link" + if [ ! -f "$FW_DL_FPATH" ]; then + Say "${REDct}**ERROR**${NOct}: Firmware file [$FW_DL_FPATH] was not downloaded successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + fi + return 1 + fi - Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" # Download the latest MD5 checksum + Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" wget -O "$FW_MD5_GITHUB" "$md5_url" + if [ ! -f "$FW_MD5_GITHUB" ]; then + Say "${REDct}**ERROR**${NOct}: MD5 checksum file [$FW_MD5_GITHUB] was not downloaded successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + fi + return 1 + fi - Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" # Download the latest changelog + Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + if [ ! -f "$FW_Changelog_GITHUB" ]; then + Say "${REDct}**ERROR**${NOct}: Changelog file [$FW_Changelog_GITHUB] was not downloaded successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + fi + return 1 + fi } _DownloadForMerlin_() { - - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") # Extract the filename from the URL local original_filename="${effective_url##*/}" @@ -3890,6 +3905,9 @@ Please manually update to version $minimum_supported_version or higher to use th wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + if "$isGNUtonFW" then _DownloadForGnuton_ From 755cf7d539851b1fd7f67601fc3637bc68f49af8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 18 Apr 2024 22:45:48 -0400 Subject: [PATCH 024/185] Update MerlinAU.sh --- MerlinAU.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c52a6e5f..377740ee 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Apr-15 +# Last Modified: 2024-Apr-18 ################################################################### set -u @@ -1216,6 +1216,9 @@ _GetLatestFWUpdateVersionFromRouter_() echo "$newVersionStr" ; return "$retCode" } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _GetFirmwareVariantFromRouter_() { local retCode=0 newVersionStr @@ -1989,7 +1992,7 @@ check_memory_and_prompt_reboot() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jan-06] ## +## Modified by ExtremeFiretop [2024-Apr-18] ## ##------------------------------------------## # Function to check if the current router model is supported check_version_support() { @@ -2579,6 +2582,9 @@ GetLatestChangelogUrl() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _DownloadForGnuton_() { # Use the effective URL to capture the Content-Disposition header @@ -2628,6 +2634,9 @@ _DownloadForGnuton_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _DownloadForMerlin_() { # Extract the filename from the URL @@ -2655,6 +2664,9 @@ _DownloadForMerlin_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _UnzipMerlin_() { Say "-----------------------------------------------------------" # List & log the contents of the ZIP file @@ -2703,6 +2715,9 @@ _UnzipMerlin_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _CopyGnutonFiles_() { # Check if the download path is on a USB-attached drive or specific directories if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" @@ -2724,6 +2739,9 @@ _CopyGnutonFiles_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _CheckFirmwareSHA256_() { # Check if both the SHA256 signature file and the firmware file exist if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then @@ -2758,6 +2776,9 @@ _CheckFirmwareSHA256_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## _CheckFirmwareMD5_() { # Check if both the MD5 checksum file and the firmware file exist if [ -f "$FW_MD5_GITHUB" ] && [ -f "$firmware_file" ]; then @@ -2796,6 +2817,9 @@ _CheckFirmwareMD5_() { fi } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -2832,6 +2856,9 @@ _toggle_change_log_check_() { _WaitForEnterKey_ } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-27] ## ##---------------------------------------## @@ -4753,7 +4780,7 @@ _PrintNodeInfo() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Feb-19] ## +## Modified by ExtremeFiretop [2024-Apr-18] ## ##------------------------------------------## _ShowMainMenu_() { @@ -4806,7 +4833,7 @@ _ShowMainMenu_() fi ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Mar-27] ## + ## Modified by ExtremeFiretop [2024-Apr-18] ## ##------------------------------------------## printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] From 27b062816b8c047f0bf6867865446a98dd27b8d0 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 01:18:32 -0400 Subject: [PATCH 025/185] Update MerlinAU.sh --- MerlinAU.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 377740ee..6ff82295 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3923,7 +3923,7 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Latest release version is ${GRNct}${release_version}${NOct}." Say "Downloading ${GRNct}${release_link}${NOct}" - echo + echo "" ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-28] ## @@ -3933,7 +3933,7 @@ Please manually update to version $minimum_supported_version or higher to use th [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") if "$isGNUtonFW" then @@ -4593,6 +4593,7 @@ fi # it has the minimum firmware version supported. check_model_support check_version_support +isGNUtonFW=$(_GetFirmwareVariantFromRouter_) ##-------------------------------------## ## Added by Martinski W. [2024-Jan-24] ## @@ -4823,7 +4824,6 @@ _ShowMainMenu_() then notificationStr="${REDct}NOT SET${NOct}" else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}" fi - isGNUtonFW=$(_GetFirmwareVariantFromRouter_) # Use the global variable if "$isGNUtonFW" then From 00a54286ddfcdeada717fe7fcdc040ed96adc761 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 03:06:15 -0400 Subject: [PATCH 026/185] Update MerlinAU.sh --- MerlinAU.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 6ff82295..33065b76 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1224,10 +1224,6 @@ _GetFirmwareVariantFromRouter_() local retCode=0 newVersionStr newVersionStr="$(nvram get webs_state_info | sed 's/_/./g')" - if [ $# -eq 0 ] || [ -z "$1" ] - then - newVersionStr="$(echo "$newVersionStr" | awk -F '-' '{print $1}')" - fi ##FOR TESTING/DEBUG ONLY## if false # Change to true for forcing GNUton flag @@ -1242,7 +1238,6 @@ _GetFirmwareVariantFromRouter_() fi fi - [ -z "$isGNUtonFW" ] && retCode=1 echo "$isGNUtonFW" ; return "$retCode" } From 021bb76a1a6cf336b8598ebc160dbea1cfff60cf Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 05:30:55 -0400 Subject: [PATCH 027/185] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 8cfbc905..45a1b3f4 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.2 From b578f08b5e7d361043298793e286a63e27484ebc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 06:09:51 -0400 Subject: [PATCH 028/185] Update MerlinAU.sh --- MerlinAU.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 33065b76..d685addf 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4940,8 +4940,13 @@ _ShowAdvancedOptionsMenu_() # Additional Email Notification Options # if _CheckEMailConfigFileFromAMTM_ 0 then + if "$inRouterSWmode" + then + printf "\n ${GRNct}em${NOct}. Toggle F/W Update Email Notifications" + else + printf "\n ${GRNct}em${NOct}. Toggle F/W Email Notifications" + fi # F/W Update Email Notifications # - printf "\n ${GRNct}em${NOct}. Toggle F/W Update Email Notifications" if "$sendEMailNotificationsFlag" then printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}, Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" From 576a13486d21282abc414d68eb9bb70593303527 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 06:10:46 -0400 Subject: [PATCH 029/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d685addf..b0c6a552 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4940,13 +4940,13 @@ _ShowAdvancedOptionsMenu_() # Additional Email Notification Options # if _CheckEMailConfigFileFromAMTM_ 0 then + # F/W Update Email Notifications # if "$inRouterSWmode" then printf "\n ${GRNct}em${NOct}. Toggle F/W Update Email Notifications" else printf "\n ${GRNct}em${NOct}. Toggle F/W Email Notifications" fi - # F/W Update Email Notifications # if "$sendEMailNotificationsFlag" then printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}, Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" From a6e7147f77330fb58707a4c371c2ad447c325b67 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 10:26:08 -0400 Subject: [PATCH 030/185] Update MerlinAU.sh --- MerlinAU.sh | 95 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 22 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index b0c6a552..7e02b2d2 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -473,10 +473,9 @@ readonly FW_UpdateMinimumPostponementDays=0 readonly FW_UpdateDefaultPostponementDays=15 readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" - readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -#DEBUGONLY#readonly PRODUCT_ID="RT-AX92U" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="RT-AX92U" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1842,7 +1841,7 @@ _ShutDownNonCriticalServices_() ##------------------------------------------## _DoCleanUp_() { - local delBINfiles=false keepZIPfile=false moveZIPback=false + local delBINfiles=false keepZIPfile=false keepWfile=false local doTrace=false [ $# -gt 0 ] && [ "$1" -eq 0 ] && doTrace=false @@ -1854,20 +1853,35 @@ _DoCleanUp_() [ $# -gt 0 ] && [ "$1" -eq 1 ] && delBINfiles=true [ $# -gt 1 ] && [ "$2" -eq 1 ] && keepZIPfile=true + [ $# -gt 2 ] && [ "$3" -eq 1 ] && keepWfile=true # Stop the LEDs blinking # _Reset_LEDs_ 1 + # Check existence of files and preserve based on flags + local moveZIPback=false + local moveWback=false + # Move file temporarily to save it from deletion # - "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ] && \ - mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true + if "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ]; then + mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true + fi + + if "$keepWfile" && [ -f "$FW_DL_FPATH" ]; then + mv -f "$FW_DL_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveWback=true + fi rm -f "${FW_ZIP_DIR}"/* "$delBINfiles" && rm -f "${FW_BIN_DIR}"/* - # Move file back to original location # - "$keepZIPfile" && "$moveZIPback" && \ - mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" + # Move files back to their original location if they were moved + if "$moveZIPback"; then + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" + fi + + if "$moveWback"; then + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.w" "$FW_DL_FPATH" + fi if "$doTrace" then @@ -1971,7 +1985,7 @@ check_memory_and_prompt_reboot() # Restart Entware services # _EntwareServicesHandler_ start - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _DoExit_ 1 fi else @@ -2589,7 +2603,7 @@ _DownloadForGnuton_() { local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') # Extract the file extension - local extension="${sanitized_filename##*.}" + extension="${sanitized_filename##*.}" # Combine path, custom file name, and extension before download FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" @@ -2641,7 +2655,7 @@ _DownloadForMerlin_() { local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') # Extract the file extension - local extension="${sanitized_filename##*.}" + extension="${sanitized_filename##*.}" # Combine path, custom file name, and extension before download local FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" @@ -2714,16 +2728,48 @@ _UnzipMerlin_() { ## Added by ExtremeFiretop [2024-Apr-18] ## ##---------------------------------------## _CopyGnutonFiles_() { - # Check if the download path is on a USB-attached drive or specific directories - if echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + +Say "Checking if file copy is required" + +local copy_success=0 +local copy_attempted=1 + +# Check and copy the firmware file if different from destination +if [ "$FW_DL_FPATH" != "${FW_BIN_DIR}/${FW_FileName}.${extension}" ]; then + Say "File copy is required" + copy_attempted=0 + cp "$FW_DL_FPATH" "$FW_BIN_DIR" && Say "Copying firmware..." || copy_success=1 +else + Say "File copy is not required" +fi + +# Check and copy the MD5 file if different from destination +if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then + copy_attempted=0 + cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Copying MD5 file..." || copy_success=1 +fi + +# Check and copy the Changelog file if different from destination +if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then + copy_attempted=0 + cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Copying changelog..." || copy_success=1 +fi + +if [ $copy_attempted -eq 0 ] && [ $copy_success -eq 0 ] +then + #---------------------------------------------------------------# + # Check if Gntuon file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# + if ! echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" then - # Copy the firmware and associated files to the binary directory - cp "$FW_DL_FPATH" "$FW_BIN_DIR" - cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" - cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" + # It's not on a USB drive, so it's safe to delete it + rm -f "$FW_DL_FPATH" + rm -f "$FW_Changelog_GITHUB" + rm -f "$FW_MD5_GITHUB" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then - #-------------------------------------------------------------# + -------------------------------------------------------------# # This should not happen because we already checked for it # at the very beginning of this function, but just in case # it does (drive going bad suddenly?) we'll report it here. @@ -2731,7 +2777,11 @@ _CopyGnutonFiles_() { Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." "$inMenuMode" && _WaitForEnterKey_ + # Consider how to handle this error. For now, we'll not delete the firmware file. + else + keepWfile=1 fi +fi } ##---------------------------------------## @@ -3973,7 +4023,7 @@ Please manually update to version $minimum_supported_version or higher to use th then if "$isGNUtonFW" then - changeLogFile="$FW_Changelog_GITHUB" + changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" @@ -4124,7 +4174,7 @@ Please manually update to version $minimum_supported_version or higher to use th if ! _WaitForYESorNO_ "Continue?" then Say "F/W Update was cancelled by user." - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" return 1 fi fi @@ -4223,7 +4273,7 @@ Please manually update to version $minimum_supported_version or higher to use th 2. Update credentials by selecting \"Set Router Login Credentials\" from the Main Menu." _SendEMailNotification_ FAILED_FW_UPDATE_STATUS - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _EntwareServicesHandler_ start fi @@ -4567,7 +4617,8 @@ _SetSecondaryEMailAddress_() } keepZIPfile=0 -trap '_DoCleanUp_ 0 "$keepZIPfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM +keepWfile=0 +trap '_DoCleanUp_ 0 "$keepZIPfile" "$keepWfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-28] ## From 5d89d92128a42d12b2f7faeabf3216f68d54e3ba Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 10:27:42 -0400 Subject: [PATCH 031/185] Update MerlinAU.sh --- MerlinAU.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index 7e02b2d2..c650a106 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -473,6 +473,7 @@ readonly FW_UpdateMinimumPostponementDays=0 readonly FW_UpdateDefaultPostponementDays=15 readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" + readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" ##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="RT-AX92U" From dff2bf58663a4608f474e63c9523ddab5e270493 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 11:32:12 -0400 Subject: [PATCH 032/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c650a106..141fd5f4 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1223,7 +1223,7 @@ _GetFirmwareVariantFromRouter_() { local retCode=0 newVersionStr - newVersionStr="$(nvram get webs_state_info | sed 's/_/./g')" + buildInfoStr="$(nvram get buildinfo)" ##FOR TESTING/DEBUG ONLY## if false # Change to true for forcing GNUton flag @@ -1231,7 +1231,7 @@ _GetFirmwareVariantFromRouter_() isGNUtonFW=true else # Check if the version string contains "gnuton" - if echo "$newVersionStr" | grep -iq "gnuton"; then + if echo "$buildInfoStr" | grep -iq "merlin"; then isGNUtonFW=true else isGNUtonFW=false From 9dbc854f0b5c87d27d759d1cd8395a7c99d862da Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 11:34:11 -0400 Subject: [PATCH 033/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 141fd5f4..8120e78b 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1232,9 +1232,9 @@ _GetFirmwareVariantFromRouter_() else # Check if the version string contains "gnuton" if echo "$buildInfoStr" | grep -iq "merlin"; then - isGNUtonFW=true - else isGNUtonFW=false + else + isGNUtonFW=true fi fi From 8fecf48ca30957a57e9cf23cde2f3cad2ca47a36 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 18:09:28 -0400 Subject: [PATCH 034/185] Update MerlinAU.sh --- MerlinAU.sh | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8120e78b..e098e61f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2618,7 +2618,7 @@ _DownloadForGnuton_() { if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi - return 1 + _DoExit_ 1 fi # Download the latest MD5 checksum @@ -2629,7 +2629,7 @@ _DownloadForGnuton_() { if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi - return 1 + _DoExit_ 1 fi # Download the latest changelog @@ -2640,7 +2640,7 @@ _DownloadForGnuton_() { if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi - return 1 + _DoExit_ 1 fi } @@ -2670,7 +2670,7 @@ _DownloadForMerlin_() { if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi - return 1 + _DoExit_ 1 fi } @@ -2721,7 +2721,7 @@ _UnzipMerlin_() { _SendEMailNotification_ FAILED_FW_UNZIP_STATUS Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + _DoExit_ 1 fi } @@ -2730,30 +2730,30 @@ _UnzipMerlin_() { ##---------------------------------------## _CopyGnutonFiles_() { -Say "Checking if file copy is required" +Say "Checking if file management is required" local copy_success=0 local copy_attempted=1 # Check and copy the firmware file if different from destination if [ "$FW_DL_FPATH" != "${FW_BIN_DIR}/${FW_FileName}.${extension}" ]; then - Say "File copy is required" + Say "File management is required" copy_attempted=0 - cp "$FW_DL_FPATH" "$FW_BIN_DIR" && Say "Copying firmware..." || copy_success=1 + cp "$FW_DL_FPATH" "$FW_BIN_DIR" && Say "Copying firmware file..." || copy_success=1 else - Say "File copy is not required" + Say "File management is not required" fi # Check and copy the MD5 file if different from destination if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then copy_attempted=0 - cp "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Copying MD5 file..." || copy_success=1 + mv -f "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Moving MD5 file..." || copy_success=1 fi # Check and copy the Changelog file if different from destination if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then copy_attempted=0 - cp "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Copying changelog..." || copy_success=1 + mv -f "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Moving changelog file..." || copy_success=1 fi if [ $copy_attempted -eq 0 ] && [ $copy_success -eq 0 ] @@ -2803,7 +2803,7 @@ _CheckFirmwareSHA256_() { _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + _DoExit_ 1 else # Non-interactive mode; perform an exit. _DoExit_ 1 @@ -2814,7 +2814,7 @@ _CheckFirmwareSHA256_() { _DoCleanUp_ 1 if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + _DoExit_ 1 else # Non-interactive mode; perform an exit. _DoExit_ 1 @@ -2827,10 +2827,10 @@ _CheckFirmwareSHA256_() { ##---------------------------------------## _CheckFirmwareMD5_() { # Check if both the MD5 checksum file and the firmware file exist - if [ -f "$FW_MD5_GITHUB" ] && [ -f "$firmware_file" ]; then + if [ -f "${FW_BIN_DIR}/${FW_FileName}.md5" ] && [ -f "$firmware_file" ]; then # Extract the MD5 checksum from the downloaded .md5 file # Assuming the .md5 file contains a single line with the checksum followed by the filename - local md5_expected=$(cut -d' ' -f1 "$FW_MD5_GITHUB") + local md5_expected=$(cut -d' ' -f1 "${FW_BIN_DIR}/${FW_FileName}.md5") # Calculate the MD5 checksum of the firmware file local md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) @@ -2842,7 +2842,7 @@ _CheckFirmwareMD5_() { _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + _DoExit_ 1 else # Non-interactive mode; perform exit. _DoExit_ 1 @@ -2855,7 +2855,7 @@ _CheckFirmwareMD5_() { _DoCleanUp_ 1 if [ "$inMenuMode" = true ]; then _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + _DoExit_ 1 else # Non-interactive mode; perform exit. _DoExit_ 1 @@ -2863,9 +2863,6 @@ _CheckFirmwareMD5_() { fi } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## @@ -4874,9 +4871,9 @@ _ShowMainMenu_() # Use the global variable if "$isGNUtonFW" then - FirmwareFlavor="${GRNct}GNUton${NOct}" + FirmwareFlavor="${MAGENTAct}GNUton${NOct}" else - FirmwareFlavor="${GRNct}Merlin${NOct}" + FirmwareFlavor="${BLUEct}Merlin${NOct}" fi ##------------------------------------------## From 1e71943da86a2f1b0a3e24485f9b9c16ebdb4385 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 18:39:42 -0400 Subject: [PATCH 035/185] Update MerlinAU.sh --- MerlinAU.sh | 122 ++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e098e61f..28a13358 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2614,33 +2614,23 @@ _DownloadForGnuton_() { # Download the firmware using the release link wget -O "$FW_DL_FPATH" "$release_link" if [ ! -f "$FW_DL_FPATH" ]; then - Say "${REDct}**ERROR**${NOct}: Firmware file [$FW_DL_FPATH] was not downloaded successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - fi - _DoExit_ 1 + return 1 fi # Download the latest MD5 checksum Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" wget -O "$FW_MD5_GITHUB" "$md5_url" if [ ! -f "$FW_MD5_GITHUB" ]; then - Say "${REDct}**ERROR**${NOct}: MD5 checksum file [$FW_MD5_GITHUB] was not downloaded successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - fi - _DoExit_ 1 + return 1 fi # Download the latest changelog Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" if [ ! -f "$FW_Changelog_GITHUB" ]; then - Say "${REDct}**ERROR**${NOct}: Changelog file [$FW_Changelog_GITHUB] was not downloaded successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - fi - _DoExit_ 1 + return 1 + else + return 0 fi } @@ -2666,11 +2656,9 @@ _DownloadForMerlin_() { # Check if the file was downloaded successfully if [ ! -f "$FW_DL_FPATH" ]; then - Say "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_DL_FPATH] was not downloaded." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - fi - _DoExit_ 1 + return 1 + else + return 0 fi } @@ -2706,7 +2694,7 @@ _UnzipMerlin_() { #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ + return 1 # Consider how to handle this error. For now, we'll not delete the ZIP file. else keepZIPfile=1 @@ -2720,9 +2708,9 @@ _UnzipMerlin_() { rm -f "$FW_ZIP_FPATH" _SendEMailNotification_ FAILED_FW_UNZIP_STATUS Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - _DoExit_ 1 + _return 1 fi + return 0 } ##---------------------------------------## @@ -2777,12 +2765,13 @@ then #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ + return 1 # Consider how to handle this error. For now, we'll not delete the firmware file. else keepWfile=1 fi fi +return 0 } ##---------------------------------------## @@ -2801,24 +2790,12 @@ _CheckFirmwareSHA256_() { Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" _DoCleanUp_ 1 _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - _DoExit_ 1 - else - # Non-interactive mode; perform an exit. - _DoExit_ 1 - fi + return 1 fi else Say "${REDct}**ERROR**${NOct}: SHA256 signature file or firmware file not found!" _DoCleanUp_ 1 - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - _DoExit_ 1 - else - # Non-interactive mode; perform an exit. - _DoExit_ 1 - fi + return 1 fi } @@ -2840,26 +2817,14 @@ _CheckFirmwareMD5_() { Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" _DoCleanUp_ 1 _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - _DoExit_ 1 - else - # Non-interactive mode; perform exit. - _DoExit_ 1 - fi + return 1 else Say "Firmware MD5 checksum verified successfully." fi else Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" _DoCleanUp_ 1 - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - _DoExit_ 1 - else - # Non-interactive mode; perform exit. - _DoExit_ 1 - fi + return 1 fi } @@ -2899,9 +2864,6 @@ _toggle_change_log_check_() { _WaitForEnterKey_ } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-27] ## ##---------------------------------------## @@ -3827,22 +3789,26 @@ Please manually update to version $minimum_supported_version or higher to use th md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") - rectCode="$?" + retCode="$?" else Say "Using release information for Merlin Firmware." set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - rectCode="$?" + retCode="$?" fi - if [ "$rectCode" -eq 0 ] && [ "$#" -eq 2 ] && \ + if [ "$retCode" -eq 0 ] && [ "$#" -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] then release_version="$1" release_link="$2" else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + _DoExit_ 1 + fi fi # Extracting the first octet to use in the curl @@ -3981,8 +3947,20 @@ Please manually update to version $minimum_supported_version or higher to use th if "$isGNUtonFW" then _DownloadForGnuton_ + retCode="$?" else _DownloadForMerlin_ + retCode="$?" + fi + if [ "$retCode" -eq 1 ] + then + Say "${REDct}**ERROR**${NOct}: Firmware files were not downloaded successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + _DoExit_ 1 + fi fi fi @@ -4000,8 +3978,20 @@ Please manually update to version $minimum_supported_version or higher to use th if "$isGNUtonFW" then _CopyGnutonFiles_ + retCode="$?" else _UnzipMerlin_ + retCode="$?" + fi + if [ "$retCode" -eq 1 ] + then + Say "${REDct}**ERROR**${NOct}: Firmware file (unzip, move, copy) management was not completed successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + _DoExit_ 1 + fi fi freeRAM_kb="$(_GetFreeRAM_KB_)" @@ -4149,8 +4139,20 @@ Please manually update to version $minimum_supported_version or higher to use th if "$isGNUtonFW" then _CheckFirmwareMD5_ + retCode="$?" else _CheckFirmwareSHA256_ + retCode="$?" + fi + if [ "$retCode" -eq 1 ] + then + Say "${REDct}**ERROR**${NOct}: Firmware signature verification was not completed successfully." + if [ "$inMenuMode" = true ]; then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + _DoExit_ 1 + fi fi ##----------------------------------------## From 4f51510bc8478a2d1e668e8a57600293cdfbeaf1 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 18:44:52 -0400 Subject: [PATCH 036/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 28a13358..bef62f3e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2694,7 +2694,7 @@ _UnzipMerlin_() { #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - return 1 + return 1 # Consider how to handle this error. For now, we'll not delete the ZIP file. else keepZIPfile=1 @@ -2765,7 +2765,7 @@ then #-------------------------------------------------------------# Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - return 1 + return 1 # Consider how to handle this error. For now, we'll not delete the firmware file. else keepWfile=1 From c7f6fe616e1c5cbb65b2d82d51a330aa01e825e5 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 21:38:35 -0400 Subject: [PATCH 037/185] Update MerlinAU.sh --- MerlinAU.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index bef62f3e..54cd95c5 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1091,6 +1091,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() echo "The directory path for the F/W ZIP file was updated successfully." _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi + keepWfile=0 return 0 } From 0ba3ed8e1784d503f0b67902cbbe3478a8b797d2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 19 Apr 2024 21:51:35 -0400 Subject: [PATCH 038/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 54cd95c5..a9cc7bae 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1089,9 +1089,9 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" echo "The directory path for the F/W ZIP file was updated successfully." + keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi - keepWfile=0 return 0 } From 76f7597cbb1900df92b7c5eb2be6aa0af187e059 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 25 Apr 2024 13:36:31 -0400 Subject: [PATCH 039/185] Update MerlinAU.sh --- MerlinAU.sh | 166 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 142 insertions(+), 24 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a9cc7bae..29007c46 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -475,8 +475,8 @@ readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" -readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="RT-AX92U" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="$(_GetRouterProductID_)" +readonly PRODUCT_ID="TUF-AX3000" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -763,7 +763,8 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -840,7 +841,8 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -1227,7 +1229,7 @@ _GetFirmwareVariantFromRouter_() buildInfoStr="$(nvram get buildinfo)" ##FOR TESTING/DEBUG ONLY## - if false # Change to true for forcing GNUton flag + if true # Change to true for forcing GNUton flag then isGNUtonFW=true else @@ -1261,8 +1263,14 @@ _CreateEMailContent_() nodefwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" fi - # Remove "_rog" suffix to avoid version comparison failures # - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" + if "$isGNUtonFW" + then + # To Be Determined + echo "" + else + # Remove "_rog" suffix to avoid version comparison failures # + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" + fi case "$1" in FW_UPDATE_TEST_EMAIL) @@ -2556,12 +2564,13 @@ _GetLatestFWUpdateVersionFromGithub_() ##---------------------------------------## GetLatestFirmwareMD5Url() { local url="$1" # GitHub API URL for the latest release + local firmware_choice="$2" # Choice of Firmware to Download # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") - # Parse the release data to find the download URL of the .md5 file that matches the model number - local md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\.md5\"" | grep -o "https://[^ ]*\.md5" | head -1) + # Parse the release data to find the appropriate .md5 file URL based on the firmware choice + local md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*_${firmware_choice}_.*\.md5\"" | grep -o "https://[^ ]*\.md5" | head -1) if [ -z "$md5_url" ]; then echo "**ERROR** **NO_MD5_FILE_URL_FOUND**" @@ -2650,7 +2659,7 @@ _DownloadForMerlin_() { extension="${sanitized_filename##*.}" # Combine path, custom file name, and extension before download - local FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" # Download the file using the release link wget -O "$FW_DL_FPATH" "$release_link" @@ -2942,7 +2951,67 @@ _Toggle_Auto_Backups_() { ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -change_build_type() +_ChangeBuildType_Gnuton_() +{ + local doReturnToMenu buildtypechoice + printf "Changing Flash Build Type...\n" + + # Use Get_Custom_Setting to retrieve the previous choice + previous_choice="$(Get_Custom_Setting "TUFBuild")" + + # If the previous choice is not set, default to 'n' + if [ "$previous_choice" = "TBD" ]; then + previous_choice="n" + fi + + # Convert previous choice to a descriptive text + if [ "$previous_choice" = "y" ]; then + display_choice="TUF Build" + else + display_choice="Pure Build" + fi + + printf "\nCurrent Build Type: ${GRNct}$display_choice${NOct}.\n" + + doReturnToMenu=false + while true + do + printf "\n${SEPstr}" + printf "\nChoose your preferred option for the build type to flash:\n" + printf "\n ${GRNct}1${NOct}. Original ${REDct}TUF${NOct} themed user interface${NOct}\n" + printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-TUF${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" + printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" + printf "${SEPstr}\n" + printf "[$display_choice] Enter selection: " + read -r choice + + [ -z "$choice" ] && break + + if echo "$choice" | grep -qE "^(e|exit|Exit)$" + then doReturnToMenu=true ; break ; fi + + case $choice in + 1) buildtypechoice="y" ; break + ;; + 2) buildtypechoice="n" ; break + ;; + *) echo ; _InvalidMenuSelection_ + ;; + esac + done + + "$doReturnToMenu" && return 0 + + Update_Custom_Settings "TUFBuild" "$buildtypechoice" + printf "\nThe build type to flash was updated successfully.\n" + + _WaitForEnterKey_ "$advnMenuReturnPromptStr" +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Feb-18] ## +##------------------------------------------## +_ChangeBuildType_Merlin_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -3787,9 +3856,41 @@ Please manually update to version $minimum_supported_version or higher to use th if "$isGNUtonFW" then Say "Using release information for Gnuton Firmware." - md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE") + # Check if PRODUCT_ID is for a TUF model and requires user choice + if echo "$PRODUCT_ID" | grep -q "^TUF-"; then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "TUFBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + echo "Would you like to use the TUF build? (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + Update_Custom_Settings "TUFBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + else + # If not a TUF model, process as usual + firmware_choice="pure" + fi + md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE" "$firmware_choice") Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE") + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") retCode="$?" else Say "Using release information for Merlin Firmware." @@ -5024,19 +5125,34 @@ _ShowAdvancedOptionsMenu_() fi fi - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "ROGBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="ROG Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" + if "$isGNUtonFW" + then + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "TUFBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="TUF Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi else - current_build_type_menu="NOT SET" + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="ROG Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi fi - if echo "$PRODUCT_ID" | grep -q "^GT-" + if echo "$PRODUCT_ID" | grep -q "^GT-" || echo "$PRODUCT_ID" | grep -q "^TUF-" then printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" if [ "$current_build_type_menu" = "NOT SET" ] @@ -5192,7 +5308,9 @@ _advanced_options_menu_() fi ;; bt) if echo "$PRODUCT_ID" | grep -q "^GT-" - then change_build_type + then _ChangeBuildType_Merlin_ + elif echo "$PRODUCT_ID" | grep -q "^TUF-" + then _ChangeBuildType_Gnuton_ else _InvalidMenuSelection_ fi ;; From 8a5d69db996d0883e254b98f74bed542419300da Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 01:00:16 -0400 Subject: [PATCH 040/185] Update MerlinAU.sh --- MerlinAU.sh | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 29007c46..639486e6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,7 +476,7 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" ##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="$(_GetRouterProductID_)" -readonly PRODUCT_ID="TUF-AX3000" +readonly PRODUCT_ID="TUF-AX5400" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -2538,21 +2538,26 @@ _GetLatestFWUpdateVersionFromWebsite_() ##---------------------------------------## _GetLatestFWUpdateVersionFromGithub_() { - local url="$1" + local url="$1" # GitHub API URL for the latest release + local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" - # Use curl to fetch the latest release data from GitHub - local release_data=$(curl -s "$1") + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging - # Parse the release data to find the download URL of the asset that matches the model number - local download_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*\"" | grep -o "https://[^ ]*\.w" | head -1) + # Filter the JSON for the desired firmware using grep and head to fetch the URL + local download_url=$(echo "$release_data" | + grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.w\"" | + grep -o "https://[^ ]*\.w" | + head -1) - if [ -z "$download_url" ] - then - echo "**ERROR** **NO_GITHUB_URL**" ; + # Check if a URL was found + if [ -z "$download_url" ]; then + echo "**ERROR** **NO_GITHUB_URL**" return 1 else - # Extract version from the download URL or release data - local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.zip$//;s/.trx$//;s/_/./g") + # Extract the version from the download URL or release data + local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g") echo "$version" echo "$download_url" return 0 @@ -2564,19 +2569,24 @@ _GetLatestFWUpdateVersionFromGithub_() ##---------------------------------------## GetLatestFirmwareMD5Url() { local url="$1" # GitHub API URL for the latest release - local firmware_choice="$2" # Choice of Firmware to Download + local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") + echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging - # Parse the release data to find the appropriate .md5 file URL based on the firmware choice - local md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*_${firmware_choice}_.*\.md5\"" | grep -o "https://[^ ]*\.md5" | head -1) + # Filter the JSON for the desired firmware using grep and sed + local firmware_url=$(echo "$release_data" | + grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.md5\"" | + sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | + head -1) - if [ -z "$md5_url" ]; then - echo "**ERROR** **NO_MD5_FILE_URL_FOUND**" + # Check if a URL was found and output result or error + if [ -z "$firmware_url" ]; then + echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**" return 1 else - echo "$md5_url" + echo "$firmware_url" fi } @@ -4975,7 +4985,7 @@ _ShowMainMenu_() # Use the global variable if "$isGNUtonFW" then - FirmwareFlavor="${MAGENTAct}GNUton${NOct}" + FirmwareFlavor="${MAGENTAct}GNUton${NOct} (Limited Support)" else FirmwareFlavor="${BLUEct}Merlin${NOct}" fi From f7531c470d33295cbdf7ab42f20799e03a6bb6b6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 01:02:43 -0400 Subject: [PATCH 041/185] Update MerlinAU.sh --- MerlinAU.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 639486e6..708dcdd7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -475,8 +475,8 @@ readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="$(_GetRouterProductID_)" -readonly PRODUCT_ID="TUF-AX5400" +readonly PRODUCT_ID="$(_GetRouterProductID_)" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX5400" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -2576,17 +2576,17 @@ GetLatestFirmwareMD5Url() { echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging # Filter the JSON for the desired firmware using grep and sed - local firmware_url=$(echo "$release_data" | + local $md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.md5\"" | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | head -1) # Check if a URL was found and output result or error - if [ -z "$firmware_url" ]; then + if [ -z "$md5_url" ]; then echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**" return 1 else - echo "$firmware_url" + echo "$md5_url" fi } From 190c57f3449f7c68d176489da6cec0f08d2a9391 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 01:12:41 -0400 Subject: [PATCH 042/185] Update MerlinAU.sh --- MerlinAU.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 708dcdd7..1a2a6106 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,7 +476,7 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX5400" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX3000_V2" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1229,7 +1229,7 @@ _GetFirmwareVariantFromRouter_() buildInfoStr="$(nvram get buildinfo)" ##FOR TESTING/DEBUG ONLY## - if true # Change to true for forcing GNUton flag + if false # Change to true for forcing GNUton flag then isGNUtonFW=true else @@ -2543,12 +2543,11 @@ _GetLatestFWUpdateVersionFromGithub_() # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") - echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging # Filter the JSON for the desired firmware using grep and head to fetch the URL local download_url=$(echo "$release_data" | - grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.w\"" | - grep -o "https://[^ ]*\.w" | + grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.\(w\|pkgtb\)\"" | + grep -o "https://[^ ]*\.\(w\|pkgtb\)" | head -1) # Check if a URL was found @@ -2573,10 +2572,9 @@ GetLatestFirmwareMD5Url() { # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") - echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging # Filter the JSON for the desired firmware using grep and sed - local $md5_url=$(echo "$release_data" | + local md5_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.md5\"" | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | head -1) From 944786c992f6de1635e856a25a1d47263f6eb367 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 01:27:34 -0400 Subject: [PATCH 043/185] Update MerlinAU.sh --- MerlinAU.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 1a2a6106..349798db 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -475,8 +475,8 @@ readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" -readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX3000_V2" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="$(_GetRouterProductID_)" +readonly PRODUCT_ID="TUF-AX3000_V2" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1229,7 +1229,7 @@ _GetFirmwareVariantFromRouter_() buildInfoStr="$(nvram get buildinfo)" ##FOR TESTING/DEBUG ONLY## - if false # Change to true for forcing GNUton flag + if true # Change to true for forcing GNUton flag then isGNUtonFW=true else @@ -2543,6 +2543,7 @@ _GetLatestFWUpdateVersionFromGithub_() # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") + echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging # Filter the JSON for the desired firmware using grep and head to fetch the URL local download_url=$(echo "$release_data" | @@ -2572,6 +2573,7 @@ GetLatestFirmwareMD5Url() { # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") + echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging # Filter the JSON for the desired firmware using grep and sed local md5_url=$(echo "$release_data" | @@ -3876,7 +3878,9 @@ Please manually update to version $minimum_supported_version or higher to use th echo "Pure Build selected for flashing" firmware_choice="pure" elif [ "$inMenuMode" = true ]; then - echo "Would you like to use the TUF build? (y/n): " + printf "${REDct}Found TUF build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the TUF build?${NOct}\n" + printf "Enter your choice (y/n): " read -r choice if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then echo "TUF Build selected for flashing" From 36769c290325aeb8bae8cd7abb68237fd6a926cc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 01:36:07 -0400 Subject: [PATCH 044/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 349798db..be10df71 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1890,7 +1890,7 @@ _DoCleanUp_() fi if "$moveWback"; then - mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.w" "$FW_DL_FPATH" + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.${extension}" "$FW_DL_FPATH" fi if "$doTrace" From 1d78ea4ab8764d1d9e95ae92f5d78825a82f8279 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 02:00:46 -0400 Subject: [PATCH 045/185] Update MerlinAU.sh --- MerlinAU.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index be10df71..fc0782b4 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -475,8 +475,8 @@ readonly FW_UpdateMaximumPostponementDays=60 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="$(_GetRouterProductID_)" -readonly PRODUCT_ID="TUF-AX3000_V2" +readonly PRODUCT_ID="$(_GetRouterProductID_)" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX5400" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1229,7 +1229,7 @@ _GetFirmwareVariantFromRouter_() buildInfoStr="$(nvram get buildinfo)" ##FOR TESTING/DEBUG ONLY## - if true # Change to true for forcing GNUton flag + if false # Change to true for forcing GNUton flag then isGNUtonFW=true else @@ -2541,13 +2541,22 @@ _GetLatestFWUpdateVersionFromGithub_() local url="$1" # GitHub API URL for the latest release local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" + local 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" = "pure" ]; then + search_type="pure\|squashfs" + fi + # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") - echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging + + # Construct the grep pattern based on search_type + local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\"" # Filter the JSON for the desired firmware using grep and head to fetch the URL local download_url=$(echo "$release_data" | - grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.\(w\|pkgtb\)\"" | + grep -o "$grep_pattern" | grep -o "https://[^ ]*\.\(w\|pkgtb\)" | head -1) @@ -2571,13 +2580,22 @@ GetLatestFirmwareMD5Url() { local url="$1" # GitHub API URL for the latest release local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" + local 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" = "pure" ]; then + search_type="pure\|squashfs" + fi + # Fetch the latest release data from GitHub local release_data=$(curl -s "$url") - echo "$release_data" > /tmp/full_release_data.txt # Save the full data for debugging + + # Construct the grep pattern based on search_type + local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.md5\"" # Filter the JSON for the desired firmware using grep and sed local md5_url=$(echo "$release_data" | - grep -o "\"browser_download_url\": \".*${PRODUCT_ID}.*${firmware_type}.*\.md5\"" | + grep -o "$grep_pattern" | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | head -1) From ba744f9539a34f7006078474b520cf649874d304 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 02:26:24 -0400 Subject: [PATCH 046/185] Update MerlinAU.sh --- MerlinAU.sh | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index fc0782b4..5b0b4016 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2635,6 +2635,9 @@ GetLatestChangelogUrl() { ##---------------------------------------## _DownloadForGnuton_() { + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + # Use the effective URL to capture the Content-Disposition header local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') @@ -2677,23 +2680,10 @@ _DownloadForGnuton_() { ##---------------------------------------## _DownloadForMerlin_() { - # Extract the filename from the URL - local original_filename="${effective_url##*/}" - - # Sanitize filename by removing problematic characters (if necessary) - local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - - # Extract the file extension - extension="${sanitized_filename##*.}" - - # Combine path, custom file name, and extension before download - FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" - - # Download the file using the release link - wget -O "$FW_DL_FPATH" "$release_link" + wget -O "$FW_ZIP_FPATH" "$release_link" # Check if the file was downloaded successfully - if [ ! -f "$FW_DL_FPATH" ]; then + if [ ! -f "$FW_ZIP_FPATH" ]; then return 1 else return 0 @@ -4073,9 +4063,6 @@ Please manually update to version $minimum_supported_version or higher to use th wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - # Follow redirects and capture the effective URL - effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") - if "$isGNUtonFW" then _DownloadForGnuton_ From b4806abf686f49968fe54a0fe344fac9b140be2b Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 08:14:47 -0400 Subject: [PATCH 047/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5b0b4016..99a91b87 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1265,8 +1265,8 @@ _CreateEMailContent_() if "$isGNUtonFW" then - # To Be Determined - echo "" + # First remove "-gnuton" followed by any digits at the end, then replace the last hyphen with a period + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/gnuton[0-9]+$//; s/-([0-9]+)$/\.\1/')" else # Remove "_rog" suffix to avoid version comparison failures # fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" From a90735da198ee7c1c9f7de85c301e0fd56979aca Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 08:44:52 -0400 Subject: [PATCH 048/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 99a91b87..ebeddbc1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1265,8 +1265,8 @@ _CreateEMailContent_() if "$isGNUtonFW" then - # First remove "-gnuton" followed by any digits at the end, then replace the last hyphen with a period - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/gnuton[0-9]+$//; s/-([0-9]+)$/\.\1/')" + # First remove "-gnuton" followed by any digits at the end, then removes a trailing hyphen # + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/gnuton[0-9]+$//; s/-$//')" else # Remove "_rog" suffix to avoid version comparison failures # fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" From b423a70a3a83a1bf11ebab7ba52b48a0a848247f Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 20:36:22 -0400 Subject: [PATCH 049/185] Update MerlinAU.sh --- MerlinAU.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index ebeddbc1..afa7d7c1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,7 +476,7 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX5400" +##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX3000_V2" readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -793,12 +793,12 @@ Get_Custom_Setting() fi } -##----------------------------------------## -## Modified by Martinski W. [2024-Apr-06] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Apr-26] ## +##------------------------------------------## _GetAllNodeSettings_() { - if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] ; then return 1 ; fi + if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ]; then return 1; fi local node_mac_address="$1" pattern local setting_value setting_part="$2" matched_lines @@ -809,15 +809,18 @@ _GetAllNodeSettings_() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" if [ -f "$SETTINGSFILE" ]; then - # Construct the setting key pattern to match - pattern="${node_mac_address}.*${setting_part}" + # Escape characters that might be interpreted by regex engines, like ':' in MAC addresses + local escaped_mac_address=$(echo "$node_mac_address" | sed 's/[\*\.]/\\&/g') + + # Construct the pattern to match the entire line containing the MAC address and the setting part + pattern="${escaped_mac_address}.*${setting_part}=\"[^\"]*\"" # Search for the setting in the settings file - matched_lines="$(grep -o "FW_Node.*_${setting_part}=\"[^\"]*\"" "$SETTINGSFILE" | grep -o "${pattern}=\"[^\"]*\"" || echo "")" + matched_lines=$(grep -o "$pattern" "$SETTINGSFILE" || echo "") if [ -n "$matched_lines" ]; then - # If multiple lines match, this extracts the value from the first matched line - setting_value="$(echo "$matched_lines" | head -n 1 | awk -F '=' '{print $2}' | tr -d '"')" + # Extract the value from the first matched line + setting_value=$(echo "$matched_lines" | head -n 1 | awk -F '=' '{print $2}' | tr -d '"') echo "$setting_value" else echo "$default_value" @@ -3549,7 +3552,7 @@ _CheckNodeFWUpdateNotification_() _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "NameID")" echo "" > "$tempNodeEMailList" - echo "Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" + echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" fi return 0 } From 2ef76e99dc84d489658b4f3f2dbf80dca65d5125 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 20:55:53 -0400 Subject: [PATCH 050/185] Update MerlinAU.sh --- MerlinAU.sh | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index afa7d7c1..135c73bf 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Apr-18 +# Last Modified: 2024-Apr-26 ################################################################### set -u -readonly SCRIPT_VERSION=1.1.2 +readonly SCRIPT_VERSION=1.1.3 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -3874,6 +3874,9 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apr-18] ## + ##------------------------------------------## if "$isGNUtonFW" then Say "Using release information for Gnuton Firmware." @@ -4059,9 +4062,9 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Downloading ${GRNct}${release_link}${NOct}" echo "" - ##----------------------------------------## - ## Modified by Martinski W. [2024-Feb-28] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apl-24] ## + ##------------------------------------------## # Avoid error message about HSTS database # wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" @@ -4095,7 +4098,7 @@ Please manually update to version $minimum_supported_version or higher to use th check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Mar-19] ## + ## Modified by ExtremeFiretop [2024-Apr-21] ## ##------------------------------------------## if "$isGNUtonFW" then @@ -4124,9 +4127,9 @@ Please manually update to version $minimum_supported_version or higher to use th # Navigate to the firmware directory cd "$FW_BIN_DIR" - ##----------------------------------------## - ## Modified by Martinski W. [2024-Mar-16] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Aprl-24] ## + ##------------------------------------------## local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" if [ "$checkChangeLogSetting" = "ENABLED" ] @@ -4256,7 +4259,7 @@ Please manually update to version $minimum_supported_version or higher to use th fi ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Feb-03] ## + ## Modified by ExtremeFiretop [2024-Apr-25] ## ##------------------------------------------## if "$isGNUtonFW" then @@ -4949,7 +4952,7 @@ _PrintNodeInfo() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-18] ## +## Modified by ExtremeFiretop [2024-Apr-24] ## ##------------------------------------------## _ShowMainMenu_() { @@ -5062,9 +5065,9 @@ _ShowMainMenu_() printf "${SEPstr}\n" } -##----------------------------------------## -## Modified by Martinski W. [2024-Apr-06] ## -##----------------------------------------## +##-----------------------------------------## +## Modified by ExtemeFiretop [2024-Apr-24] ## +##-----------------------------------------## _ShowAdvancedOptionsMenu_() { clear @@ -5285,9 +5288,9 @@ _InvalidMenuSelection_() _WaitForEnterKey_ } -##----------------------------------------## -## Modified by Martinski W. [2024-Mar-24] ## -##----------------------------------------## +##-----------------------------------------## +## Modified by ExtemeFiretop [2024-Apr-24] ## +##-----------------------------------------## _advanced_options_menu_() { while true From 37ceb59281493e22ec02f4af1e9a99a90ad5a5ef Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 26 Apr 2024 20:56:10 -0400 Subject: [PATCH 051/185] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 45a1b3f4..781dcb07 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.2 +1.1.3 From f43ffa602f79c39a774d5740cbd4abd36ea6a167 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 01:25:24 -0400 Subject: [PATCH 052/185] Update MerlinAU.sh --- MerlinAU.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 135c73bf..b10b45bb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -810,17 +810,17 @@ _GetAllNodeSettings_() if [ -f "$SETTINGSFILE" ]; then # Escape characters that might be interpreted by regex engines, like ':' in MAC addresses - local escaped_mac_address=$(echo "$node_mac_address" | sed 's/[\*\.]/\\&/g') + local escaped_mac_address="$(echo "$node_mac_address" | sed 's/[\*\.]/\\&/g')" # Construct the pattern to match the entire line containing the MAC address and the setting part pattern="${escaped_mac_address}.*${setting_part}=\"[^\"]*\"" # Search for the setting in the settings file - matched_lines=$(grep -o "$pattern" "$SETTINGSFILE" || echo "") + matched_lines="$(grep -o "$pattern" "$SETTINGSFILE" || echo "")" if [ -n "$matched_lines" ]; then # Extract the value from the first matched line - setting_value=$(echo "$matched_lines" | head -n 1 | awk -F '=' '{print $2}' | tr -d '"') + setting_value="$(echo "$matched_lines" | head -n 1 | awk -F '=' '{print $2}' | tr -d '"')" echo "$setting_value" else echo "$default_value" From 98bb8036fb6cc59ea6e0366a9b998f4348ec7f2a Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 10:11:47 -0400 Subject: [PATCH 053/185] Update MerlinAU.sh --- MerlinAU.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index b10b45bb..66986aa1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -476,7 +476,9 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## readonly PRODUCT_ID="TUF-AX3000_V2" +##FOR TESTING/DEBUG ONLY## +#readonly PRODUCT_ID="TUF-AX3000_V2" +##FOR TESTING/DEBUG ONLY## readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" @@ -1262,9 +1264,6 @@ _CreateEMailContent_() subjectStr="F/W Update Status for $MODEL_ID" fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - if "$inRouterSWmode" && [ -n "$node_list" ]; then - nodefwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" - fi if "$isGNUtonFW" then @@ -1292,6 +1291,9 @@ _CreateEMailContent_() } > "$tempEMailBodyMsg" ;; AGGREGATED_UPDATE_NOTIFICATION) + if "$inRouterSWmode" && [ -n "$node_list" ]; then + nodefwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" + fi emailBodyTitle="New Firmware Update(s) for AiMesh Node(s)" NODE_UPDATE_CONTENT="$(cat "$tempNodeEMailList")" { @@ -1725,7 +1727,7 @@ _GetCurrentFWInstalledLongVersion_() _GetCurrentFWInstalledShortVersion_() { ##FOR TESTING/DEBUG ONLY## -if true ; then echo "388.5.0" ; return 0 ; fi +if false ; then echo "388.5.0" ; return 0 ; fi local theVersionStr extVersNum From 9d3788c189a1668dc0e7cfc50703389421f0f417 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 10:14:08 -0400 Subject: [PATCH 054/185] Update MerlinAU.sh From 99153a3f3b22f8faa1c44b2ac166040f65398966 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 12:23:56 -0400 Subject: [PATCH 055/185] Update MerlinAU.sh --- MerlinAU.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 66986aa1..3d0afcb5 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -804,18 +804,14 @@ _GetAllNodeSettings_() local node_mac_address="$1" pattern local setting_value setting_part="$2" matched_lines - # Set a default value internally if not provided local default_value="TBD" # Ensure the settings directory exists [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" if [ -f "$SETTINGSFILE" ]; then - # Escape characters that might be interpreted by regex engines, like ':' in MAC addresses - local escaped_mac_address="$(echo "$node_mac_address" | sed 's/[\*\.]/\\&/g')" - # Construct the pattern to match the entire line containing the MAC address and the setting part - pattern="${escaped_mac_address}.*${setting_part}=\"[^\"]*\"" + pattern="${node_mac_address}.*${setting_part}=\"[^\"]*\"" # Search for the setting in the settings file matched_lines="$(grep -o "$pattern" "$SETTINGSFILE" || echo "")" @@ -1294,6 +1290,11 @@ _CreateEMailContent_() if "$inRouterSWmode" && [ -n "$node_list" ]; then nodefwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" fi + if [ ! -n "$nodefwNewUpdateVersion" ] + then + Say "${REDct}**ERROR**${NOct}: Unable to send node email notification [No saved info]." + return 1 + fi emailBodyTitle="New Firmware Update(s) for AiMesh Node(s)" NODE_UPDATE_CONTENT="$(cat "$tempNodeEMailList")" { From 9106e54904fe9d2f18311c19b29505ca46f1d426 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 13:40:31 -0400 Subject: [PATCH 056/185] Update MerlinAU.sh --- MerlinAU.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 3d0afcb5..a1161f3e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4087,6 +4087,7 @@ Please manually update to version $minimum_supported_version or higher to use th _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 else + _DoCleanUp_ 1 _DoExit_ 1 fi fi @@ -4118,6 +4119,7 @@ Please manually update to version $minimum_supported_version or higher to use th _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 else + _DoCleanUp_ 1 _DoExit_ 1 fi fi @@ -4142,7 +4144,11 @@ Please manually update to version $minimum_supported_version or higher to use th changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + if echo "$release_version" | grep -q "386"; then + changeLogTag="386" + else + changeLogTag="NG" + fi changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" fi @@ -4279,6 +4285,7 @@ Please manually update to version $minimum_supported_version or higher to use th _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 else + _DoCleanUp_ 1 _DoExit_ 1 fi fi From c49334e54f03d9d0f8e14135fe974e2407c1f887 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 27 Apr 2024 19:12:37 -0400 Subject: [PATCH 057/185] Update MerlinAU.sh --- MerlinAU.sh | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a1161f3e..8c66cc7b 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4161,19 +4161,36 @@ Please manually update to version $minimum_supported_version or higher to use th else # Use awk to format the version based on the number of initial digits formatted_current_version=$(echo "$current_version" | awk -F. '{ - if (length($1) == 4 && NF >= 3) { - # For version starting with four digits like 3004.388.5.0 - # Format as the next two fields (388.5) - printf "%s.%s", $2, $3 - } else if (NF >= 2) { - # For version with three initial digits like 388.5.0 - # Format as the first two fields (388.5) - printf "%s.%s", $1, $2 + if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix + if (NF == 4 && $4 == "0") { + printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 + } else if (NF == 4) { + printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit + } + } else if (NF == 3) { # For version without a four-digit prefix + if ($3 == "0") { + printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 + } else { + printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit + } } }') - # Format release_version by removing the prefix '3004.' and the last '.0' - formatted_release_version="$(echo "$release_version" | awk -F. '{print $2"."$3}')" + formatted_release_version=$(echo "$release_version" | awk -F. '{ + if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix + if (NF == 4 && $4 == "0") { + printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 + } else if (NF == 4) { + printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit + } + } else if (NF == 3) { # For version without a four-digit prefix + if ($3 == "0") { + printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 + } else { + printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit + } + } + }') # Define regex patterns for both versions release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" From 010a83545414b62de92caa78532419ca2308d2ce Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 30 Apr 2024 12:15:28 -0400 Subject: [PATCH 058/185] Update MerlinAU.sh --- MerlinAU.sh | 135 +++++++++++++++++++++++++--------------------------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8c66cc7b..59eeebff 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Apr-26 +# Last Modified: 2024-Apr-30 ################################################################### set -u -readonly SCRIPT_VERSION=1.1.3 +readonly SCRIPT_VERSION=1.1.4 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -4768,6 +4768,70 @@ _SetSecondaryEMailAddress_() _WaitForEnterKey_ "$advnMenuReturnPromptStr" } +# RegExp for IPv4 address # +readonly IPv4octet_RegEx="([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])" +readonly IPv4addrs_RegEx="((${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx})" +readonly IPv4privt_RegEx="((^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.))" + +##----------------------------------------## +## Modified by Martinski W. [2024-Apr-06] ## +##----------------------------------------## +_ValidatePrivateIPv4Address_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] || \ + ! echo "$1" | grep -qE "^${IPv4addrs_RegEx}$" || \ + ! echo "$1" | grep -qE "^${IPv4privt_RegEx}" + then return 1 + else return 0 + fi +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Apr-30] ## +##------------------------------------------## +_ProcessMeshNodes_() +{ + includeExtraLogic="$1" # Use '1' to include extra logic, '0' to exclude + if [ $# -eq 0 ] || [ -z "$1" ] + then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi + + uid=1 + if ! node_list="$(_GetNodeIPv4List_)" + then node_list="" ; fi + + if "$inRouterSWmode" + then + if [ -n "$node_list" ] + then + # Iterate over the list of nodes and print information for each node + for nodeIPv4addr in $node_list + do + ! _ValidatePrivateIPv4Address_ "$nodeIPv4addr" && continue + _GetNodeInfo_ "$nodeIPv4addr" + if ! Node_FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" + then + Node_FW_NewUpdateVersion="NONE FOUND" + else + _CheckNodeFWUpdateNotification_ "$Node_combinedVer" "$Node_FW_NewUpdateVersion" + fi + + # Apply extra logic if flag is '1' + if [ "$includeExtraLogic" -eq 1 ]; then + _PrintNodeInfo "$nodeIPv4addr" "$node_online_status" "$Node_FW_NewUpdateVersion" "$uid" + uid="$((uid + 1))" + fi + done + if [ -s "$tempNodeEMailList" ]; then + _SendEMailNotification_ AGGREGATED_UPDATE_NOTIFICATION + fi + else + if [ "$includeExtraLogic" -eq 1 ]; then + printf "\n${padStr}${padStr}${padStr}${REDct}No AiMesh Node(s)${NOct}" + fi + fi + fi +} + keepZIPfile=0 keepWfile=0 trap '_DoCleanUp_ 0 "$keepZIPfile" "$keepWfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM @@ -5215,70 +5279,6 @@ _ShowAdvancedOptionsMenu_() printf "${SEPstr}" } -# RegExp for IPv4 address # -readonly IPv4octet_RegEx="([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])" -readonly IPv4addrs_RegEx="((${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx})" -readonly IPv4privt_RegEx="((^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.))" - -##----------------------------------------## -## Modified by Martinski W. [2024-Apr-06] ## -##----------------------------------------## -_ValidatePrivateIPv4Address_() -{ - if [ $# -eq 0 ] || [ -z "$1" ] || \ - ! echo "$1" | grep -qE "^${IPv4addrs_RegEx}$" || \ - ! echo "$1" | grep -qE "^${IPv4privt_RegEx}" - then return 1 - else return 0 - fi -} - -##----------------------------------------## -## Modified by Martinski W. [2024-Apr-06] ## -##----------------------------------------## -_ProcessMeshNodes_() -{ - includeExtraLogic="$1" # Use '1' to include extra logic, '0' to exclude - if [ $# -eq 0 ] || [ -z "$1" ] - then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - - uid=1 - if ! node_list="$(_GetNodeIPv4List_)" - then node_list="" ; fi - - if "$inRouterSWmode" - then - if [ -n "$node_list" ] - then - # Iterate over the list of nodes and print information for each node - for nodeIPv4addr in $node_list - do - ! _ValidatePrivateIPv4Address_ "$nodeIPv4addr" && continue - _GetNodeInfo_ "$nodeIPv4addr" - if ! Node_FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" - then - Node_FW_NewUpdateVersion="NONE FOUND" - else - _CheckNodeFWUpdateNotification_ "$Node_combinedVer" "$Node_FW_NewUpdateVersion" - fi - - # Apply extra logic if flag is '1' - if [ "$includeExtraLogic" -eq 1 ]; then - _PrintNodeInfo "$nodeIPv4addr" "$node_online_status" "$Node_FW_NewUpdateVersion" "$uid" - uid="$((uid + 1))" - fi - done - if [ -s "$tempNodeEMailList" ]; then - _SendEMailNotification_ AGGREGATED_UPDATE_NOTIFICATION - fi - else - if [ "$includeExtraLogic" -eq 1 ]; then - printf "\n${padStr}${padStr}${padStr}${REDct}No AiMesh Node(s)${NOct}" - fi - fi - fi -} - ##---------------------------------------## ## Added by ExtremeFiretop [2024-Apr-02] ## ##---------------------------------------## @@ -5289,9 +5289,6 @@ _ShowNodesMenu_() printf "============== AiMesh Node(s) Info Menu ==============\n" printf "${SEPstr}\n" - if ! node_online_status="$(_NodeActiveStatus_)" - then node_online_status="" ; fi - # Count the number of IP addresses local numIPs="$(echo "$node_list" | wc -w)" From d937335eb3a382a45bca0f243b4f0df21f67e0a2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 30 Apr 2024 12:16:18 -0400 Subject: [PATCH 059/185] Update MerlinAU.sh --- MerlinAU.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index 59eeebff..107ebe35 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5289,6 +5289,9 @@ _ShowNodesMenu_() printf "============== AiMesh Node(s) Info Menu ==============\n" printf "${SEPstr}\n" + if ! node_online_status="$(_NodeActiveStatus_)" + then node_online_status="" ; fi + # Count the number of IP addresses local numIPs="$(echo "$node_list" | wc -w)" From 2694d189c6637471f8db89aa51dff47ce25f4dfe Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 30 Apr 2024 18:39:02 -0400 Subject: [PATCH 060/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 107ebe35..e1d3a485 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -453,7 +453,7 @@ readonly WHITEct="\e[1;37m" ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-22] ## ##----------------------------------------## -readonly FW_Update_CRON_DefaultSchedule="0 0 * * Sun" +readonly FW_Update_CRON_DefaultSchedule="0 0 * * *" readonly CRON_MINS_RegEx="([*0-9]|[1-5][0-9])([\/,-]([0-9]|[1-5][0-9]))*" readonly CRON_HOUR_RegEx="([*0-9]|1[0-9]|2[0-3])([\/,-]([0-9]|1[0-9]|2[0-3]))*" From b20045cdec010bb5d2a2210ce7d6d1f094a23fd0 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 30 Apr 2024 18:42:05 -0400 Subject: [PATCH 061/185] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 781dcb07..65087b4f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.3 +1.1.4 From ebadc87a3d34bd901fd4ffc0e8b481442f5e196d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 2 May 2024 19:19:30 -0400 Subject: [PATCH 062/185] Update MerlinAU.sh --- MerlinAU.sh | 95 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e1d3a485..212689a1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Apr-30 +# Last Modified: 2024-May-02 ################################################################### set -u @@ -35,15 +35,6 @@ readonly ScriptFileName="${0##*/}" readonly ScriptFNameTag="${ScriptFileName%%.*}" readonly ScriptDirNameD="${ScriptFNameTag}.d" -ScriptsDirPath="$(/usr/bin/dirname "$0")" -if [ "$ScriptsDirPath" != "." ] -then - ScriptFilePath="$0" -else - ScriptsDirPath="$(pwd)" - ScriptFilePath="$(pwd)/$ScriptFileName" -fi - ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jan-21] ## ##------------------------------------------## @@ -53,6 +44,18 @@ readonly SETTINGS_DIR="${ADDONS_PATH}/$ScriptDirNameD" readonly SETTINGSFILE="${SETTINGS_DIR}/custom_settings.txt" readonly SCRIPTVERPATH="${SETTINGS_DIR}/version.txt" +##----------------------------------------## +## Modified by Martinski W. [2024-May-01] ## +##----------------------------------------## +ScriptsDirPath="$SCRIPTS_PATH" +ScriptFilePath="${SCRIPTS_PATH}/$ScriptFileName" + +if [ ! -f "$ScriptFilePath" ] +then + ScriptsDirPath="$(pwd)" + ScriptFilePath="$(pwd)/$ScriptFileName" +fi + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Apr-02] ## ##------------------------------------------## @@ -795,37 +798,31 @@ Get_Custom_Setting() fi } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-26] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Apr-30] ## +##----------------------------------------## _GetAllNodeSettings_() { - if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ]; then return 1; fi + if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] + then echo "**ERROR**" ; return 1; fi - local node_mac_address="$1" pattern - local setting_value setting_part="$2" matched_lines - local default_value="TBD" + ## Node Setting KEY="Node_{MACaddress}_{keySuffix}" ## + local fullKeyName="Node_${1}_${2}" + local setting_value="TBD" matched_lines - # Ensure the settings directory exists + # Ensure the settings directory exists # [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" - if [ -f "$SETTINGSFILE" ]; then - # Construct the pattern to match the entire line containing the MAC address and the setting part - pattern="${node_mac_address}.*${setting_part}=\"[^\"]*\"" - - # Search for the setting in the settings file - matched_lines="$(grep -o "$pattern" "$SETTINGSFILE" || echo "")" - - if [ -n "$matched_lines" ]; then - # Extract the value from the first matched line + if [ -f "$SETTINGSFILE" ] + then + matched_lines="$(grep -E "^${fullKeyName}=.*" "$SETTINGSFILE")" + if [ -n "$matched_lines" ] + then + # Extract the value from the first matched line # setting_value="$(echo "$matched_lines" | head -n 1 | awk -F '=' '{print $2}' | tr -d '"')" - echo "$setting_value" - else - echo "$default_value" fi - else - echo "$default_value" fi + echo "$setting_value" } ##----------------------------------------## @@ -1313,6 +1310,8 @@ _CreateEMailContent_() emailBodyTitle="WARNING" { echo "Found high-risk phrases in the change-logs while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." + echo "Changelog contents include the following changes:" + echo "$changelog_contents" printf "\nPlease run script interactively to approve this F/W Update from current version:\n${fwInstalledVersion}\n" } > "$tempEMailBodyMsg" ;; @@ -2333,21 +2332,21 @@ _NodeActiveStatus_() return 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Mar-31] ## -##---------------------------------------## -_Populate_Node_Settings_() { - local mac_address="$1" +##----------------------------------------## +## Modified by Martinski W. [2024-Apr-30] ## +##----------------------------------------## +_Populate_Node_Settings_() +{ + local MAC_address="$1" local model_id="$2" local update_date="$3" local update_vers="$4" - local node_suffix="$mac_address" - local node_prefix="Node_" + local nodeKeyPrefix="Node_${MAC_address}_" # Update or add each piece of information - Update_Custom_Settings "${node_prefix}${node_suffix}_Model_NameID" "$model_id" - Update_Custom_Settings "${node_prefix}${node_suffix}_New_Notification_Date" "$update_date" - Update_Custom_Settings "${node_prefix}${node_suffix}_New_Notification_Vers" "$update_vers" + Update_Custom_Settings "${nodeKeyPrefix}Model_NameID" "$model_id" + Update_Custom_Settings "${nodeKeyPrefix}New_Notification_Date" "$update_date" + Update_Custom_Settings "${nodeKeyPrefix}New_Notification_Vers" "$update_vers" } ##---------------------------------------## @@ -3509,9 +3508,9 @@ _CheckNewUpdateFirmwareNotification_() return 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-02] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Apr-30] ## +##----------------------------------------## _CheckNodeFWUpdateNotification_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] @@ -3542,7 +3541,7 @@ _CheckNodeFWUpdateNotification_() nodefwNewUpdateNotificationVers="$2" nodefwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" - nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "NameID")" + nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" echo "" > "$tempNodeEMailList" echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" fi @@ -3553,7 +3552,7 @@ _CheckNodeFWUpdateNotification_() then nodefwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" - nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "NameID")" + nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" echo "" > "$tempNodeEMailList" echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" fi @@ -4154,7 +4153,7 @@ Please manually update to version $minimum_supported_version or higher to use th if [ ! -f "$changeLogFile" ] then - Say "Change-log file [$changeLogFile] does NOT exist." + Say "Change-log file [${FW_BIN_DIR}/$Changelog-${changeLogTag}.txt] does NOT exist." _DoCleanUp_ "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 From f9519b7f78287d6c2cb175ab91328bea0cd73a5a Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 3 May 2024 03:59:07 -0400 Subject: [PATCH 063/185] Update MerlinAU.sh --- MerlinAU.sh | 163 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 38 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 212689a1..395fb9ce 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -23,6 +23,13 @@ readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" readonly FW_SFURL_RELEASE_SUFFIX="Release" readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.ng/releases/latest" +##---------------------------------------## +## Added by ExtremeFiretop [2024-May-03] ## +##---------------------------------------## +# Changelog URL Info # +readonly CL_URL_NG="https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" +readonly CL_URL_386="https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" + # For new script version updates from source repository # UpdateNotify=0 DLRepoVersion="" @@ -1243,7 +1250,7 @@ _GetFirmwareVariantFromRouter_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-02] ## +## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## _CreateEMailContent_() { @@ -2335,7 +2342,7 @@ _NodeActiveStatus_() ##----------------------------------------## ## Modified by Martinski W. [2024-Apr-30] ## ##----------------------------------------## -_Populate_Node_Settings_() +_Populate_Node_Settings_() { local MAC_address="$1" local model_id="$2" @@ -5042,7 +5049,7 @@ _PrintNodeInfo() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-24] ## +## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## _ShowMainMenu_() { @@ -5141,6 +5148,9 @@ _ShowMainMenu_() printf "\n ${GRNct}mn${NOct}. AiMesh Node(s) Info\n" fi + # Add selection for "Log Options" sub-menu # + printf "\n ${GRNct}lo${NOct}. Log Options Menu\n" + # Add selection for "Advanced Options" sub-menu # printf "\n ${GRNct}ad${NOct}. Advanced Options\n" @@ -5155,9 +5165,9 @@ _ShowMainMenu_() printf "${SEPstr}\n" } -##-----------------------------------------## -## Modified by ExtemeFiretop [2024-Apr-24] ## -##-----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-03] ## +##------------------------------------------## _ShowAdvancedOptionsMenu_() { clear @@ -5168,26 +5178,23 @@ _ShowAdvancedOptionsMenu_() printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" - printf "\n ${GRNct}2${NOct}. Set Directory for F/W Update Log Files" - printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" - local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" if [ "$checkChangeLogSetting" = "DISABLED" ] then - printf "\n ${GRNct}3${NOct}. Toggle Change-log Check" + printf "\n ${GRNct}2${NOct}. Toggle Change-log Check" printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}3${NOct}. Toggle Change-log Check" + printf "\n ${GRNct}2${NOct}. Toggle Change-log Check" printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" if [ "$BetaProductionSetting" = "DISABLED" ] then - printf "\n ${GRNct}4${NOct}. Toggle Beta-to-Release Upgrades" + printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release Upgrades" printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}4${NOct}. Toggle Beta-to-Release Upgrades" + printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release Upgrades" printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi @@ -5305,6 +5312,103 @@ _ShowNodesMenu_() printf "${SEPstr}" } +_ShowNodesMenuOptions_() +{ + while true + do + _ShowNodesMenu_ + printf "\nEnter selection: " + read -r nodesChoice + echo + case $nodesChoice in + e|exit) break + ;; + *) _InvalidMenuSelection_ + ;; + esac + done +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-May-02] ## +##---------------------------------------## +_DownloadChangelogs_() +{ + if "$isGNUtonFW" + then + FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + changeLogFile="$FW_Changelog_GITHUB" + else + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + if [ "$changeLogTag" = "386" ] + then + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" + elif [ "$changeLogTag" = "NG" ] + then + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" + fi + changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" + fi + if [ ! -f "$changeLogFile" ] + then + Say "Change-log file [$changeLogFile] does NOT exist." + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + else + clear + printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + _WaitForEnterKey_ + less "$changeLogFile" + fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-May-02] ## +##---------------------------------------## +_ShowLogsMenu_() +{ + clear + logo + printf "===================== Logs Menu =====================\n" + printf "${SEPstr}\n" + + printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" + printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" + + printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" + + printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" + printf "${SEPstr}" +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-May-02] ## +##---------------------------------------## +_AdvancedLogsOptions_() +{ + while true + do + _ShowLogsMenu_ + printf "\nEnter selection: " + read -r nodesChoice + echo + case $nodesChoice in + 1) _Set_FW_UpdateLOG_DirectoryPath_ + ;; + cl) _DownloadChangelogs_ + ;; + e|exit) break + ;; + *) _InvalidMenuSelection_ + ;; + esac + done +} + ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-18] ## ##----------------------------------------## @@ -5314,9 +5418,9 @@ _InvalidMenuSelection_() _WaitForEnterKey_ } -##-----------------------------------------## -## Modified by ExtemeFiretop [2024-Apr-24] ## -##-----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-03] ## +##------------------------------------------## _advanced_options_menu_() { while true @@ -5328,11 +5432,9 @@ _advanced_options_menu_() case $advancedChoice in 1) _Set_FW_UpdateZIP_DirectoryPath_ ;; - 2) _Set_FW_UpdateLOG_DirectoryPath_ - ;; - 3) _toggle_change_log_check_ + 2) _toggle_change_log_check_ ;; - 4) _toggle_beta_updates_ + 3) _toggle_beta_updates_ ;; ab) if [ -f "/jffs/scripts/backupmon.sh" ] then _Toggle_Auto_Backups_ @@ -5371,25 +5473,8 @@ _advanced_options_menu_() done } -_ShowNodesMenuOptions_() -{ - while true - do - _ShowNodesMenu_ - printf "\nEnter selection: " - read -r nodesChoice - echo - case $nodesChoice in - e|exit) break - ;; - *) _InvalidMenuSelection_ - ;; - esac - done -} - ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Mar-27] ## +## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## # Main Menu loop inMenuMode=true @@ -5428,6 +5513,8 @@ do else _InvalidMenuSelection_ fi ;; + lo) _AdvancedLogsOptions_ + ;; ad) _advanced_options_menu_ ;; up) _SCRIPTUPDATE_ From ad478abd01076cf8405a6fc24a08c56d3a3b188e Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 3 May 2024 11:04:25 -0400 Subject: [PATCH 064/185] Update MerlinAU.sh --- MerlinAU.sh | 61 +++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 395fb9ce..9124a94d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5334,36 +5334,37 @@ _ShowNodesMenuOptions_() ##---------------------------------------## _DownloadChangelogs_() { - if "$isGNUtonFW" - then - FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" - changeLogFile="$FW_Changelog_GITHUB" - else - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" - if [ "$changeLogTag" = "386" ] - then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" - elif [ "$changeLogTag" = "NG" ] - then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" - fi - changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" - fi - if [ ! -f "$changeLogFile" ] - then - Say "Change-log file [$changeLogFile] does NOT exist." - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" - else - clear - printf "\n${GRNct}Changelog is ready to review!${NOct}\n" - printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" - _WaitForEnterKey_ - less "$changeLogFile" - fi - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if "$isGNUtonFW" + then + FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + changeLogFile="$FW_Changelog_GITHUB" + else + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + if [ "$changeLogTag" = "386" ] + then + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" + elif [ "$changeLogTag" = "NG" ] + then + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" + fi + changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" + fi + if [ ! -f "$changeLogFile" ] + then + Say "Change-log file [$changeLogFile] does NOT exist." + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + else + clear + printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + _WaitForEnterKey_ + less "$changeLogFile" + fi + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 } ##---------------------------------------## From fee7d7f42d8fc38297506a3f257f4983d79b4cdc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 3 May 2024 11:05:46 -0400 Subject: [PATCH 065/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9124a94d..218eb554 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5344,10 +5344,10 @@ _DownloadChangelogs_() changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" if [ "$changeLogTag" = "386" ] then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "${CL_URL_386}" elif [ "$changeLogTag" = "NG" ] then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" + wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "${CL_URL_NG}" fi changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" fi From bb62bfb1aae193070ad8c38c5f77b73807d70dac Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 3 May 2024 11:33:00 -0400 Subject: [PATCH 066/185] Update MerlinAU.sh --- MerlinAU.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 218eb554..33f47cc8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -460,10 +460,15 @@ readonly MAGENTAct="\e[1;35m" readonly CYANct="\e[1;36m" readonly WHITEct="\e[1;37m" -##----------------------------------------## -## Modified by Martinski W. [2024-Feb-22] ## -##----------------------------------------## -readonly FW_Update_CRON_DefaultSchedule="0 0 * * *" +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-03] ## +##------------------------------------------## +if "$inRouterSWmode" +then + readonly FW_Update_CRON_DefaultSchedule="0 0 * * *" +else + readonly FW_Update_CRON_DefaultSchedule="15 0 * * *" +fi readonly CRON_MINS_RegEx="([*0-9]|[1-5][0-9])([\/,-]([0-9]|[1-5][0-9]))*" readonly CRON_HOUR_RegEx="([*0-9]|1[0-9]|2[0-3])([\/,-]([0-9]|1[0-9]|2[0-3]))*" From e33b2e78c84af5c879513e7582feac02891d20a8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 3 May 2024 20:53:36 -0400 Subject: [PATCH 067/185] Update MerlinAU.sh --- MerlinAU.sh | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 33f47cc8..6bf77d1e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3571,16 +3571,17 @@ _CheckNodeFWUpdateNotification_() return 0 } -##----------------------------------------## -## Modified by Martinski W. [2024-Mar-21] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-03] ## +##------------------------------------------## _CheckTimeToUpdateFirmware_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays - local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays + local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays + local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays + local currCronSchedule cronHour cronMinute nextCronRunSecs _CheckNewUpdateFirmwareNotification_ "$1" "$2" @@ -3599,33 +3600,36 @@ _CheckTimeToUpdateFirmware_() currentTimeSecs="$(date +%s)" notifyTimeStrn="$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')" - notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" + notifyTimeSecs="$(date -d "$notifyTimeStrn" +%s)" - #---------------------------------------------------------------------- - # Adjust calculation of postponed days as elapsed time in seconds to - # account for the hour discrepancy when Daylight Saving Time happens. - # This way we can avoid a scenario where the F/W Update "date+time" - # threshold is set one hour *after* the scheduled cron job is set - # to run again and check if it's time to update the router. - #---------------------------------------------------------------------- - if [ "$(date -d @$currentTimeSecs +'%Z')" = "$(date -d @$notifyTimeSecs +'%Z')" ] + # DST Adjustment Calculation + if [ "$(date +'%Z')" = "$(date -d "@$notifyTimeSecs" +'%Z')" ] then dstAdjustSecs=86400 #24-hour day is same as always# else dstAdjustSecs=82800 #23-hour day only when DST happens# fi + dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" - if [ "$dstAdjustDays" -eq 0 ] - then postponeTimeSecs="$dstAdjustSecs" - else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" - fi + postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" + upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" - if [ "$((currentTimeSecs - notifyTimeSecs))" -ge "$postponeTimeSecs" ] - then return 0 ; fi + # Retrieve current CRON schedule setting and calculate next run time + currCronSchedule="$(Get_Custom_Setting FW_New_Update_Cron_Job_Schedule)" + cronMinute=$(echo "$currCronSchedule" | cut -d ' ' -f 1) + cronHour=$(echo "$currCronSchedule" | cut -d ' ' -f 2) - upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" - upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" + # Calculate next cron run based on updated firmware date time + nextCronRunDate="$(date -d "@$upfwDateTimeSecs" +"%Y-%m-%d $cronHour:$cronMinute")" + nextCronRunSecs="$(date -d "$nextCronRunDate" +%s)" + + # Check if calculated cron run time is before the postponed update time, add a day + if [ "$nextCronRunSecs" -lt "$upfwDateTimeSecs" ]; then + nextCronRunSecs="$(($nextCronRunSecs + 86400))" + fi + + upfwDateTimeStrn="$(date -d "@$nextCronRunSecs" +"%A, %Y-%b-%d %I:%M %p")" Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." - Say "The firmware update is expected to occur on or after ${GRNct}${upfwDateTimeStrn}${NOct}, depending on when your cron job is scheduled to check again." + Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." return 1 } From e82c4813f195073dad15c03a006788221e768185 Mon Sep 17 00:00:00 2001 From: ExtremeFiretop Date: Sat, 4 May 2024 01:10:36 -0400 Subject: [PATCH 068/185] Revert "Update MerlinAU.sh" This reverts commit e33b2e78c84af5c879513e7582feac02891d20a8. --- MerlinAU.sh | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 6bf77d1e..33f47cc8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3571,17 +3571,16 @@ _CheckNodeFWUpdateNotification_() return 0 } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Mar-21] ## +##----------------------------------------## _CheckTimeToUpdateFirmware_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays - local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays - local currCronSchedule cronHour cronMinute nextCronRunSecs + local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays + local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays _CheckNewUpdateFirmwareNotification_ "$1" "$2" @@ -3600,36 +3599,33 @@ _CheckTimeToUpdateFirmware_() currentTimeSecs="$(date +%s)" notifyTimeStrn="$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')" - notifyTimeSecs="$(date -d "$notifyTimeStrn" +%s)" + notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" - # DST Adjustment Calculation - if [ "$(date +'%Z')" = "$(date -d "@$notifyTimeSecs" +'%Z')" ] + #---------------------------------------------------------------------- + # Adjust calculation of postponed days as elapsed time in seconds to + # account for the hour discrepancy when Daylight Saving Time happens. + # This way we can avoid a scenario where the F/W Update "date+time" + # threshold is set one hour *after* the scheduled cron job is set + # to run again and check if it's time to update the router. + #---------------------------------------------------------------------- + if [ "$(date -d @$currentTimeSecs +'%Z')" = "$(date -d @$notifyTimeSecs +'%Z')" ] then dstAdjustSecs=86400 #24-hour day is same as always# else dstAdjustSecs=82800 #23-hour day only when DST happens# fi - dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" - postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" - upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" - - # Retrieve current CRON schedule setting and calculate next run time - currCronSchedule="$(Get_Custom_Setting FW_New_Update_Cron_Job_Schedule)" - cronMinute=$(echo "$currCronSchedule" | cut -d ' ' -f 1) - cronHour=$(echo "$currCronSchedule" | cut -d ' ' -f 2) - - # Calculate next cron run based on updated firmware date time - nextCronRunDate="$(date -d "@$upfwDateTimeSecs" +"%Y-%m-%d $cronHour:$cronMinute")" - nextCronRunSecs="$(date -d "$nextCronRunDate" +%s)" - - # Check if calculated cron run time is before the postponed update time, add a day - if [ "$nextCronRunSecs" -lt "$upfwDateTimeSecs" ]; then - nextCronRunSecs="$(($nextCronRunSecs + 86400))" + if [ "$dstAdjustDays" -eq 0 ] + then postponeTimeSecs="$dstAdjustSecs" + else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" fi - upfwDateTimeStrn="$(date -d "@$nextCronRunSecs" +"%A, %Y-%b-%d %I:%M %p")" + if [ "$((currentTimeSecs - notifyTimeSecs))" -ge "$postponeTimeSecs" ] + then return 0 ; fi + + upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" + upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." - Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." + Say "The firmware update is expected to occur on or after ${GRNct}${upfwDateTimeStrn}${NOct}, depending on when your cron job is scheduled to check again." return 1 } From b62bc936a6ea28ca2973ef1575a877bb41049927 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 4 May 2024 04:03:19 -0400 Subject: [PATCH 069/185] Update MerlinAU.sh --- MerlinAU.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 33f47cc8..ccca8eea 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5359,7 +5359,6 @@ _DownloadChangelogs_() if [ ! -f "$changeLogFile" ] then Say "Change-log file [$changeLogFile] does NOT exist." - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" else clear printf "\n${GRNct}Changelog is ready to review!${NOct}\n" @@ -5367,7 +5366,7 @@ _DownloadChangelogs_() _WaitForEnterKey_ less "$changeLogFile" fi - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + rm -f "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 } From 409d0150f1b74484326a959948809e2653813fb2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 4 May 2024 04:44:49 -0400 Subject: [PATCH 070/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index ccca8eea..23bb4143 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5364,7 +5364,7 @@ _DownloadChangelogs_() printf "\n${GRNct}Changelog is ready to review!${NOct}\n" printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" _WaitForEnterKey_ - less "$changeLogFile" + more "$changeLogFile" fi rm -f "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" From b8cb2064785edbe22053a09c6a57f2bd4ec2e2f9 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 4 May 2024 19:56:52 -0400 Subject: [PATCH 071/185] Update MerlinAU.sh --- MerlinAU.sh | 195 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 173 insertions(+), 22 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 23bb4143..a0beeb69 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3571,16 +3571,172 @@ _CheckNodeFWUpdateNotification_() return 0 } -##----------------------------------------## -## Modified by Martinski W. [2024-Mar-21] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Conversion functions for month and day names to numbers +convert_month_to_number() { + case "$1" in + [Jj][Aa][Nn]) echo 1 ;; + [Ff][Ee][Bb]) echo 2 ;; + [Mm][Aa][Rr]) echo 3 ;; + [Aa][Pp][Rr]) echo 4 ;; + [Mm][Aa][Yy]) echo 5 ;; + [Jj][Uu][Nn]) echo 6 ;; + [Jj][Uu][Ll]) echo 7 ;; + [Aa][Uu][Gg]) echo 8 ;; + [Ss][Ee][Pp]) echo 9 ;; + [Oo][Cc][Tt]) echo 10 ;; + [Nn][Oo][Vv]) echo 11 ;; + [Dd][Ee][Cc]) echo 12 ;; + *) + echo "No match found, returning original input: $1" + echo "$1" + ;; + esac +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +convert_day_to_number() { + case "$1" in + [Ss][Uu][Nn]) echo 0 ;; + [Mm][Oo][Nn]) echo 1 ;; + [Tt][Uu][Ee]) echo 2 ;; + [Ww][Ee][Dd]) echo 3 ;; + [Tt][Hh][Uu]) echo 4 ;; + [Ff][Rr][Ii]) echo 5 ;; + [Ss][Aa][Tt]) echo 6 ;; + *) + echo "No match found, returning original input: $1" + echo "$1" + ;; + esac +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Sakamoto's algorithm to find the day of the week +calculate_day_of_week() { + day=$1 + month=$2 + year=$3 + + if [ $month -le 2 ]; then + month=$((month + 12)) + year=$((year - 1)) + fi + + t=$(((13 * (month + 1)) / 5)) + K=$((year % 100)) + J=$((year / 100)) + dow=$(((day + t + K + (K / 4) + (J / 4) - (2 * J)) % 7)) + + if [ $dow -eq 0 ]; then + dow=6 # Saturday + else + dow=$((dow - 1)) # Adjusting the result so Sunday = 0 + fi + + echo $dow +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Manually calculate the next day +increment_date() { + day=$1 + month=$2 + year=$3 + days_in_month="31 28 31 30 31 30 31 31 30 31 30 31" + set -- $days_in_month + month_days=$(eval echo \${$((month + 0))}) + + if [ $month -eq 2 ]; then + if [ $((year % 4)) -eq 0 ] && { [ $((year % 100)) -ne 0 ] || [ $((year % 400)) -eq 0 ]; }; then + month_days=29 + fi + fi + + day=$((day + 1)) + if [ $day -gt $month_days ]; then + day=1 + month=$((month + 1)) + fi + if [ $month -gt 12 ]; then + month=1 + year=$((year + 1)) + fi + + echo $day $month $year +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Function to estimate the next run time of a cron job after a specific date +estimate_next_cron_after_date() { + post_date_secs=$1 + cron_schedule="$2" + minute=$(echo "$cron_schedule" | cut -d' ' -f1) + hour=$(echo "$cron_schedule" | cut -d' ' -f2) + dom=$(echo "$cron_schedule" | cut -d' ' -f3) + month_cron=$(echo "$cron_schedule" | cut -d' ' -f4) + dow=$(echo "$cron_schedule" | cut -d' ' -f5) + + # Check for alphabetic characters and convert if necessary + case "$month_cron" in + *[a-zA-Z]*) + month_cron=$(convert_month_to_number "$month_cron") + ;; + esac + + case "$dow" in + *[a-zA-Z]*) + dow=$(convert_day_to_number "$dow") + ;; + esac + + # Convert post_date_secs to date components + eval $(date '+day=%d month=%m year=%Y' -d @$post_date_secs) + + day_count=0 + while [ $day_count -lt 365 ]; do + current_dow=$(calculate_day_of_week $day $month $year) + if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && + { [ "$month_cron" = "*" ] || [ "$month_cron" = "$month" ]; } && + { [ "$dow" = "*" ] || [ "$dow" = "$current_dow" ]; }; then + next_cron_run=$(date +%s -d "$year-$month-$day $hour:$minute") + if [ $next_cron_run -gt $post_date_secs ]; then + echo $next_cron_run + return + fi + fi + new_date=$(increment_date $day $month $year) + set -- $new_date + day=$1 + month=$2 + year=$3 + day_count=$((day_count + 1)) + done + + echo "no_date_found" +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## _CheckTimeToUpdateFirmware_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays - local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays + local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays + local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays + local nextCronTimeSecs upfwDateTimeStrn _CheckNewUpdateFirmwareNotification_ "$1" "$2" @@ -3590,7 +3746,7 @@ _CheckTimeToUpdateFirmware_() fwNewUpdatePostponementDays="$(Get_Custom_Setting FW_New_Update_Postponement_Days TBD)" if [ -z "$fwNewUpdatePostponementDays" ] || [ "$fwNewUpdatePostponementDays" = "TBD" ] then - fwNewUpdatePostponementDays="$FW_UpdateDefaultPostponementDays" + fwNewUpdatePostponementDays="$fwNewUpdatePostponementDays" Update_Custom_Settings FW_New_Update_Postponement_Days "$fwNewUpdatePostponementDays" fi @@ -3601,31 +3757,26 @@ _CheckTimeToUpdateFirmware_() notifyTimeStrn="$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')" notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" - #---------------------------------------------------------------------- - # Adjust calculation of postponed days as elapsed time in seconds to - # account for the hour discrepancy when Daylight Saving Time happens. - # This way we can avoid a scenario where the F/W Update "date+time" - # threshold is set one hour *after* the scheduled cron job is set - # to run again and check if it's time to update the router. - #---------------------------------------------------------------------- + # Adjust for DST discrepancies if [ "$(date -d @$currentTimeSecs +'%Z')" = "$(date -d @$notifyTimeSecs +'%Z')" ] then dstAdjustSecs=86400 #24-hour day is same as always# else dstAdjustSecs=82800 #23-hour day only when DST happens# fi dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" - if [ "$dstAdjustDays" -eq 0 ] - then postponeTimeSecs="$dstAdjustSecs" - else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" - fi + postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" + upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" - if [ "$((currentTimeSecs - notifyTimeSecs))" -ge "$postponeTimeSecs" ] - then return 0 ; fi + nextCronTimeSecs=$(estimate_next_cron_after_date $upfwDateTimeSecs "$FW_UpdateCronJobSchedule") - upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" - upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" + if [ "$nextCronTimeSecs" = "no_date_found" ]; then + Say "No suitable date found for the firmware update within the next year." + return 1 + fi + + upfwDateTimeStrn="$(date -d @$nextCronTimeSecs +"%A, %Y-%b-%d %I:%M %p")" Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." - Say "The firmware update is expected to occur on or after ${GRNct}${upfwDateTimeStrn}${NOct}, depending on when your cron job is scheduled to check again." + Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." return 1 } From 3f3ac298cee8c8098592875398330dc6c73cadb2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 4 May 2024 20:54:43 -0400 Subject: [PATCH 072/185] Update MerlinAU.sh --- MerlinAU.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a0beeb69..1843f8f6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3746,7 +3746,7 @@ _CheckTimeToUpdateFirmware_() fwNewUpdatePostponementDays="$(Get_Custom_Setting FW_New_Update_Postponement_Days TBD)" if [ -z "$fwNewUpdatePostponementDays" ] || [ "$fwNewUpdatePostponementDays" = "TBD" ] then - fwNewUpdatePostponementDays="$fwNewUpdatePostponementDays" + fwNewUpdatePostponementDays="$FW_UpdateDefaultPostponementDays" Update_Custom_Settings FW_New_Update_Postponement_Days "$fwNewUpdatePostponementDays" fi @@ -3763,7 +3763,10 @@ _CheckTimeToUpdateFirmware_() else dstAdjustSecs=82800 #23-hour day only when DST happens# fi dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" - postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" + if [ "$dstAdjustDays" -eq 0 ] + then postponeTimeSecs="$dstAdjustSecs" + else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" + fi upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" nextCronTimeSecs=$(estimate_next_cron_after_date $upfwDateTimeSecs "$FW_UpdateCronJobSchedule") From 0765131e626449e3dc87bd5d29522a44abc7f92d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 5 May 2024 12:56:11 -0400 Subject: [PATCH 073/185] Update MerlinAU.sh --- MerlinAU.sh | 74 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 1843f8f6..7557eefe 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3655,6 +3655,7 @@ increment_date() { set -- $days_in_month month_days=$(eval echo \${$((month + 0))}) + # Adjust for leap year in February if [ $month -eq 2 ]; then if [ $((year % 4)) -eq 0 ] && { [ $((year % 100)) -ne 0 ] || [ $((year % 400)) -eq 0 ]; }; then month_days=29 @@ -3687,34 +3688,59 @@ estimate_next_cron_after_date() { month_cron=$(echo "$cron_schedule" | cut -d' ' -f4) dow=$(echo "$cron_schedule" | cut -d' ' -f5) - # Check for alphabetic characters and convert if necessary - case "$month_cron" in - *[a-zA-Z]*) - month_cron=$(convert_month_to_number "$month_cron") - ;; - esac - - case "$dow" in - *[a-zA-Z]*) - dow=$(convert_day_to_number "$dow") - ;; - esac - # Convert post_date_secs to date components eval $(date '+day=%d month=%m year=%Y' -d @$post_date_secs) + month=$(echo $month | sed 's/^0*//') # Remove leading zeros for month day_count=0 while [ $day_count -lt 365 ]; do current_dow=$(calculate_day_of_week $day $month $year) - if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && - { [ "$month_cron" = "*" ] || [ "$month_cron" = "$month" ]; } && - { [ "$dow" = "*" ] || [ "$dow" = "$current_dow" ]; }; then - next_cron_run=$(date +%s -d "$year-$month-$day $hour:$minute") - if [ $next_cron_run -gt $post_date_secs ]; then - echo $next_cron_run - return - fi - fi + + num_dow_entries=$(echo $dow | tr ',' '\n' | wc -l) # Count number of dow entries + dow_index=1 + while [ $dow_index -le $num_dow_entries ]; do + dow_entry=$(echo $dow | cut -d',' -f$dow_index) # Get the dow_index-th entry + + # Convert alphabetic day of the week to number if necessary + case "$dow_entry" in + *[a-zA-Z]*) + dow_entry=$(convert_day_to_number "$dow_entry") + ;; + esac + + num_month_entries=$(echo $month_cron | tr ',' '\n' | wc -l) # Count number of month entries + month_index=1 + while [ $month_index -le $num_month_entries ]; do + month_entry=$(echo $month_cron | cut -d',' -f$month_index) # Get the month_index-th entry + + # Convert month name to number if necessary + case "$month_entry" in + *[a-zA-Z]*) + month_entry=$(convert_month_to_number "$month_entry") + ;; + *) + month_entry=$(echo $month_entry | sed 's/^0*//') # Remove leading zeros + ;; + esac + + if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && + { [ "$month_entry" = "*" ] || [ "$month_entry" = "$month" ]; } && + { [ "$dow_entry" = "*" ] || [ "$dow_entry" = "$current_dow" ]; }; then + cron_date="$year-$month-$day $hour:$minute" + next_cron_run=$(date +%s -d "$cron_date") + if [ $next_cron_run -gt $post_date_secs ]; then + echo $next_cron_run + return + fi + fi + + month_index=$((month_index + 1)) + done + + dow_index=$((dow_index + 1)) + done + + # Increment date new_date=$(increment_date $day $month $year) set -- $new_date day=$1 @@ -3722,7 +3748,6 @@ estimate_next_cron_after_date() { year=$3 day_count=$((day_count + 1)) done - echo "no_date_found" } @@ -3772,7 +3797,8 @@ _CheckTimeToUpdateFirmware_() nextCronTimeSecs=$(estimate_next_cron_after_date $upfwDateTimeSecs "$FW_UpdateCronJobSchedule") if [ "$nextCronTimeSecs" = "no_date_found" ]; then - Say "No suitable date found for the firmware update within the next year." + upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" + Say "The firmware update is expected to occur on or after ${GRNct}${upfwDateTimeStrn}${NOct}, depending on when your cron job is scheduled to check again." return 1 fi From f1f5c62de4cbe8e003a169b0f452d40b1eb2c8c4 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 9 May 2024 22:18:38 -0400 Subject: [PATCH 074/185] Update MerlinAU.sh --- MerlinAU.sh | 786 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 531 insertions(+), 255 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 7557eefe..e833f4aa 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-02 +# Last Modified: 2024-May-09 ################################################################### set -u @@ -27,8 +27,8 @@ readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.n ## Added by ExtremeFiretop [2024-May-03] ## ##---------------------------------------## # Changelog URL Info # -readonly CL_URL_NG="https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-NG.txt/download" -readonly CL_URL_386="https://sourceforge.net/projects/asuswrt-merlin/files/Documentation/Changelog-386.txt/download" +readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" +readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" # For new script version updates from source repository # UpdateNotify=0 @@ -789,6 +789,7 @@ Get_Custom_Setting() setting_value="$(grep "^${setting_type} " "$SETTINGSFILE" | awk -F ' ' '{print $2}')" ;; "FW_New_Update_Postponement_Days" | \ + "FW_New_Update_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ "FW_New_Update_LOG_Directory_Path" | \ @@ -872,6 +873,7 @@ Update_Custom_Settings() fi ;; "FW_New_Update_Postponement_Days" | \ + "FW_New_Update_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ "FW_New_Update_LOG_Directory_Path" | \ @@ -1739,7 +1741,8 @@ _GetCurrentFWInstalledLongVersion_() _GetCurrentFWInstalledShortVersion_() { ##FOR TESTING/DEBUG ONLY## -if false ; then echo "388.5.0" ; return 0 ; fi +if false ; then echo "388.6.2" ; return 0 ; fi +##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum @@ -2670,21 +2673,24 @@ _DownloadForGnuton_() { FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" # Download the firmware using the release link - wget -O "$FW_DL_FPATH" "$release_link" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_DL_FPATH" "$release_link" if [ ! -f "$FW_DL_FPATH" ]; then return 1 fi # Download the latest MD5 checksum Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" - wget -O "$FW_MD5_GITHUB" "$md5_url" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_MD5_GITHUB" "$md5_url" if [ ! -f "$FW_MD5_GITHUB" ]; then return 1 fi # Download the latest changelog Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" - wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" if [ ! -f "$FW_Changelog_GITHUB" ]; then return 1 else @@ -2697,7 +2703,8 @@ _DownloadForGnuton_() { ##---------------------------------------## _DownloadForMerlin_() { - wget -O "$FW_ZIP_FPATH" "$release_link" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_ZIP_FPATH" "$release_link" # Check if the file was downloaded successfully if [ ! -f "$FW_ZIP_FPATH" ]; then @@ -3199,6 +3206,248 @@ translate_schedule() echo "$day_of_week_text, $day_of_month_text, in $month_text." } +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Conversion functions for month and day names to numbers +convert_month_to_number() { + case "$1" in + [Jj][Aa][Nn]) echo 1 ;; + [Ff][Ee][Bb]) echo 2 ;; + [Mm][Aa][Rr]) echo 3 ;; + [Aa][Pp][Rr]) echo 4 ;; + [Mm][Aa][Yy]) echo 5 ;; + [Jj][Uu][Nn]) echo 6 ;; + [Jj][Uu][Ll]) echo 7 ;; + [Aa][Uu][Gg]) echo 8 ;; + [Ss][Ee][Pp]) echo 9 ;; + [Oo][Cc][Tt]) echo 10 ;; + [Nn][Oo][Vv]) echo 11 ;; + [Dd][Ee][Cc]) echo 12 ;; + *) + echo "$1" + ;; + esac +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +convert_day_to_number() { + case "$1" in + [Ss][Uu][Nn]) echo 0 ;; + [Mm][Oo][Nn]) echo 1 ;; + [Tt][Uu][Ee]) echo 2 ;; + [Ww][Ee][Dd]) echo 3 ;; + [Tt][Hh][Uu]) echo 4 ;; + [Ff][Rr][Ii]) echo 5 ;; + [Ss][Aa][Tt]) echo 6 ;; + *) + echo "$1" + ;; + esac +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Sakamoto's algorithm to find the day of the week +calculate_day_of_week() { + day="$1" + month="$2" + year="$3" + + if [ "$month" -le 2 ]; then + month="$((month + 12))" + year="$((year - 1))" + fi + + t="$(((13 * (month + 1)) / 5))" + K="$((year % 100))" + J="$((year / 100))" + dow="$(((day + t + K + (K / 4) + (J / 4) - (2 * J)) % 7))" + + if [ "$dow" -eq 0 ]; then + dow=6 # Saturday + else + dow="$((dow - 1))" # Adjusting the result so Sunday = 0 + fi + + echo "$dow" +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Manually calculate the next day +increment_date() { + local day="$1" + local month="$2" + local year="$3" + + # Validate input + if [ -z "$day" ] || [ -z "$month" ] || [ -z "$year" ]; then + echo "Error: Missing day, month, or year parameter." + return 1 # Return error + fi + + days_in_month="31 28 31 30 31 30 31 31 30 31 30 31" + set -- $days_in_month + month_days=$(eval echo \${$((month + 0))}) + + # Adjust for leap year in February + if [ "$month" -eq 2 ]; then + if [ "$((year % 4))" -eq 0 ] && { [ "$((year % 100))" -ne 0 ] || [ "$((year % 400))" -eq 0 ]; }; then + month_days=29 + fi + fi + + day="$((day + 1))" + if [ "$day" -gt "$month_days" ]; then + day=1 + month="$((month + 1))" + fi + if [ "$month" -gt 12 ]; then + month=1 + year="$((year + 1))" + fi + + echo "$day" "$month" "$year" +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-04] ## +##------------------------------------------## +# Function to estimate the next run time of a cron job after a specific date +estimate_next_cron_after_date() { + local post_date_secs="$1" + local cron_schedule="$2" + local minute="$(echo "$cron_schedule" | cut -d' ' -f1)" + local hour="$(echo "$cron_schedule" | cut -d' ' -f2)" + local dom="$(echo "$cron_schedule" | cut -d' ' -f3)" + local month_cron="$(echo "$cron_schedule" | cut -d' ' -f4)" + local dow="$(echo "$cron_schedule" | cut -d' ' -f5)" + + # Convert post_date_secs to date components + eval $(date '+day=%d month=%m year=%Y' -d @$post_date_secs) + day="$(echo "$day" | sed 's/^0*//')" # Remove leading zeros + month="$(echo "$month" | sed 's/^0*//')" # Remove leading zeros + + day_count=0 + while [ "$day_count" -lt 365 ]; do + current_dow="$(calculate_day_of_week "$day" "$month" "$year")" + + num_dow_entries="$(echo "$dow" | tr ',' '\n' | wc -l)" # Count number of dow entries + dow_index=1 + while [ "$dow_index" -le "$num_dow_entries" ]; do + dow_entry="$(echo "$dow" | cut -d',' -f"$dow_index")" # Get the dow_index-th entry + + # Convert alphabetic day of the week to number if necessary + case "$dow_entry" in + *[[:alpha:]]*) + dow_entry=$(convert_day_to_number "$dow_entry") + ;; + esac + + num_month_entries="$(echo "$month_cron" | tr ',' '\n' | wc -l)" # Count number of month entries + month_index=1 + while [ "$month_index" -le "$num_month_entries" ]; do + month_entry="$(echo "$month_cron" | cut -d',' -f"$month_index")" # Get the month_index-th entry + + # Convert month name to number if necessary + case "$month_entry" in + *[[:alpha:]]*) + month_entry=$(convert_month_to_number "$month_entry") + ;; + *) + month_entry="$(echo "$month_entry" | sed 's/^0*//')" # Remove leading zeros + ;; + esac + + if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && + { [ "$month_entry" = "*" ] || [ "$month_entry" = "$month" ]; } && + { [ "$dow_entry" = "*" ] || [ "$dow_entry" = "$current_dow" ]; }; then + cron_date="$year-$month-$day $hour:$minute" + next_cron_run="$(date +%s -d "$cron_date")" + if [ "$next_cron_run" -gt "$post_date_secs" ]; then + echo "$next_cron_run" + return + fi + fi + + month_index="$((month_index + 1))" + done + + dow_index="$((dow_index + 1))" + done + + # Increment date + new_date="$(increment_date "$day" "$month" "$year")" + set -- $new_date + local day="$1" + local month="$2" + local year="$3" + local day_count="$((day_count + 1))" + done + echo "no_date_found" +} + +calculate_DST() { + local notifyTimeStrn notifyTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays + local postponeTimeSecs fwNewUpdatePostponementDays + + notifyTimeStrn="$1" + + currentTimeSecs="$(date +%s)" + notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" + + # Adjust for DST discrepancies + if [ "$(date -d @$currentTimeSecs +'%Z')" = "$(date -d @$notifyTimeSecs +'%Z')" ] + then dstAdjustSecs=86400 # 24-hour day is same as always + else dstAdjustSecs=82800 # 23-hour day only when DST happens + fi + + fwNewUpdatePostponementDays="$(Get_Custom_Setting FW_New_Update_Postponement_Days)" + dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" + if [ "$dstAdjustDays" -eq 0 ] + then postponeTimeSecs="$dstAdjustSecs" + else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" + fi + + echo "$((notifyTimeSecs + postponeTimeSecs))" +} + +_calculate_NextRunTime_() { + # Check for available firmware update + local fwNewUpdateVersion + if ! fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)"; then + fwNewUpdateVersion="NONE FOUND" + fi + + ExpectedFWUpdateRuntime="$(Get_Custom_Setting FW_New_Update_Run_Date)" + + # Determine appropriate messaging based on the firmware update availability and check state + if [ "$FW_UpdateCheckState" -eq 0 ]; then + ExpectedFWUpdateRuntime="${REDct}NO CRON JOB${NOct}" + elif [ "$fwNewUpdateVersion" = "NONE FOUND" ]; then + ExpectedFWUpdateRuntime="${REDct}NONE FOUND${NOct}" + elif [ "$ExpectedFWUpdateRuntime" = "TBD" ] || [ -z "$ExpectedFWUpdateRuntime" ]; then + # If conditions are met (cron job enabled and update available), calculate the next runtime + local fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" + if [ "$fwNewUpdateNotificationDate" = "TBD" ] || [ -z "$fwNewUpdateNotificationDate" ]; then + fwNewUpdateNotificationDate="$(date +%Y-%m-%d_%H:%M:%S)" + fi + local upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") + local nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") + Update_Custom_Settings FW_New_Update_Run_Date "$nextCronTimeSecs" + ExpectedFWUpdateRuntime="$(date -d @$nextCronTimeSecs +"%Y-%b-%d %I:%M %p")" + ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" + else + ExpectedFWUpdateRuntime="$(date -d @$ExpectedFWUpdateRuntime +"%Y-%b-%d %I:%M %p")" + ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" + fi +} + ##----------------------------------------------## ## Added/Modified by Martinski W. [2023-Nov-19] ## ##----------------------------------------------## @@ -3265,9 +3514,9 @@ _CheckPostponementDays_() return "$retCode" } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Nov-19] ## -##----------------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-06] ## +##------------------------------------------## _Set_FW_UpdatePostponementDays_() { local validNumRegExp="([0-9]|[1-9][0-9])" @@ -3306,6 +3555,7 @@ _Set_FW_UpdatePostponementDays_() then Update_Custom_Settings FW_New_Update_Postponement_Days "$newPostponementDays" echo "The number of days to postpone F/W Update was updated successfully." + _calculate_NextRunTime_ _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi return 0 @@ -3386,9 +3636,9 @@ _ValidateCronJobSchedule_() return 0 } -##----------------------------------------## -## Modified by Martinski W. [2024-Feb-22] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-06] ## +##------------------------------------------## _Set_FW_UpdateCronSchedule_() { printf "Changing Firmware Update Schedule...\n" @@ -3450,6 +3700,7 @@ _Set_FW_UpdateCronSchedule_() printf "Cron job '${GRNct}${CRON_JOB_TAG}${NOct}' was updated successfully.\n" current_schedule_english="$(translate_schedule "$nextCronSchedule")" printf "Job Schedule: ${GRNct}${current_schedule_english}${NOct}\n" + _calculate_NextRunTime_ else retCode=1 printf "${REDct}**ERROR**${NOct}: Failed to add/update the cron job [${CRON_JOB_TAG}].\n" @@ -3465,7 +3716,7 @@ _Set_FW_UpdateCronSchedule_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-13] ## +## Modified by ExtremeFiretop [2024-May-06] ## ##------------------------------------------## _CheckNewUpdateFirmwareNotification_() { @@ -3517,6 +3768,10 @@ _CheckNewUpdateFirmwareNotification_() _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi fi + fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" + upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") + nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") + Update_Custom_Settings FW_New_Update_Run_Date "$nextCronTimeSecs" return 0 } @@ -3572,196 +3827,14 @@ _CheckNodeFWUpdateNotification_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## +## Modified by ExtremeFiretop [2024-May-06] ## ##------------------------------------------## -# Conversion functions for month and day names to numbers -convert_month_to_number() { - case "$1" in - [Jj][Aa][Nn]) echo 1 ;; - [Ff][Ee][Bb]) echo 2 ;; - [Mm][Aa][Rr]) echo 3 ;; - [Aa][Pp][Rr]) echo 4 ;; - [Mm][Aa][Yy]) echo 5 ;; - [Jj][Uu][Nn]) echo 6 ;; - [Jj][Uu][Ll]) echo 7 ;; - [Aa][Uu][Gg]) echo 8 ;; - [Ss][Ee][Pp]) echo 9 ;; - [Oo][Cc][Tt]) echo 10 ;; - [Nn][Oo][Vv]) echo 11 ;; - [Dd][Ee][Cc]) echo 12 ;; - *) - echo "No match found, returning original input: $1" - echo "$1" - ;; - esac -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -convert_day_to_number() { - case "$1" in - [Ss][Uu][Nn]) echo 0 ;; - [Mm][Oo][Nn]) echo 1 ;; - [Tt][Uu][Ee]) echo 2 ;; - [Ww][Ee][Dd]) echo 3 ;; - [Tt][Hh][Uu]) echo 4 ;; - [Ff][Rr][Ii]) echo 5 ;; - [Ss][Aa][Tt]) echo 6 ;; - *) - echo "No match found, returning original input: $1" - echo "$1" - ;; - esac -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Sakamoto's algorithm to find the day of the week -calculate_day_of_week() { - day=$1 - month=$2 - year=$3 - - if [ $month -le 2 ]; then - month=$((month + 12)) - year=$((year - 1)) - fi - - t=$(((13 * (month + 1)) / 5)) - K=$((year % 100)) - J=$((year / 100)) - dow=$(((day + t + K + (K / 4) + (J / 4) - (2 * J)) % 7)) - - if [ $dow -eq 0 ]; then - dow=6 # Saturday - else - dow=$((dow - 1)) # Adjusting the result so Sunday = 0 - fi - - echo $dow -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Manually calculate the next day -increment_date() { - day=$1 - month=$2 - year=$3 - days_in_month="31 28 31 30 31 30 31 31 30 31 30 31" - set -- $days_in_month - month_days=$(eval echo \${$((month + 0))}) - - # Adjust for leap year in February - if [ $month -eq 2 ]; then - if [ $((year % 4)) -eq 0 ] && { [ $((year % 100)) -ne 0 ] || [ $((year % 400)) -eq 0 ]; }; then - month_days=29 - fi - fi - - day=$((day + 1)) - if [ $day -gt $month_days ]; then - day=1 - month=$((month + 1)) - fi - if [ $month -gt 12 ]; then - month=1 - year=$((year + 1)) - fi - - echo $day $month $year -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Function to estimate the next run time of a cron job after a specific date -estimate_next_cron_after_date() { - post_date_secs=$1 - cron_schedule="$2" - minute=$(echo "$cron_schedule" | cut -d' ' -f1) - hour=$(echo "$cron_schedule" | cut -d' ' -f2) - dom=$(echo "$cron_schedule" | cut -d' ' -f3) - month_cron=$(echo "$cron_schedule" | cut -d' ' -f4) - dow=$(echo "$cron_schedule" | cut -d' ' -f5) - - # Convert post_date_secs to date components - eval $(date '+day=%d month=%m year=%Y' -d @$post_date_secs) - month=$(echo $month | sed 's/^0*//') # Remove leading zeros for month - - day_count=0 - while [ $day_count -lt 365 ]; do - current_dow=$(calculate_day_of_week $day $month $year) - - num_dow_entries=$(echo $dow | tr ',' '\n' | wc -l) # Count number of dow entries - dow_index=1 - while [ $dow_index -le $num_dow_entries ]; do - dow_entry=$(echo $dow | cut -d',' -f$dow_index) # Get the dow_index-th entry - - # Convert alphabetic day of the week to number if necessary - case "$dow_entry" in - *[a-zA-Z]*) - dow_entry=$(convert_day_to_number "$dow_entry") - ;; - esac - - num_month_entries=$(echo $month_cron | tr ',' '\n' | wc -l) # Count number of month entries - month_index=1 - while [ $month_index -le $num_month_entries ]; do - month_entry=$(echo $month_cron | cut -d',' -f$month_index) # Get the month_index-th entry - - # Convert month name to number if necessary - case "$month_entry" in - *[a-zA-Z]*) - month_entry=$(convert_month_to_number "$month_entry") - ;; - *) - month_entry=$(echo $month_entry | sed 's/^0*//') # Remove leading zeros - ;; - esac - - if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && - { [ "$month_entry" = "*" ] || [ "$month_entry" = "$month" ]; } && - { [ "$dow_entry" = "*" ] || [ "$dow_entry" = "$current_dow" ]; }; then - cron_date="$year-$month-$day $hour:$minute" - next_cron_run=$(date +%s -d "$cron_date") - if [ $next_cron_run -gt $post_date_secs ]; then - echo $next_cron_run - return - fi - fi - - month_index=$((month_index + 1)) - done - - dow_index=$((dow_index + 1)) - done - - # Increment date - new_date=$(increment_date $day $month $year) - set -- $new_date - day=$1 - month=$2 - year=$3 - day_count=$((day_count + 1)) - done - echo "no_date_found" -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -_CheckTimeToUpdateFirmware_() -{ +_CheckTimeToUpdateFirmware_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local notifyTimeSecs postponeTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays - local fwNewUpdateNotificationDate fwNewUpdateNotificationVers fwNewUpdatePostponementDays - local nextCronTimeSecs upfwDateTimeStrn + local upfwDateTimeSecs nextCronTimeSecs upfwDateTimeStrn + local fwNewUpdatePostponementDays fwNewUpdateNotificationDate _CheckNewUpdateFirmwareNotification_ "$1" "$2" @@ -3778,23 +3851,13 @@ _CheckTimeToUpdateFirmware_() if [ "$fwNewUpdatePostponementDays" -eq 0 ] then return 0 ; fi - currentTimeSecs="$(date +%s)" - notifyTimeStrn="$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')" - notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" + upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") - # Adjust for DST discrepancies - if [ "$(date -d @$currentTimeSecs +'%Z')" = "$(date -d @$notifyTimeSecs +'%Z')" ] - then dstAdjustSecs=86400 #24-hour day is same as always# - else dstAdjustSecs=82800 #23-hour day only when DST happens# - fi - dstAdjustDays="$((fwNewUpdatePostponementDays - 1))" - if [ "$dstAdjustDays" -eq 0 ] - then postponeTimeSecs="$dstAdjustSecs" - else postponeTimeSecs="$(((dstAdjustDays * 86400) + dstAdjustSecs))" - fi - upfwDateTimeSecs="$((notifyTimeSecs + postponeTimeSecs))" + local currentTimeSecs="$(date +%s)" + if [ "$((currentTimeSecs - upfwDateTimeSecs))" -ge 0 ] + then return 0 ; fi - nextCronTimeSecs=$(estimate_next_cron_after_date $upfwDateTimeSecs "$FW_UpdateCronJobSchedule") + nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") if [ "$nextCronTimeSecs" = "no_date_found" ]; then upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" @@ -5145,6 +5208,197 @@ FW_InstalledVers="$(_GetCurrentFWInstalledShortVersion_)" FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" FW_InstalledVersion="${GRNct}$(_GetCurrentFWInstalledLongVersion_)${NOct}" +##-------------------------------------## +## Added by Martinski W. [2024-May-03] ## +##-------------------------------------## +_list2_() +{ + if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] + then return 1 ; fi + local prevIFS="$IFS" + IFS="$(printf '\n\t')" + ls $1 $2 ; retcode="$?" + IFS="$prevIFS" + return "$retcode" +} + +##-------------------------------------## +## Added by Martinski W. [2024-May-03] ## +##-------------------------------------## +_GetFileSelectionIndex_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi + + local selectStr promptStr numRegEx indexNum indexList + local multiIndexListOK theAllStr="${GRNct}all${NOct}" + + if [ "$1" -eq 1 ] + then selectStr="${GRNct}1${NOct}" + else selectStr="${GRNct}1${NOct}-${GRNct}${1}${NOct}" + fi + + if [ $# -lt 2 ] || [ "$2" != "-MULTIOK" ] + then + multiIndexListOK=false + promptStr="Enter selection [${selectStr}] [${theExitStr}]?" + else + multiIndexListOK=true + promptStr="Enter selection [${selectStr} | ${theAllStr}] [${theExitStr}]?" + fi + fileIndex=0 multiIndex=false + numRegEx="([1-9]|[1-9][0-9])" + + while true + do + printf "${promptStr} " ; read -r userInput + + if [ -z "$userInput" ] || \ + echo "$userInput" | grep -qE "^(e|exit|Exit)$" + then fileIndex="NONE" ; break ; fi + + if "$multiIndexListOK" && \ + echo "$userInput" | grep -qE "^(all|All)$" + then fileIndex="ALL" ; break ; fi + + if echo "$userInput" | grep -qE "^${numRegEx}$" && \ + [ "$userInput" -gt 0 ] && [ "$userInput" -le "$1" ] + then fileIndex="$userInput" ; break ; fi + + if "$multiIndexListOK" && \ + echo "$userInput" | grep -qE "^${numRegEx}\-${numRegEx}[ ]*$" + then ## Index Range ## + index1st="$(echo "$userInput" | awk -F '-' '{print $1}')" + indexMax="$(echo "$userInput" | awk -F '-' '{print $2}')" + if [ "$index1st" -lt "$indexMax" ] && \ + [ "$index1st" -gt 0 ] && [ "$index1st" -le "$1" ] && \ + [ "$indexMax" -gt 0 ] && [ "$indexMax" -le "$1" ] + then + indexNum="$index1st" + indexList="$indexNum" + while [ "$indexNum" -lt "$indexMax" ] + do + indexNum="$((indexNum+1))" + indexList="${indexList},${indexNum}" + done + userInput="$indexList" + fi + fi + + if "$multiIndexListOK" && \ + echo "$userInput" | grep -qE "^${numRegEx}(,[ ]*${numRegEx}[ ]*)+$" + then ## Index List ## + indecesOK=true + indexList="$(echo "$userInput" | sed 's/ //g' | sed 's/,/ /g')" + for theIndex in $indexList + do + if [ "$theIndex" -eq 0 ] || [ "$theIndex" -gt "$1" ] + then indecesOK=false ; break ; fi + done + "$indecesOK" && fileIndex="$indexList" && multiIndex=true && break + fi + + printf "${REDct}INVALID selection.${NOct}\n" + done +} + +##-------------------------------------## +## Added by Martinski W. [2024-May-03] ## +##-------------------------------------## +_GetFileSelection_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi + + if [ $# -lt 2 ] || [ "$2" != "-MULTIOK" ] + then indexType="" ; else indexType="$2" ; fi + + theFilePath="" theFileName="" fileTemp="" + fileCount=0 fileIndex=0 multiIndex=false + local sourceDirPath="$FW_LOG_DIR" + local maxFileCount=20 + + printf "\n${1}\n[Directory: ${GRNct}${sourceDirPath}${NOct}]\n\n" + + while IFS="$(printf '\n\t')" read -r backupFilePath + do + fileCount=$((fileCount+1)) + fileVar="file_${fileCount}_Name" + eval file_${fileCount}_Name="${backupFilePath##*/}" + printf "${GRNct}%3d${NOct}. " "$fileCount" + eval echo "\$${fileVar}" + [ "$fileCount" -ge "$maxFileCount" ] && break + done </dev/null) +EOT + + echo + _GetFileSelectionIndex_ "$fileCount" "$indexType" + + if [ "$fileIndex" = "ALL" ] || [ "$fileIndex" = "NONE" ] + then theFilePath="$fileIndex" ; return 0 ; fi + + if [ "$indexType" = "-MULTIOK" ] && "$multiIndex" + then + for index in $fileIndex + do + fileVar="file_${index}_Name" + eval fileTemp="\$${fileVar}" + if [ -z "$theFilePath" ] + then theFilePath="${sourceDirPath}/$fileTemp" + else theFilePath="${theFilePath}|${sourceDirPath}/$fileTemp" + fi + done + else + fileVar="file_${fileIndex}_Name" + eval theFileName="\$${fileVar}" + theFilePath="${sourceDirPath}/$theFileName" + fi + return 0 +} + +##----------------------------------------## +## Modified by Martinski W. [2024-May-04] ## +##----------------------------------------## +_CheckForUpdateLogFiles_() +{ + theLogFilesMatch="${FW_LOG_DIR}/${MODEL_ID}_FW_Update_*.log" + theFileCount="$(_list2_ -1 "$theLogFilesMatch" 2>/dev/null | wc -l)" + + if [ ! -d "$FW_LOG_DIR" ] || [ "$theFileCount" -eq 0 ] + then + updateLogFileFound=false + return 1 + fi + chmod 444 "${FW_LOG_DIR}"/${MODEL_ID}_FW_Update_*.log + updateLogFileFound=true + return 0 +} + +##----------------------------------------## +## Modified by Martinski W. [2024-May-05] ## +##----------------------------------------## +_ViewUpdateLogFile_() +{ + local theFilePath="" theFileCount theLogFilesMatch retCode + + if ! _CheckForUpdateLogFiles_ + then + printf "\n${REDct}**ERROR**${NOct}: Log file(s) [$theLogFilesMatch] NOT FOUND." + return 1 + fi + printf "\n---------------------------------------------------" + _GetFileSelection_ "Select a log file to view:" + + if [ "$theFilePath" = "NONE" ] || [ ! -f "$theFilePath" ] + then return 1 ; fi + + printf "\nLog file to view:\n${GRNct}${theFilePath}${NOct}\n" + printf "\n[Press '${REDct}q${NOct}' to quit when finished]\n" + _WaitForEnterKey_ + less "$theFilePath" + + return 0 +} + ##-------------------------------------## ## Added by Martinski W. [2024-Mar-20] ## ##-------------------------------------## @@ -5233,6 +5487,15 @@ _PrintNodeInfo() fi } +##----------------------------------------## +## Modified by Martinski W. [2024-Feb-18] ## +##----------------------------------------## +_InvalidMenuSelection_() +{ + printf "${REDct}INVALID selection.${NOct} Please try again." + _WaitForEnterKey_ +} + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## @@ -5272,6 +5535,8 @@ _ShowMainMenu_() arrowStr=" ${REDct}<<---${NOct}" + _calculate_NextRunTime_ + # Show or hide F/W Update ETA based on whether a meaningful ETA exists notifyDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" if [ "$notifyDate" = "TBD" ] then notificationStr="${REDct}NOT SET${NOct}" @@ -5297,9 +5562,10 @@ _ShowMainMenu_() fi printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(H)ide" printf "\n${padStr}F/W Variant Detected: $FirmwareFlavor" - printf "\n${padStr}F/W Update Available: $FW_NewUpdateVersion" - printf "\n${padStr}F/W Version Installed: $FW_InstalledVersion" printf "\n${padStr}USB Storage Connected: $USBConnected" + printf "\n${padStr}F/W Version Installed: $FW_InstalledVersion" + printf "\n${padStr}F/W Update Available: $FW_NewUpdateVersion" + printf "\n${padStr}F/W Upd Expected ETA: $ExpectedFWUpdateRuntime" else printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(S)how" fi @@ -5514,46 +5780,49 @@ _ShowNodesMenuOptions_() done } -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-02] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-05] ## +##----------------------------------------## _DownloadChangelogs_() { - if "$isGNUtonFW" + local wgetLogFile changeLogTag changeLogFile changeLogURL + + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + if [ "$changeLogTag" = "386" ] then - FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - wget -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" - changeLogFile="$FW_Changelog_GITHUB" - else - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" - if [ "$changeLogTag" = "386" ] - then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "${CL_URL_386}" - elif [ "$changeLogTag" = "NG" ] - then - wget -O "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" "${CL_URL_NG}" - fi - changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" + changeLogURL="${CL_URL_386}" + elif [ "$changeLogTag" = "NG" ] + then + changeLogURL="${CL_URL_NG}" fi + + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" + printf "\nRetrieving ${GRNct}Changelog-${changeLogTag}.txt${NOct} ...\n" + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$changeLogFile" -o "$wgetLogFile" "${changeLogURL}" + if [ ! -f "$changeLogFile" ] then Say "Change-log file [$changeLogFile] does NOT exist." + echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" else clear printf "\n${GRNct}Changelog is ready to review!${NOct}\n" printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + dos2unix "$changeLogFile" _WaitForEnterKey_ - more "$changeLogFile" + less "$changeLogFile" fi - rm -f "$FW_BIN_DIR/Changelog-${changeLogTag}.txt" + rm -f "$changeLogFile" "$wgetLogFile" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-02] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-04] ## +##----------------------------------------## _ShowLogsMenu_() { clear @@ -5564,15 +5833,20 @@ _ShowLogsMenu_() printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" + if _CheckForUpdateLogFiles_ + then + printf "\n ${GRNct}lg${NOct}. View F/W Update Log File\n" + fi + printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" printf "${SEPstr}" } -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-02] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-04] ## +##----------------------------------------## _AdvancedLogsOptions_() { while true @@ -5584,9 +5858,20 @@ _AdvancedLogsOptions_() case $nodesChoice in 1) _Set_FW_UpdateLOG_DirectoryPath_ ;; - cl) _DownloadChangelogs_ + lg) if _CheckForUpdateLogFiles_ + then + while true + do + if _ViewUpdateLogFile_ + then continue ; else break ; fi + done + else + _InvalidMenuSelection_ + fi + ;; + cl) _DownloadChangelogs_ ;; - e|exit) break + e|exit) break ;; *) _InvalidMenuSelection_ ;; @@ -5594,15 +5879,6 @@ _AdvancedLogsOptions_() done } -##----------------------------------------## -## Modified by Martinski W. [2024-Feb-18] ## -##----------------------------------------## -_InvalidMenuSelection_() -{ - printf "${REDct}INVALID selection.${NOct} Please try again." - _WaitForEnterKey_ -} - ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## From 3a540a9baebc737b738d02db910f7389a0256a5c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 00:13:07 -0400 Subject: [PATCH 075/185] Update MerlinAU.sh --- MerlinAU.sh | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e833f4aa..7feb63d1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4188,12 +4188,8 @@ Please manually update to version $minimum_supported_version or higher to use th release_link="$2" else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoExit_ 1 - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi # Extracting the first octet to use in the curl @@ -4337,13 +4333,8 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$retCode" -eq 1 ] then Say "${REDct}**ERROR**${NOct}: Firmware files were not downloaded successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoCleanUp_ 1 - _DoExit_ 1 - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi fi @@ -4369,13 +4360,8 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$retCode" -eq 1 ] then Say "${REDct}**ERROR**${NOct}: Firmware file (unzip, move, copy) management was not completed successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoCleanUp_ 1 - _DoExit_ 1 - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi freeRAM_kb="$(_GetFreeRAM_KB_)" @@ -4552,13 +4538,8 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$retCode" -eq 1 ] then Say "${REDct}**ERROR**${NOct}: Firmware signature verification was not completed successfully." - if [ "$inMenuMode" = true ]; then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoCleanUp_ 1 - _DoExit_ 1 - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi ##----------------------------------------## From feb8e9c65d51b165664764c9ad32192d7e08c328 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 06:32:13 -0400 Subject: [PATCH 076/185] Update MerlinAU.sh --- MerlinAU.sh | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 26bf800c..55c124d6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5833,30 +5833,6 @@ _ShowLogsMenu_() printf "${SEPstr}" } -##----------------------------------------## -## Modified by Martinski W. [2024-May-04] ## -##----------------------------------------## -_ShowLogsMenu_() -{ - clear - logo - printf "===================== Logs Menu =====================\n" - printf "${SEPstr}\n" - - printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" - printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" - - if _CheckForUpdateLogFiles_ - then - printf "\n ${GRNct}lg${NOct}. View F/W Update Log File\n" - fi - - printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" - - printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPstr}" -} - ##----------------------------------------## ## Modified by Martinski W. [2024-May-04] ## ##----------------------------------------## From 2904cd14896328a033262ca42789b71040021c24 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 06:37:36 -0400 Subject: [PATCH 077/185] Update MerlinAU.sh --- MerlinAU.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 55c124d6..a591f083 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -30,13 +30,6 @@ readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.n readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-03] ## -##---------------------------------------## -# Changelog URL Info # -readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" -readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" - # For new script version updates from source repository # UpdateNotify=0 DLRepoVersion="" From 495ba23f209ba35d64e422c7187b71b1cba1bca9 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 06:39:11 -0400 Subject: [PATCH 078/185] Update MerlinAU.sh --- MerlinAU.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a591f083..bd1cefe9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5799,7 +5799,6 @@ _DownloadChangelogs_() rm -f "$changeLogFile" "$wgetLogFile" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 - } ##----------------------------------------## From 3db441f961a59beae67327b56d1e96ceeff546f4 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 07:05:44 -0400 Subject: [PATCH 079/185] Update MerlinAU.sh --- MerlinAU.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index bd1cefe9..63fd4078 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -27,8 +27,8 @@ readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.n ## Added by ExtremeFiretop [2024-May-03] ## ##---------------------------------------## # Changelog URL Info # -readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" -readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" +readonly CL_URL_NG="${FW_SFURL_BASE}/Documentation/Changelog-NG.txt/download" +readonly CL_URL_386="${FW_SFURL_BASE}/Documentation/Changelog-386.txt/download" # For new script version updates from source repository # UpdateNotify=0 @@ -5768,6 +5768,9 @@ _DownloadChangelogs_() { local wgetLogFile changeLogTag changeLogFile changeLogURL + # In case ZIP directory is different from BIN directory # + if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" if [ "$changeLogTag" = "386" ] then From 8ec6f0eec308b0cafe6b32ab387367b293b1b0cb Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 10 May 2024 07:08:13 -0400 Subject: [PATCH 080/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 63fd4078..7f019ef7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5768,7 +5768,7 @@ _DownloadChangelogs_() { local wgetLogFile changeLogTag changeLogFile changeLogURL - # In case ZIP directory is different from BIN directory # + # Create directory to download changelog if missing if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" From 699f58d3918e1904c2a9561057cf514d31629135 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 12 May 2024 08:13:47 -0400 Subject: [PATCH 081/185] Update MerlinAU.sh --- MerlinAU.sh | 336 ++++++++++++++++++++++++++++------------------------ 1 file changed, 181 insertions(+), 155 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 7f019ef7..caf6d806 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3209,187 +3209,212 @@ translate_schedule() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-04] ## ##------------------------------------------## -# Conversion functions for month and day names to numbers -convert_month_to_number() { - case "$1" in - [Jj][Aa][Nn]) echo 1 ;; - [Ff][Ee][Bb]) echo 2 ;; - [Mm][Aa][Rr]) echo 3 ;; - [Aa][Pp][Rr]) echo 4 ;; - [Mm][Aa][Yy]) echo 5 ;; - [Jj][Uu][Nn]) echo 6 ;; - [Jj][Uu][Ll]) echo 7 ;; - [Aa][Uu][Gg]) echo 8 ;; - [Ss][Ee][Pp]) echo 9 ;; - [Oo][Cc][Tt]) echo 10 ;; - [Nn][Oo][Vv]) echo 11 ;; - [Dd][Ee][Cc]) echo 12 ;; - *) - echo "$1" - ;; - esac -} +# Manually calculate the next day +increment_day() { + local day="$1" + local month="$2" + local year="$3" -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -convert_day_to_number() { - case "$1" in - [Ss][Uu][Nn]) echo 0 ;; - [Mm][Oo][Nn]) echo 1 ;; - [Tt][Uu][Ee]) echo 2 ;; - [Ww][Ee][Dd]) echo 3 ;; - [Tt][Hh][Uu]) echo 4 ;; - [Ff][Rr][Ii]) echo 5 ;; - [Ss][Aa][Tt]) echo 6 ;; - *) - echo "$1" - ;; + # Define number of days in each month considering leap year + local leap_year=0 + if [ $((year % 4)) -eq 0 ]; then + if [ $((year % 100)) -ne 0 ] || [ $((year % 400)) -eq 0 ]; then + leap_year=1 + fi + fi + + local days_in_feb=$((28 + leap_year)) + local days_in_month=31 + + case $month in + 4|6|9|11) days_in_month=30;; + 2) days_in_month=$days_in_feb;; esac -} -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Sakamoto's algorithm to find the day of the week -calculate_day_of_week() { - day="$1" - month="$2" - year="$3" - - if [ "$month" -le 2 ]; then - month="$((month + 12))" - year="$((year - 1))" + day=$((day + 1)) + if [ $day -gt $days_in_month ]; then + day=1 + month=$((month + 1)) + fi + if [ $month -gt 12 ]; then + month=1 + year=$((year + 1)) fi - t="$(((13 * (month + 1)) / 5))" - K="$((year % 100))" - J="$((year / 100))" - dow="$(((day + t + K + (K / 4) + (J / 4) - (2 * J)) % 7))" + echo "$day $month $year" +} - if [ "$dow" -eq 0 ]; then - dow=6 # Saturday +matches_day_of_month() { + local day="$1" + local dom_expr="$2" + if [[ "$dom_expr" == "*" ]]; then + return 0 # Match any day + elif echo "$dom_expr" | grep -q '-'; then + local start=$(echo "$dom_expr" | cut -d'-' -f1) + local end=$(echo "$dom_expr" | cut -d'-' -f2) + if [[ "$day" -ge "$start" && "$day" -le "$end" ]]; then + return 0 # Day is within the range + fi else - dow="$((dow - 1))" # Adjusting the result so Sunday = 0 + for d in $(echo "$dom_expr" | tr ',' ' '); do + if [[ "$d" == "$day" ]]; then + return 0 # Day matches one of the list items + fi + done fi - - echo "$dow" + return 1 # No match } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Manually calculate the next day -increment_date() { - local day="$1" - local month="$2" - local year="$3" +matches_month() { + local month="$1" + local month_expr="$2" + if [ "$month_expr" = "*" ]; then + return 0 # Match any month + else + for m in $(echo "$month_expr" | tr ',' ' '); do + case "$m" in + [Jj][Aa][Nn]) m=1 ;; + [Ff][Ee][Bb]) m=2 ;; + [Mm][Aa][Rr]) m=3 ;; + [Aa][Pp][Rr]) m=4 ;; + [Mm][Aa][Yy]) m=5 ;; + [Jj][Uu][Nn]) m=6 ;; + [Jj][Uu][Ll]) m=7 ;; + [Aa][Uu][Gg]) m=8 ;; + [Ss][Ee][Pp]) m=9 ;; + [Oo][Cc][Tt]) m=10 ;; + [Nn][Oo][Vv]) m=11 ;; + [Dd][Ee][Cc]) m=12 ;; + *) ;; + esac + if [ "$m" -eq "$month" ]; then + return 0 # Month matches one of the list items + fi + done + fi + return 1 # No match +} - # Validate input - if [ -z "$day" ] || [ -z "$month" ] || [ -z "$year" ]; then - echo "Error: Missing day, month, or year parameter." - return 1 # Return error +matches_day_of_week() { + local dow="$1" + local dow_expr="$2" + if [ "$dow_expr" = "*" ]; then + return 0 # Match any day of the week + else + for d in $(echo "$dow_expr" | tr ',' ' '); do + case "$d" in + [Ss][Uu][Nn]) d=0 ;; + [Mm][Oo][Nn]) d=1 ;; + [Tt][Uu][Ee]) d=2 ;; + [Ww][Ee][Dd]) d=3 ;; + [Tt][Hh][Uu]) d=4 ;; + [Ff][Rr][Ii]) d=5 ;; + [Ss][Aa][Tt]) d=6 ;; + *) ;; + esac + if [ "$d" -eq "$dow" ]; then + return 0 # Day of week matches one of the list items + fi + done fi + return 1 # No match +} + +expand_cron_field() { + local field="$1" + local min="$2" + local max="$3" - days_in_month="31 28 31 30 31 30 31 31 30 31 30 31" - set -- $days_in_month - month_days=$(eval echo \${$((month + 0))}) + if echo "$field" | grep -q '/'; then + local range_part="${field%/*}" + local step="${field##*/}" + local start="$min" + local end="$max" - # Adjust for leap year in February - if [ "$month" -eq 2 ]; then - if [ "$((year % 4))" -eq 0 ] && { [ "$((year % 100))" -ne 0 ] || [ "$((year % 400))" -eq 0 ]; }; then - month_days=29 + if echo "$range_part" | grep -q '-'; then + start="${range_part%-*}" + end="${range_part#*-}" fi - fi - day="$((day + 1))" - if [ "$day" -gt "$month_days" ]; then - day=1 - month="$((month + 1))" - fi - if [ "$month" -gt 12 ]; then - month=1 - year="$((year + 1))" + local i="$start" + while [ "$i" -le "$end" ]; do + echo "$i" + i=$((i + step)) + done + elif echo "$field" | grep -q '-'; then + local start="${field%-*}" + local end="${field#*-}" + local i="$start" + while [ "$i" -le "$end" ]; do + echo "$i" + i=$((i + 1)) + done + elif [ "$field" = "*" ]; then + local i="$min" + while [ "$i" -le "$max" ]; do + echo "$i" + i=$((i + 1)) + done + else + echo "$field" fi - - echo "$day" "$month" "$year" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-04] ## -##------------------------------------------## -# Function to estimate the next run time of a cron job after a specific date +# Function to process minute intervals, e.g., */15 estimate_next_cron_after_date() { local post_date_secs="$1" local cron_schedule="$2" - local minute="$(echo "$cron_schedule" | cut -d' ' -f1)" - local hour="$(echo "$cron_schedule" | cut -d' ' -f2)" - local dom="$(echo "$cron_schedule" | cut -d' ' -f3)" - local month_cron="$(echo "$cron_schedule" | cut -d' ' -f4)" - local dow="$(echo "$cron_schedule" | cut -d' ' -f5)" - - # Convert post_date_secs to date components - eval $(date '+day=%d month=%m year=%Y' -d @$post_date_secs) - day="$(echo "$day" | sed 's/^0*//')" # Remove leading zeros - month="$(echo "$month" | sed 's/^0*//')" # Remove leading zeros - - day_count=0 - while [ "$day_count" -lt 365 ]; do - current_dow="$(calculate_day_of_week "$day" "$month" "$year")" - - num_dow_entries="$(echo "$dow" | tr ',' '\n' | wc -l)" # Count number of dow entries - dow_index=1 - while [ "$dow_index" -le "$num_dow_entries" ]; do - dow_entry="$(echo "$dow" | cut -d',' -f"$dow_index")" # Get the dow_index-th entry - - # Convert alphabetic day of the week to number if necessary - case "$dow_entry" in - *[[:alpha:]]*) - dow_entry=$(convert_day_to_number "$dow_entry") - ;; - esac - - num_month_entries="$(echo "$month_cron" | tr ',' '\n' | wc -l)" # Count number of month entries - month_index=1 - while [ "$month_index" -le "$num_month_entries" ]; do - month_entry="$(echo "$month_cron" | cut -d',' -f"$month_index")" # Get the month_index-th entry - - # Convert month name to number if necessary - case "$month_entry" in - *[[:alpha:]]*) - month_entry=$(convert_month_to_number "$month_entry") - ;; - *) - month_entry="$(echo "$month_entry" | sed 's/^0*//')" # Remove leading zeros - ;; - esac - - if { [ "$dom" = "*" ] || [ "$dom" = "$day" ]; } && - { [ "$month_entry" = "*" ] || [ "$month_entry" = "$month" ]; } && - { [ "$dow_entry" = "*" ] || [ "$dow_entry" = "$current_dow" ]; }; then - cron_date="$year-$month-$day $hour:$minute" - next_cron_run="$(date +%s -d "$cron_date")" - if [ "$next_cron_run" -gt "$post_date_secs" ]; then - echo "$next_cron_run" + local minute_field="$(echo "$cron_schedule" | awk '{print $1}')" + local hour_field="$(echo "$cron_schedule" | awk '{print $2}')" + local dom_field="$(echo "$cron_schedule" | awk '{print $3}')" + local month_field="$(echo "$cron_schedule" | awk '{print $4}')" + local dow_field="$(echo "$cron_schedule" | awk '{print $5}')" + + eval $(date '+day=%d month=%m year=%Y hour=%H minute=%M dow=%u' -d "@$post_date_secs") + local current_day=$(echo $day | sed 's/^0*\([0-9]\)/\1/') + local current_month=$(echo $month | sed 's/^0*\([0-9]\)/\1/') + local current_year=$year + local current_hour=$(echo $hour | sed 's/^0*\([0-9]\)/\1/') + local current_minute=$(echo $minute | sed 's/^0*\([0-9]\)/\1/') + local current_dow=$((dow % 7)) # Adjusting so Sunday is 0 + + # Apply default values if variables are empty + current_day=${current_day:-0} + current_month=${current_month:-0} + current_hour=${current_hour:-0} + current_minute=${current_minute:-0} + + local found=false + + while [ "$found" = "false" ]; do + if matches_month "$current_month" "$month_field" && matches_day_of_month "$current_day" "$dom_field" && matches_day_of_week "$current_dow" "$dow_field"; then + for h in $(expand_cron_field "$hour_field" 0 23); do + if [ "$h" -gt "$current_hour" ]; then + for m in $(expand_cron_field "$minute_field" 0 59); do + echo "$(date '+%s' -d "$current_year-$current_month-$current_day $h:$m")" + found=true return - fi + done + elif [ "$h" -eq "$current_hour" ]; then + for m in $(expand_cron_field "$minute_field" 0 59); do + if [ "$m" -gt "$current_minute" ]; then + echo "$(date '+%s' -d "$current_year-$current_month-$current_day $h:$m")" + found=true + return + fi + done fi - - month_index="$((month_index + 1))" done - - dow_index="$((dow_index + 1))" - done - - # Increment date - new_date="$(increment_date "$day" "$month" "$year")" - set -- $new_date - local day="$1" - local month="$2" - local year="$3" - local day_count="$((day_count + 1))" + fi + # Increment the day and check again + set -- $(increment_day $current_day $current_month $current_year) + current_day=$1 + current_month=$2 + current_year=$3 + current_dow=$(date '+%u' -d "$current_year-$current_month-$current_day" | awk '{print $1%7}') # Recalculate day of the week + current_hour=0 # Reset hours and minutes for the new day + current_minute=0 done - echo "no_date_found" } calculate_DST() { @@ -4572,6 +4597,7 @@ Please manually update to version $minimum_supported_version or higher to use th #------------------------------------------------------------# "$isInteractive" && printf "\nRestarting web server... Please wait.\n" /sbin/service restart_httpd >/dev/null 2>&1 & + _DoExit_ 1 sleep 5 # Send last email notification before F/W flash # From 8211b5914059b2164d3dc230c6ce537bddb83705 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 12 May 2024 08:14:49 -0400 Subject: [PATCH 082/185] Update MerlinAU.sh --- MerlinAU.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index caf6d806..9462d3cd 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4597,7 +4597,6 @@ Please manually update to version $minimum_supported_version or higher to use th #------------------------------------------------------------# "$isInteractive" && printf "\nRestarting web server... Please wait.\n" /sbin/service restart_httpd >/dev/null 2>&1 & - _DoExit_ 1 sleep 5 # Send last email notification before F/W flash # From eaad5fea8886c8fc77a6e6769d59f88a8d939b41 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 12 May 2024 08:52:58 -0400 Subject: [PATCH 083/185] Update MerlinAU.sh --- MerlinAU.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9462d3cd..9c7f1652 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3894,6 +3894,16 @@ _CheckTimeToUpdateFirmware_() { Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." + echo "" + + # Check if running in a menu environment + if "$isInteractive" && _WaitForYESorNO_ "Would you like to proceed with the update now?" + then + return 0 + else + return 1 + fi + return 1 } From 22778a84df44024fd3e920a23ee6f5994ef6af61 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 18 May 2024 18:07:14 -0400 Subject: [PATCH 084/185] Update MerlinAU.sh --- MerlinAU.sh | 544 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 336 insertions(+), 208 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9c7f1652..f65f0452 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -480,6 +480,7 @@ readonly CRON_DAYofWEEK_RegEx="$CRON_DAYofWEEK_NAMES([\/,-]$CRON_DAYofWEEK_NAMES readonly CRON_MONTH_NAMES="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)" readonly CRON_MONTH_RegEx="$CRON_MONTH_NAMES([\/,-]$CRON_MONTH_NAMES)*|([*1-9]|1[0-2])([\/,-]([1-9]|1[0-2]))*" +readonly CRON_UNKNOWN_DATE="**ERROR**: UNKNOWN Date Found" ##------------------------------------------## ## Modified by Martinski W. [2024-Jan-22] ## ##------------------------------------------## @@ -789,7 +790,7 @@ Get_Custom_Setting() setting_value="$(grep "^${setting_type} " "$SETTINGSFILE" | awk -F ' ' '{print $2}')" ;; "FW_New_Update_Postponement_Days" | \ - "FW_New_Update_Run_Date" | \ + "FW_New_Update_Expected_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ "FW_New_Update_LOG_Directory_Path" | \ @@ -873,7 +874,7 @@ Update_Custom_Settings() fi ;; "FW_New_Update_Postponement_Days" | \ - "FW_New_Update_Run_Date" | \ + "FW_New_Update_Expected_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ "FW_New_Update_LOG_Directory_Path" | \ @@ -1301,7 +1302,7 @@ _CreateEMailContent_() if "$inRouterSWmode" && [ -n "$node_list" ]; then nodefwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromNode_ 1)" fi - if [ ! -n "$nodefwNewUpdateVersion" ] + if [ -z "$nodefwNewUpdateVersion" ] then Say "${REDct}**ERROR**${NOct}: Unable to send node email notification [No saved info]." return 1 @@ -1595,17 +1596,14 @@ _CreateDirectory_() return 0 } -##-------------------------------------## -## Added by Martinski W. [2024-Jan-24] ## -##-------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _DelPostUpdateEmailNotifyScriptHook_() { local hookScriptFile - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] ; then return 1 ; fi if grep -qE "$POST_UPDATE_EMAIL_SCRIPT_JOB" "$hookScriptFile" @@ -1620,18 +1618,14 @@ _DelPostUpdateEmailNotifyScriptHook_() fi } -##-------------------------------------## -## Added by Martinski W. [2024-Jan-24] ## -##-------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _AddPostUpdateEmailNotifyScriptHook_() { local hookScriptFile jobHookAdded=false - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi - + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] then jobHookAdded=true @@ -1655,17 +1649,14 @@ _AddPostUpdateEmailNotifyScriptHook_() fi } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Nov-28] ## -##----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _DelPostRebootRunScriptHook_() { local hookScriptFile - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] ; then return 1 ; fi if grep -qE "$POST_REBOOT_SCRIPT_JOB" "$hookScriptFile" @@ -1680,18 +1671,14 @@ _DelPostRebootRunScriptHook_() fi } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Oct-17] ## -##----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _AddPostRebootRunScriptHook_() { local hookScriptFile jobHookAdded=false - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi - + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] then jobHookAdded=true @@ -3209,159 +3196,268 @@ translate_schedule() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-04] ## ##------------------------------------------## -# Manually calculate the next day -increment_day() { +_IncrementDay_() +{ local day="$1" local month="$2" local year="$3" # Define number of days in each month considering leap year local leap_year=0 - if [ $((year % 4)) -eq 0 ]; then - if [ $((year % 100)) -ne 0 ] || [ $((year % 400)) -eq 0 ]; then + if [ "$((year % 4))" -eq 0 ] + then + if [ "$((year % 100))" -ne 0 ] || [ "$((year % 400))" -eq 0 ]; then leap_year=1 fi fi - local days_in_feb=$((28 + leap_year)) + local days_in_feb="$((28 + leap_year))" local days_in_month=31 case $month in - 4|6|9|11) days_in_month=30;; - 2) days_in_month=$days_in_feb;; + 4|6|9|11) days_in_month=30 ;; + 2) days_in_month="$days_in_feb" ;; esac - day=$((day + 1)) - if [ $day -gt $days_in_month ]; then + day="$((day + 1))" + if [ "$day" -gt "$days_in_month" ] + then day=1 - month=$((month + 1)) + month="$((month + 1))" fi - if [ $month -gt 12 ]; then + if [ "$month" -gt 12 ] + then month=1 - year=$((year + 1)) + year="$((year + 1))" fi echo "$day $month $year" } -matches_day_of_month() { - local day="$1" +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +matches_day_of_month() +{ + local curr_dom="$1" local dom_expr="$2" - if [[ "$dom_expr" == "*" ]]; then - return 0 # Match any day - elif echo "$dom_expr" | grep -q '-'; then - local start=$(echo "$dom_expr" | cut -d'-' -f1) - local end=$(echo "$dom_expr" | cut -d'-' -f2) - if [[ "$day" -ge "$start" && "$day" -le "$end" ]]; then - return 0 # Day is within the range + local domStart domEnd + + if [ "$dom_expr" = "*" ] + then # Matches any day of the month # + return 0 + elif echo "$dom_expr" | grep -q '-' + then + domStart="$(echo "$dom_expr" | cut -d'-' -f1)" + domEnd="$(echo "$dom_expr" | cut -d'-' -f2)" + + if [ "$domStart" -le "$domEnd" ] && \ + [ "$curr_dom" -ge "$domStart" ] && \ + [ "$curr_dom" -le "$domEnd" ] + then # Current day is within the range # + return 0 fi else - for d in $(echo "$dom_expr" | tr ',' ' '); do - if [[ "$d" == "$day" ]]; then - return 0 # Day matches one of the list items + for day in $(echo "$dom_expr" | tr ',' ' ') + do + if [ "$day" -eq "$curr_dom" ] + then # Current day matches one in the list # + return 0 fi done fi - return 1 # No match + return 1 # No match # } -matches_month() { - local month="$1" +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +matches_month() +{ + local curr_month="$1" local month_expr="$2" - if [ "$month_expr" = "*" ]; then - return 0 # Match any month + local monthStart monthEnd monthStartNum monthEndNum + + _MonthNameToNumber_() + { + if echo "$1" | grep -qE "^([1-9]|1[0-2])$" + then echo "$1" ; return 0 ; fi + + local monthNum="$1" + case "$1" in + [Jj][Aa][Nn]) monthNum=1 ;; + [Ff][Ee][Bb]) monthNum=2 ;; + [Mm][Aa][Rr]) monthNum=3 ;; + [Aa][Pp][Rr]) monthNum=4 ;; + [Mm][Aa][Yy]) monthNum=5 ;; + [Jj][Uu][Nn]) monthNum=6 ;; + [Jj][Uu][Ll]) monthNum=7 ;; + [Aa][Uu][Gg]) monthNum=8 ;; + [Ss][Ee][Pp]) monthNum=9 ;; + [Oo][Cc][Tt]) monthNum=10 ;; + [Nn][Oo][Vv]) monthNum=11 ;; + [Dd][Ee][Cc]) monthNum=12 ;; + *) ;; + esac + echo "$monthNum" ; return 0 + } + + if [ "$month_expr" = "*" ] + then # Matches any month # + return 0 + elif echo "$month_expr" | grep -q '-' + then + monthStart="$(echo "$month_expr" | cut -d'-' -f1)" + monthEnd="$(echo "$month_expr" | cut -d'-' -f2)" + monthStartNum="$(_MonthNameToNumber_ "$monthStart")" + monthEndNum="$(_MonthNameToNumber_ "$monthEnd")" + + if [ "$monthStartNum" -le "$monthEndNum" ] && \ + [ "$curr_month" -ge "$monthStartNum" ] && \ + [ "$curr_month" -le "$monthEndNum" ] + then # Current month is within the range # + return 0 + fi else - for m in $(echo "$month_expr" | tr ',' ' '); do - case "$m" in - [Jj][Aa][Nn]) m=1 ;; - [Ff][Ee][Bb]) m=2 ;; - [Mm][Aa][Rr]) m=3 ;; - [Aa][Pp][Rr]) m=4 ;; - [Mm][Aa][Yy]) m=5 ;; - [Jj][Uu][Nn]) m=6 ;; - [Jj][Uu][Ll]) m=7 ;; - [Aa][Uu][Gg]) m=8 ;; - [Ss][Ee][Pp]) m=9 ;; - [Oo][Cc][Tt]) m=10 ;; - [Nn][Oo][Vv]) m=11 ;; - [Dd][Ee][Cc]) m=12 ;; - *) ;; - esac - if [ "$m" -eq "$month" ]; then - return 0 # Month matches one of the list items + for month in $(echo "$month_expr" | tr ',' ' ') + do + if [ "$(_MonthNameToNumber_ "$month")" -eq "$curr_month" ] + then # Current month matches one in the list # + return 0 fi done fi - return 1 # No match + return 1 # No match # } -matches_day_of_week() { - local dow="$1" +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +matches_day_of_week() +{ + local curr_dow="$1" local dow_expr="$2" - if [ "$dow_expr" = "*" ]; then - return 0 # Match any day of the week + local dowStart dowEnd dowStartNum dowEndNum + + _DayOfWeekNameToNumber_() + { + if echo "$1" | grep -qE "^[0-6]$" + then echo "$1" ; return 0 ; fi + + local dowNum="$1" + case "$1" in + [Ss][Uu][Nn]) dowNum=0 ;; + [Mm][Oo][Nn]) dowNum=1 ;; + [Tt][Uu][Ee]) dowNum=2 ;; + [Ww][Ee][Dd]) dowNum=3 ;; + [Tt][Hh][Uu]) dowNum=4 ;; + [Ff][Rr][Ii]) dowNum=5 ;; + [Ss][Aa][Tt]) dowNum=6 ;; + *) ;; + esac + echo "$dowNum" ; return 0 + } + + if [ "$dow_expr" = "*" ] + then # Matches any day of the week # + return 0 + elif echo "$dow_expr" | grep -q '-' + then + dowStart="$(echo "$dow_expr" | cut -d'-' -f1)" + dowEnd="$(echo "$dow_expr" | cut -d'-' -f2)" + dowStartNum="$(_DayOfWeekNameToNumber_ "$dowStart")" + dowEndNum="$(_DayOfWeekNameToNumber_ "$dowEnd")" + if [ "$dowStartNum" -gt "$dowEndNum" ] + then + dow_expr="$dowStartNum" + while true + do + dowStartNum="$((++dowStartNum))" + if [ "$dowStartNum" -lt 7 ] + then + dow_expr="${dow_expr},$dowStartNum" + else + dowStartNum=0 + dow_expr="${dow_expr},$dowStartNum" + fi + [ "$dowStartNum" -eq "$dowEndNum" ] && break + done + if matches_day_of_week "$curr_dow" "$dow_expr" + then return 0 + else return 1 + fi + elif [ "$dowStartNum" -le "$dowEndNum" ] && \ + [ "$curr_dow" -ge "$dowStartNum" ] && \ + [ "$curr_dow" -le "$dowEndNum" ] + then # Current day of the week is within the range # + return 0 + fi else - for d in $(echo "$dow_expr" | tr ',' ' '); do - case "$d" in - [Ss][Uu][Nn]) d=0 ;; - [Mm][Oo][Nn]) d=1 ;; - [Tt][Uu][Ee]) d=2 ;; - [Ww][Ee][Dd]) d=3 ;; - [Tt][Hh][Uu]) d=4 ;; - [Ff][Rr][Ii]) d=5 ;; - [Ss][Aa][Tt]) d=6 ;; - *) ;; - esac - if [ "$d" -eq "$dow" ]; then - return 0 # Day of week matches one of the list items + for day in $(echo "$dow_expr" | tr ',' ' ') + do + if [ "$(_DayOfWeekNameToNumber_ "$day")" -eq "$curr_dow" ] + then # Current day of the week matches one in the list # + return 0 fi done fi - return 1 # No match + return 1 # No match # } -expand_cron_field() { +expand_cron_field() +{ local field="$1" local min="$2" local max="$3" + local range_part step start end num - if echo "$field" | grep -q '/'; then - local range_part="${field%/*}" - local step="${field##*/}" - local start="$min" - local end="$max" + if echo "$field" | grep -q '/' + then + range_part="${field%/*}" + step="${field##*/}" + start="$min" + end="$max" - if echo "$range_part" | grep -q '-'; then + if echo "$range_part" | grep -q '-' + then start="${range_part%-*}" end="${range_part#*-}" fi - local i="$start" - while [ "$i" -le "$end" ]; do - echo "$i" - i=$((i + step)) + num="$start" + while [ "$num" -le "$end" ] + do + echo "$num" + num="$((num + step))" done - elif echo "$field" | grep -q '-'; then - local start="${field%-*}" - local end="${field#*-}" - local i="$start" - while [ "$i" -le "$end" ]; do - echo "$i" - i=$((i + 1)) + elif echo "$field" | grep -q '-' + then + start="${field%-*}" + end="${field#*-}" + num="$start" + while [ "$num" -le "$end" ] + do + echo "$num" + num="$((num + 1))" done - elif [ "$field" = "*" ]; then - local i="$min" - while [ "$i" -le "$max" ]; do - echo "$i" - i=$((i + 1)) + elif [ "$field" = "*" ] + then + num="$min" + while [ "$num" -le "$max" ] + do + echo "$num" + num="$((num + 1))" done else echo "$field" fi } -# Function to process minute intervals, e.g., */15 -estimate_next_cron_after_date() { +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +_EstimateNextCronTimeAfterDate_() +{ local post_date_secs="$1" local cron_schedule="$2" local minute_field="$(echo "$cron_schedule" | awk '{print $1}')" @@ -3369,55 +3465,73 @@ estimate_next_cron_after_date() { local dom_field="$(echo "$cron_schedule" | awk '{print $3}')" local month_field="$(echo "$cron_schedule" | awk '{print $4}')" local dow_field="$(echo "$cron_schedule" | awk '{print $5}')" + local day month year hour minute dow eval $(date '+day=%d month=%m year=%Y hour=%H minute=%M dow=%u' -d "@$post_date_secs") - local current_day=$(echo $day | sed 's/^0*\([0-9]\)/\1/') - local current_month=$(echo $month | sed 's/^0*\([0-9]\)/\1/') - local current_year=$year - local current_hour=$(echo $hour | sed 's/^0*\([0-9]\)/\1/') - local current_minute=$(echo $minute | sed 's/^0*\([0-9]\)/\1/') - local current_dow=$((dow % 7)) # Adjusting so Sunday is 0 + local current_day="$(echo "$day" | sed 's/^0*\([0-9]\)/\1/')" + local current_month="$(echo "$month" | sed 's/^0*\([0-9]\)/\1/')" + local current_year="$year" + local current_hour="$(echo "$hour" | sed 's/^0*\([0-9]\)/\1/')" + local current_minute="$(echo "$minute" | sed 's/^0*\([0-9]\)/\1/')" + local current_dow="$((dow % 7))" # Adjusting so Sunday is 0 # Apply default values if variables are empty - current_day=${current_day:-0} - current_month=${current_month:-0} - current_hour=${current_hour:-0} - current_minute=${current_minute:-0} - - local found=false - - while [ "$found" = "false" ]; do - if matches_month "$current_month" "$month_field" && matches_day_of_month "$current_day" "$dom_field" && matches_day_of_week "$current_dow" "$dow_field"; then - for h in $(expand_cron_field "$hour_field" 0 23); do - if [ "$h" -gt "$current_hour" ]; then - for m in $(expand_cron_field "$minute_field" 0 59); do - echo "$(date '+%s' -d "$current_year-$current_month-$current_day $h:$m")" + current_day="${current_day:-0}" + current_month="${current_month:-0}" + current_hour="${current_hour:-0}" + current_minute="${current_minute:-0}" + + local found=false loopCount=0 maxLoopCount=120 + + while [ "$found" = "false" ] + do + loopCount="$((loopCount + 1))" + if matches_month "$current_month" "$month_field" && \ + matches_day_of_month "$current_day" "$dom_field" && \ + matches_day_of_week "$current_dow" "$dow_field" + then + for this_hour in $(expand_cron_field "$hour_field" 0 23) + do + if [ "$this_hour" -gt "$current_hour" ] + then + for this_min in $(expand_cron_field "$minute_field" 0 59) + do + echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" found=true - return + return 0 done - elif [ "$h" -eq "$current_hour" ]; then - for m in $(expand_cron_field "$minute_field" 0 59); do - if [ "$m" -gt "$current_minute" ]; then - echo "$(date '+%s' -d "$current_year-$current_month-$current_day $h:$m")" + elif [ "$this_hour" -eq "$current_hour" ] + then + for this_min in $(expand_cron_field "$minute_field" 0 59) + do + if [ "$this_min" -gt "$current_minute" ] + then + echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" found=true - return + return 0 fi done fi done fi - # Increment the day and check again - set -- $(increment_day $current_day $current_month $current_year) - current_day=$1 - current_month=$2 - current_year=$3 - current_dow=$(date '+%u' -d "$current_year-$current_month-$current_day" | awk '{print $1%7}') # Recalculate day of the week + if [ "$loopCount" -gt "$maxLoopCount" ] + then # Avoid possible endless loop at this point # + echo "$CRON_UNKNOWN_DATE" + return 1 + fi + # Increment the day and check again # + set -- $(_IncrementDay_ "$current_day" "$current_month" "$current_year") + current_day="$1" + current_month="$2" + current_year="$3" + current_dow="$(date '+%u' -d "$current_year-$current_month-$current_day" | awk '{print $1%7}')" # Recalculate day of the week current_hour=0 # Reset hours and minutes for the new day current_minute=0 done } -calculate_DST() { +_Calculate_DST_() +{ local notifyTimeStrn notifyTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays local postponeTimeSecs fwNewUpdatePostponementDays @@ -3442,31 +3556,47 @@ calculate_DST() { echo "$((notifyTimeSecs + postponeTimeSecs))" } -_calculate_NextRunTime_() { +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +_Calculate_NextRunTime_() +{ + local fwNewUpdateVersion fwNewUpdateNotificationDate + local upfwDateTimeSecs nextCronTimeSecs + # Check for available firmware update - local fwNewUpdateVersion if ! fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)"; then fwNewUpdateVersion="NONE FOUND" fi - ExpectedFWUpdateRuntime="$(Get_Custom_Setting FW_New_Update_Run_Date)" + ExpectedFWUpdateRuntime="$(Get_Custom_Setting FW_New_Update_Expected_Run_Date)" # Determine appropriate messaging based on the firmware update availability and check state - if [ "$FW_UpdateCheckState" -eq 0 ]; then + if [ "$FW_UpdateCheckState" -eq 0 ] + then ExpectedFWUpdateRuntime="${REDct}NO CRON JOB${NOct}" - elif [ "$fwNewUpdateVersion" = "NONE FOUND" ]; then + elif [ "$fwNewUpdateVersion" = "NONE FOUND" ] + then ExpectedFWUpdateRuntime="${REDct}NONE FOUND${NOct}" - elif [ "$ExpectedFWUpdateRuntime" = "TBD" ] || [ -z "$ExpectedFWUpdateRuntime" ]; then + elif [ "$ExpectedFWUpdateRuntime" = "TBD" ] || [ -z "$ExpectedFWUpdateRuntime" ] + then # If conditions are met (cron job enabled and update available), calculate the next runtime - local fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" - if [ "$fwNewUpdateNotificationDate" = "TBD" ] || [ -z "$fwNewUpdateNotificationDate" ]; then + fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" + if [ "$fwNewUpdateNotificationDate" = "TBD" ] || [ -z "$fwNewUpdateNotificationDate" ] + then fwNewUpdateNotificationDate="$(date +%Y-%m-%d_%H:%M:%S)" fi - local upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") - local nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") - Update_Custom_Settings FW_New_Update_Run_Date "$nextCronTimeSecs" - ExpectedFWUpdateRuntime="$(date -d @$nextCronTimeSecs +"%Y-%b-%d %I:%M %p")" - ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" + upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")" + nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" + if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ] + then + Update_Custom_Settings FW_New_Update_Expected_Run_Date "TBD" + ExpectedFWUpdateRuntime="${REDct}UNKNOWN${NOct}" + else + Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs" + ExpectedFWUpdateRuntime="$(date -d @$nextCronTimeSecs +"%Y-%b-%d %I:%M %p")" + ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" + fi else ExpectedFWUpdateRuntime="$(date -d @$ExpectedFWUpdateRuntime +"%Y-%b-%d %I:%M %p")" ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" @@ -3580,7 +3710,7 @@ _Set_FW_UpdatePostponementDays_() then Update_Custom_Settings FW_New_Update_Postponement_Days "$newPostponementDays" echo "The number of days to postpone F/W Update was updated successfully." - _calculate_NextRunTime_ + _Calculate_NextRunTime_ _WaitForEnterKey_ "$mainMenuReturnPromptStr" fi return 0 @@ -3725,7 +3855,7 @@ _Set_FW_UpdateCronSchedule_() printf "Cron job '${GRNct}${CRON_JOB_TAG}${NOct}' was updated successfully.\n" current_schedule_english="$(translate_schedule "$nextCronSchedule")" printf "Job Schedule: ${GRNct}${current_schedule_english}${NOct}\n" - _calculate_NextRunTime_ + _Calculate_NextRunTime_ else retCode=1 printf "${REDct}**ERROR**${NOct}: Failed to add/update the cron job [${CRON_JOB_TAG}].\n" @@ -3740,9 +3870,9 @@ _Set_FW_UpdateCronSchedule_() return "$retCode" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-06] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## _CheckNewUpdateFirmwareNotification_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] @@ -3793,10 +3923,16 @@ _CheckNewUpdateFirmwareNotification_() _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi fi + fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" - upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") - nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") - Update_Custom_Settings FW_New_Update_Run_Date "$nextCronTimeSecs" + upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")" + nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" + if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ] + then + Update_Custom_Settings FW_New_Update_Expected_Run_Date "TBD" + else + Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs" + fi return 0 } @@ -3851,15 +3987,16 @@ _CheckNodeFWUpdateNotification_() return 0 } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-06] ## -##------------------------------------------## -_CheckTimeToUpdateFirmware_() { +##----------------------------------------## +## Modified by Martinski W. [2024-May-18] ## +##----------------------------------------## +_CheckTimeToUpdateFirmware_() +{ if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi local upfwDateTimeSecs nextCronTimeSecs upfwDateTimeStrn - local fwNewUpdatePostponementDays fwNewUpdateNotificationDate + local fwNewUpdatePostponementDays fwNewUpdateNotificationDate fwNewUpdateNotificationVers _CheckNewUpdateFirmwareNotification_ "$1" "$2" @@ -3876,23 +4013,23 @@ _CheckTimeToUpdateFirmware_() { if [ "$fwNewUpdatePostponementDays" -eq 0 ] then return 0 ; fi - upfwDateTimeSecs=$(calculate_DST "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')") + upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")" local currentTimeSecs="$(date +%s)" if [ "$((currentTimeSecs - upfwDateTimeSecs))" -ge 0 ] then return 0 ; fi - nextCronTimeSecs=$(estimate_next_cron_after_date "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule") + Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." - if [ "$nextCronTimeSecs" = "no_date_found" ]; then + nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" + if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ] + then upfwDateTimeStrn="$(date -d @$upfwDateTimeSecs +"%A, %Y-%b-%d %I:%M %p")" Say "The firmware update is expected to occur on or after ${GRNct}${upfwDateTimeStrn}${NOct}, depending on when your cron job is scheduled to check again." return 1 fi upfwDateTimeStrn="$(date -d @$nextCronTimeSecs +"%A, %Y-%b-%d %I:%M %p")" - - Say "The firmware update to ${GRNct}${2}${NOct} version is currently postponed for ${GRNct}${fwNewUpdatePostponementDays}${NOct} day(s)." Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." echo "" @@ -3903,8 +4040,6 @@ _CheckTimeToUpdateFirmware_() { else return 1 fi - - return 1 } ##-------------------------------------## @@ -4348,7 +4483,7 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Latest release version is ${GRNct}${release_version}${NOct}." Say "Downloading ${GRNct}${release_link}${NOct}" - echo "" + echo ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Apl-24] ## @@ -4429,7 +4564,7 @@ Please manually update to version $minimum_supported_version or higher to use th if [ ! -f "$changeLogFile" ] then - Say "Change-log file [${FW_BIN_DIR}/$Changelog-${changeLogTag}.txt] does NOT exist." + Say "Change-log file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." _DoCleanUp_ "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 @@ -4762,17 +4897,14 @@ _PostRebootRunNow_() _RunFirmwareUpdateNow_ } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Nov-19] ## -##----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _DelCronJobRunScriptHook_() { local hookScriptFile - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] ; then return 1 ; fi if grep -qE "$CRON_SCRIPT_JOB" "$hookScriptFile" @@ -4787,18 +4919,14 @@ _DelCronJobRunScriptHook_() fi } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Oct-17] ## -##----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-17] ## +##----------------------------------------## _AddCronJobRunScriptHook_() { local hookScriptFile jobHookAdded=false - if [ $# -gt 0 ] && [ -n "$1" ] - then hookScriptFile="$1" - else hookScriptFile="$hookScriptFPath" - fi - + hookScriptFile="$hookScriptFPath" if [ ! -f "$hookScriptFile" ] then jobHookAdded=true @@ -5551,8 +5679,8 @@ _ShowMainMenu_() arrowStr=" ${REDct}<<---${NOct}" - _calculate_NextRunTime_ - # Show or hide F/W Update ETA based on whether a meaningful ETA exists + _Calculate_NextRunTime_ + notifyDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" if [ "$notifyDate" = "TBD" ] then notificationStr="${REDct}NOT SET${NOct}" From 8b0169145fab4bc6e4b0344988ccbcf5aadf5bc3 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 19 May 2024 03:58:07 -0400 Subject: [PATCH 085/185] Update MerlinAU.sh --- MerlinAU.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d77c22b4..f7ca7e9c 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-18 +# Last Modified: 2024-May-09 ################################################################### set -u @@ -481,7 +481,6 @@ readonly CRON_MONTH_NAMES="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)" readonly CRON_MONTH_RegEx="$CRON_MONTH_NAMES([\/,-]$CRON_MONTH_NAMES)*|([*1-9]|1[0-2])([\/,-]([1-9]|1[0-2]))*" readonly CRON_UNKNOWN_DATE="**ERROR**: UNKNOWN Date Found" - ##------------------------------------------## ## Modified by Martinski W. [2024-Jan-22] ## ##------------------------------------------## @@ -3373,14 +3372,9 @@ matches_day_of_week() dow_expr="$dowStartNum" while true do - dowStartNum="$((++dowStartNum))" - if [ "$dowStartNum" -lt 7 ] - then - dow_expr="${dow_expr},$dowStartNum" - else - dowStartNum=0 - dow_expr="${dow_expr},$dowStartNum" - fi + dowStartNum="$((dowStartNum + 1))" + [ "$dowStartNum" -ge 7 ] && dowStartNum=0 + dow_expr="${dow_expr},$dowStartNum" [ "$dowStartNum" -eq "$dowEndNum" ] && break done if matches_day_of_week "$curr_dow" "$dow_expr" From 1acc40ee4d689eaaa698dc6052305e2ed62ec458 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 19 May 2024 03:58:43 -0400 Subject: [PATCH 086/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f7ca7e9c..7e494bd7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-09 +# Last Modified: 2024-May-18 ################################################################### set -u From 54e3aa8c18585fa78d61e2f92a3202ad1db819ee Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 21 May 2024 02:00:26 -0400 Subject: [PATCH 087/185] Update MerlinAU.sh --- MerlinAU.sh | 64 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 7e494bd7..4d9a11e9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-18 +# Last Modified: 2024-May-19 ################################################################### set -u -readonly SCRIPT_VERSION=1.1.4 +readonly SCRIPT_VERSION=1.1.5 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -503,13 +503,14 @@ readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUF ##------------------------------------------## logo() { echo -e "${YLWct}" - echo -e " __ __ _ _ _ _ " - echo -e " | \/ | | (_) /\ | | | |" - echo -e " | \ / | ___ _ __| |_ _ __ / \ | | | |" - echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |" - echo -e " | | | | __| | | | | | | |/ ____ | |__| |" - echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}" + echo -e " __ __ _ _ _ _ " + echo -e " | \/ | | (_) /\ | | | |" + echo -e " | \ / | ___ _ __| |_ _ __ / \ | | | |" + echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |" + echo -e " | | | | __| | | | | | | |/ ____ | |__| |" + echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}" echo -e " ${NOct}" + printf "${YLWct}============ By ExtremeFiretop & Martinski W. ============${NOct}\n\n" } ##-----------------------------------------------## @@ -5336,6 +5337,7 @@ theExitStr="${GRNct}e${NOct}=Exit to Main Menu" theADExitStr="${GRNct}e${NOct}=Exit to Advanced Menu" padStr=" " SEPstr="-----------------------------------------------------" +SEPtop="----------------------------------------------------------" FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}" if [ "$PRODUCT_ID" = "$MODEL_ID" ] @@ -5650,7 +5652,6 @@ _ShowMainMenu_() clear logo - printf "${YLWct}========= By ExtremeFiretop & Martinski W. ==========${NOct}\n\n" # New Script Update Notification # if [ "$UpdateNotify" != "0" ]; then @@ -5689,27 +5690,26 @@ _ShowMainMenu_() FirmwareFlavor="${BLUEct}Merlin${NOct}" fi - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-18] ## - ##------------------------------------------## - printf "${SEPstr}" + ##----------------------------------------## + ## Modified by Martinski W. [2024-May-19] ## + ##----------------------------------------## + printf "${SEPtop}" if [ "$HIDE_ROUTER_SECTION" = "false" ] then if ! FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" then FW_NewUpdateVersion="${REDct}NONE FOUND${NOct}" else FW_NewUpdateVersion="${GRNct}${FW_NewUpdateVersion}${NOct}$arrowStr" fi - printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(H)ide" - printf "\n${padStr}F/W Variant Detected: $FirmwareFlavor" - printf "\n${padStr}USB Storage Connected: $USBConnected" - printf "\n${padStr}F/W Version Installed: $FW_InstalledVersion" - printf "\n${padStr}F/W Update Available: $FW_NewUpdateVersion" - printf "\n${padStr}F/W Upd Expected ETA: $ExpectedFWUpdateRuntime" + printf "\n Router's Product Name/Model ID: $FW_RouterModelID${padStr}(H)ide" + printf "\n USB-Attached Storage Connected: $USBConnected" + printf "\n F/W Version Currently Installed: $FW_InstalledVersion" + printf "\n F/W Variant Configuration Found: $FirmwareFlavor" + printf "\n F/W Update Version Available: $FW_NewUpdateVersion" + printf "\n F/W Update Estimate Run Date: $ExpectedFWUpdateRuntime" else - printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(S)how" + printf "\n Router's Product Name/Model ID: $FW_RouterModelID${padStr}(S)how" fi - - printf "\n${SEPstr}" + printf "\n${SEPtop}" printf "\n ${GRNct}1${NOct}. Run F/W Update Check Now\n" printf "\n ${GRNct}2${NOct}. Set Router Login Credentials\n" @@ -5752,7 +5752,7 @@ _ShowMainMenu_() printf "\n ${GRNct}un${NOct}. Uninstall\n" printf "\n ${GRNct}e${NOct}. Exit\n" - printf "${SEPstr}\n" + printf "${SEPtop}\n" } ##------------------------------------------## @@ -5762,8 +5762,8 @@ _ShowAdvancedOptionsMenu_() { clear logo - printf "=============== Advanced Options Menu ===============\n" - printf "${SEPstr}\n" + printf "================== Advanced Options Menu =================\n" + printf "${SEPtop}\n" printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" @@ -5872,7 +5872,7 @@ _ShowAdvancedOptionsMenu_() fi printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPstr}" + printf "${SEPtop}" } ##---------------------------------------## @@ -5882,8 +5882,8 @@ _ShowNodesMenu_() { clear logo - printf "============== AiMesh Node(s) Info Menu ==============\n" - printf "${SEPstr}\n" + printf "================= AiMesh Node(s) Info Menu ================\n" + printf "${SEPtop}\n" if ! node_online_status="$(_NodeActiveStatus_)" then node_online_status="" ; fi @@ -5899,7 +5899,7 @@ _ShowNodesMenu_() echo "" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPstr}" + printf "${SEPtop}" } _ShowNodesMenuOptions_() @@ -5969,8 +5969,8 @@ _ShowLogsMenu_() { clear logo - printf "===================== Logs Menu =====================\n" - printf "${SEPstr}\n" + printf "======================== Logs Menu =======================\n" + printf "${SEPtop}\n" printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" @@ -5983,7 +5983,7 @@ _ShowLogsMenu_() printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPstr}" + printf "${SEPtop}" } ##----------------------------------------## From 0c4a321e5b045ae38d6c9af0f4b3cc7c3dc864d8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 21 May 2024 02:02:34 -0400 Subject: [PATCH 088/185] Update MerlinAU.sh --- MerlinAU.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 4d9a11e9..25c02497 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3006,12 +3006,12 @@ _ChangeBuildType_Gnuton_() doReturnToMenu=false while true do - printf "\n${SEPstr}" + printf "\n${SEPtop}" printf "\nChoose your preferred option for the build type to flash:\n" printf "\n ${GRNct}1${NOct}. Original ${REDct}TUF${NOct} themed user interface${NOct}\n" printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-TUF${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPstr}\n" + printf "${SEPtop}\n" printf "[$display_choice] Enter selection: " read -r choice @@ -3066,12 +3066,12 @@ _ChangeBuildType_Merlin_() doReturnToMenu=false while true do - printf "\n${SEPstr}" + printf "\n${SEPtop}" printf "\nChoose your preferred option for the build type to flash:\n" printf "\n ${GRNct}1${NOct}. Original ${REDct}ROG${NOct} themed user interface${NOct}\n" printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-ROG${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPstr}\n" + printf "${SEPtop}\n" printf "[$display_choice] Enter selection: " read -r choice @@ -4993,12 +4993,12 @@ _SetEMailFormatType_() doReturnToMenu=false while true do - printf "\n${SEPstr}" + printf "\n${SEPtop}" printf "\nChoose the format type for email notifications:\n" printf "\n ${GRNct}1${NOct}. HTML\n" printf "\n ${GRNct}2${NOct}. Plain Text\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPstr}\n" + printf "${SEPtop}\n" printf "[$currFormatStr] Enter selection: " read -r userInput @@ -5336,7 +5336,6 @@ fi theExitStr="${GRNct}e${NOct}=Exit to Main Menu" theADExitStr="${GRNct}e${NOct}=Exit to Advanced Menu" padStr=" " -SEPstr="-----------------------------------------------------" SEPtop="----------------------------------------------------------" FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}" From 523a19ffcf2e6926935e10b85f3ae28ebf1104b3 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 21 May 2024 11:58:59 -0400 Subject: [PATCH 089/185] Update MerlinAU.sh --- MerlinAU.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 25c02497..c45eda24 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-19 +# Last Modified: 2024-May-21 ################################################################### set -u @@ -499,7 +499,7 @@ readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Feb-01] ## +## Modified by ExtremeFiretop [2024-May-21] ## ##------------------------------------------## logo() { echo -e "${YLWct}" @@ -1324,11 +1324,19 @@ _CreateEMailContent_() ;; STOP_FW_UPDATE_APPROVAL) emailBodyTitle="WARNING" + high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" + if $isEMailFormatHTML; then + # Highlight high-risk terms using HTML with a yellow background + highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/\1<\/span>/gi") + else + # Highlight high-risk terms in plain text using asterisks + highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/*\1*/gi") + fi { - echo "Found high-risk phrases in the change-logs while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." - echo "Changelog contents include the following changes:" - echo "$changelog_contents" - printf "\nPlease run script interactively to approve this F/W Update from current version:\n${fwInstalledVersion}\n" + echo "Found high-risk phrases in the change-logs while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." + echo "Changelog contents include the following changes:" + echo "$highlighted_changelog_contents" + printf "\nPlease run script interactively to approve this F/W Update from current version:\n${fwInstalledVersion}\n" } > "$tempEMailBodyMsg" ;; NEW_BM_BACKUP_FAILED) @@ -4424,11 +4432,11 @@ Please manually update to version $minimum_supported_version or higher to use th fi # Convert version strings to comparable numbers - current_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")" - required_version="$(_ScriptVersionStrToNum_ "1.5.3")" + local currentBM_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")" + local requiredBM_version="$(_ScriptVersionStrToNum_ "1.5.3")" # Check if BACKUPMON version is greater than or equal to 1.5.3 - if [ "$current_version" -ge "$required_version" ]; then + if [ "$currentBM_version" -ge "$requiredBM_version" ]; then # Execute the backup script if it exists # echo "" Say "Backup Started (by BACKUPMON)" From 11d7390f513052011cf8fe300039c0aac685e215 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 21 May 2024 12:28:26 -0400 Subject: [PATCH 090/185] Update MerlinAU.sh --- MerlinAU.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c45eda24..5b6b231e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2823,25 +2823,24 @@ return 0 } ##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## +## Added by ExtremeFiretop [2024-May-21] ## ##---------------------------------------## _CheckFirmwareSHA256_() { - # Check if both the SHA256 signature file and the firmware file exist - if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then - # Extract the SHA256 signature from the firmware file - local fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - # Extract the recorded SHA256 signature from the checksum file - local dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)" - - # Compare the extracted signature and the recorded signature + # Fetch the latest checksums from ASUSWRT-Merlin website + checksums=$(curl -s https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g') + + if [ -f "$firmware_file" ]; then + fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" + # Extract the corresponding checksum for the firmware file from the fetched data + dl_sig="$(echo "$checksums" | grep "$(basename $firmware_file)" | cut -d' ' -f1)" if [ "$fw_sig" != "$dl_sig" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!" + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature from the website!" _DoCleanUp_ 1 _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS return 1 fi else - Say "${REDct}**ERROR**${NOct}: SHA256 signature file or firmware file not found!" + Say "${REDct}**ERROR**${NOct}: Firmware file not found!" _DoCleanUp_ 1 return 1 fi From 6cf1637c381888dcdb536f1df22ea317a1247264 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 21 May 2024 13:06:24 -0400 Subject: [PATCH 091/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5b6b231e..145d6881 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2827,7 +2827,7 @@ return 0 ##---------------------------------------## _CheckFirmwareSHA256_() { # Fetch the latest checksums from ASUSWRT-Merlin website - checksums=$(curl -s https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g') + checksums=$(curl --silent --connect-timeout 10 --retry 4 --max-time 12 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g') if [ -f "$firmware_file" ]; then fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" From 930a3dce35925c2952e6a1fa6fd3045f1cfedd5c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 23 May 2024 00:53:18 -0400 Subject: [PATCH 092/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 145d6881..e5039d9f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -510,7 +510,6 @@ logo() { echo -e " | | | | __| | | | | | | |/ ____ | |__| |" echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}" echo -e " ${NOct}" - printf "${YLWct}============ By ExtremeFiretop & Martinski W. ============${NOct}\n\n" } ##-----------------------------------------------## @@ -5658,6 +5657,7 @@ _ShowMainMenu_() clear logo + printf "${YLWct}============ By ExtremeFiretop & Martinski W. ============${NOct}\n\n" # New Script Update Notification # if [ "$UpdateNotify" != "0" ]; then @@ -5711,7 +5711,7 @@ _ShowMainMenu_() printf "\n F/W Version Currently Installed: $FW_InstalledVersion" printf "\n F/W Variant Configuration Found: $FirmwareFlavor" printf "\n F/W Update Version Available: $FW_NewUpdateVersion" - printf "\n F/W Update Estimate Run Date: $ExpectedFWUpdateRuntime" + printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" else printf "\n Router's Product Name/Model ID: $FW_RouterModelID${padStr}(S)how" fi From 86f7813acebf92f2de7c2d249288087ae7507cea Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 23 May 2024 05:28:15 -0400 Subject: [PATCH 093/185] Update MerlinAU.sh --- MerlinAU.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e5039d9f..115ae606 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5928,7 +5928,7 @@ _ShowNodesMenuOptions_() ##----------------------------------------## ## Modified by Martinski W. [2024-May-05] ## ##----------------------------------------## -_DownloadChangelogs_() +_DownloadChangelogsMerlin_() { local wgetLogFile changeLogTag changeLogFile changeLogURL @@ -5968,6 +5968,49 @@ _DownloadChangelogs_() return 1 } +_DownloadChangelogsGnuton_() +{ + local wgetLogFile changeLogURL FW_Changelog_GITHUB + + # Create directory to download changelog if missing + if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi + + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$Gnuton_changelogurl") + + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "$Gnuton_changelogurl" + + if [ ! -f "$FW_Changelog_GITHUB" ] + then + Say "Change-log file [$FW_Changelog_GITHUB] does NOT exist." + echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" + else + clear + printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + dos2unix "$FW_Changelog_GITHUB" + _WaitForEnterKey_ + less "$FW_Changelog_GITHUB" + fi + rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-04] ## ##----------------------------------------## @@ -6017,7 +6060,12 @@ _AdvancedLogsOptions_() _InvalidMenuSelection_ fi ;; - cl) _DownloadChangelogs_ + cl) if "$isGNUtonFW" + then + _DownloadChangelogsGnuton_ + else + _DownloadChangelogsMerlin_ + fi ;; e|exit) break ;; From 1acab764cf65bbb0b7992eebb09520134b8abf17 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 23 May 2024 05:37:00 -0400 Subject: [PATCH 094/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 115ae606..417ed90e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5970,7 +5970,7 @@ _DownloadChangelogsMerlin_() _DownloadChangelogsGnuton_() { - local wgetLogFile changeLogURL FW_Changelog_GITHUB + local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB # Create directory to download changelog if missing if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi From 81a795a3b776850e234920fa9b3525ae60b54aba Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 23 May 2024 12:18:11 -0400 Subject: [PATCH 095/185] Update MerlinAU.sh --- MerlinAU.sh | 138 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 56 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 417ed90e..9a123b70 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-21 +# Last Modified: 2024-May-23 ################################################################### set -u @@ -26,9 +26,10 @@ readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.n ##---------------------------------------## ## Added by ExtremeFiretop [2024-May-03] ## ##---------------------------------------## -# Changelog URL Info # +# Changelog Info # readonly CL_URL_NG="${FW_SFURL_BASE}/Documentation/Changelog-NG.txt/download" readonly CL_URL_386="${FW_SFURL_BASE}/Documentation/Changelog-386.txt/download" +readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" # For new script version updates from source repository # UpdateNotify=0 @@ -99,8 +100,9 @@ then inRouterSWmode=true else inRouterSWmode=false fi -mainMenuReturnPromptStr="Press to return to the Main Menu..." -advnMenuReturnPromptStr="Press to return to the Advanced Menu..." +readonly mainMenuReturnPromptStr="Press to return to the Main Menu..." +readonly advnMenuReturnPromptStr="Press to return to the Advanced Menu..." +readonly logsMenuReturnPromptStr="Press to return to the Logs Menu..." [ -t 0 ] && ! tty | grep -qwi "NOT" && isInteractive=true @@ -202,10 +204,10 @@ _AcquireLock_() then Say "Stale lock found (older than $LockFileMaxSecs secs.) Reset lock file." oldPID="$(cat "$LockFilePath")" - if [ -n "$oldPID" ] && kill -EXIT $oldPID 2>/dev/null && \ - echo "$(pidof "$ScriptFileName")" | grep -qow "$oldPID" + if [ -n "$oldPID" ] && kill -EXIT "$oldPID" 2>/dev/null && \ + pidof "$ScriptFileName" | grep -qow "$oldPID" then - kill -TERM $oldPID ; wait $oldPID + kill -TERM "$oldPID" ; wait "$oldPID" fi rm -f "$LockFilePath" echo "$$" > "$LockFilePath" @@ -509,7 +511,7 @@ logo() { echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |" echo -e " | | | | __| | | | | | | |/ ____ | |__| |" echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}" - echo -e " ${NOct}" + echo -e "${NOct}" } ##-----------------------------------------------## @@ -1323,12 +1325,12 @@ _CreateEMailContent_() ;; STOP_FW_UPDATE_APPROVAL) emailBodyTitle="WARNING" - high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" - if $isEMailFormatHTML; then - # Highlight high-risk terms using HTML with a yellow background + if $isEMailFormatHTML + then + # Highlight high-risk terms using HTML with a yellow background # highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/\1<\/span>/gi") else - # Highlight high-risk terms in plain text using asterisks + # Highlight high-risk terms in plain text using asterisks # highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/*\1*/gi") fi { @@ -2104,15 +2106,15 @@ _TestLoginCredentials_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Apr-15] ## +## Modified by Martinski W. [2024-May-23] ## ##----------------------------------------## _GetPasswordInput_() { local PSWDstrLenMIN=1 PSWDstrLenMAX=64 local PSWDstring PSWDtmpStr PSWDprompt local retCode charNum pswdLength showPSWD - # Added for TAB keypress debounce # - local lastTabTime=0 currentTime + # For more responsive TAB keypress debounce # + local tabKeyDebounceSem="/tmp/var/tmp/${ScriptFNameTag}_TabKeySEM.txt" if [ $# -eq 0 ] || [ -z "$1" ] then @@ -2130,6 +2132,13 @@ _GetPasswordInput_() stty "$savedSettings" } + _TabKeyDebounceWait_() + { + touch "$tabKeyDebounceSem" + usleep 300000 #0.3 sec# + rm -f "$tabKeyDebounceSem" + } + _ShowAsterisks_() { if [ $# -eq 0 ] || [ "$1" -eq 0 ] @@ -2189,12 +2198,11 @@ _GetPasswordInput_() ## TAB keypress as toggle with debounce ## if [ "$charNum" -eq 9 ] then - currentTime="$(date +%s)" - if [ "$((currentTime - lastTabTime))" -gt 0 ] + if [ ! -f "$tabKeyDebounceSem" ] then showPSWD="$((! showPSWD))" - lastTabTime="$currentTime" # Update TAB keypress time # _ShowPSWDPrompt_ + _TabKeyDebounceWait_ & fi continue fi @@ -2828,18 +2836,34 @@ _CheckFirmwareSHA256_() { # Fetch the latest checksums from ASUSWRT-Merlin website checksums=$(curl --silent --connect-timeout 10 --retry 4 --max-time 12 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g') - if [ -f "$firmware_file" ]; then + if [ -z "$checksums" ] + then + Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website." + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ] + then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi + fi + + if [ -f "$firmware_file" ] + then fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - # Extract the corresponding checksum for the firmware file from the fetched data + # Extract the corresponding signature for the firmware file from the fetched checksums # dl_sig="$(echo "$checksums" | grep "$(basename $firmware_file)" | cut -d' ' -f1)" - if [ "$fw_sig" != "$dl_sig" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature from the website!" + if [ "$fw_sig" != "$dl_sig" ] + then + Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." _DoCleanUp_ 1 _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS return 1 fi else - Say "${REDct}**ERROR**${NOct}: Firmware file not found!" + Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!" _DoCleanUp_ 1 return 1 fi @@ -3012,12 +3036,12 @@ _ChangeBuildType_Gnuton_() doReturnToMenu=false while true do - printf "\n${SEPtop}" + printf "\n${SEPstr}" printf "\nChoose your preferred option for the build type to flash:\n" printf "\n ${GRNct}1${NOct}. Original ${REDct}TUF${NOct} themed user interface${NOct}\n" printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-TUF${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" printf "[$display_choice] Enter selection: " read -r choice @@ -3072,12 +3096,12 @@ _ChangeBuildType_Merlin_() doReturnToMenu=false while true do - printf "\n${SEPtop}" + printf "\n${SEPstr}" printf "\nChoose your preferred option for the build type to flash:\n" printf "\n ${GRNct}1${NOct}. Original ${REDct}ROG${NOct} themed user interface${NOct}\n" printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-ROG${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" printf "[$display_choice] Enter selection: " read -r choice @@ -4078,7 +4102,7 @@ _Toggle_FW_UpdateEmailNotifications_() if ! _WaitForYESorNO_ "Do you want to ${emailNotificationNewStateStr} F/W Update email notifications?" then - _RunEMailNotificationTest_ && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + _RunEMailNotificationTest_ && _WaitForEnterKey_ "$advnMenuReturnPromptStr" return 1 fi @@ -4095,7 +4119,7 @@ _Toggle_FW_UpdateEmailNotifications_() printf "F/W Update email notifications are now ${emailNotificationNewStateStr}.\n" _RunEMailNotificationTest_ - _WaitForEnterKey_ "$mainMenuReturnPromptStr" + _WaitForEnterKey_ "$advnMenuReturnPromptStr" } ##------------------------------------------## @@ -4610,31 +4634,31 @@ Please manually update to version $minimum_supported_version or higher to use th if "$isGNUtonFW" then - # For Gnuton, the whole file is relevant as it only contains the current version + # For Gnuton, the whole file is relevant as it only contains the current version # changelog_contents="$(cat "$changeLogFile")" else if ! grep -Eq "$current_version_regex" "$changeLogFile"; then Say "Current version not found in change-log. Bypassing change-log verification for this run." return 1 else - # Extract log contents between two firmware versions for non-Gnuton changelogs + # Extract log contents between two firmware versions for non-Gnuton changelogs # changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" fi fi - high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" - - # Search for high-risk terms in the extracted log contents - if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then - if [ "$inMenuMode" = true ]; then - printf "\n ${REDct}Warning: Found high-risk phrases in the change-log.${NOct}" + # Search for high-risk terms in the extracted log contents # + if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" + then + if [ "$inMenuMode" = true ] + then + printf "\n ${REDct}*WARNING*: Found high-risk phrases in the change-log.${NOct}" printf "\n ${REDct}Would you like to continue anyways?${NOct}" if ! _WaitForYESorNO_ ; then Say "Exiting for change-log review." _DoCleanUp_ 1 ; return 1 fi else - Say "Warning: Found high-risk phrases in the change-log." + Say "*WARNING*: Found high-risk phrases in the change-log." Say "Please run script interactively to approve the upgrade." _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL _DoCleanUp_ 1 @@ -4999,12 +5023,12 @@ _SetEMailFormatType_() doReturnToMenu=false while true do - printf "\n${SEPtop}" + printf "\n${SEPstr}" printf "\nChoose the format type for email notifications:\n" printf "\n ${GRNct}1${NOct}. HTML\n" printf "\n ${GRNct}2${NOct}. Plain Text\n" printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" printf "[$currFormatStr] Enter selection: " read -r userInput @@ -5341,8 +5365,10 @@ fi # menu setup variables # theExitStr="${GRNct}e${NOct}=Exit to Main Menu" theADExitStr="${GRNct}e${NOct}=Exit to Advanced Menu" +theLGExitStr="${GRNct}e${NOct}=Exit to Logs Menu" + padStr=" " -SEPtop="----------------------------------------------------------" +SEPstr="----------------------------------------------------------" FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}" if [ "$PRODUCT_ID" = "$MODEL_ID" ] @@ -5386,10 +5412,10 @@ _GetFileSelectionIndex_() if [ $# -lt 2 ] || [ "$2" != "-MULTIOK" ] then multiIndexListOK=false - promptStr="Enter selection [${selectStr}] [${theExitStr}]?" + promptStr="Enter selection [${selectStr}] [${theLGExitStr}]?" else multiIndexListOK=true - promptStr="Enter selection [${selectStr} | ${theAllStr}] [${theExitStr}]?" + promptStr="Enter selection [${selectStr} | ${theAllStr}] [${theLGExitStr}]?" fi fileIndex=0 multiIndex=false numRegEx="([1-9]|[1-9][0-9])" @@ -5699,23 +5725,23 @@ _ShowMainMenu_() ##----------------------------------------## ## Modified by Martinski W. [2024-May-19] ## ##----------------------------------------## - printf "${SEPtop}" + printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] then if ! FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" then FW_NewUpdateVersion="${REDct}NONE FOUND${NOct}" else FW_NewUpdateVersion="${GRNct}${FW_NewUpdateVersion}${NOct}$arrowStr" fi - printf "\n Router's Product Name/Model ID: $FW_RouterModelID${padStr}(H)ide" + printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide" printf "\n USB-Attached Storage Connected: $USBConnected" printf "\n F/W Version Currently Installed: $FW_InstalledVersion" printf "\n F/W Variant Configuration Found: $FirmwareFlavor" printf "\n F/W Update Version Available: $FW_NewUpdateVersion" printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" else - printf "\n Router's Product Name/Model ID: $FW_RouterModelID${padStr}(S)how" + printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(S)how" fi - printf "\n${SEPtop}" + printf "\n${SEPstr}" printf "\n ${GRNct}1${NOct}. Run F/W Update Check Now\n" printf "\n ${GRNct}2${NOct}. Set Router Login Credentials\n" @@ -5758,7 +5784,7 @@ _ShowMainMenu_() printf "\n ${GRNct}un${NOct}. Uninstall\n" printf "\n ${GRNct}e${NOct}. Exit\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" } ##------------------------------------------## @@ -5769,7 +5795,7 @@ _ShowAdvancedOptionsMenu_() clear logo printf "================== Advanced Options Menu =================\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" @@ -5878,7 +5904,7 @@ _ShowAdvancedOptionsMenu_() fi printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPtop}" + printf "${SEPstr}" } ##---------------------------------------## @@ -5889,7 +5915,7 @@ _ShowNodesMenu_() clear logo printf "================= AiMesh Node(s) Info Menu ================\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" if ! node_online_status="$(_NodeActiveStatus_)" then node_online_status="" ; fi @@ -5905,7 +5931,7 @@ _ShowNodesMenu_() echo "" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPtop}" + printf "${SEPstr}" } _ShowNodesMenuOptions_() @@ -5964,7 +5990,7 @@ _DownloadChangelogsMerlin_() less "$changeLogFile" fi rm -f "$changeLogFile" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr"" return 1 } @@ -6007,7 +6033,7 @@ _DownloadChangelogsGnuton_() less "$FW_Changelog_GITHUB" fi rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr"" return 1 } @@ -6019,7 +6045,7 @@ _ShowLogsMenu_() clear logo printf "======================== Logs Menu =======================\n" - printf "${SEPtop}\n" + printf "${SEPstr}\n" printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" printf "\n${padStr}[Current Path: ${GRNct}${FW_LOG_DIR}${NOct}]\n" @@ -6032,7 +6058,7 @@ _ShowLogsMenu_() printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPtop}" + printf "${SEPstr}" } ##----------------------------------------## From 7bd5701859db1896c6e65ff9d447b82703f72067 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 23 May 2024 12:32:23 -0400 Subject: [PATCH 096/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9a123b70..8c03cc57 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5990,7 +5990,7 @@ _DownloadChangelogsMerlin_() less "$changeLogFile" fi rm -f "$changeLogFile" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr"" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" return 1 } @@ -6033,7 +6033,7 @@ _DownloadChangelogsGnuton_() less "$FW_Changelog_GITHUB" fi rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr"" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" return 1 } From 27d9c54fe0e5808a822524a86539b860526a5f54 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 27 May 2024 07:05:21 -0400 Subject: [PATCH 097/185] Update MerlinAU.sh --- MerlinAU.sh | 709 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 436 insertions(+), 273 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8c03cc57..77bfd367 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-23 +# Last Modified: 2024-May-26 ################################################################### set -u -readonly SCRIPT_VERSION=1.1.5 +readonly SCRIPT_VERSION=1.1.6 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -678,7 +678,7 @@ else fi ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Mar-20] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _Init_Custom_Settings_Config_() { @@ -699,6 +699,7 @@ _Init_Custom_Settings_Config_() echo "FW_New_Update_EMail_CC_Name=TBD" echo "FW_New_Update_EMail_CC_Address=TBD" echo "CheckChangeLog ENABLED" + echo "FW_New_Update_Changelog_Approval=TBD" echo "FW_Allow_Beta_Production_Up ENABLED" echo "FW_Auto_Backupmon ENABLED" } > "$SETTINGSFILE" @@ -767,6 +768,11 @@ _Init_Custom_Settings_Config_() sed -i "12 i FW_Auto_Backupmon ENABLED" "$SETTINGSFILE" retCode=1 fi + if ! grep -q "^FW_New_Update_Changelog_Approval" "$SETTINGSFILE" + then + sed -i "13 i FW_New_Update_Changelog_Approval=TBD" "$SETTINGSFILE" + retCode=1 + fi return "$retCode" } @@ -783,8 +789,7 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -792,6 +797,7 @@ Get_Custom_Setting() setting_value="$(grep "^${setting_type} " "$SETTINGSFILE" | awk -F ' ' '{print $2}')" ;; "FW_New_Update_Postponement_Days" | \ + "FW_New_Update_Changelog_Approval" | \ "FW_New_Update_Expected_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ @@ -855,8 +861,7 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -876,6 +881,7 @@ Update_Custom_Settings() fi ;; "FW_New_Update_Postponement_Days" | \ + "FW_New_Update_Changelog_Approval" | \ "FW_New_Update_Expected_Run_Date" | \ "FW_New_Update_Cron_Job_Schedule" | \ "FW_New_Update_ZIP_Directory_Path" | \ @@ -2912,6 +2918,7 @@ _toggle_change_log_check_() { case $response in [Yy]* ) Update_Custom_Settings "CheckChangeLog" "DISABLED" + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "TBD" printf "Change-log verification check is now ${REDct}DISABLED.${NOct}\n" ;; *) @@ -3128,6 +3135,46 @@ _ChangeBuildType_Merlin_() _WaitForEnterKey_ "$advnMenuReturnPromptStr" } +##---------------------------------------## +## Added by ExtremeFiretop [2024-May-25] ## +##---------------------------------------## +_ApproveUpgrade_() { + local currentSetting="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" + + if [ "$currentSetting" = "BLOCKED" ] + then + printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the change-log.\n" + printf "The advice is to approve if you're read the firmware changelog and you want to proceed with the update.\n" + printf "Are you sure you want to approve the latest firmware update? [y/N]: " + read -r response + case $response in + [Yy]* ) + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" + printf "The latest firmware upgrade is now ${GRNct}APPROVED.${NOct}\n" + ;; + *) + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + printf "The latest firmware upgrade remain ${REDct}BLOCKED.${NOct}\n" + ;; + esac + else + printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the change-log.\n" + printf "Are you sure you want to block the latest firmware update? [y/N]: " + read -r response + case $response in + [Yy]* ) + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + printf "The latest firmware upgrade is now ${REDct}BLOCKED.${NOct}\n" + ;; + *) + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" + printf "The latest firmware upgrade remain ${GRNct}APPROVED.${NOct}\n" + ;; + esac + fi + _WaitForEnterKey_ +} + ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-22] ## ##----------------------------------------## @@ -3896,6 +3943,273 @@ _Set_FW_UpdateCronSchedule_() return "$retCode" } +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-26] ## +##------------------------------------------## +_high_risk_phrases_interactive_() { + local changelog_contents="$1" + + if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then + ChangelogApproval="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" + if [ "$ChangelogApproval" = "BLOCKED" ] + then + if [ "$inMenuMode" = true ] + then + printf "\n ${REDct}*WARNING*: Found high-risk phrases in the change-log.${NOct}" + printf "\n ${REDct}Would you like to continue anyways?${NOct}" + if ! _WaitForYESorNO_ + then + Say "Exiting for change-log review." + _DoCleanUp_ 1 + return 1 + else + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" + fi + else + Say "*WARNING*: Found high-risk phrases in the change-log." + Say "Please run script interactively to approve the upgrade." + _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL + _DoCleanUp_ 1 + _DoExit_ 1 + fi + else + Say "Changelog pre-approved!" + fi + else + Say "No high-risk phrases found in the change-log." + fi + return 0 +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-26] ## +##------------------------------------------## +_high_risk_phrases_nointeractive_() { + local changelog_contents="$1" + + if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" + then + printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the change-log." + printf "\nPlease approve the update by selecting ${GRNct}'Toggle F/W Update Changelog Approval'${NOct}\n" + if [ "$inMenuMode" = false ] + then + Say "\nPlease run script interactively to approve the upgrade." + fi + _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + return 1 + else + return 0 + fi +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-26] ## +##------------------------------------------## +_ChangelogVerificationCheck_() { + local mode="$1" # Mode should be 'auto' or 'interactive' + local formatted_current_version + local formatted_release_version + local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" + + if [ "$checkChangeLogSetting" = "ENABLED" ] + then + local current_version="$(_GetCurrentFWInstalledShortVersion_)" + local release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" + + if "$isGNUtonFW" + then + changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + else + # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # + if echo "$release_version" | grep -q "386"; then + changeLogTag="386" + else + changeLogTag="NG" + fi + changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" + fi + + if [ ! -f "$changeLogFile" ] + then + Say "Change-log file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + _DoCleanUp_ + return 1 + else + # Use awk to format the version based on the number of initial digits + formatted_current_version=$(echo "$current_version" | awk -F. '{ + if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix + if (NF == 4 && $4 == "0") { + printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 + } else if (NF == 4) { + printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit + } + } else if (NF == 3) { # For version without a four-digit prefix + if ($3 == "0") { + printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 + } else { + printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit + } + } + }') + + formatted_release_version=$(echo "$release_version" | awk -F. '{ + if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix + if (NF == 4 && $4 == "0") { + printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 + } else if (NF == 4) { + printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit + } + } else if (NF == 3) { # For version without a four-digit prefix + if ($3 == "0") { + printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 + } else { + printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit + } + } + }') + + # Define regex patterns for both versions + release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" + current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" + + if "$isGNUtonFW" + then + # For Gnuton, the whole file is relevant as it only contains the current version # + changelog_contents="$(cat "$changeLogFile")" + else + if ! grep -Eq "$current_version_regex" "$changeLogFile"; then + Say "Current version not found in change-log. Bypassing change-log verification for this run." + return 0 + else + # Extract log contents between two firmware versions for non-Gnuton changelogs # + changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" + fi + fi + + if [ "$mode" = "interactive" ] + then + _high_risk_phrases_interactive_ "$changelog_contents" + if [ $? -ne 0 ] + then + return 1 + fi + else + _high_risk_phrases_nointeractive_ "$changelog_contents" + if [ $? -ne 0 ] + then + return 1 + fi + fi + fi + else + [ "$mode" = "interactive" ] && Say "Change-logs check disabled." + return 0 + fi +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-25] ## +##------------------------------------------## +_ManageChangelogMerlin_() +{ + local mode="$1" # Mode should be 'download' or 'view' + local wgetLogFile changeLogTag changeLogFile changeLogURL + + # Create directory to download changelog if missing + if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi + + changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" + if [ "$changeLogTag" = "386" ] + then + changeLogURL="${CL_URL_386}" + elif [ "$changeLogTag" = "NG" ] + then + changeLogURL="${CL_URL_NG}" + fi + + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" + + if [ "$mode" = "view" ]; then + printf "\nRetrieving ${GRNct}Changelog-${changeLogTag}.txt${NOct} ...\n" + fi + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$changeLogFile" -o "$wgetLogFile" "${changeLogURL}" + + if [ ! -f "$changeLogFile" ] + then + Say "Change-log file [$changeLogFile] does NOT exist." + echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" + else + if [ "$mode" = "download" ] + then + _ChangelogVerificationCheck_ "auto" + elif [ "$mode" = "view" ] + then + clear + printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + dos2unix "$changeLogFile" + _WaitForEnterKey_ + less "$changeLogFile" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" + fi + fi + rm -f "$changeLogFile" "$wgetLogFile" + return 0 +} + +_ManageChangelogGnuton_() +{ + local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB + + # Create directory to download changelog if missing + if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi + + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$Gnuton_changelogurl") + + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "$Gnuton_changelogurl" + + if [ ! -f "$FW_Changelog_GITHUB" ] + then + Say "Change-log file [$FW_Changelog_GITHUB] does NOT exist." + echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" + else + if [ "$mode" = "download" ] + then + _ChangelogVerificationCheck_ "auto" + elif [ "$mode" = "view" ] + then + clear + printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + dos2unix "$FW_Changelog_GITHUB" + _WaitForEnterKey_ + less "$FW_Changelog_GITHUB" + fi + fi + rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" + "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" + return 1 +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-18] ## ##----------------------------------------## @@ -3915,6 +4229,7 @@ _CheckNewUpdateFirmwareNotification_() Say "Current firmware version '$1' is up to date." Update_Custom_Settings FW_New_Update_Notification_Date TBD Update_Custom_Settings FW_New_Update_Notification_Vers TBD + Update_Custom_Settings FW_New_Update_Changelog_Approval TBD return 1 fi @@ -3936,6 +4251,12 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "view" + else + _ManageChangelogMerlin_ "view" + fi fi fi @@ -3948,6 +4269,12 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "view" + else + _ManageChangelogMerlin_ "view" + fi fi fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" @@ -4569,108 +4896,16 @@ Please manually update to version $minimum_supported_version or higher to use th cd "$FW_BIN_DIR" ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Aprl-24] ## + ## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## - local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" + _ChangelogVerificationCheck_ "interactive" + retCode="$?" - if [ "$checkChangeLogSetting" = "ENABLED" ] + if [ "$retCode" -eq 1 ] then - if "$isGNUtonFW" - then - changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - else - # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # - if echo "$release_version" | grep -q "386"; then - changeLogTag="386" - else - changeLogTag="NG" - fi - changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" - fi - - if [ ! -f "$changeLogFile" ] - then - Say "Change-log file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." - _DoCleanUp_ - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Use awk to format the version based on the number of initial digits - formatted_current_version=$(echo "$current_version" | awk -F. '{ - if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix - if (NF == 4 && $4 == "0") { - printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 - } else if (NF == 4) { - printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit - } - } else if (NF == 3) { # For version without a four-digit prefix - if ($3 == "0") { - printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 - } else { - printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit - } - } - }') - - formatted_release_version=$(echo "$release_version" | awk -F. '{ - if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix - if (NF == 4 && $4 == "0") { - printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0 - } else if (NF == 4) { - printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit - } - } else if (NF == 3) { # For version without a four-digit prefix - if ($3 == "0") { - printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0 - } else { - printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit - } - } - }') - - # Define regex patterns for both versions - release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - - if "$isGNUtonFW" - then - # For Gnuton, the whole file is relevant as it only contains the current version # - changelog_contents="$(cat "$changeLogFile")" - else - if ! grep -Eq "$current_version_regex" "$changeLogFile"; then - Say "Current version not found in change-log. Bypassing change-log verification for this run." - return 1 - else - # Extract log contents between two firmware versions for non-Gnuton changelogs # - changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" - fi - fi - - # Search for high-risk terms in the extracted log contents # - if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" - then - if [ "$inMenuMode" = true ] - then - printf "\n ${REDct}*WARNING*: Found high-risk phrases in the change-log.${NOct}" - printf "\n ${REDct}Would you like to continue anyways?${NOct}" - if ! _WaitForYESorNO_ ; then - Say "Exiting for change-log review." - _DoCleanUp_ 1 ; return 1 - fi - else - Say "*WARNING*: Found high-risk phrases in the change-log." - Say "Please run script interactively to approve the upgrade." - _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL - _DoCleanUp_ 1 - _DoExit_ 1 - fi - else - Say "No high-risk phrases found in the change-log." - fi - fi - else - Say "Change-logs check disabled." - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi freeRAM_kb="$(_GetFreeRAM_KB_)" availableRAM_kb="$(_GetAvailableRAM_KB_)" @@ -4869,6 +5104,7 @@ Please manually update to version $minimum_supported_version or higher to use th _PostUpdateEmailNotification_() { _DelPostUpdateEmailNotifyScriptHook_ + Update_Custom_Settings FW_New_Update_Changelog_Approval TBD local theWaitDelaySecs=10 local maxWaitDelaySecs=360 #6 minutes# @@ -5669,7 +5905,7 @@ _InvalidMenuSelection_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _ShowMainMenu_() { @@ -5709,7 +5945,7 @@ _ShowMainMenu_() _Calculate_NextRunTime_ - notifyDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" + notifyDate="$(Get_Custom_Setting "FW_New_Update_Notification_Date")" if [ "$notifyDate" = "TBD" ] then notificationStr="${REDct}NOT SET${NOct}" else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}" @@ -5722,9 +5958,6 @@ _ShowMainMenu_() FirmwareFlavor="${BLUEct}Merlin${NOct}" fi - ##----------------------------------------## - ## Modified by Martinski W. [2024-May-19] ## - ##----------------------------------------## printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] then @@ -5762,19 +5995,26 @@ _ShowMainMenu_() printf "\n ${GRNct}4${NOct}. Set F/W Update Postponement Days" printf "\n${padStr}[Current Days: ${GRNct}${FW_UpdatePostponementDays}${NOct}]\n" - printf "\n ${GRNct}5${NOct}. Set F/W Update Check Schedule" - printf "\n${padStr}[Current Schedule: ${GRNct}${FW_UpdateCronJobSchedule}${NOct}]\n" - - # Check for AiMesh Nodes # - if "$inRouterSWmode" && [ -n "$node_list" ]; then - printf "\n ${GRNct}mn${NOct}. AiMesh Node(s) Info\n" + local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" + if [ "$checkChangeLogSetting" = "DISABLED" ] + then + printf "\n ${GRNct}5${NOct}. Toggle Change-log Check" + printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" + else + printf "\n ${GRNct}5${NOct}. Toggle Change-log Check" + printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi - # Add selection for "Log Options" sub-menu # - printf "\n ${GRNct}lo${NOct}. Log Options Menu\n" - - # Add selection for "Advanced Options" sub-menu # - printf "\n ${GRNct}ad${NOct}. Advanced Options\n" + ChangelogApproval="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" + if [ "$ChangelogApproval" = "BLOCKED" ] + then + printf "\n ${GRNct}6${NOct}. Toggle F/W Update Changelog Approval" + printf "\n${padStr}[Currently ${REDct}${ChangelogApproval}${NOct}]\n" + elif [ "$ChangelogApproval" = "APPROVED" ] + then + printf "\n ${GRNct}6${NOct}. Toggle F/W Update Changelog Approval" + printf "\n${padStr}[Currently ${GRNct}${ChangelogApproval}${NOct}]\n" + fi # Check for new script updates # if [ "$UpdateNotify" != "0" ]; then @@ -5782,13 +6022,23 @@ _ShowMainMenu_() printf "\n${padStr}[Version: ${GRNct}${DLRepoVersion}${NOct} Available for Download]\n" fi - printf "\n ${GRNct}un${NOct}. Uninstall\n" + # Add selection for "Advanced Options" sub-menu # + printf "\n ${GRNct}ad${NOct}. Advanced Options\n" + + # Check for AiMesh Nodes # + if "$inRouterSWmode" && [ -n "$node_list" ]; then + printf "\n ${GRNct}mn${NOct}. AiMesh Node(s) Info\n" + fi + + # Add selection for "Log Options" sub-menu # + printf "\n ${GRNct}lo${NOct}. Log Options Menu\n" + printf "\n ${GRNct}e${NOct}. Exit\n" printf "${SEPstr}\n" } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -5800,15 +6050,8 @@ _ShowAdvancedOptionsMenu_() printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" - local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" - if [ "$checkChangeLogSetting" = "DISABLED" ] - then - printf "\n ${GRNct}2${NOct}. Toggle Change-log Check" - printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" - else - printf "\n ${GRNct}2${NOct}. Toggle Change-log Check" - printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" - fi + printf "\n ${GRNct}2${NOct}. Set F/W Update Check Schedule" + printf "\n${padStr}[Current Schedule: ${GRNct}${FW_UpdateCronJobSchedule}${NOct}]\n" local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" if [ "$BetaProductionSetting" = "DISABLED" ] @@ -5832,41 +6075,6 @@ _ShowAdvancedOptionsMenu_() fi fi - # Additional Email Notification Options # - if _CheckEMailConfigFileFromAMTM_ 0 - then - # F/W Update Email Notifications # - if "$inRouterSWmode" - then - printf "\n ${GRNct}em${NOct}. Toggle F/W Update Email Notifications" - else - printf "\n ${GRNct}em${NOct}. Toggle F/W Email Notifications" - fi - if "$sendEMailNotificationsFlag" - then - printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}, Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" - else - printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" - fi - - if "$sendEMailNotificationsFlag" - then - # Format Types: "HTML" or "Plain Text" # - printf "\n ${GRNct}ef${NOct}. Set Email Format Type" - printf "\n${padStr}[Current Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" - - # Secondary Email Address Setup for "CC" option # - printf "\n ${GRNct}se${NOct}. Set Email Notifications Secondary Address" - if [ -n "$CC_NAME" ] && [ -n "$CC_ADDRESS" ] - then - printf "\n${padStr}[Current Name/Alias: ${GRNct}${CC_NAME}${NOct}]" - printf "\n${padStr}[Current 2nd Address: ${GRNct}${CC_ADDRESS}${NOct}]\n" - else - echo - fi - fi - fi - if "$isGNUtonFW" then # Retrieve the current build type setting @@ -5903,6 +6111,42 @@ _ShowAdvancedOptionsMenu_() fi fi + # Additional Email Notification Options # + if _CheckEMailConfigFileFromAMTM_ 0 + then + # F/W Update Email Notifications # + if "$inRouterSWmode" + then + printf "\n ${GRNct}em${NOct}. Toggle F/W Update Email Notifications" + else + printf "\n ${GRNct}em${NOct}. Toggle F/W Email Notifications" + fi + if "$sendEMailNotificationsFlag" + then + printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}, Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" + else + printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" + fi + + if "$sendEMailNotificationsFlag" + then + # Format Types: "HTML" or "Plain Text" # + printf "\n ${GRNct}ef${NOct}. Set Email Format Type" + printf "\n${padStr}[Current Format: ${GRNct}${sendEMailFormaType}${NOct}]\n" + + # Secondary Email Address Setup for "CC" option # + printf "\n ${GRNct}se${NOct}. Set Email Notifications Secondary Address" + if [ -n "$CC_NAME" ] && [ -n "$CC_ADDRESS" ] + then + printf "\n${padStr}[Current Name/Alias: ${GRNct}${CC_NAME}${NOct}]" + printf "\n${padStr}[Current 2nd Address: ${GRNct}${CC_ADDRESS}${NOct}]\n" + else + echo + fi + fi + fi + + printf "\n ${GRNct}un${NOct}. Uninstall\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" printf "${SEPstr}" } @@ -5914,7 +6158,7 @@ _ShowNodesMenu_() { clear logo - printf "================= AiMesh Node(s) Info Menu ================\n" + printf "================ AiMesh Node(s) Info Menu ================\n" printf "${SEPstr}\n" if ! node_online_status="$(_NodeActiveStatus_)" @@ -5951,92 +6195,6 @@ _ShowNodesMenuOptions_() done } -##----------------------------------------## -## Modified by Martinski W. [2024-May-05] ## -##----------------------------------------## -_DownloadChangelogsMerlin_() -{ - local wgetLogFile changeLogTag changeLogFile changeLogURL - - # Create directory to download changelog if missing - if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi - - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" - if [ "$changeLogTag" = "386" ] - then - changeLogURL="${CL_URL_386}" - elif [ "$changeLogTag" = "NG" ] - then - changeLogURL="${CL_URL_NG}" - fi - - wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" - changeLogFile="${FW_BIN_DIR}/Changelog-${changeLogTag}.txt" - printf "\nRetrieving ${GRNct}Changelog-${changeLogTag}.txt${NOct} ...\n" - - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$changeLogFile" -o "$wgetLogFile" "${changeLogURL}" - - if [ ! -f "$changeLogFile" ] - then - Say "Change-log file [$changeLogFile] does NOT exist." - echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" - else - clear - printf "\n${GRNct}Changelog is ready to review!${NOct}\n" - printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" - dos2unix "$changeLogFile" - _WaitForEnterKey_ - less "$changeLogFile" - fi - rm -f "$changeLogFile" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" - return 1 -} - -_DownloadChangelogsGnuton_() -{ - local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB - - # Create directory to download changelog if missing - if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi - - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$Gnuton_changelogurl") - - # Use the effective URL to capture the Content-Disposition header - local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') - - # Sanitize filename by removing problematic characters - local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - - FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" - - wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" - printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" - - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "$Gnuton_changelogurl" - - if [ ! -f "$FW_Changelog_GITHUB" ] - then - Say "Change-log file [$FW_Changelog_GITHUB] does NOT exist." - echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" - else - clear - printf "\n${GRNct}Changelog is ready to review!${NOct}\n" - printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" - dos2unix "$FW_Changelog_GITHUB" - _WaitForEnterKey_ - less "$FW_Changelog_GITHUB" - fi - rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" - return 1 -} - ##----------------------------------------## ## Modified by Martinski W. [2024-May-04] ## ##----------------------------------------## @@ -6088,9 +6246,9 @@ _AdvancedLogsOptions_() ;; cl) if "$isGNUtonFW" then - _DownloadChangelogsGnuton_ + _ManageChangelogGnuton_ "view" else - _DownloadChangelogsMerlin_ + _ManageChangelogMerlin_ "view" fi ;; e|exit) break @@ -6102,7 +6260,7 @@ _AdvancedLogsOptions_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _advanced_options_menu_() { @@ -6115,7 +6273,7 @@ _advanced_options_menu_() case $advancedChoice in 1) _Set_FW_UpdateZIP_DirectoryPath_ ;; - 2) _toggle_change_log_check_ + 2) _Set_FW_UpdateCronSchedule_ ;; 3) _toggle_beta_updates_ ;; @@ -6124,6 +6282,13 @@ _advanced_options_menu_() else _InvalidMenuSelection_ fi ;; + bt) if echo "$PRODUCT_ID" | grep -q "^GT-" + then _ChangeBuildType_Merlin_ + elif echo "$PRODUCT_ID" | grep -q "^TUF-" + then _ChangeBuildType_Gnuton_ + else _InvalidMenuSelection_ + fi + ;; em) if "$isEMailConfigEnabledInAMTM" then _Toggle_FW_UpdateEmailNotifications_ else _InvalidMenuSelection_ @@ -6141,12 +6306,7 @@ _advanced_options_menu_() else _InvalidMenuSelection_ fi ;; - bt) if echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_Merlin_ - elif echo "$PRODUCT_ID" | grep -q "^TUF-" - then _ChangeBuildType_Gnuton_ - else _InvalidMenuSelection_ - fi + un) _DoUninstall_ && _WaitForEnterKey_ ;; e|exit) break ;; @@ -6157,7 +6317,7 @@ _advanced_options_menu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## # Main Menu loop inMenuMode=true @@ -6189,20 +6349,23 @@ do ;; 4) _Set_FW_UpdatePostponementDays_ ;; - 5) _Set_FW_UpdateCronSchedule_ + 5) _toggle_change_log_check_ ;; - mn) if "$inRouterSWmode" && [ -n "$node_list" ] - then _ShowNodesMenuOptions_ - else _InvalidMenuSelection_ + 6) if [ "$ChangelogApproval" = "TBD" ] || [ -z "$ChangelogApproval" ] + then _InvalidMenuSelection_ + else _ApproveUpgrade_ fi ;; - lo) _AdvancedLogsOptions_ + up) _SCRIPTUPDATE_ ;; ad) _advanced_options_menu_ ;; - up) _SCRIPTUPDATE_ + mn) if "$inRouterSWmode" && [ -n "$node_list" ] + then _ShowNodesMenuOptions_ + else _InvalidMenuSelection_ + fi ;; - un) _DoUninstall_ && _WaitForEnterKey_ + lo) _AdvancedLogsOptions_ ;; e|exit) _DoExit_ 0 ;; From 1b3fabd33f816cb733e9753e06f1d16d3b464c80 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 27 May 2024 07:14:36 -0400 Subject: [PATCH 098/185] Update MerlinAU.sh --- MerlinAU.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 77bfd367..d2bbb29d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -789,7 +789,8 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -861,7 +862,8 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ From 89ca1f67623430025280bfa8ed95f601f497d3a0 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 27 May 2024 08:38:57 -0400 Subject: [PATCH 099/185] Update MerlinAU.sh --- MerlinAU.sh | 158 +++++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 75 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d2bbb29d..2221c7dd 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-26 +# Last Modified: 2024-May-27 ################################################################### set -u @@ -101,8 +101,8 @@ else inRouterSWmode=false fi readonly mainMenuReturnPromptStr="Press to return to the Main Menu..." -readonly advnMenuReturnPromptStr="Press to return to the Advanced Menu..." -readonly logsMenuReturnPromptStr="Press to return to the Logs Menu..." +readonly advnMenuReturnPromptStr="Press to return to the Advanced Options Menu..." +readonly logsMenuReturnPromptStr="Press to return to the Log Options Menu..." [ -t 0 ] && ! tty | grep -qwi "NOT" && isInteractive=true @@ -753,22 +753,22 @@ _Init_Custom_Settings_Config_() sed -i "9 i FW_New_Update_LOG_Preferred_Path=\"${preferredPath}\"" "$SETTINGSFILE" retCode=1 fi - if ! grep -q "^CheckChangeLog" "$SETTINGSFILE" + if ! grep -q "^CheckChangeLog " "$SETTINGSFILE" then sed -i "10 i CheckChangeLog ENABLED" "$SETTINGSFILE" retCode=1 fi - if ! grep -q "^FW_Allow_Beta_Production_Up" "$SETTINGSFILE" + if ! grep -q "^FW_Allow_Beta_Production_Up " "$SETTINGSFILE" then sed -i "11 i FW_Allow_Beta_Production_Up ENABLED" "$SETTINGSFILE" retCode=1 fi - if ! grep -q "^FW_Auto_Backupmon" "$SETTINGSFILE" + if ! grep -q "^FW_Auto_Backupmon " "$SETTINGSFILE" then sed -i "12 i FW_Auto_Backupmon ENABLED" "$SETTINGSFILE" retCode=1 fi - if ! grep -q "^FW_New_Update_Changelog_Approval" "$SETTINGSFILE" + if ! grep -q "^FW_New_Update_Changelog_Approval=" "$SETTINGSFILE" then sed -i "13 i FW_New_Update_Changelog_Approval=TBD" "$SETTINGSFILE" retCode=1 @@ -1342,7 +1342,7 @@ _CreateEMailContent_() highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/*\1*/gi") fi { - echo "Found high-risk phrases in the change-logs while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." + echo "Found high-risk phrases in the changelog file while Auto-Updating to version ${fwNewUpdateVersion} on the ${MODEL_ID} router." echo "Changelog contents include the following changes:" echo "$highlighted_changelog_contents" printf "\nPlease run script interactively to approve this F/W Update from current version:\n${fwInstalledVersion}\n" @@ -2862,7 +2862,7 @@ _CheckFirmwareSHA256_() { then fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" # Extract the corresponding signature for the firmware file from the fetched checksums # - dl_sig="$(echo "$checksums" | grep "$(basename $firmware_file)" | cut -d' ' -f1)" + dl_sig="$(echo "$checksums" | grep "$(basename "$firmware_file")" | cut -d' ' -f1)" if [ "$fw_sig" != "$dl_sig" ] then Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." @@ -2909,34 +2909,36 @@ _CheckFirmwareMD5_() { ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-23] ## ##---------------------------------------## -_toggle_change_log_check_() { +_toggle_change_log_check_() +{ local currentSetting="$(Get_Custom_Setting "CheckChangeLog")" - if [ "$currentSetting" = "ENABLED" ]; then - printf "${REDct}*WARNING*:${NOct} Disabling change-log verification may risk unanticipated changes.\n" - printf "The advice is to proceed only if you review the change-logs manually.\n" + if [ "$currentSetting" = "ENABLED" ] + then + printf "${REDct}*WARNING*:${NOct} Disabling changelog verification may risk unanticipated changes.\n" + printf "The advice is to proceed only if you review the latest firmware changelog file manually.\n" printf "\nProceed to disable? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "CheckChangeLog" "DISABLED" Update_Custom_Settings "FW_New_Update_Changelog_Approval" "TBD" - printf "Change-log verification check is now ${REDct}DISABLED.${NOct}\n" + printf "Changelog verification check is now ${REDct}DISABLED.${NOct}\n" ;; *) - printf "Change-log verification check remains ${GRNct}ENABLED.${NOct}\n" + printf "Changelog verification check remains ${GRNct}ENABLED.${NOct}\n" ;; esac else - printf "Are you sure you want to enable the change-log verification check? [y/N]: " + printf "Are you sure you want to enable the changelog verification check? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "CheckChangeLog" "ENABLED" - printf "Change-log verification check is now ${GRNct}ENABLED.${NOct}\n" + printf "Changelog verification check is now ${GRNct}ENABLED.${NOct}\n" ;; *) - printf "Change-log verification check remains ${REDct}DISABLED.${NOct}\n" + printf "Changelog verification check remains ${REDct}DISABLED.${NOct}\n" ;; esac fi @@ -2946,35 +2948,37 @@ _toggle_change_log_check_() { ##---------------------------------------## ## Added by ExtremeFiretop [2024-Jan-27] ## ##---------------------------------------## -_toggle_beta_updates_() { +_Toggle_FW_UpdatesFromBeta_() +{ local currentSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" - if [ "$currentSetting" = "ENABLED" ]; then + if [ "$currentSetting" = "ENABLED" ] + then printf "${REDct}*WARNING*:${NOct}\n" - printf "Disabling updates from beta to release firmware may limit access to new features and fixes.\n" - printf "Keep this enabled if you prefer to stay up-to-date with the latest releases.\n" + printf "Disabling firmware updates from beta to production releases may limit access to new features and fixes.\n" + printf "Keep this option ENABLED if you prefer to stay up-to-date with the latest production releases.\n" printf "\nProceed to disable? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "FW_Allow_Beta_Production_Up" "DISABLED" - printf "Updates from beta firmwares to production firmwares are now ${REDct}DISABLED.${NOct}\n" + printf "Firmware updates from beta to production releases are now ${REDct}DISABLED.${NOct}\n" ;; *) - printf "Updates from beta firmwares to production firmwares remain ${GRNct}ENABLED.${NOct}\n" + printf "Firmware updates from beta to production releases remain ${GRNct}ENABLED.${NOct}\n" ;; esac else - printf "Are you sure you want to enable updates from beta F/Ws to production F/Ws?" + printf "Are you sure you want to enable firmware updates from beta to production?" printf "\nProceed to enable? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "FW_Allow_Beta_Production_Up" "ENABLED" - printf "Updates from beta firmwares to production firmwares are now ${GRNct}ENABLED.${NOct}\n" + printf "Firmware updates from beta to production releases are now ${GRNct}ENABLED.${NOct}\n" ;; *) - printf "Updates from beta firmwares to production firmwares remain ${REDct}DISABLED.${NOct}\n" + printf "Firmware updates from beta to production releases remain ${REDct}DISABLED.${NOct}\n" ;; esac fi @@ -2984,10 +2988,12 @@ _toggle_beta_updates_() { ##---------------------------------------## ## Added by ExtremeFiretop [2024-Mar-20] ## ##---------------------------------------## -_Toggle_Auto_Backups_() { +_Toggle_Auto_Backups_() +{ local currentSetting="$(Get_Custom_Setting "FW_Auto_Backupmon")" - if [ "$currentSetting" = "ENABLED" ]; then + if [ "$currentSetting" = "ENABLED" ] + then printf "${REDct}*WARNING*:${NOct} Disabling auto backups may risk data loss or inconsistency.\n" printf "The advice is to proceed only if you're sure you want to disable auto backups.\n" printf "\nProceed to disable? [y/N]: " @@ -3140,37 +3146,38 @@ _ChangeBuildType_Merlin_() ##---------------------------------------## ## Added by ExtremeFiretop [2024-May-25] ## ##---------------------------------------## -_ApproveUpgrade_() { +_ApproveUpgrade_() +{ local currentSetting="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" if [ "$currentSetting" = "BLOCKED" ] then - printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the change-log.\n" + printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the changelog file.\n" printf "The advice is to approve if you're read the firmware changelog and you want to proceed with the update.\n" printf "Are you sure you want to approve the latest firmware update? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" - printf "The latest firmware upgrade is now ${GRNct}APPROVED.${NOct}\n" + printf "The latest firmware update is now ${GRNct}APPROVED.${NOct}\n" ;; *) Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" - printf "The latest firmware upgrade remain ${REDct}BLOCKED.${NOct}\n" + printf "The latest firmware update remain ${REDct}BLOCKED.${NOct}\n" ;; esac else - printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the change-log.\n" + printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the changelog file.\n" printf "Are you sure you want to block the latest firmware update? [y/N]: " read -r response case $response in [Yy]* ) Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" - printf "The latest firmware upgrade is now ${REDct}BLOCKED.${NOct}\n" + printf "The latest firmware update is now ${REDct}BLOCKED.${NOct}\n" ;; *) Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" - printf "The latest firmware upgrade remain ${GRNct}APPROVED.${NOct}\n" + printf "The latest firmware update remain ${GRNct}APPROVED.${NOct}\n" ;; esac fi @@ -3948,37 +3955,39 @@ _Set_FW_UpdateCronSchedule_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-26] ## ##------------------------------------------## -_high_risk_phrases_interactive_() { +_high_risk_phrases_interactive_() +{ local changelog_contents="$1" - if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then + if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" + then ChangelogApproval="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" if [ "$ChangelogApproval" = "BLOCKED" ] then if [ "$inMenuMode" = true ] then - printf "\n ${REDct}*WARNING*: Found high-risk phrases in the change-log.${NOct}" - printf "\n ${REDct}Would you like to continue anyways?${NOct}" + printf "\n ${REDct}*WARNING*: Found high-risk phrases in the changelog file.${NOct}" + printf "\n ${REDct}Would you like to continue with the firmware update anyways?${NOct}" if ! _WaitForYESorNO_ then - Say "Exiting for change-log review." + Say "Exiting for changelog review." _DoCleanUp_ 1 return 1 else Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" fi else - Say "*WARNING*: Found high-risk phrases in the change-log." - Say "Please run script interactively to approve the upgrade." + Say "*WARNING*: Found high-risk phrases in the changelog file." + Say "Please run script interactively to approve the firmware update." _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL _DoCleanUp_ 1 _DoExit_ 1 fi else - Say "Changelog pre-approved!" + Say "Changelog review is pre-approved!" fi else - Say "No high-risk phrases found in the change-log." + Say "No high-risk phrases found in the changelog file." fi return 0 } @@ -3991,11 +4000,11 @@ _high_risk_phrases_nointeractive_() { if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" then - printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the change-log." + printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the changelog file." printf "\nPlease approve the update by selecting ${GRNct}'Toggle F/W Update Changelog Approval'${NOct}\n" if [ "$inMenuMode" = false ] then - Say "\nPlease run script interactively to approve the upgrade." + Say "\nPlease run script interactively to approve the firmware update." fi _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" @@ -4008,7 +4017,8 @@ _high_risk_phrases_nointeractive_() { ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-26] ## ##------------------------------------------## -_ChangelogVerificationCheck_() { +_ChangelogVerificationCheck_() +{ local mode="$1" # Mode should be 'auto' or 'interactive' local formatted_current_version local formatted_release_version @@ -4034,7 +4044,7 @@ _ChangelogVerificationCheck_() { if [ ! -f "$changeLogFile" ] then - Say "Change-log file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." _DoCleanUp_ return 1 else @@ -4081,7 +4091,7 @@ _ChangelogVerificationCheck_() { changelog_contents="$(cat "$changeLogFile")" else if ! grep -Eq "$current_version_regex" "$changeLogFile"; then - Say "Current version not found in change-log. Bypassing change-log verification for this run." + Say "Current version NOT found in changelog file. Bypassing changelog verification for this run." return 0 else # Extract log contents between two firmware versions for non-Gnuton changelogs # @@ -4091,21 +4101,19 @@ _ChangelogVerificationCheck_() { if [ "$mode" = "interactive" ] then - _high_risk_phrases_interactive_ "$changelog_contents" - if [ $? -ne 0 ] - then - return 1 + if _high_risk_phrases_interactive_ "$changelog_contents" + then return 0 + else return 1 fi else - _high_risk_phrases_nointeractive_ "$changelog_contents" - if [ $? -ne 0 ] - then - return 1 + if _high_risk_phrases_nointeractive_ "$changelog_contents" + then return 0 + else return 1 fi fi fi else - [ "$mode" = "interactive" ] && Say "Change-logs check disabled." + [ "$mode" = "interactive" ] && Say "Changelog check is DISABLED." return 0 fi } @@ -4142,7 +4150,7 @@ _ManageChangelogMerlin_() if [ ! -f "$changeLogFile" ] then - Say "Change-log file [$changeLogFile] does NOT exist." + Say "Changelog file [$changeLogFile] does NOT exist." echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" else if [ "$mode" = "download" ] @@ -4151,7 +4159,7 @@ _ManageChangelogMerlin_() elif [ "$mode" = "view" ] then clear - printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\n${GRNct}Changelog file is ready to review!${NOct}\n" printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" dos2unix "$changeLogFile" _WaitForEnterKey_ @@ -4191,7 +4199,7 @@ _ManageChangelogGnuton_() if [ ! -f "$FW_Changelog_GITHUB" ] then - Say "Change-log file [$FW_Changelog_GITHUB] does NOT exist." + Say "Changelog file [$FW_Changelog_GITHUB] does NOT exist." echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" else if [ "$mode" = "download" ] @@ -4200,7 +4208,7 @@ _ManageChangelogGnuton_() elif [ "$mode" = "view" ] then clear - printf "\n${GRNct}Changelog is ready to review!${NOct}\n" + printf "\n${GRNct}Changelog file is ready to review!${NOct}\n" printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" dos2unix "$FW_Changelog_GITHUB" _WaitForEnterKey_ @@ -5602,8 +5610,8 @@ fi # menu setup variables # theExitStr="${GRNct}e${NOct}=Exit to Main Menu" -theADExitStr="${GRNct}e${NOct}=Exit to Advanced Menu" -theLGExitStr="${GRNct}e${NOct}=Exit to Logs Menu" +theADExitStr="${GRNct}e${NOct}=Exit to Advanced Options Menu" +theLGExitStr="${GRNct}e${NOct}=Exit to Log Options Menu" padStr=" " SEPstr="----------------------------------------------------------" @@ -5778,7 +5786,7 @@ _CheckForUpdateLogFiles_() updateLogFileFound=false return 1 fi - chmod 444 "${FW_LOG_DIR}"/${MODEL_ID}_FW_Update_*.log + chmod 444 "${FW_LOG_DIR}/${MODEL_ID}"_FW_Update_*.log updateLogFileFound=true return 0 } @@ -6000,10 +6008,10 @@ _ShowMainMenu_() local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" if [ "$checkChangeLogSetting" = "DISABLED" ] then - printf "\n ${GRNct}5${NOct}. Toggle Change-log Check" + printf "\n ${GRNct}5${NOct}. Toggle F/W Changelog Check" printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}5${NOct}. Toggle Change-log Check" + printf "\n ${GRNct}5${NOct}. Toggle F/W Changelog Check" printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi @@ -6058,10 +6066,10 @@ _ShowAdvancedOptionsMenu_() local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" if [ "$BetaProductionSetting" = "DISABLED" ] then - printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release Upgrades" + printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates" printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release Upgrades" + printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates" printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi @@ -6200,11 +6208,11 @@ _ShowNodesMenuOptions_() ##----------------------------------------## ## Modified by Martinski W. [2024-May-04] ## ##----------------------------------------## -_ShowLogsMenu_() +_ShowLogOptionsMenu_() { clear logo - printf "======================== Logs Menu =======================\n" + printf "==================== Log Options Menu ====================\n" printf "${SEPstr}\n" printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files" @@ -6215,7 +6223,7 @@ _ShowLogsMenu_() printf "\n ${GRNct}lg${NOct}. View F/W Update Log File\n" fi - printf "\n ${GRNct}cl${NOct}. View latest F/W Changelog\n" + printf "\n ${GRNct}cl${NOct}. View Latest F/W Changelog\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" printf "${SEPstr}" @@ -6228,7 +6236,7 @@ _AdvancedLogsOptions_() { while true do - _ShowLogsMenu_ + _ShowLogOptionsMenu_ printf "\nEnter selection: " read -r nodesChoice echo @@ -6277,7 +6285,7 @@ _advanced_options_menu_() ;; 2) _Set_FW_UpdateCronSchedule_ ;; - 3) _toggle_beta_updates_ + 3) _Toggle_FW_UpdatesFromBeta_ ;; ab) if [ -f "/jffs/scripts/backupmon.sh" ] then _Toggle_Auto_Backups_ From f99b53e3cba3d33c16f70f14992763dafe17f1cc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 27 May 2024 10:54:01 -0400 Subject: [PATCH 100/185] Update MerlinAU.sh --- MerlinAU.sh | 202 +++++++++++++++++++++++----------------------------- 1 file changed, 89 insertions(+), 113 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 2221c7dd..1df75dcb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -173,12 +173,12 @@ _WaitForYESorNO_() local promptStr if [ $# -eq 0 ] || [ -z "$1" ] - then promptStr=" [yY|nN] N? " - else promptStr="$1 [yY|nN] N? " + then promptStr=" [yY|nN]? " + else promptStr="$1 [yY|nN]? " fi printf "$promptStr" ; read -r YESorNO - if echo "$YESorNO" | grep -qE "^([Yy](es)?)$" + if echo "$YESorNO" | grep -qE "^([Yy](es)?|YES)$" then echo "OK" ; return 0 else echo "NO" ; return 1 fi @@ -2906,119 +2906,102 @@ _CheckFirmwareMD5_() { fi } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Jan-23] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-27] ## +##----------------------------------------## _toggle_change_log_check_() { local currentSetting="$(Get_Custom_Setting "CheckChangeLog")" if [ "$currentSetting" = "ENABLED" ] then - printf "${REDct}*WARNING*:${NOct} Disabling changelog verification may risk unanticipated changes.\n" + printf "${REDct}*WARNING*${NOct}\n" + printf "Disabling the changelog verification check may risk unanticipated firmware changes.\n" printf "The advice is to proceed only if you review the latest firmware changelog file manually.\n" - printf "\nProceed to disable? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "CheckChangeLog" "DISABLED" - Update_Custom_Settings "FW_New_Update_Changelog_Approval" "TBD" - printf "Changelog verification check is now ${REDct}DISABLED.${NOct}\n" - ;; - *) - printf "Changelog verification check remains ${GRNct}ENABLED.${NOct}\n" - ;; - esac + + if _WaitForYESorNO_ "\nProceed to ${REDct}DISABLE${NOct}?" + then + Update_Custom_Settings "CheckChangeLog" "DISABLED" + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "TBD" + printf "Changelog verification check is now ${REDct}DISABLED.${NOct}\n" + else + printf "Changelog verification check remains ${GRNct}ENABLED.${NOct}\n" + fi else - printf "Are you sure you want to enable the changelog verification check? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "CheckChangeLog" "ENABLED" - printf "Changelog verification check is now ${GRNct}ENABLED.${NOct}\n" - ;; - *) - printf "Changelog verification check remains ${REDct}DISABLED.${NOct}\n" - ;; - esac + printf "Confirm to enable the changelog verification check." + if _WaitForYESorNO_ "\nProceed to ${GRNct}ENABLE${NOct}?" + then + Update_Custom_Settings "CheckChangeLog" "ENABLED" + printf "Changelog verification check is now ${GRNct}ENABLED.${NOct}\n" + else + printf "Changelog verification check remains ${REDct}DISABLED.${NOct}\n" + fi fi _WaitForEnterKey_ } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Jan-27] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-27] ## +##----------------------------------------## _Toggle_FW_UpdatesFromBeta_() { local currentSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" if [ "$currentSetting" = "ENABLED" ] then - printf "${REDct}*WARNING*:${NOct}\n" + printf "${REDct}*WARNING*${NOct}\n" printf "Disabling firmware updates from beta to production releases may limit access to new features and fixes.\n" printf "Keep this option ENABLED if you prefer to stay up-to-date with the latest production releases.\n" - printf "\nProceed to disable? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_Allow_Beta_Production_Up" "DISABLED" - printf "Firmware updates from beta to production releases are now ${REDct}DISABLED.${NOct}\n" - ;; - *) - printf "Firmware updates from beta to production releases remain ${GRNct}ENABLED.${NOct}\n" - ;; - esac + + if _WaitForYESorNO_ "\nProceed to ${REDct}DISABLE${NOct}?" + then + Update_Custom_Settings "FW_Allow_Beta_Production_Up" "DISABLED" + printf "Firmware updates from beta to production releases are now ${REDct}DISABLED.${NOct}\n" + else + printf "Firmware updates from beta to production releases remain ${GRNct}ENABLED.${NOct}\n" + fi else - printf "Are you sure you want to enable firmware updates from beta to production?" - printf "\nProceed to enable? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_Allow_Beta_Production_Up" "ENABLED" - printf "Firmware updates from beta to production releases are now ${GRNct}ENABLED.${NOct}\n" - ;; - *) - printf "Firmware updates from beta to production releases remain ${REDct}DISABLED.${NOct}\n" - ;; - esac + printf "Confirm to enable firmware updates from beta to production." + if _WaitForYESorNO_ "\nProceed to ${GRNct}ENABLE${NOct}?" + then + Update_Custom_Settings "FW_Allow_Beta_Production_Up" "ENABLED" + printf "Firmware updates from beta to production releases are now ${GRNct}ENABLED.${NOct}\n" + else + printf "Firmware updates from beta to production releases remain ${REDct}DISABLED.${NOct}\n" + fi fi _WaitForEnterKey_ } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Mar-20] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-27] ## +##----------------------------------------## _Toggle_Auto_Backups_() { local currentSetting="$(Get_Custom_Setting "FW_Auto_Backupmon")" if [ "$currentSetting" = "ENABLED" ] then - printf "${REDct}*WARNING*:${NOct} Disabling auto backups may risk data loss or inconsistency.\n" + printf "${REDct}*WARNING*${NOct}\n" + printf "Disabling automatic backups may risk data loss or inconsistency.\n" printf "The advice is to proceed only if you're sure you want to disable auto backups.\n" - printf "\nProceed to disable? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_Auto_Backupmon" "DISABLED" - printf "Auto backups are now ${REDct}DISABLED.${NOct}\n" - ;; - *) - printf "Auto backups remain ${GRNct}ENABLED.${NOct}\n" - ;; - esac + + if _WaitForYESorNO_ "\nProceed to ${REDct}DISABLE${NOct}?" + then + Update_Custom_Settings "FW_Auto_Backupmon" "DISABLED" + printf "Automatic backups are now ${REDct}DISABLED.${NOct}\n" + else + printf "Automatic backups remain ${GRNct}ENABLED.${NOct}\n" + fi else - printf "Are you sure you want to enable auto backups? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_Auto_Backupmon" "ENABLED" - printf "Auto backups are now ${GRNct}ENABLED.${NOct}\n" - ;; - *) - printf "Auto backups remain ${REDct}DISABLED.${NOct}\n" - ;; - esac + printf "Confirm to enable automatic backups before firmware flash." + if _WaitForYESorNO_ "\nProceed to ${GRNct}ENABLE${NOct}?" + then + Update_Custom_Settings "FW_Auto_Backupmon" "ENABLED" + printf "Automatic backups are now ${GRNct}ENABLED.${NOct}\n" + else + printf "Automatic backups remain ${REDct}DISABLED.${NOct}\n" + fi fi _WaitForEnterKey_ } @@ -3143,43 +3126,36 @@ _ChangeBuildType_Merlin_() _WaitForEnterKey_ "$advnMenuReturnPromptStr" } -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-25] ## -##---------------------------------------## -_ApproveUpgrade_() +##----------------------------------------## +## Modified by Martinski W. [2024-May-27] ## +##----------------------------------------## +_Approve_FW_Update_() { local currentSetting="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" if [ "$currentSetting" = "BLOCKED" ] then printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the changelog file.\n" - printf "The advice is to approve if you're read the firmware changelog and you want to proceed with the update.\n" - printf "Are you sure you want to approve the latest firmware update? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" - printf "The latest firmware update is now ${GRNct}APPROVED.${NOct}\n" - ;; - *) - Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" - printf "The latest firmware update remain ${REDct}BLOCKED.${NOct}\n" - ;; - esac + printf "The advice is to approve if you've read the firmware changelog and you want to proceed with the update.\n" + + if _WaitForYESorNO_ "Do you want to ${GRNct}APPROVE${NOct} the latest firmware update?" + then + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" + printf "The latest firmware update is now ${GRNct}APPROVED.${NOct}\n" + else + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + printf "The latest firmware update remain ${REDct}BLOCKED.${NOct}\n" + fi else printf "${REDct}*WARNING*:${NOct} Found high-risk phrases in the changelog file.\n" - printf "Are you sure you want to block the latest firmware update? [y/N]: " - read -r response - case $response in - [Yy]* ) - Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" - printf "The latest firmware update is now ${REDct}BLOCKED.${NOct}\n" - ;; - *) - Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" - printf "The latest firmware update remain ${GRNct}APPROVED.${NOct}\n" - ;; - esac + if _WaitForYESorNO_ "Do you want to ${REDct}BLOCK${NOct} the latest firmware update?" + then + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + printf "The latest firmware update is now ${REDct}BLOCKED.${NOct}\n" + else + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "APPROVED" + printf "The latest firmware update remain ${GRNct}APPROVED.${NOct}\n" + fi fi _WaitForEnterKey_ } @@ -6363,7 +6339,7 @@ do ;; 6) if [ "$ChangelogApproval" = "TBD" ] || [ -z "$ChangelogApproval" ] then _InvalidMenuSelection_ - else _ApproveUpgrade_ + else _Approve_FW_Update_ fi ;; up) _SCRIPTUPDATE_ From e4f7800dee36d7f1bbb578155fad215117cf7593 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 27 May 2024 11:01:25 -0400 Subject: [PATCH 101/185] Update MerlinAU.sh --- MerlinAU.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 09971d11..1df75dcb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2936,7 +2936,6 @@ _toggle_change_log_check_() else printf "Changelog verification check remains ${REDct}DISABLED.${NOct}\n" fi - fi _WaitForEnterKey_ } @@ -3003,7 +3002,6 @@ _Toggle_Auto_Backups_() else printf "Automatic backups remain ${REDct}DISABLED.${NOct}\n" fi - fi _WaitForEnterKey_ } From e0d1cde033707f74d6902ef60d92c612a9baae23 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 30 May 2024 11:01:59 -0400 Subject: [PATCH 102/185] Update MerlinAU.sh --- MerlinAU.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 1df75dcb..b521d66d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4239,9 +4239,9 @@ _CheckNewUpdateFirmwareNotification_() fi if "$isGNUtonFW" then - _ManageChangelogGnuton_ "view" + _ManageChangelogGnuton_ "download" else - _ManageChangelogMerlin_ "view" + _ManageChangelogMerlin_ "download" fi fi fi @@ -4257,9 +4257,9 @@ _CheckNewUpdateFirmwareNotification_() fi if "$isGNUtonFW" then - _ManageChangelogGnuton_ "view" + _ManageChangelogGnuton_ "download" else - _ManageChangelogMerlin_ "view" + _ManageChangelogMerlin_ "download" fi fi From 48f819edffd5b6a808b080b64395bc7aa6ac2ece Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 30 May 2024 11:03:33 -0400 Subject: [PATCH 103/185] Update MerlinAU.sh --- MerlinAU.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index b521d66d..8b9213c7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4149,6 +4149,7 @@ _ManageChangelogMerlin_() _ManageChangelogGnuton_() { + local mode="$1" # Mode should be 'download' or 'view' local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB # Create directory to download changelog if missing From 696d621325186bfe11de92a61a3ec6a6f5c4f9dc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 30 May 2024 12:06:41 -0400 Subject: [PATCH 104/185] Update MerlinAU.sh --- MerlinAU.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8b9213c7..a24a01fb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3976,14 +3976,17 @@ _high_risk_phrases_nointeractive_() { if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" then - printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the changelog file." - printf "\nPlease approve the update by selecting ${GRNct}'Toggle F/W Update Changelog Approval'${NOct}\n" - if [ "$inMenuMode" = false ] - then - Say "\nPlease run script interactively to approve the firmware update." - fi _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" + if [ "$inMenuMode" = true ] + then + printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the changelog file." + printf "\nPlease approve the update by selecting ${GRNct}'Toggle F/W Update Changelog Approval'${NOct}\n" + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + else + Say "Please run script interactively to approve the firmware update." + Say "To approve the update, select 'Toggle F/W Update Changelog Approval'" + fi return 1 else return 0 From 9e3dc73ebe2ffd158d1e2829d00c747aed37121a Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 31 May 2024 11:27:54 -0400 Subject: [PATCH 105/185] Update MerlinAU.sh --- MerlinAU.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a24a01fb..4e78016d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1746,7 +1746,7 @@ _GetCurrentFWInstalledLongVersion_() _GetCurrentFWInstalledShortVersion_() { ##FOR TESTING/DEBUG ONLY## -if false ; then echo "388.6.2" ; return 0 ; fi +if false ; then echo "388.6.0" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum @@ -4010,7 +4010,12 @@ _ChangelogVerificationCheck_() if "$isGNUtonFW" then - changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + if [ "$mode" = "auto" ] + then + changeLogFile="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + else + changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + fi else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # if echo "$release_version" | grep -q "386"; then @@ -4171,11 +4176,11 @@ _ManageChangelogGnuton_() FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" - wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + wgetLogFile="${FW_ZIP_DIR}/${ScriptFNameTag}.WGET.LOG" printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "$Gnuton_changelogurl" + -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "${Gnuton_changelogurl}" if [ ! -f "$FW_Changelog_GITHUB" ] then @@ -4196,7 +4201,6 @@ _ManageChangelogGnuton_() fi fi rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" - "$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr" return 1 } From e04e264e785c6f026cd468eb82e5f06e2e2e3cef Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 31 May 2024 13:08:57 -0400 Subject: [PATCH 106/185] Update MerlinAU.sh --- MerlinAU.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 4e78016d..55207632 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4010,12 +4010,7 @@ _ChangelogVerificationCheck_() if "$isGNUtonFW" then - if [ "$mode" = "auto" ] - then - changeLogFile="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" - else - changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - fi + changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" else # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # if echo "$release_version" | grep -q "386"; then @@ -4028,7 +4023,12 @@ _ChangelogVerificationCheck_() if [ ! -f "$changeLogFile" ] then - Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + if "$isGNUtonFW" + then + Say "Changelog file [${FW_BIN_DIR}/${FW_FileName}_Changelog.txt] does NOT exist." + else + Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + fi _DoCleanUp_ return 1 else @@ -4161,7 +4161,7 @@ _ManageChangelogGnuton_() local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB # Create directory to download changelog if missing - if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi + if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") @@ -4174,9 +4174,9 @@ _ManageChangelogGnuton_() # Sanitize filename by removing problematic characters local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - wgetLogFile="${FW_ZIP_DIR}/${ScriptFNameTag}.WGET.LOG" + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ From c5fc2da019c2ccdfb09d176cbd45bb0dff332328 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 2 Jun 2024 01:18:08 -0400 Subject: [PATCH 107/185] Update MerlinAU.sh --- MerlinAU.sh | 291 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 167 insertions(+), 124 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 55207632..9c5c3144 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-May-27 +# Last Modified: 2024-Jun-01 ################################################################### set -u -readonly SCRIPT_VERSION=1.1.6 +readonly SCRIPT_VERSION=1.2.1 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -23,12 +23,14 @@ readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" readonly FW_SFURL_RELEASE_SUFFIX="Release" readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.ng/releases/latest" -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-03] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## # Changelog Info # readonly CL_URL_NG="${FW_SFURL_BASE}/Documentation/Changelog-NG.txt/download" readonly CL_URL_386="${FW_SFURL_BASE}/Documentation/Changelog-386.txt/download" +readonly CL_URL_3006="${FW_SFURL_BASE}/Documentation/Changelog-3006.txt/download" + readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" # For new script version updates from source repository # @@ -88,12 +90,15 @@ else cronListCmd="crontab -l" fi ##----------------------------------------## -## Modified by Martinski W. [2024-Apr-06] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## inMenuMode=true isInteractive=false -mainLAN_IPaddr="$(nvram get lan_ipaddr)" +readonly mainLAN_IPaddr="$(nvram get lan_ipaddr)" +readonly fwInstalledBaseVers="$(nvram get firmver | sed 's/\.//g')" +readonly fwInstalledBuildVers="$(nvram get buildno)" +readonly fwInstalledExtendNum="$(nvram get extendno)" if [ "$(nvram get sw_mode)" -eq 1 ] then inRouterSWmode=true @@ -228,12 +233,18 @@ _DoExit_() _ReleaseLock_ ; exit "$exitCode" } -##----------------------------------------------## -## Added/Modified by Martinski W. [2023-Nov-18] ## -##----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## +## To support new "3006" F/W Basecode ## +if [ "$fwInstalledBaseVers" -ge 3006 ] +then readonly nvramLEDsVar=AllLED +else readonly nvramLEDsVar=led_disable +fi + # Save initial LEDs state to put it back later # -readonly LED_InitState="$(nvram get led_disable)" -LED_ToggleState="$LED_InitState" +readonly LEDsInitState="$(nvram get "$nvramLEDsVar")" +LEDsToggleState="$LEDsInitState" Toggle_LEDs_PID="" # To enable/disable the built-in "F/W Update Check" # @@ -263,12 +274,12 @@ _GetDefaultUSBMountPoint_() } ##----------------------------------------## -## Modified by Martinski W. [2023-Dec-22] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## # Background function to create a blinking LED effect # Toggle_LEDs() { - if [ -z "$LED_ToggleState" ] + if [ -z "$LEDsToggleState" ] then sleep 1 Toggle_LEDs_PID="" @@ -283,8 +294,8 @@ Toggle_LEDs() while true do - LED_ToggleState="$((! LED_ToggleState))" - nvram set led_disable="$LED_ToggleState" + LEDsToggleState="$((! LEDsToggleState))" + nvram set ${nvramLEDsVar}="$LEDsToggleState" /sbin/service restart_leds > /dev/null 2>&1 sleep "$blinkRateSecs" done @@ -292,7 +303,7 @@ Toggle_LEDs() } ##----------------------------------------## -## Modified by Martinski W. [2023-Dec-23] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _Reset_LEDs_() { @@ -311,7 +322,7 @@ _Reset_LEDs_() kill -TERM $Toggle_LEDs_PID wait $Toggle_LEDs_PID # Set LEDs to their "initial state" # - nvram set led_disable="$LED_InitState" + nvram set ${nvramLEDsVar}="$LEDsInitState" /sbin/service restart_leds >/dev/null 2>&1 sleep 2 fi @@ -396,7 +407,7 @@ _ScriptVersionStrToNum_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Feb-28] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _FWVersionStrToNum_() { @@ -406,7 +417,7 @@ _FWVersionStrToNum_() USE_BETA_WEIGHT="$(Get_Custom_Setting FW_Allow_Beta_Production_Up)" local verNum verStr="$1" nonProductionVersionWeight=0 - local fwBranchVers="" numFields + local fwBasecodeVers="" numOfFields #-------------------------------------------------------------- # Handle any 'alpha/beta' in the version string to be sure @@ -423,19 +434,19 @@ _FWVersionStrToNum_() verStr="$(echo "$verStr" | sed 's/[_-]\?[Aa]lpha.*// ; s/[_-]\?[Bb]eta.*//')" fi - numFields="$(echo "$verStr" | awk -F '.' '{print NF}')" + numOfFields="$(echo "$verStr" | awk -F '.' '{print NF}')" - if [ "$numFields" -lt "$2" ] - then fwBranchVers="$(nvram get firmver | sed 's/\.//g')" ; fi + if [ "$numOfFields" -lt "$2" ] + then fwBasecodeVers="$fwInstalledBaseVers" ; fi #----------------------------------------------------------- - # Temporarily remove Branch version to avoid issues with + # Temporarily remove Basecode version to avoid issues with # integers greater than the maximum 32-bit signed integer # when doing arithmetic computations with shell cmds. #----------------------------------------------------------- - if [ "$numFields" -gt 3 ] + if [ "$numOfFields" -gt 3 ] then - fwBranchVers="$(echo "$verStr" | cut -d'.' -f1)" + fwBasecodeVers="$(echo "$verStr" | cut -d'.' -f1)" verStr="$(echo "$verStr" | cut -d'.' -f2-)" fi verNum="$(echo "$verStr" | awk -F '.' '{printf ("%d%02d%02d\n", $1,$2,$3);}')" @@ -443,8 +454,8 @@ _FWVersionStrToNum_() # Subtract non-production weight from the version number # verNum="$((verNum + nonProductionVersionWeight))" - # Now prepend the F/W Branch version # - [ -n "$fwBranchVers" ] && verNum="${fwBranchVers}$verNum" + # Now prepend the F/W Basecode version # + [ -n "$fwBasecodeVers" ] && verNum="${fwBasecodeVers}$verNum" echo "$verNum" ; return 0 } @@ -1726,39 +1737,24 @@ _AddPostRebootRunScriptHook_() ##----------------------------------------## _GetCurrentFWInstalledLongVersion_() { - local theBranchVers theVersionStr extVersNum - theBranchVers="$(nvram get firmver | sed 's/\.//g')" +##FOR TESTING/DEBUG ONLY## +if true ; then echo "3004.388.6.2" ; return 0 ; fi +##FOR TESTING/DEBUG ONLY## - extVersNum="$(nvram get extendno)" + local theVersionStr extVersNum + + extVersNum="$fwInstalledExtendNum" echo "$extVersNum" | grep -qiE "^(alpha|beta)" && extVersNum="0_$extVersNum" [ -z "$extVersNum" ] && extVersNum=0 - theVersionStr="$(nvram get buildno).$extVersNum" - [ -n "$theBranchVers" ] && theVersionStr="${theBranchVers}.${theVersionStr}" + theVersionStr="${fwInstalledBuildVers}.$extVersNum" + [ -n "$fwInstalledBaseVers" ] && \ + theVersionStr="${fwInstalledBaseVers}.${theVersionStr}" echo "$theVersionStr" } -##----------------------------------------## -## Modified by Martinski W. [2024-Feb-28] ## -##----------------------------------------## -_GetCurrentFWInstalledShortVersion_() -{ -##FOR TESTING/DEBUG ONLY## -if false ; then echo "388.6.0" ; return 0 ; fi -##FOR TESTING/DEBUG ONLY## - - local theVersionStr extVersNum - - extVersNum="$(nvram get extendno | awk -F '-' '{print $1}')" - echo "$extVersNum" | grep -qiE "^(alpha|beta)" && extVersNum="0_$extVersNum" - [ -z "$extVersNum" ] && extVersNum=0 - - theVersionStr="$(nvram get buildno).$extVersNum" - echo "$theVersionStr" -} - ##----------------------------------------## ## Modified by Martinski W. [2024-Mar-31] ## ##----------------------------------------## @@ -2035,20 +2031,22 @@ check_memory_and_prompt_reboot() fi } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Apr-18] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## # Function to check if the current router model is supported -check_version_support() { - # Minimum supported firmware version - minimum_supported_version="386.12.0" +check_version_support() +{ + local numOfFields current_version numCurrentVers numMinimumVers - # Get the current firmware version - local current_version="$(_GetCurrentFWInstalledShortVersion_)" + # Minimum supported firmware version # + minimum_supported_version="3004.386.12.0" - local numFields="$(echo "$current_version" | awk -F '.' '{print NF}')" - local numCurrentVers="$(_FWVersionStrToNum_ "$current_version" "$numFields")" - local numMinimumVers="$(_FWVersionStrToNum_ "$minimum_supported_version" "$numFields")" + current_version="$(_GetCurrentFWInstalledLongVersion_)" + + numOfFields="$(echo "$current_version" | awk -F '.' '{print NF}')" + numCurrentVers="$(_FWVersionStrToNum_ "$current_version" "$numOfFields")" + numMinimumVers="$(_FWVersionStrToNum_ "$minimum_supported_version" "$numOfFields")" # If the current firmware version is lower than the minimum supported firmware version, exit. if [ "$numCurrentVers" -lt "$numMinimumVers" ] @@ -3928,9 +3926,9 @@ _Set_FW_UpdateCronSchedule_() return "$retCode" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-26] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## _high_risk_phrases_interactive_() { local changelog_contents="$1" @@ -3938,7 +3936,14 @@ _high_risk_phrases_interactive_() if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" then ChangelogApproval="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")" - if [ "$ChangelogApproval" = "BLOCKED" ] + + if [ "$ChangelogApproval" = "APPROVED" ] + then + Say "Changelog review is pre-approved!" + # + elif [ -z "$ChangelogApproval" ] || \ + [ "$ChangelogApproval" = "TBD" ] || \ + [ "$ChangelogApproval" = "BLOCKED" ] then if [ "$inMenuMode" = true ] then @@ -3947,6 +3952,7 @@ _high_risk_phrases_interactive_() if ! _WaitForYESorNO_ then Say "Exiting for changelog review." + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" _DoCleanUp_ 1 return 1 else @@ -3955,12 +3961,11 @@ _high_risk_phrases_interactive_() else Say "*WARNING*: Found high-risk phrases in the changelog file." Say "Please run script interactively to approve the firmware update." + Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL _DoCleanUp_ 1 _DoExit_ 1 fi - else - Say "Changelog review is pre-approved!" fi else Say "No high-risk phrases found in the changelog file." @@ -3971,7 +3976,8 @@ _high_risk_phrases_interactive_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-26] ## ##------------------------------------------## -_high_risk_phrases_nointeractive_() { +_high_risk_phrases_nointeractive_() +{ local changelog_contents="$1" if echo "$changelog_contents" | grep -Eiq "$high_risk_terms" @@ -3979,7 +3985,7 @@ _high_risk_phrases_nointeractive_() { _SendEMailNotification_ STOP_FW_UPDATE_APPROVAL Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED" if [ "$inMenuMode" = true ] - then + then printf "\n${REDct}*WARNING*${NOct}: Found high-risk phrases in the changelog file." printf "\nPlease approve the update by selecting ${GRNct}'Toggle F/W Update Changelog Approval'${NOct}\n" _WaitForEnterKey_ "$mainMenuReturnPromptStr" @@ -3998,22 +4004,26 @@ _high_risk_phrases_nointeractive_() { ##------------------------------------------## _ChangelogVerificationCheck_() { - local mode="$1" # Mode should be 'auto' or 'interactive' - local formatted_current_version - local formatted_release_version + local mode="$1" # Mode should be 'auto' or 'interactive' # + local current_version formatted_current_version + local release_version formatted_release_version local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")" if [ "$checkChangeLogSetting" = "ENABLED" ] then - local current_version="$(_GetCurrentFWInstalledShortVersion_)" + local current_version="$(_GetCurrentFWInstalledLongVersion_)" local release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" if "$isGNUtonFW" then changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" else - # Get the correct Changelog filename (Changelog-[386|NG].txt) based on the "build number" # - if echo "$release_version" | grep -q "386"; then + # Get the correct Changelog filename: "Changelog-[3006|386|NG].txt" # + if echo "$release_version" | grep -qE "^3006[.]" + then + changeLogTag="3006" + elif echo "$release_version" | grep -q "386[.]" + then changeLogTag="386" else changeLogTag="NG" @@ -4107,19 +4117,45 @@ _ChangelogVerificationCheck_() ##------------------------------------------## _ManageChangelogMerlin_() { - local mode="$1" # Mode should be 'download' or 'view' - local wgetLogFile changeLogTag changeLogFile changeLogURL + if [ $# -eq 0 ] || [ -z "$1" ] + then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi + + local mode="$1" # Mode should be 'download' or 'view' # + local newUpdateVerStr="" + local wgetLogFile changeLogFile changeLogTag changeLogURL # Create directory to download changelog if missing if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi - changeLogTag="$(echo "$(nvram get buildno)" | grep -qE "^386[.]" && echo "386" || echo "NG")" - if [ "$changeLogTag" = "386" ] + if [ "$mode" = "view" ] then - changeLogURL="${CL_URL_386}" - elif [ "$changeLogTag" = "NG" ] + if [ "$fwInstalledBaseVers" -eq 3006 ] + then + changeLogTag="3006" + changeLogURL="${CL_URL_3006}" + elif echo "$fwInstalledBuildVers" | grep -qE "^386[.]" + then + changeLogTag="386" + changeLogURL="${CL_URL_386}" + else + changeLogTag="NG" + changeLogURL="${CL_URL_NG}" + fi + elif [ "$mode" = "download" ] then - changeLogURL="${CL_URL_NG}" + [ $# -gt 1 ] && [ -n "$2" ] && newUpdateVerStr="$2" + if echo "$newUpdateVerStr" | grep -qE "^3006[.]" + then + changeLogTag="3006" + changeLogURL="${CL_URL_3006}" + elif echo "$newUpdateVerStr" | grep -q "386[.]" + then + changeLogTag="386" + changeLogURL="${CL_URL_386}" + else + changeLogTag="NG" + changeLogURL="${CL_URL_NG}" + fi fi wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" @@ -4157,8 +4193,12 @@ _ManageChangelogMerlin_() _ManageChangelogGnuton_() { - local mode="$1" # Mode should be 'download' or 'view' - local wgetLogFile Gnuton_changelogurl FW_Changelog_GITHUB + if [ $# -eq 0 ] || [ -z "$1" ] + then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi + + local mode="$1" # Mode should be 'download' or 'view' # + local newUpdateVerStr="" + local wgetLogFile changeLogFile changeLogTag changeLogURL # Create directory to download changelog if missing if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi @@ -4205,22 +4245,23 @@ _ManageChangelogGnuton_() } ##----------------------------------------## -## Modified by Martinski W. [2024-May-18] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _CheckNewUpdateFirmwareNotification_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local numVersionFields fwNewUpdateVersNum + local numOfFields fwNewUpdateVersNum + local currentVersionStr="$1" releaseVersionStr="$2" - numVersionFields="$(echo "$2" | awk -F '.' '{print NF}')" - currentVersionNum="$(_FWVersionStrToNum_ "$1" "$numVersionFields")" - releaseVersionNum="$(_FWVersionStrToNum_ "$2" "$numVersionFields")" + numOfFields="$(echo "$currentVersionStr" | awk -F '.' '{print NF}')" + currentVersionNum="$(_FWVersionStrToNum_ "$currentVersionStr" "$numOfFields")" + releaseVersionNum="$(_FWVersionStrToNum_ "$releaseVersionStr" "$numOfFields")" if [ "$currentVersionNum" -ge "$releaseVersionNum" ] then - Say "Current firmware version '$1' is up to date." + Say "Current firmware version '${currentVersionStr}' is up to date." Update_Custom_Settings FW_New_Update_Notification_Date TBD Update_Custom_Settings FW_New_Update_Notification_Vers TBD Update_Custom_Settings FW_New_Update_Changelog_Approval TBD @@ -4230,14 +4271,14 @@ _CheckNewUpdateFirmwareNotification_() fwNewUpdateNotificationVers="$(Get_Custom_Setting FW_New_Update_Notification_Vers TBD)" if [ -z "$fwNewUpdateNotificationVers" ] || [ "$fwNewUpdateNotificationVers" = "TBD" ] then - fwNewUpdateNotificationVers="$2" + fwNewUpdateNotificationVers="$releaseVersionStr" Update_Custom_Settings FW_New_Update_Notification_Vers "$fwNewUpdateNotificationVers" else - numVersionFields="$(echo "$fwNewUpdateNotificationVers" | awk -F '.' '{print NF}')" - fwNewUpdateVersNum="$(_FWVersionStrToNum_ "$fwNewUpdateNotificationVers" "$numVersionFields")" + numOfFields="$(echo "$fwNewUpdateNotificationVers" | awk -F '.' '{print NF}')" + fwNewUpdateVersNum="$(_FWVersionStrToNum_ "$fwNewUpdateNotificationVers" "$numOfFields")" if [ "$releaseVersionNum" -gt "$fwNewUpdateVersNum" ] then - fwNewUpdateNotificationVers="$2" + fwNewUpdateNotificationVers="$releaseVersionStr" fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Vers "$fwNewUpdateNotificationVers" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" @@ -4247,9 +4288,9 @@ _CheckNewUpdateFirmwareNotification_() fi if "$isGNUtonFW" then - _ManageChangelogGnuton_ "download" + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" else - _ManageChangelogMerlin_ "download" + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" fi fi fi @@ -4265,9 +4306,9 @@ _CheckNewUpdateFirmwareNotification_() fi if "$isGNUtonFW" then - _ManageChangelogGnuton_ "download" + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" else - _ManageChangelogMerlin_ "download" + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" fi fi @@ -4284,18 +4325,19 @@ _CheckNewUpdateFirmwareNotification_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Apr-30] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _CheckNodeFWUpdateNotification_() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - local nodenumVersionFields nodefwNewUpdateVersNum + local nodeNumOfFields nodefwNewUpdateVersNum + local currentVersionStr="$1" releaseVersionStr="$2" - nodenumVersionFields="$(echo "$2" | awk -F '.' '{print NF}')" - nodecurrentVersionNum="$(_FWVersionStrToNum_ "$1" "$nodenumVersionFields")" - nodereleaseVersionNum="$(_FWVersionStrToNum_ "$2" "$nodenumVersionFields")" + nodeNumOfFields="$(echo "$currentVersionStr" | awk -F '.' '{print NF}')" + nodecurrentVersionNum="$(_FWVersionStrToNum_ "$currentVersionStr" "$nodeNumOfFields")" + nodereleaseVersionNum="$(_FWVersionStrToNum_ "$releaseVersionStr" "$nodeNumOfFields")" if [ "$nodecurrentVersionNum" -ge "$nodereleaseVersionNum" ] then @@ -4306,14 +4348,14 @@ _CheckNodeFWUpdateNotification_() nodefwNewUpdateNotificationVers="$(_GetAllNodeSettings_ "$node_label_mac" "New_Notification_Vers")" if [ -z "$nodefwNewUpdateNotificationVers" ] || [ "$nodefwNewUpdateNotificationVers" = "TBD" ] then - nodefwNewUpdateNotificationVers="$2" + nodefwNewUpdateNotificationVers="$releaseVersionStr" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "TBD" "$nodefwNewUpdateNotificationVers" "$uid" else - nodenumVersionFields="$(echo "$nodefwNewUpdateNotificationVers" | awk -F '.' '{print NF}')" - nodefwNewUpdateVersNum="$(_FWVersionStrToNum_ "$nodefwNewUpdateNotificationVers" "$nodenumVersionFields")" + nodeNumOfFields="$(echo "$nodefwNewUpdateNotificationVers" | awk -F '.' '{print NF}')" + nodefwNewUpdateVersNum="$(_FWVersionStrToNum_ "$nodefwNewUpdateNotificationVers" "$nodeNumOfFields")" if [ "$nodereleaseVersionNum" -gt "$nodefwNewUpdateVersNum" ] then - nodefwNewUpdateNotificationVers="$2" + nodefwNewUpdateNotificationVers="$releaseVersionStr" nodefwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" @@ -4617,7 +4659,7 @@ Please manually update to version $minimum_supported_version or higher to use th ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi # Get current firmware version # - current_version="$(_GetCurrentFWInstalledShortVersion_)" + current_version="$(_GetCurrentFWInstalledLongVersion_)" #---------------------------------------------------------# # If the "F/W Update Check" in the WebGUI is disabled @@ -5606,9 +5648,8 @@ then FW_RouterModelID="${FW_RouterProductID}" else FW_RouterModelID="${FW_RouterProductID}/${GRNct}${MODEL_ID}${NOct}" fi -FW_InstalledVers="$(_GetCurrentFWInstalledShortVersion_)" -FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" -FW_InstalledVersion="${GRNct}$(_GetCurrentFWInstalledLongVersion_)${NOct}" +FW_InstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" +FW_InstalledVerStr="${GRNct}${FW_InstalledVersion}${NOct}" ##-------------------------------------## ## Added by Martinski W. [2024-May-03] ## @@ -5898,18 +5939,20 @@ _InvalidMenuSelection_() _WaitForEnterKey_ } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## _ShowMainMenu_() { + local FW_NewUpdateVerStr FW_NewUpdateVersion + #-----------------------------------------------------------# # Check if router reports a new F/W update is available. # If yes, modify the notification settings accordingly. #-----------------------------------------------------------# - FW_NewUpdateVers="$(_GetLatestFWUpdateVersionFromRouter_)" && \ - [ -n "$FW_InstalledVers" ] && [ -n "$FW_NewUpdateVers" ] && \ - _CheckNewUpdateFirmwareNotification_ "$FW_InstalledVers" "$FW_NewUpdateVers" + FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_)" && \ + [ -n "$FW_InstalledVersion" ] && [ -n "$FW_NewUpdateVersion" ] && \ + _CheckNewUpdateFirmwareNotification_ "$FW_InstalledVersion" "$FW_NewUpdateVersion" clear logo @@ -5955,15 +5998,15 @@ _ShowMainMenu_() printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] then - if ! FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - then FW_NewUpdateVersion="${REDct}NONE FOUND${NOct}" - else FW_NewUpdateVersion="${GRNct}${FW_NewUpdateVersion}${NOct}$arrowStr" + if ! FW_NewUpdateVerStr="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + then FW_NewUpdateVerStr="${REDct}NONE FOUND${NOct}" + else FW_NewUpdateVerStr="${GRNct}${FW_NewUpdateVerStr}${NOct}$arrowStr" fi printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide" printf "\n USB-Attached Storage Connected: $USBConnected" - printf "\n F/W Version Currently Installed: $FW_InstalledVersion" + printf "\n F/W Version Currently Installed: $FW_InstalledVerStr" printf "\n F/W Variant Configuration Found: $FirmwareFlavor" - printf "\n F/W Update Version Available: $FW_NewUpdateVersion" + printf "\n F/W Update Version Available: $FW_NewUpdateVerStr" printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" else printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(S)how" From bdc679d42ea98c46d183d8b9d01c590656eeb747 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 2 Jun 2024 01:22:58 -0400 Subject: [PATCH 108/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9c5c3144..df534bee 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4011,8 +4011,8 @@ _ChangelogVerificationCheck_() if [ "$checkChangeLogSetting" = "ENABLED" ] then - local current_version="$(_GetCurrentFWInstalledLongVersion_)" - local release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" + current_version="$(_GetCurrentFWInstalledLongVersion_)" + release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" if "$isGNUtonFW" then From 3eb05553e6849844b201080e1f793365544ea981 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 2 Jun 2024 01:28:24 -0400 Subject: [PATCH 109/185] Update MerlinAU.sh --- MerlinAU.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 6a5febc2..a263ef20 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1733,13 +1733,13 @@ _AddPostRebootRunScriptHook_() } ##----------------------------------------## -## Modified by Martinski W. [2024-May-31] ## +## Modified by Martinski W. [2024-Feb-28] ## ##----------------------------------------## _GetCurrentFWInstalledLongVersion_() { ##FOR TESTING/DEBUG ONLY## -if true ; then echo "3004.388.6.2" ; return 0 ; fi +if false ; then echo "3004.388.6.2" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum @@ -2479,8 +2479,8 @@ _GetNodeInfo_() node_lan_hostname="$(echo "$htmlContent" | grep -o '"lan_hostname":"[^"]*' | sed 's/"lan_hostname":"//')" node_label_mac="$(echo "$htmlContent" | grep -o '"label_mac":"[^"]*' | sed 's/"label_mac":"//')" - # Combine extracted information into one string # - Node_combinedVer="${node_firmver}.${node_buildno}.$node_extendno" + # Combine extracted information into one string + Node_combinedVer="$node_firmver.$node_buildno.$node_extendno" # Perform logout request curl -s -k "${NodeURLstr}/Logout.asp" \ @@ -3999,9 +3999,9 @@ _high_risk_phrases_nointeractive_() fi } -##----------------------------------------## -## Modified by Martinski W. [2024-May-31] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-26] ## +##------------------------------------------## _ChangelogVerificationCheck_() { local mode="$1" # Mode should be 'auto' or 'interactive' # From 55dd030ef91183a56c6ea11abe798c763915471e Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 2 Jun 2024 01:31:32 -0400 Subject: [PATCH 110/185] Update MerlinAU.sh --- MerlinAU.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a263ef20..b16e9544 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1733,7 +1733,7 @@ _AddPostRebootRunScriptHook_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Feb-28] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _GetCurrentFWInstalledLongVersion_() { @@ -2479,8 +2479,8 @@ _GetNodeInfo_() node_lan_hostname="$(echo "$htmlContent" | grep -o '"lan_hostname":"[^"]*' | sed 's/"lan_hostname":"//')" node_label_mac="$(echo "$htmlContent" | grep -o '"label_mac":"[^"]*' | sed 's/"label_mac":"//')" - # Combine extracted information into one string - Node_combinedVer="$node_firmver.$node_buildno.$node_extendno" + # Combine extracted information into one string # + Node_combinedVer="${node_firmver}.${node_buildno}.$node_extendno" # Perform logout request curl -s -k "${NodeURLstr}/Logout.asp" \ @@ -3999,9 +3999,9 @@ _high_risk_phrases_nointeractive_() fi } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-26] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-May-31] ## +##----------------------------------------## _ChangelogVerificationCheck_() { local mode="$1" # Mode should be 'auto' or 'interactive' # From 49fb303ee077f0cb65e371402498bf98fe4b66aa Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 3 Jun 2024 23:45:17 -0400 Subject: [PATCH 111/185] Update MerlinAU.sh --- MerlinAU.sh | 208 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 78 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index b16e9544..19ab7438 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-01 +# Last Modified: 2024-Jun-03 ################################################################### set -u -readonly SCRIPT_VERSION=1.2.1 +readonly SCRIPT_VERSION=1.3.0 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -406,6 +406,31 @@ _ScriptVersionStrToNum_() echo "$verNum" ; return 0 } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_GetFirmwareVariantFromRouter_() +{ + local retCode=0 newVersionStr + + buildInfoStr="$(nvram get buildinfo)" + + ##FOR TESTING/DEBUG ONLY## + if false # Change to true for forcing GNUton flag + then + isGNUtonFW=true + else + # Check if the version string contains "gnuton" + if echo "$buildInfoStr" | grep -iq "merlin"; then + isGNUtonFW=false + else + isGNUtonFW=true + fi + fi + + echo "$isGNUtonFW" ; return "$retCode" +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## @@ -510,6 +535,7 @@ readonly PRODUCT_ID="$(_GetRouterProductID_)" ##FOR TESTING/DEBUG ONLY## readonly FW_FileName="${PRODUCT_ID}_firmware" readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" +readonly isGNUtonFW=$(_GetFirmwareVariantFromRouter_) ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-21] ## @@ -1133,6 +1159,21 @@ _Set_FW_UpdateZIP_DirectoryPath_() _Init_Custom_Settings_Config_ +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jun-03] ## +##------------------------------------------## +# NOTE: +# ROG upgrades to 3006 codebase should have +# the ROG option deleted. +#----------------------------------------------------------- +if ! "$isGNUtonFW" +then + if [ "$fwInstalledBaseVers" -ge 3006 ] && grep -q "^ROGBuild" "$SETTINGSFILE" + then + Delete_Custom_Settings "ROGBuild" + fi +fi + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jan-27] ## ##------------------------------------------## @@ -1253,31 +1294,6 @@ _GetLatestFWUpdateVersionFromRouter_() echo "$newVersionStr" ; return "$retCode" } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_GetFirmwareVariantFromRouter_() -{ - local retCode=0 newVersionStr - - buildInfoStr="$(nvram get buildinfo)" - - ##FOR TESTING/DEBUG ONLY## - if false # Change to true for forcing GNUton flag - then - isGNUtonFW=true - else - # Check if the version string contains "gnuton" - if echo "$buildInfoStr" | grep -iq "merlin"; then - isGNUtonFW=false - else - isGNUtonFW=true - fi - fi - - echo "$isGNUtonFW" ; return "$retCode" -} - ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-03] ## ##------------------------------------------## @@ -4948,47 +4964,72 @@ Please manually update to version $minimum_supported_version or higher to use th 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" - rog_file="" - # Detect ROG and pure firmware files - rog_file="$(ls | grep -i '_rog_')" - pure_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Jun-03] ## + ##------------------------------------------## + if [ "$fwInstalledBaseVers" -le 3004 ] + then + # Handle upgrades from 3004 and lower + pure_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" - # Fetch the previous choice from the settings file - previous_choice="$(Get_Custom_Setting "ROGBuild")" + # Detect ROG and pure firmware files + rog_file="" + rog_file="$(ls | grep -i '_rog_')" - # Check if a ROG build is present - if [ -n "$rog_file" ]; then - # Use the previous choice if it exists and valid, else prompt the user for their choice in interactive mode - if [ "$previous_choice" = "y" ]; then - Say "ROG Build selected for flashing" - firmware_file="$rog_file" - elif [ "$previous_choice" = "n" ]; then - Say "Pure Build selected for flashing" - firmware_file="$pure_file" - elif [ "$inMenuMode" = true ]; then - printf "${REDct}Found ROG build: $rog_file.${NOct}\n" - printf "${REDct}Would you like to use the ROG build?${NOct}\n" - printf "Enter your choice (y/n): " - read -r choice - if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + # Fetch the previous choice from the settings file + previous_choice="$(Get_Custom_Setting "ROGBuild")" + + # Check if a ROG build is present + if [ -n "$rog_file" ]; then + # Use the previous choice if it exists and valid, else prompt the user for their choice in interactive mode + if [ "$previous_choice" = "y" ]; then Say "ROG Build selected for flashing" firmware_file="$rog_file" - Update_Custom_Settings "ROGBuild" "y" - else + elif [ "$previous_choice" = "n" ]; then Say "Pure Build selected for flashing" firmware_file="$pure_file" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found ROG build: $rog_file.${NOct}\n" + printf "${REDct}Would you like to use the ROG build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + Say "ROG Build selected for flashing" + firmware_file="$rog_file" + Update_Custom_Settings "ROGBuild" "y" + else + Say "Pure Build selected for flashing" + firmware_file="$pure_file" + Update_Custom_Settings "ROGBuild" "n" + fi + else + # Default to pure_file in non-interactive mode if no previous choice + Say "Pure Build selected for flashing" Update_Custom_Settings "ROGBuild" "n" + firmware_file="$pure_file" fi else - # Default to pure_file in non-interactive mode if no previous choice - Say "Pure Build selected for flashing" - Update_Custom_Settings "ROGBuild" "n" + # No ROG build found, use the pure build + Say "No ROG Build detected. Skipping." firmware_file="$pure_file" fi + elif [ "$fwInstalledBaseVers" -eq 3004 ] && [ "$firstOctet" -ge 3006 ] + then + # Handle upgrade from 3004 to 3006 + # Fetch the previous choice from the settings file + previous_choice="$(Get_Custom_Setting "ROGBuild")" + + # Handle upgrade from 3004 to 3006 if there is a ROG setting + if [ "$previous_choice" = "y" ]; then + Say "Upgrading from 3004 to 3006, ROG UI is no longer supported, auto-selecting Pure UI firmware." + firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + Update_Custom_Settings "ROGBuild" "n" + else + firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + fi else - # No ROG build found, use the pure build - Say "No ROG Build detected. Skipping." - firmware_file="$pure_file" + # Handle upgrades from 3006 and higher + firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" fi ##------------------------------------------## @@ -5551,7 +5592,6 @@ fi # it has the minimum firmware version supported. check_model_support check_version_support -isGNUtonFW=$(_GetFirmwareVariantFromRouter_) ##-------------------------------------## ## Added by Martinski W. [2024-Jan-24] ## @@ -6125,27 +6165,39 @@ _ShowAdvancedOptionsMenu_() else current_build_type_menu="NOT SET" fi - else - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "ROGBuild")" - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="ROG Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" - else - current_build_type_menu="NOT SET" + if echo "$PRODUCT_ID" | grep -q "^TUF-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + fi fi - fi + else + if [ "$fwInstalledBaseVers" -le 3004 ] + then + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="ROG Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi - if echo "$PRODUCT_ID" | grep -q "^GT-" || echo "$PRODUCT_ID" | grep -q "^TUF-" - then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menu" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" - fi + if echo "$PRODUCT_ID" | grep -q "^GT-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + fi + fi + fi fi # Additional Email Notification Options # @@ -6319,10 +6371,10 @@ _advanced_options_menu_() else _InvalidMenuSelection_ fi ;; - bt) if echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_Merlin_ - elif echo "$PRODUCT_ID" | grep -q "^TUF-" + bt) if echo "$PRODUCT_ID" | grep -q "^TUF-" then _ChangeBuildType_Gnuton_ + elif [ "$fwInstalledBaseVers" -le 3004 ] || echo "$PRODUCT_ID" | grep -q "^GT-" + then _ChangeBuildType_Merlin_ else _InvalidMenuSelection_ fi ;; From 40acb7f330834d211cb6dfeba9ad38c0a19d472e Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 4 Jun 2024 07:44:39 -0400 Subject: [PATCH 112/185] Update MerlinAU.sh --- MerlinAU.sh | 63 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 19ab7438..84a08555 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1001,6 +1001,19 @@ Update_Custom_Settings() esac } +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-04] ## +##----------------------------------------## +Delete_Custom_Settings() +{ + if [ $# -lt 1 ] || [ -z "$1" ] || [ ! -f "$SETTINGSFILE" ] + then return 1 ; fi + + local setting_type="$1" + sed -i "/^${setting_type}[ =]/d" "$SETTINGSFILE" + return $? +} + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jan-24] ## ##------------------------------------------## @@ -4767,10 +4780,10 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi - # Extracting the first octet to use in the curl - firstOctet="$(echo "$release_version" | cut -d'.' -f1)" + # Extracting the F/W Update codebase number to use in the curl # + fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)" # Inserting dots between each number - dottedVersion="$(echo "$firstOctet" | sed 's/./&./g' | sed 's/.$//')" + dottedVersion="$(echo "$fwUpdateBaseNum" | sed 's/./&./g' | sed 's/.$//')" if ! _CheckTimeToUpdateFirmware_ "$current_version" "$release_version" then @@ -4964,31 +4977,35 @@ Please manually update to version $minimum_supported_version or higher to use th 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" - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Jun-03] ## - ##------------------------------------------## - if [ "$fwInstalledBaseVers" -le 3004 ] + ##----------------------------------------## + ## Modified by Martinski W. [2024-Jun-04] ## + ##----------------------------------------## + pure_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + + if [ "$fwInstalledBaseVers" -le 3004 ] && [ "$fwUpdateBaseNum" -le 3004 ] then - # Handle upgrades from 3004 and lower - pure_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + # Handle upgrades from 3004 and lower # - # Detect ROG and pure firmware files - rog_file="" + # Detect ROG firmware file # rog_file="$(ls | grep -i '_rog_')" # Fetch the previous choice from the settings file previous_choice="$(Get_Custom_Setting "ROGBuild")" # Check if a ROG build is present - if [ -n "$rog_file" ]; then + if [ -n "$rog_file" ] + then # Use the previous choice if it exists and valid, else prompt the user for their choice in interactive mode - if [ "$previous_choice" = "y" ]; then + if [ "$previous_choice" = "y" ] + then Say "ROG Build selected for flashing" firmware_file="$rog_file" - elif [ "$previous_choice" = "n" ]; then + elif [ "$previous_choice" = "n" ] + then Say "Pure Build selected for flashing" firmware_file="$pure_file" - elif [ "$inMenuMode" = true ]; then + elif [ "$inMenuMode" = true ] + then printf "${REDct}Found ROG build: $rog_file.${NOct}\n" printf "${REDct}Would you like to use the ROG build?${NOct}\n" printf "Enter your choice (y/n): " @@ -5013,23 +5030,24 @@ Please manually update to version $minimum_supported_version or higher to use th Say "No ROG Build detected. Skipping." firmware_file="$pure_file" fi - elif [ "$fwInstalledBaseVers" -eq 3004 ] && [ "$firstOctet" -ge 3006 ] + elif [ "$fwInstalledBaseVers" -eq 3004 ] && [ "$fwUpdateBaseNum" -ge 3006 ] then # Handle upgrade from 3004 to 3006 # Fetch the previous choice from the settings file previous_choice="$(Get_Custom_Setting "ROGBuild")" # Handle upgrade from 3004 to 3006 if there is a ROG setting - if [ "$previous_choice" = "y" ]; then + if [ "$previous_choice" = "y" ] + then Say "Upgrading from 3004 to 3006, ROG UI is no longer supported, auto-selecting Pure UI firmware." - firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + firmware_file="$pure_file" Update_Custom_Settings "ROGBuild" "n" else - firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + firmware_file="$pure_file" fi else - # Handle upgrades from 3006 and higher - firmware_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')" + # Handle upgrades from 3006 and higher # + firmware_file="$pure_file" fi ##------------------------------------------## @@ -6373,7 +6391,8 @@ _advanced_options_menu_() ;; bt) if echo "$PRODUCT_ID" | grep -q "^TUF-" then _ChangeBuildType_Gnuton_ - elif [ "$fwInstalledBaseVers" -le 3004 ] || echo "$PRODUCT_ID" | grep -q "^GT-" + elif [ "$fwInstalledBaseVers" -le 3004 ] && \ + echo "$PRODUCT_ID" | grep -q "^GT-" then _ChangeBuildType_Merlin_ else _InvalidMenuSelection_ fi From 535dbcd41fcbea30f262521555b239f37a010da5 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 8 Jun 2024 04:52:30 -0400 Subject: [PATCH 113/185] Update MerlinAU.sh --- MerlinAU.sh | 128 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 48 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9f171e2f..88f4e255 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-03 +# Last Modified: 2024-Jun-05 ################################################################### set -u @@ -34,8 +34,8 @@ readonly CL_URL_3006="${FW_SFURL_BASE}/Documentation/Changelog-3006.txt/download readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" # For new script version updates from source repository # -UpdateNotify=0 DLRepoVersion="" +scriptUpdateNotify=0 # For supported version and model checks # MinFirmwareCheckFailed=0 @@ -55,10 +55,10 @@ readonly SETTINGSFILE="${SETTINGS_DIR}/custom_settings.txt" readonly SCRIPTVERPATH="${SETTINGS_DIR}/version.txt" ##----------------------------------------## -## Modified by Martinski W. [2024-May-01] ## +## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## ScriptsDirPath="$SCRIPTS_PATH" -ScriptFilePath="${SCRIPTS_PATH}/$ScriptFileName" +ScriptFilePath="${SCRIPTS_PATH}/${SCRIPT_NAME}.sh" if [ ! -f "$ScriptFilePath" ] then @@ -397,7 +397,7 @@ _GetRouterProductID_() ##-------------------------------------## _ScriptVersionStrToNum_() { - if [ $# -eq 0 ] || [ -z "$1" ] ; then echo ; return 1 ; fi + if [ $# -eq 0 ] || [ -z "$1" ] ; then echo 0 ; return 1 ; fi local verNum verStr verStr="$(echo "$1" | awk -F '_' '{print $1}')" @@ -551,21 +551,30 @@ logo() { echo -e "${NOct}" } -##-----------------------------------------------## -## Modified by: ExtremeFiretop [2023-Dec-16] ## -##-----------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-05] ## +##----------------------------------------## _CheckForNewScriptUpdates_() { local DLRepoVersionNum ScriptVersionNum echo "" + [ -s "$SCRIPTVERPATH" ] && DLRepoVersion="$(cat "$SCRIPTVERPATH")" + rm -f "$SCRIPTVERPATH" + # Download the latest version file from the source repository - curl --silent --retry 3 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" - if [ ! -f "$SCRIPTVERPATH" ] ; then UpdateNotify=0 ; return 1 ; fi + if [ $? -ne 0 ] || [ ! -s "$SCRIPTVERPATH" ] + then scriptUpdateNotify=0 ; return 1 ; fi # Read in its contents for the current version file DLRepoVersion="$(cat "$SCRIPTVERPATH")" + if [ -z "$DLRepoVersion" ]; then + echo "Variable for downloaded version is empty." + scriptUpdateNotify=0 + return 1 + fi DLRepoVersionNum="$(_ScriptVersionStrToNum_ "$DLRepoVersion")" ScriptVersionNum="$(_ScriptVersionStrToNum_ "$SCRIPT_VERSION")" @@ -573,21 +582,23 @@ _CheckForNewScriptUpdates_() # Version comparison if [ "$DLRepoVersionNum" -gt "$ScriptVersionNum" ] then - UpdateNotify="New script update available. + scriptUpdateNotify="New script update available. ${REDct}v$SCRIPT_VERSION${NOct} --> ${GRNct}v$DLRepoVersion${NOct}" Say "$(date +'%b %d %Y %X') $(nvram get lan_hostname) ${ScriptFNameTag}_[$$] - INFO: A new script update (v$DLRepoVersion) is available to download." else - UpdateNotify=0 + scriptUpdateNotify=0 fi } + ##----------------------------------------## -## Modified by Martinski W. [2023-Dec-17] ## +## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## #a function that provides a UI to check for script updates and allows you to install the latest version... _SCRIPTUPDATE_() { - # Check for the latest version from source repository + local ScriptFileDL="${ScriptFilePath}.DL" + _CheckForNewScriptUpdates_ clear logo @@ -597,19 +608,31 @@ _SCRIPTUPDATE_() echo -e "${CYANct}Current Version: ${YLWct}${SCRIPT_VERSION}${NOct}" echo -e "${CYANct}Updated Version: ${YLWct}${DLRepoVersion}${NOct}" echo + if [ "$SCRIPT_VERSION" = "$DLRepoVersion" ] then echo -e "${CYANct}You are on the latest version! Would you like to download anyways?${NOct}" echo -e "${CYANct}This will overwrite your currently installed version.${NOct}" - if _WaitForYESorNO_ ; then + if _WaitForYESorNO_ + then echo ; echo echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v$DLRepoVersion${NOct}" - curl --silent --retry 3 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" - curl --silent --retry 3 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "${ScriptsDirPath}/${SCRIPT_NAME}.sh" && chmod +x "${ScriptsDirPath}/${SCRIPT_NAME}.sh" - echo - echo -e "${CYANct}Download successful!${NOct}" - echo -e "$(date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion" - echo + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "$ScriptFileDL" + + if [ $? -eq 0 ] && [ -s "$ScriptFileDL" ] + then + mv -f "$ScriptFileDL" "$ScriptFilePath" + chmod 755 "$ScriptFilePath" + echo + echo -e "${CYANct}Download successful!${NOct}" + echo -e "$(date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion" + echo + else + rm -f "$ScriptFileDL" + echo + echo -e "${REDct}Download failed.${NOct}" + fi _WaitForEnterKey_ return else @@ -618,26 +641,30 @@ _SCRIPTUPDATE_() sleep 1 return fi - elif [ "$UpdateNotify" != "0" ] + elif [ "$scriptUpdateNotify" != "0" ] then echo -e "${CYANct}Bingo! New version available! Would you like to update now?${NOct}" - if _WaitForYESorNO_ ; then + if _WaitForYESorNO_ + then echo ; echo echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v$DLRepoVersion${NOct}" - curl --silent --retry 3 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" - curl --silent --retry 3 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "${ScriptsDirPath}/${SCRIPT_NAME}.sh" - if [ $? -eq 0 ]; then - chmod a+x "${ScriptsDirPath}/${SCRIPT_NAME}.sh" + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "$ScriptFileDL" + + if [ $? -eq 0 ] && [ -s "$ScriptFileDL" ] + then + mv -f "$ScriptFileDL" "$ScriptFilePath" + chmod 755 "$ScriptFilePath" echo echo -e "$(date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion" echo -e "${CYANct}Update successful! Restarting script...${NOct}" _ReleaseLock_ - exec "${ScriptsDirPath}/${SCRIPT_NAME}.sh" # Re-execute the updated script - exit 0 # This line will not be executed as exec replaces the current process + exec "$ScriptFilePath" # Re-execute the updated script # + exit 0 # This line will not be executed due to above exec # else + rm -f "$ScriptFileDL" echo echo -e "${REDct}Download failed.${NOct}" - # Handle download failure _WaitForEnterKey_ return fi @@ -1614,7 +1641,7 @@ _SendEMailNotification_() date +"$LOGdateFormat" > "$userTraceFile" - /usr/sbin/curl -v --url "${PROTOCOL}://${SMTP}:${PORT}" \ + curl -Lv --retry 4 --retry-delay 5 --url "${PROTOCOL}://${SMTP}:${PORT}" \ --mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS" $CC_ADDRESS_ARG \ --user "${USERNAME}:$(/usr/sbin/openssl aes-256-cbc "$emailPwEnc" -d -in "$amtmMailPswdFile" -pass pass:ditbabot,isoi)" \ --upload-file "$tempEMailContent" \ @@ -1858,7 +1885,7 @@ _GetRequiredRAM_KB_() local total_required_kb overhead_percentage=50 # Size of the ZIP file in bytes - zip_file_size_bytes="$(curl -sIL "$url" | grep -i Content-Length | tail -1 | awk '{print $2}')" + zip_file_size_bytes="$(curl -LsI --retry 4 --retry-delay 5 "$url" | grep -i Content-Length | tail -1 | awk '{print $2}')" # Convert bytes to kilobytes zip_file_size_kb="$((zip_file_size_bytes / 1024))" @@ -2564,7 +2591,7 @@ _GetLatestFWUpdateVersionFromWebsite_() { local url="$1" - local links_and_versions="$(curl -s "$url" | grep -o 'href="[^"]*'"$PRODUCT_ID"'[^"]*\.zip' | sed 's/amp;//g; s/href="//' | \ + local links_and_versions="$(curl -Ls --retry 4 --retry-delay 5 "$url" | grep -o 'href="[^"]*'"$PRODUCT_ID"'[^"]*\.zip' | sed 's/amp;//g; s/href="//' | \ awk -F'[_\.]' '{print $3"."$4"."$5" "$0}' | sort -t. -k1,1n -k2,2n -k3,3n)" if [ -z "$links_and_versions" ] @@ -2868,8 +2895,8 @@ return 0 ## Added by ExtremeFiretop [2024-May-21] ## ##---------------------------------------## _CheckFirmwareSHA256_() { - # Fetch the latest checksums from ASUSWRT-Merlin website - checksums=$(curl --silent --connect-timeout 10 --retry 4 --max-time 12 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g') + # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # + checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" if [ -z "$checksums" ] then @@ -5307,9 +5334,9 @@ _AddCronJobRunScriptHook_() fi } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jan-26] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jan-05] ## +##----------------------------------------## _DoUninstall_() { printf "Are you sure you want to uninstall $ScriptFileName script now" @@ -5320,10 +5347,10 @@ _DoUninstall_() _DelPostRebootRunScriptHook_ _DelPostUpdateEmailNotifyScriptHook_ - if rm -fr "$SETTINGS_DIR" && \ - rm -fr "${FW_BIN_BASE_DIR}/$ScriptDirNameD" && \ - rm -fr "${FW_LOG_BASE_DIR}/$ScriptDirNameD" && \ - rm -fr "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && \ + if rm -fr "${SETTINGS_DIR:?}" && \ + rm -fr "${FW_BIN_BASE_DIR:?}/$ScriptDirNameD" && \ + rm -fr "${FW_LOG_BASE_DIR:?}/$ScriptDirNameD" && \ + rm -fr "${FW_ZIP_BASE_DIR:?}/$ScriptDirNameD" && \ rm -f "$ScriptFilePath" then Say "${GRNct}Successfully Uninstalled.${NOct}" @@ -5700,8 +5727,12 @@ theLGExitStr="${GRNct}e${NOct}=Exit to Log Options Menu" padStr=" " SEPstr="----------------------------------------------------------" +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-05] ## +##----------------------------------------## FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}" -if [ "$PRODUCT_ID" = "$MODEL_ID" ] +# Some Model IDs have a lower case suffix of the same Product ID # +if [ "$PRODUCT_ID" = "$(echo "$MODEL_ID" | tr 'a-z' 'A-Z')" ] then FW_RouterModelID="${FW_RouterProductID}" else FW_RouterModelID="${FW_RouterProductID}/${GRNct}${MODEL_ID}${NOct}" fi @@ -6017,8 +6048,8 @@ _ShowMainMenu_() printf "${YLWct}============ By ExtremeFiretop & Martinski W. ============${NOct}\n\n" # New Script Update Notification # - if [ "$UpdateNotify" != "0" ]; then - Say "${REDct}WARNING:${NOct} ${UpdateNotify}${NOct}\n" + if [ "$scriptUpdateNotify" != "0" ]; then + Say "${REDct}WARNING:${NOct} ${scriptUpdateNotify}${NOct}\n" fi # Unsupported Model Checks # @@ -6112,7 +6143,8 @@ _ShowMainMenu_() fi # Check for new script updates # - if [ "$UpdateNotify" != "0" ]; then + if [ "$scriptUpdateNotify" != "0" ] + then printf "\n ${GRNct}up${NOct}. Update $SCRIPT_NAME Script Now" printf "\n${padStr}[Version: ${GRNct}${DLRepoVersion}${NOct} Available for Download]\n" fi @@ -6133,7 +6165,7 @@ _ShowMainMenu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -6367,7 +6399,7 @@ _AdvancedLogsOptions_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _advanced_options_menu_() { From b116791a97c9911cc8b0762715b13fc4c184e722 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 8 Jun 2024 04:58:40 -0400 Subject: [PATCH 114/185] Update MerlinAU.sh --- MerlinAU.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 88f4e255..58e05403 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1615,7 +1615,7 @@ _CheckEMailConfigFileFromAMTM_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Feb-16] ## +## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## _SendEMailNotification_() { @@ -1876,7 +1876,7 @@ _GetFreeRAM_KB_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Mar-31] ## +## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## _GetRequiredRAM_KB_() { @@ -2585,7 +2585,7 @@ _GetLatestFWUpdateVersionFromNode_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Mar-25] ## +## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## _GetLatestFWUpdateVersionFromWebsite_() { @@ -2891,9 +2891,9 @@ fi return 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-May-21] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-05] ## +##----------------------------------------## _CheckFirmwareSHA256_() { # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" From 8759186422bb5400cbd38bc4ce3fa99bda365815 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 8 Jun 2024 09:08:18 -0400 Subject: [PATCH 115/185] Update MerlinAU.sh --- MerlinAU.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 58e05403..06725129 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4782,6 +4782,36 @@ Please manually update to version $minimum_supported_version or higher to use th firmware_choice="pure" Update_Custom_Settings "TUFBuild" "n" fi + elif echo "$PRODUCT_ID" | grep -q "^GT-" + then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "ROGBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found ROG build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the ROG build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + Update_Custom_Settings "ROGBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi else # If not a TUF model, process as usual firmware_choice="pure" @@ -4974,7 +5004,6 @@ Please manually update to version $minimum_supported_version or higher to use th fi if [ "$retCode" -eq 1 ] then - Say "${REDct}**ERROR**${NOct}: Firmware file (unzip, move, copy) management was not completed successfully." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi @@ -5090,7 +5119,6 @@ Please manually update to version $minimum_supported_version or higher to use th fi if [ "$retCode" -eq 1 ] then - Say "${REDct}**ERROR**${NOct}: Firmware signature verification was not completed successfully." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi From a4aa1f2535c3708291868f5f44b36c6554664172 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 9 Jun 2024 22:49:29 -0400 Subject: [PATCH 116/185] Update MerlinAU.sh --- MerlinAU.sh | 91 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 06725129..f97a2804 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2624,7 +2624,7 @@ _GetLatestFWUpdateVersionFromWebsite_() _GetLatestFWUpdateVersionFromGithub_() { local url="$1" # GitHub API URL for the latest release - local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" + local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" local search_type="$firmware_type" # Default to the input firmware_type @@ -2663,7 +2663,7 @@ _GetLatestFWUpdateVersionFromGithub_() ##---------------------------------------## GetLatestFirmwareMD5Url() { local url="$1" # GitHub API URL for the latest release - local firmware_type="$2" # Type of firmware, e.g., "tuf" or "pure" + local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" local search_type="$firmware_type" # Default to the input firmware_type @@ -3063,7 +3063,7 @@ _Toggle_Auto_Backups_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -_ChangeBuildType_Gnuton_() +_ChangeBuildTypeTUF_Gnuton_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -6107,7 +6107,7 @@ _ShowMainMenu_() # Use the global variable if "$isGNUtonFW" then - FirmwareFlavor="${MAGENTAct}GNUton${NOct} (Limited Support)" + FirmwareFlavor="${MAGENTAct}GNUton${NOct}" else FirmwareFlavor="${BLUEct}Merlin${NOct}" fi @@ -6232,26 +6232,72 @@ _ShowAdvancedOptionsMenu_() if "$isGNUtonFW" then - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "TUFBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="TUF Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" - else - current_build_type_menu="NOT SET" - fi + if [ "$fwInstalledBaseVers" -le 3004 ] + then + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "TUFBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="TUF Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi - if echo "$PRODUCT_ID" | grep -q "^TUF-" + if echo "$PRODUCT_ID" | grep -q "^TUF-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + fi + fi + elif [ "$fwInstalledBaseVers" -ge 3006 ] then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menu" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + # Retrieve the current build type setting + local current_build_typerog="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_typerog" = "y" ]; then + current_build_type_menurog="ROG Build" + elif [ "$current_build_typerog" = "n" ]; then + current_build_type_menurog="Pure Build" + else + current_build_type_menurog="NOT SET" fi - fi + + if echo "$PRODUCT_ID" | grep -q "^GT-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menurog" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menurog}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menurog}${NOct}]\n" + fi + fi + + # Retrieve the current build type setting + local current_build_typetuf="$(Get_Custom_Setting "TUFBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_typetuf" = "y" ]; then + current_build_type_menutuf="TUF Build" + elif [ "$current_build_typetuf" = "n" ]; then + current_build_type_menutuf="Pure Build" + else + current_build_type_menutuf="NOT SET" + fi + + if echo "$PRODUCT_ID" | grep -q "^TUF-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menutuf" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menutuf}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menutuf}${NOct}]\n" + fi + fi + fi else if [ "$fwInstalledBaseVers" -le 3004 ] then @@ -6454,6 +6500,9 @@ _advanced_options_menu_() elif [ "$fwInstalledBaseVers" -le 3004 ] && \ echo "$PRODUCT_ID" | grep -q "^GT-" then _ChangeBuildType_Merlin_ + elif [ "$fwInstalledBaseVers" -ge 3006 ] && [ "$isGNUtonFW" && \ + echo "$PRODUCT_ID" | grep -q "^GT-" + then _ChangeBuildType_Merlin_ else _InvalidMenuSelection_ fi ;; From b7745cae92c5076be2ea21aa6046dd8eff20904b Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 9 Jun 2024 22:50:26 -0400 Subject: [PATCH 117/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f97a2804..4c974de9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3063,7 +3063,7 @@ _Toggle_Auto_Backups_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -_ChangeBuildTypeTUF_Gnuton_() +_ChangeBuildType_Gnuton_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" From ed12efb072d73c0fde2c0aa9d90d69813e7bebe1 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 9 Jun 2024 23:25:56 -0400 Subject: [PATCH 118/185] Update MerlinAU.sh --- MerlinAU.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 4c974de9..5774bc29 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3063,7 +3063,7 @@ _Toggle_Auto_Backups_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -_ChangeBuildType_Gnuton_() +_ChangeBuildType_TUF_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -3123,7 +3123,7 @@ _ChangeBuildType_Gnuton_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -_ChangeBuildType_Merlin_() +_ChangeBuildType_ROG_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -6496,13 +6496,13 @@ _advanced_options_menu_() fi ;; bt) if echo "$PRODUCT_ID" | grep -q "^TUF-" - then _ChangeBuildType_Gnuton_ + then _ChangeBuildType_TUF_ elif [ "$fwInstalledBaseVers" -le 3004 ] && \ echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_Merlin_ + then _ChangeBuildType_ROG_ elif [ "$fwInstalledBaseVers" -ge 3006 ] && [ "$isGNUtonFW" && \ echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_Merlin_ + then _ChangeBuildType_ROG_ else _InvalidMenuSelection_ fi ;; From 8b41cf97655843e1116bbcd8750714e0eb4d1fd8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 05:35:58 -0400 Subject: [PATCH 119/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5774bc29..3b5af272 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2630,7 +2630,7 @@ _GetLatestFWUpdateVersionFromGithub_() # If firmware_type is "pure", set search_type to include "squashfs" as well if [ "$firmware_type" = "pure" ]; then - search_type="pure\|squashfs" + search_type="pure\|squashfs\|ubi" fi # Fetch the latest release data from GitHub @@ -2669,7 +2669,7 @@ GetLatestFirmwareMD5Url() { # If firmware_type is "pure", set search_type to include "squashfs" as well if [ "$firmware_type" = "pure" ]; then - search_type="pure\|squashfs" + search_type="pure\|squashfs\|ubi" fi # Fetch the latest release data from GitHub From 6dd217286f7430aeaf744f45d2374214961bbb07 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 06:28:45 -0400 Subject: [PATCH 120/185] Update MerlinAU.sh --- MerlinAU.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 3b5af272..4e4c910d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3565,9 +3565,9 @@ expand_cron_field() fi } -##----------------------------------------## -## Modified by Martinski W. [2024-May-18] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jun-10] ## +##------------------------------------------## _EstimateNextCronTimeAfterDate_() { local post_date_secs="$1" @@ -3598,17 +3598,18 @@ _EstimateNextCronTimeAfterDate_() while [ "$found" = "false" ] do loopCount="$((loopCount + 1))" + if matches_month "$current_month" "$month_field" && \ matches_day_of_month "$current_day" "$dom_field" && \ matches_day_of_week "$current_dow" "$dow_field" then for this_hour in $(expand_cron_field "$hour_field" 0 23) do - if [ "$this_hour" -gt "$current_hour" ] + if [ "$this_hour" -gt "$current_hour" ] || [ "$loopCount" -gt 1 ] then for this_min in $(expand_cron_field "$minute_field" 0 59) do - echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" + echo "$(date -d "@$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" '+%Y-%m-%d %H:%M:%S')" found=true return 0 done @@ -3618,7 +3619,7 @@ _EstimateNextCronTimeAfterDate_() do if [ "$this_min" -gt "$current_minute" ] then - echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" + echo "$(date -d "@$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" '+%Y-%m-%d %H:%M:%S')" found=true return 0 fi From 1798872eae7d6ef938db9f5125c345f2c749edfc Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 06:46:07 -0400 Subject: [PATCH 121/185] Update MerlinAU.sh --- MerlinAU.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 4e4c910d..131be1f8 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3700,18 +3700,16 @@ _Calculate_NextRunTime_() fwNewUpdateNotificationDate="$(date +%Y-%m-%d_%H:%M:%S)" fi upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")" - nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" - if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ] + ExpectedFWUpdateRuntime="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" + if [ "$ExpectedFWUpdateRuntime" = "$CRON_UNKNOWN_DATE" ] then Update_Custom_Settings FW_New_Update_Expected_Run_Date "TBD" ExpectedFWUpdateRuntime="${REDct}UNKNOWN${NOct}" else - Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs" - ExpectedFWUpdateRuntime="$(date -d @$nextCronTimeSecs +"%Y-%b-%d %I:%M %p")" + Update_Custom_Settings FW_New_Update_Expected_Run_Date "$ExpectedFWUpdateRuntime" ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" fi else - ExpectedFWUpdateRuntime="$(date -d @$ExpectedFWUpdateRuntime +"%Y-%b-%d %I:%M %p")" ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}" fi } From a961749347df94f1d886d5ccbd179c7fe5d5cf11 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 12:55:50 -0400 Subject: [PATCH 122/185] Update MerlinAU.sh --- MerlinAU.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 131be1f8..a72683d9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3669,9 +3669,9 @@ _Calculate_DST_() echo "$((notifyTimeSecs + postponeTimeSecs))" } -##----------------------------------------## -## Modified by Martinski W. [2024-May-18] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jun-10] ## +##------------------------------------------## _Calculate_NextRunTime_() { local fwNewUpdateVersion fwNewUpdateNotificationDate @@ -4473,7 +4473,6 @@ _CheckTimeToUpdateFirmware_() return 1 fi - upfwDateTimeStrn="$(date -d @$nextCronTimeSecs +"%A, %Y-%b-%d %I:%M %p")" Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." echo "" From 037cf9382134050a05c31c8db0e920ca5283fea1 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 13:25:06 -0400 Subject: [PATCH 123/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a72683d9..59936381 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4473,7 +4473,7 @@ _CheckTimeToUpdateFirmware_() return 1 fi - Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}." + Say "The firmware update is expected to occur on ${GRNct}${nextCronTimeSecs}${NOct}." echo "" # Check if running in a menu environment From 70e595f80ade0c89c77933afc95dd97cca1f6955 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 13:27:09 -0400 Subject: [PATCH 124/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 59936381..25918fa2 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-05 +# Last Modified: 2024-Jun-10 ################################################################### set -u From ef1a0e80c6fe7d31b37a31210b8f79a2721d52f8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 13:36:26 -0400 Subject: [PATCH 125/185] Update MerlinAU.sh --- MerlinAU.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 25918fa2..01fec29b 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1350,14 +1350,8 @@ _CreateEMailContent_() fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - if "$isGNUtonFW" - then - # First remove "-gnuton" followed by any digits at the end, then removes a trailing hyphen # - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/gnuton[0-9]+$//; s/-$//')" - else - # Remove "_rog" suffix to avoid version comparison failures # - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" - fi + # Remove "_rog" suffix to avoid version comparison failures # + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" case "$1" in FW_UPDATE_TEST_EMAIL) From 07255da2e6b4cb5535c714921b35b79339b5ff85 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 10 Jun 2024 14:25:52 -0400 Subject: [PATCH 126/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 01fec29b..0e67a4c6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1350,8 +1350,8 @@ _CreateEMailContent_() fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - # Remove "_rog" suffix to avoid version comparison failures # - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" + # Remove "_rog" or "_tuf" suffix to avoid version comparison failures + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_\(rog\|tuf\)$//')" case "$1" in FW_UPDATE_TEST_EMAIL) From 98e0d5c86315034e54036799b9417d88f3a05100 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Jun 2024 03:49:28 -0400 Subject: [PATCH 127/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 0e67a4c6..a387a9bc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3599,7 +3599,7 @@ _EstimateNextCronTimeAfterDate_() then for this_hour in $(expand_cron_field "$hour_field" 0 23) do - if [ "$this_hour" -gt "$current_hour" ] || [ "$loopCount" -gt 1 ] + if [ "$this_hour" -gt "$current_hour" ] then for this_min in $(expand_cron_field "$minute_field" 0 59) do @@ -3611,7 +3611,7 @@ _EstimateNextCronTimeAfterDate_() then for this_min in $(expand_cron_field "$minute_field" 0 59) do - if [ "$this_min" -gt "$current_minute" ] + if [ "$this_min" -ge "$current_minute" ] then echo "$(date -d "@$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" '+%Y-%m-%d %H:%M:%S')" found=true From 51ca8173e8ee4a831ddb396f0d966842b7b3adf6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Jun 2024 21:29:32 -0400 Subject: [PATCH 128/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a387a9bc..8ee768de 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -6113,8 +6113,8 @@ _ShowMainMenu_() fi printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide" printf "\n USB-Attached Storage Connected: $USBConnected" - printf "\n F/W Version Currently Installed: $FW_InstalledVerStr" printf "\n F/W Variant Configuration Found: $FirmwareFlavor" + printf "\n F/W Version Currently Installed: $FW_InstalledVerStr" printf "\n F/W Update Version Available: $FW_NewUpdateVerStr" printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" else From 98174d28128e3549d6272a595dc4faa07f173308 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Jun 2024 21:30:41 -0400 Subject: [PATCH 129/185] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 6085e946..f0bb29e7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.1 +1.3.0 From 67427cb23ec6d670051cca68548622cbe5c68223 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Jun 2024 21:32:55 -0400 Subject: [PATCH 130/185] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5015b1d..8d1282c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MerlinAU - AsusWRT-Merlin Firmware Auto Updater -## v1.2.1 -## 2024-06-08 +## v1.3.0 +## 2024-06-11 ![image](https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/assets/1971404/95562bee-aee7-4275-8ee2-6a049580d4aa) ![image](https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/assets/1971404/761dd6dd-aaf2-4454-a05e-7b9a4f481086) From 82b44c4bc226889ae9452f2eed28fb92694d0d47 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 19 Jun 2024 00:51:35 -0400 Subject: [PATCH 131/185] Update MerlinAU.sh --- MerlinAU.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8ee768de..b277036f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-10 +# Last Modified: 2024-Jun-16 ################################################################### set -u @@ -2785,7 +2785,7 @@ _UnzipMerlin_() { # Extracting the firmware binary image if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ - while IFS= read -r line ; do Say "$line" ; done + while IFS= read -r line ; do Say "$line" ; done then Say "-----------------------------------------------------------" #---------------------------------------------------------------# @@ -4586,13 +4586,15 @@ _Toggle_FW_UpdateCheckSetting_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Mar-16] ## +## Modified by Martinski W. [2024-Jun-16] ## ##----------------------------------------## _EntwareServicesHandler_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi - local serviceCnt entwOPT_init entwOPT_unslung actionStr="" divAction="" + local actionStr="" divAction="" + local serviceStr serviceCnt=0 + local entwOPT_init entwOPT_unslung case "$1" in stop) actionStr="Stopping" ; divAction="unmount" ;; @@ -4603,8 +4605,8 @@ _EntwareServicesHandler_() if [ -f /opt/bin/diversion ] then Say "${actionStr} Diversion service..." - /opt/bin/diversion "$divAction" - sleep 1 + /opt/bin/diversion "$divAction" & + sleep 3 fi entwOPT_init="/opt/etc/init.d" @@ -4613,11 +4615,17 @@ _EntwareServicesHandler_() if [ ! -x /opt/bin/opkg ] || [ ! -x "$entwOPT_unslung" ] then return 0 ; fi ## Entware is NOT found ## - serviceCnt="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -cE "${entwOPT_init}/S[0-9]+")" + serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")" + [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" [ "$serviceCnt" -eq 0 ] && return 0 Say "${actionStr} Entware services..." - "$isInteractive" && printf "\nPlease wait.\n" + "$isInteractive" && printf "Please wait.\n" + Say "-----------------------------------------------------------" + # List the Entware service scripts found # + echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done + Say "-----------------------------------------------------------" + $entwOPT_unslung "$1" ; sleep 5 "$isInteractive" && printf "\nDone.\n" } From 8ab2ab4432c5d4ea908916fab189b7650f45f1c3 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 19 Jun 2024 20:40:35 -0400 Subject: [PATCH 132/185] Update MerlinAU.sh --- MerlinAU.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index b277036f..bab845a7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-16 +# Last Modified: 2024-Jun-19 ################################################################### set -u @@ -407,24 +407,25 @@ _ScriptVersionStrToNum_() } ##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## +## Added by ExtremeFiretop [2024-Jun-19] ## ##---------------------------------------## _GetFirmwareVariantFromRouter_() { local retCode=0 newVersionStr buildInfoStr="$(nvram get buildinfo)" + innerverStr="$(nvram get innerver)" ##FOR TESTING/DEBUG ONLY## if false # Change to true for forcing GNUton flag then isGNUtonFW=true else - # Check if the version string contains "gnuton" - if echo "$buildInfoStr" | grep -iq "merlin"; then - isGNUtonFW=false - else + # Check if the version string contains "merlin" or if innerver contains "gnuton" + if echo "$buildInfoStr" | grep -iq "merlin" || echo "$innerverStr" | grep -iq "gnuton"; then isGNUtonFW=true + else + isGNUtonFW=false fi fi From c40a44ca4609d455526d26028e4c4238cbcacec1 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 19 Jun 2024 20:44:04 -0400 Subject: [PATCH 133/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index bab845a7..8031eafe 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -421,8 +421,8 @@ _GetFirmwareVariantFromRouter_() then isGNUtonFW=true else - # Check if the version string contains "merlin" or if innerver contains "gnuton" - if echo "$buildInfoStr" | grep -iq "merlin" || echo "$innerverStr" | grep -iq "gnuton"; then + # Check if the version string does NOT contain "merlin" or if innerver contains "gnuton" + if ! echo "$buildInfoStr" | grep -iq "merlin" || echo "$innerverStr" | grep -iq "gnuton"; then isGNUtonFW=true else isGNUtonFW=false From 240d77b9758d84cc06d7052903c56a0e86f90904 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 19 Jun 2024 20:51:01 -0400 Subject: [PATCH 134/185] Update MerlinAU.sh --- MerlinAU.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8031eafe..c422efbb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -421,9 +421,13 @@ _GetFirmwareVariantFromRouter_() then isGNUtonFW=true else - # Check if the version string does NOT contain "merlin" or if innerver contains "gnuton" - if ! echo "$buildInfoStr" | grep -iq "merlin" || echo "$innerverStr" | grep -iq "gnuton"; then + # Check if innerver contains "gnuton" + if echo "$innerverStr" | grep -iq "gnuton" + then isGNUtonFW=true + # if the version string contain "merlin" + elif echo "$buildInfoStr" | grep -iq "merlin"; then + isGNUtonFW=false else isGNUtonFW=false fi From ac86f4de86843a418e203118fb406e6cb7b2e8a6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 19 Jun 2024 20:53:07 -0400 Subject: [PATCH 135/185] Update MerlinAU.sh --- MerlinAU.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c422efbb..5293ee24 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -411,6 +411,7 @@ _ScriptVersionStrToNum_() ##---------------------------------------## _GetFirmwareVariantFromRouter_() { + ##DEFAULTS TO MERLIN## local retCode=0 newVersionStr buildInfoStr="$(nvram get buildinfo)" @@ -426,7 +427,8 @@ _GetFirmwareVariantFromRouter_() then isGNUtonFW=true # if the version string contain "merlin" - elif echo "$buildInfoStr" | grep -iq "merlin"; then + elif echo "$buildInfoStr" | grep -iq "merlin" + then isGNUtonFW=false else isGNUtonFW=false From 954bb3acc73a0bfcf732fa901511bdbe79775876 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 20 Jun 2024 22:22:17 -0400 Subject: [PATCH 136/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5293ee24..e6de84dc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -6507,7 +6507,7 @@ _advanced_options_menu_() elif [ "$fwInstalledBaseVers" -le 3004 ] && \ echo "$PRODUCT_ID" | grep -q "^GT-" then _ChangeBuildType_ROG_ - elif [ "$fwInstalledBaseVers" -ge 3006 ] && [ "$isGNUtonFW" && \ + elif [ "$fwInstalledBaseVers" -ge 3006 ] && "$isGNUtonFW" && \ echo "$PRODUCT_ID" | grep -q "^GT-" then _ChangeBuildType_ROG_ else _InvalidMenuSelection_ From b3aa26fb12208d480bd5dedb5e4935c24a5b5c0d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 20 Jun 2024 22:42:25 -0400 Subject: [PATCH 137/185] Update MerlinAU.sh --- MerlinAU.sh | 992 +++++++++------------------------------------------- 1 file changed, 175 insertions(+), 817 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e6de84dc..17659e6c 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-19 +# Last Modified: 2024-Jun-16 ################################################################### set -u -readonly SCRIPT_VERSION=1.3.0 +readonly SCRIPT_VERSION=1.2.3 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -19,17 +19,16 @@ readonly SCRIPT_BRANCH="master" readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router/$SCRIPT_BRANCH" # Firmware URL Info # -readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" -readonly FW_SFURL_RELEASE_SUFFIX="Release" -readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.ng/releases/latest" +readonly FW_URL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" +readonly FW_URL_RELEASE_SUFFIX="Release" ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## # Changelog Info # -readonly CL_URL_NG="${FW_SFURL_BASE}/Documentation/Changelog-NG.txt/download" -readonly CL_URL_386="${FW_SFURL_BASE}/Documentation/Changelog-386.txt/download" -readonly CL_URL_3006="${FW_SFURL_BASE}/Documentation/Changelog-3006.txt/download" +readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" +readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" +readonly CL_URL_3006="${FW_URL_BASE}/Documentation/Changelog-3006.txt/download" readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" @@ -406,38 +405,6 @@ _ScriptVersionStrToNum_() echo "$verNum" ; return 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Jun-19] ## -##---------------------------------------## -_GetFirmwareVariantFromRouter_() -{ - ##DEFAULTS TO MERLIN## - local retCode=0 newVersionStr - - buildInfoStr="$(nvram get buildinfo)" - innerverStr="$(nvram get innerver)" - - ##FOR TESTING/DEBUG ONLY## - if false # Change to true for forcing GNUton flag - then - isGNUtonFW=true - else - # Check if innerver contains "gnuton" - if echo "$innerverStr" | grep -iq "gnuton" - then - isGNUtonFW=true - # if the version string contain "merlin" - elif echo "$buildInfoStr" | grep -iq "merlin" - then - isGNUtonFW=false - else - isGNUtonFW=false - fi - fi - - echo "$isGNUtonFW" ; return "$retCode" -} - ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## @@ -526,6 +493,7 @@ readonly CRON_MONTH_NAMES="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)" readonly CRON_MONTH_RegEx="$CRON_MONTH_NAMES([\/,-]$CRON_MONTH_NAMES)*|([*1-9]|1[0-2])([\/,-]([1-9]|1[0-2]))*" readonly CRON_UNKNOWN_DATE="**ERROR**: UNKNOWN Date Found" + ##------------------------------------------## ## Modified by Martinski W. [2024-Jan-22] ## ##------------------------------------------## @@ -537,12 +505,8 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" -##FOR TESTING/DEBUG ONLY## -#readonly PRODUCT_ID="TUF-AX3000_V2" -##FOR TESTING/DEBUG ONLY## readonly FW_FileName="${PRODUCT_ID}_firmware" -readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" -readonly isGNUtonFW=$(_GetFirmwareVariantFromRouter_) +readonly FW_URL_RELEASE="${FW_URL_BASE}/${PRODUCT_ID}/${FW_URL_RELEASE_SUFFIX}/" ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-21] ## @@ -597,7 +561,6 @@ ${REDct}v$SCRIPT_VERSION${NOct} --> ${GRNct}v$DLRepoVersion${NOct}" fi } - ##----------------------------------------## ## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## @@ -860,8 +823,7 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -933,8 +895,7 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -1198,7 +1159,6 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" echo "The directory path for the F/W ZIP file was updated successfully." - keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi return 0 @@ -1213,12 +1173,9 @@ _Init_Custom_Settings_Config_ # ROG upgrades to 3006 codebase should have # the ROG option deleted. #----------------------------------------------------------- -if ! "$isGNUtonFW" +if [ "$fwInstalledBaseVers" -ge 3006 ] && grep -q "^ROGBuild" "$SETTINGSFILE" then - if [ "$fwInstalledBaseVers" -ge 3006 ] && grep -q "^ROGBuild" "$SETTINGSFILE" - then - Delete_Custom_Settings "ROGBuild" - fi + Delete_Custom_Settings "ROGBuild" fi ##------------------------------------------## @@ -1357,8 +1314,8 @@ _CreateEMailContent_() fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - # Remove "_rog" or "_tuf" suffix to avoid version comparison failures - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_\(rog\|tuf\)$//')" + # Remove "_rog" suffix to avoid version comparison failures # + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" case "$1" in FW_UPDATE_TEST_EMAIL) @@ -1929,7 +1886,7 @@ _ShutDownNonCriticalServices_() ##------------------------------------------## _DoCleanUp_() { - local delBINfiles=false keepZIPfile=false keepWfile=false + local delBINfiles=false keepZIPfile=false moveZIPback=false local doTrace=false [ $# -gt 0 ] && [ "$1" -eq 0 ] && doTrace=false @@ -1941,35 +1898,20 @@ _DoCleanUp_() [ $# -gt 0 ] && [ "$1" -eq 1 ] && delBINfiles=true [ $# -gt 1 ] && [ "$2" -eq 1 ] && keepZIPfile=true - [ $# -gt 2 ] && [ "$3" -eq 1 ] && keepWfile=true # Stop the LEDs blinking # _Reset_LEDs_ 1 - # Check existence of files and preserve based on flags - local moveZIPback=false - local moveWback=false - # Move file temporarily to save it from deletion # - if "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ]; then - mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true - fi - - if "$keepWfile" && [ -f "$FW_DL_FPATH" ]; then - mv -f "$FW_DL_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveWback=true - fi + "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ] && \ + mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true rm -f "${FW_ZIP_DIR}"/* "$delBINfiles" && rm -f "${FW_BIN_DIR}"/* - # Move files back to their original location if they were moved - if "$moveZIPback"; then - mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" - fi - - if "$moveWback"; then - mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.${extension}" "$FW_DL_FPATH" - fi + # Move file back to original location # + "$keepZIPfile" && "$moveZIPback" && \ + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" if "$doTrace" then @@ -2073,7 +2015,7 @@ check_memory_and_prompt_reboot() # Restart Entware services # _EntwareServicesHandler_ start - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + _DoCleanUp_ 1 "$keepZIPfile" _DoExit_ 1 fi else @@ -2114,7 +2056,7 @@ check_version_support() check_model_support() { # List of unsupported models as a space-separated string - local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900 DSL-AC68U" + local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900" # Get the current model local current_model="$(_GetRouterProductID_)" @@ -2619,348 +2561,6 @@ _GetLatestFWUpdateVersionFromWebsite_() return 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Feb-23] ## -##---------------------------------------## -_GetLatestFWUpdateVersionFromGithub_() -{ - local url="$1" # GitHub API URL for the latest release - local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" - - local 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" = "pure" ]; then - search_type="pure\|squashfs\|ubi" - fi - - # Fetch the latest release data from GitHub - local release_data=$(curl -s "$url") - - # Construct the grep pattern based on search_type - local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\"" - - # Filter the JSON for the desired firmware using grep and head to fetch the URL - local download_url=$(echo "$release_data" | - grep -o "$grep_pattern" | - grep -o "https://[^ ]*\.\(w\|pkgtb\)" | - head -1) - - # Check if a URL was found - if [ -z "$download_url" ]; then - echo "**ERROR** **NO_GITHUB_URL**" - return 1 - else - # Extract the version from the download URL or release data - local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g") - echo "$version" - echo "$download_url" - return 0 - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-05] ## -##---------------------------------------## -GetLatestFirmwareMD5Url() { - local url="$1" # GitHub API URL for the latest release - local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" - - local 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" = "pure" ]; then - search_type="pure\|squashfs\|ubi" - fi - - # Fetch the latest release data from GitHub - local release_data=$(curl -s "$url") - - # Construct the grep pattern based on search_type - local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.md5\"" - - # Filter the JSON for the desired firmware using grep and sed - local md5_url=$(echo "$release_data" | - grep -o "$grep_pattern" | - sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | - head -1) - - # Check if a URL was found and output result or error - if [ -z "$md5_url" ]; then - echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**" - return 1 - else - echo "$md5_url" - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-17] ## -##---------------------------------------## -GetLatestChangelogUrl() { - local url="$1" # GitHub API URL for the latest release - - # Fetch the latest release data from GitHub - local release_data=$(curl -s "$url") - - # Parse the release data to find the download URL of the CHANGELOG file - # Directly find the URL without matching a specific model number - local changelog_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*CHANGELOG.*\"" | grep -o "https://[^ ]*\"" | tr -d '"' | head -1) - - # Check if the URL has been found - if [ -z "$changelog_url" ]; then - echo "**ERROR** **NO_CHANGELOG_FILE_URL_FOUND**" - return 1 - else - echo "$changelog_url" - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_DownloadForGnuton_() { - - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") - - # Use the effective URL to capture the Content-Disposition header - local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') - - # Sanitize filename by removing problematic characters - local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - - # Extract the file extension - extension="${sanitized_filename##*.}" - - # Combine path, custom file name, and extension before download - FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" - FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" - FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" - - # Download the firmware using the release link - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_DL_FPATH" "$release_link" - if [ ! -f "$FW_DL_FPATH" ]; then - return 1 - fi - - # Download the latest MD5 checksum - Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_MD5_GITHUB" "$md5_url" - if [ ! -f "$FW_MD5_GITHUB" ]; then - return 1 - fi - - # Download the latest changelog - Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" - if [ ! -f "$FW_Changelog_GITHUB" ]; then - return 1 - else - return 0 - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_DownloadForMerlin_() { - - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_ZIP_FPATH" "$release_link" - - # Check if the file was downloaded successfully - if [ ! -f "$FW_ZIP_FPATH" ]; then - return 1 - else - return 0 - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_UnzipMerlin_() { - Say "-----------------------------------------------------------" - # List & log the contents of the ZIP file - unzip -l "$FW_ZIP_FPATH" 2>&1 | \ - while IFS= read -r uzLINE ; do Say "$uzLINE" ; done - Say "-----------------------------------------------------------" - - # Extracting the firmware binary image - if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ - while IFS= read -r line ; do Say "$line" ; done - then - Say "-----------------------------------------------------------" - #---------------------------------------------------------------# - # Check if ZIP file was downloaded to a USB-attached drive. - # Take into account special case for Entware "/opt/" paths. - #---------------------------------------------------------------# - if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" - then - # It's not on a USB drive, so it's safe to delete it - rm -f "$FW_ZIP_FPATH" - elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 - then - -------------------------------------------------------------# - # This should not happen because we already checked for it - # at the very beginning of this function, but just in case - # it does (drive going bad suddenly?) we'll report it here. - #-------------------------------------------------------------# - Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." - Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - return 1 - # Consider how to handle this error. For now, we'll not delete the ZIP file. - else - keepZIPfile=1 - fi - else - #------------------------------------------------------------# - # Remove ZIP file here because it may have been corrupted. - # Better to download it again and start all over, instead - # of trying to figure out why uncompressing it failed. - #------------------------------------------------------------# - rm -f "$FW_ZIP_FPATH" - _SendEMailNotification_ FAILED_FW_UNZIP_STATUS - Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." - _return 1 - fi - return 0 -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_CopyGnutonFiles_() { - -Say "Checking if file management is required" - -local copy_success=0 -local copy_attempted=1 - -# Check and copy the firmware file if different from destination -if [ "$FW_DL_FPATH" != "${FW_BIN_DIR}/${FW_FileName}.${extension}" ]; then - Say "File management is required" - copy_attempted=0 - cp "$FW_DL_FPATH" "$FW_BIN_DIR" && Say "Copying firmware file..." || copy_success=1 -else - Say "File management is not required" -fi - -# Check and copy the MD5 file if different from destination -if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then - copy_attempted=0 - mv -f "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Moving MD5 file..." || copy_success=1 -fi - -# Check and copy the Changelog file if different from destination -if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then - copy_attempted=0 - mv -f "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Moving changelog file..." || copy_success=1 -fi - -if [ $copy_attempted -eq 0 ] && [ $copy_success -eq 0 ] -then - #---------------------------------------------------------------# - # Check if Gntuon file was downloaded to a USB-attached drive. - # Take into account special case for Entware "/opt/" paths. - #---------------------------------------------------------------# - if ! echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" - then - # It's not on a USB drive, so it's safe to delete it - rm -f "$FW_DL_FPATH" - rm -f "$FW_Changelog_GITHUB" - rm -f "$FW_MD5_GITHUB" - elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 - then - -------------------------------------------------------------# - # This should not happen because we already checked for it - # at the very beginning of this function, but just in case - # it does (drive going bad suddenly?) we'll report it here. - #-------------------------------------------------------------# - Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." - Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - return 1 - # Consider how to handle this error. For now, we'll not delete the firmware file. - else - keepWfile=1 - fi -fi -return 0 -} - -##----------------------------------------## -## Modified by Martinski W. [2024-Jun-05] ## -##----------------------------------------## -_CheckFirmwareSHA256_() { - # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # - checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" - - if [ -z "$checksums" ] - then - Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website." - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ] - then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - fi - - if [ -f "$firmware_file" ] - then - fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - # Extract the corresponding signature for the firmware file from the fetched checksums # - dl_sig="$(echo "$checksums" | grep "$(basename "$firmware_file")" | cut -d' ' -f1)" - if [ "$fw_sig" != "$dl_sig" ] - then - Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." - _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - return 1 - fi - else - Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!" - _DoCleanUp_ 1 - return 1 - fi -} - -##---------------------------------------## -## Added by ExtremeFiretop [2024-Apr-18] ## -##---------------------------------------## -_CheckFirmwareMD5_() { - # Check if both the MD5 checksum file and the firmware file exist - if [ -f "${FW_BIN_DIR}/${FW_FileName}.md5" ] && [ -f "$firmware_file" ]; then - # Extract the MD5 checksum from the downloaded .md5 file - # Assuming the .md5 file contains a single line with the checksum followed by the filename - local md5_expected=$(cut -d' ' -f1 "${FW_BIN_DIR}/${FW_FileName}.md5") - - # Calculate the MD5 checksum of the firmware file - local md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) - - # Compare the calculated MD5 checksum with the expected MD5 checksum - if [ "$md5_actual" != "$md5_expected" ]; then - Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" - _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - return 1 - else - Say "Firmware MD5 checksum verified successfully." - fi - else - Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" - _DoCleanUp_ 1 - return 1 - fi -} - ##----------------------------------------## ## Modified by Martinski W. [2024-May-27] ## ##----------------------------------------## @@ -3064,67 +2664,7 @@ _Toggle_Auto_Backups_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -_ChangeBuildType_TUF_() -{ - local doReturnToMenu buildtypechoice - printf "Changing Flash Build Type...\n" - - # Use Get_Custom_Setting to retrieve the previous choice - previous_choice="$(Get_Custom_Setting "TUFBuild")" - - # If the previous choice is not set, default to 'n' - if [ "$previous_choice" = "TBD" ]; then - previous_choice="n" - fi - - # Convert previous choice to a descriptive text - if [ "$previous_choice" = "y" ]; then - display_choice="TUF Build" - else - display_choice="Pure Build" - fi - - printf "\nCurrent Build Type: ${GRNct}$display_choice${NOct}.\n" - - doReturnToMenu=false - while true - do - printf "\n${SEPstr}" - printf "\nChoose your preferred option for the build type to flash:\n" - printf "\n ${GRNct}1${NOct}. Original ${REDct}TUF${NOct} themed user interface${NOct}\n" - printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-TUF${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" - printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" - printf "${SEPstr}\n" - printf "[$display_choice] Enter selection: " - read -r choice - - [ -z "$choice" ] && break - - if echo "$choice" | grep -qE "^(e|exit|Exit)$" - then doReturnToMenu=true ; break ; fi - - case $choice in - 1) buildtypechoice="y" ; break - ;; - 2) buildtypechoice="n" ; break - ;; - *) echo ; _InvalidMenuSelection_ - ;; - esac - done - - "$doReturnToMenu" && return 0 - - Update_Custom_Settings "TUFBuild" "$buildtypechoice" - printf "\nThe build type to flash was updated successfully.\n" - - _WaitForEnterKey_ "$advnMenuReturnPromptStr" -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Feb-18] ## -##------------------------------------------## -_ChangeBuildType_ROG_() +change_build_type() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -4070,31 +3610,21 @@ _ChangelogVerificationCheck_() current_version="$(_GetCurrentFWInstalledLongVersion_)" release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" - if "$isGNUtonFW" + # Get the correct Changelog filename: "Changelog-[3006|386|NG].txt" # + if echo "$release_version" | grep -qE "^3006[.]" then - changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + changeLogTag="3006" + elif echo "$release_version" | grep -q "386[.]" + then + changeLogTag="386" else - # Get the correct Changelog filename: "Changelog-[3006|386|NG].txt" # - if echo "$release_version" | grep -qE "^3006[.]" - then - changeLogTag="3006" - elif echo "$release_version" | grep -q "386[.]" - then - changeLogTag="386" - else - changeLogTag="NG" - fi - changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" + changeLogTag="NG" fi + changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" if [ ! -f "$changeLogFile" ] then - if "$isGNUtonFW" - then - Say "Changelog file [${FW_BIN_DIR}/${FW_FileName}_Changelog.txt] does NOT exist." - else - Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." - fi + Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." _DoCleanUp_ return 1 else @@ -4135,20 +3665,16 @@ _ChangelogVerificationCheck_() release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - if "$isGNUtonFW" + # Check if the current version is present in the changelog + if ! grep -Eq "$current_version_regex" "$changeLogFile" then - # For Gnuton, the whole file is relevant as it only contains the current version # - changelog_contents="$(cat "$changeLogFile")" - else - if ! grep -Eq "$current_version_regex" "$changeLogFile"; then - Say "Current version NOT found in changelog file. Bypassing changelog verification for this run." - return 0 - else - # Extract log contents between two firmware versions for non-Gnuton changelogs # - changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" - fi + Say "Current version NOT found in changelog file. Bypassing changelog verification for this run." + return 0 fi + # Extract log contents between two firmware versions + changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" + if [ "$mode" = "interactive" ] then if _high_risk_phrases_interactive_ "$changelog_contents" @@ -4171,7 +3697,7 @@ _ChangelogVerificationCheck_() ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## -_ManageChangelogMerlin_() +_ManageChangelog_() { if [ $# -eq 0 ] || [ -z "$1" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi @@ -4247,59 +3773,6 @@ _ManageChangelogMerlin_() return 0 } -_ManageChangelogGnuton_() -{ - if [ $# -eq 0 ] || [ -z "$1" ] - then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi - - local mode="$1" # Mode should be 'download' or 'view' # - local newUpdateVerStr="" - local wgetLogFile changeLogFile changeLogTag changeLogURL - - # Create directory to download changelog if missing - if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi - - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - - # Follow redirects and capture the effective URL - local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$Gnuton_changelogurl") - - # Use the effective URL to capture the Content-Disposition header - local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') - - # Sanitize filename by removing problematic characters - local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - - FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" - - wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" - printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" - - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "${Gnuton_changelogurl}" - - if [ ! -f "$FW_Changelog_GITHUB" ] - then - Say "Changelog file [$FW_Changelog_GITHUB] does NOT exist." - echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" - else - if [ "$mode" = "download" ] - then - _ChangelogVerificationCheck_ "auto" - elif [ "$mode" = "view" ] - then - clear - printf "\n${GRNct}Changelog file is ready to review!${NOct}\n" - printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" - dos2unix "$FW_Changelog_GITHUB" - _WaitForEnterKey_ - less "$FW_Changelog_GITHUB" - fi - fi - rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" - return 1 -} - ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## @@ -4342,12 +3815,7 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - if "$isGNUtonFW" - then - _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" - else - _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" - fi + _ManageChangelog_ "download" "$fwNewUpdateNotificationVers" fi fi @@ -4360,12 +3828,7 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - if "$isGNUtonFW" - then - _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" - else - _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" - fi + _ManageChangelog_ "download" "$fwNewUpdateNotificationVers" fi fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" @@ -4753,96 +4216,18 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-18] ## - ##------------------------------------------## - if "$isGNUtonFW" - then - Say "Using release information for Gnuton Firmware." - # Check if PRODUCT_ID is for a TUF model and requires user choice - if echo "$PRODUCT_ID" | grep -q "^TUF-"; then - # Fetch the previous choice from the settings file - local previous_choice="$(Get_Custom_Setting "TUFBuild")" - - if [ "$previous_choice" = "y" ]; then - echo "TUF Build selected for flashing" - firmware_choice="tuf" - elif [ "$previous_choice" = "n" ]; then - echo "Pure Build selected for flashing" - firmware_choice="pure" - elif [ "$inMenuMode" = true ]; then - printf "${REDct}Found TUF build for: $PRODUCT_ID.${NOct}\n" - printf "${REDct}Would you like to use the TUF build?${NOct}\n" - printf "Enter your choice (y/n): " - read -r choice - if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then - echo "TUF Build selected for flashing" - firmware_choice="tuf" - Update_Custom_Settings "TUFBuild" "y" - else - echo "Pure Build selected for flashing" - firmware_choice="pure" - Update_Custom_Settings "TUFBuild" "n" - fi - else - echo "Defaulting to Pure Build due to non-interactive mode." - firmware_choice="pure" - Update_Custom_Settings "TUFBuild" "n" - fi - elif echo "$PRODUCT_ID" | grep -q "^GT-" - then - # Fetch the previous choice from the settings file - local previous_choice="$(Get_Custom_Setting "ROGBuild")" - - if [ "$previous_choice" = "y" ]; then - echo "ROG Build selected for flashing" - firmware_choice="rog" - elif [ "$previous_choice" = "n" ]; then - echo "Pure Build selected for flashing" - firmware_choice="pure" - elif [ "$inMenuMode" = true ]; then - printf "${REDct}Found ROG build for: $PRODUCT_ID.${NOct}\n" - printf "${REDct}Would you like to use the ROG build?${NOct}\n" - printf "Enter your choice (y/n): " - read -r choice - if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then - echo "ROG Build selected for flashing" - firmware_choice="rog" - Update_Custom_Settings "ROGBuild" "y" - else - echo "Pure Build selected for flashing" - firmware_choice="pure" - Update_Custom_Settings "ROGBuild" "n" - fi - else - echo "Defaulting to Pure Build due to non-interactive mode." - firmware_choice="pure" - Update_Custom_Settings "ROGBuild" "n" - fi - else - # If not a TUF model, process as usual - firmware_choice="pure" - fi - md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE" "$firmware_choice") - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") - retCode="$?" - else - Say "Using release information for Merlin Firmware." - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - retCode="$?" - fi - - if [ "$retCode" -eq 0 ] && [ "$#" -eq 2 ] && \ + # Use set to read the output of the function into variables + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + if [ $? -eq 0 ] && [ $# -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] - then + then release_version="$1" release_link="$2" - else + else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 - fi + fi # Extracting the F/W Update codebase number to use in the curl # fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)" @@ -4967,27 +4352,22 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Downloading ${GRNct}${release_link}${NOct}" echo - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apl-24] ## - ##------------------------------------------## + ##----------------------------------------## + ## Modified by Martinski W. [2024-Feb-28] ## + ##----------------------------------------## # Avoid error message about HSTS database # wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - if "$isGNUtonFW" - then - _DownloadForGnuton_ - retCode="$?" - else - _DownloadForMerlin_ - retCode="$?" - fi - if [ "$retCode" -eq 1 ] - then - Say "${REDct}**ERROR**${NOct}: Firmware files were not downloaded successfully." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - fi + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_ZIP_FPATH" "$release_link" + fi + + if [ ! -f "$FW_ZIP_FPATH" ] + then + Say "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_ZIP_FPATH] was not downloaded." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi ##------------------------------------------## @@ -4999,18 +4379,50 @@ Please manually update to version $minimum_supported_version or higher to use th check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-21] ## + ## Modified by ExtremeFiretop [2024-Mar-19] ## ##------------------------------------------## - if "$isGNUtonFW" + Say "-----------------------------------------------------------" + # List & log the contents of the ZIP file # + unzip -l "$FW_ZIP_FPATH" 2>&1 | \ + while IFS= read -r uzLINE ; do Say "$uzLINE" ; done + Say "-----------------------------------------------------------" + + # Extracting the firmware binary image # + if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ + while IFS= read -r line ; do Say "$line" ; done then - _CopyGnutonFiles_ - retCode="$?" + Say "-----------------------------------------------------------" + #---------------------------------------------------------------# + # Check if ZIP file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# + if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # It's not on a USB drive, so it's safe to delete it # + rm -f "$FW_ZIP_FPATH" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + #-------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + "$inMenuMode" && _WaitForEnterKey_ + # Consider how to handle this error. For now, we'll not delete the ZIP file. + else + keepZIPfile=1 + fi else - _UnzipMerlin_ - retCode="$?" - fi - if [ "$retCode" -eq 1 ] - then + #------------------------------------------------------------# + # Remove ZIP file here because it may have been corrupted. + # Better to download it again and start all over, instead + # of trying to figure out why uncompressing it failed. + #------------------------------------------------------------# + rm -f "$FW_ZIP_FPATH" + _SendEMailNotification_ FAILED_FW_UNZIP_STATUS + Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi @@ -5113,21 +4525,56 @@ Please manually update to version $minimum_supported_version or higher to use th firmware_file="$pure_file" fi - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-25] ## - ##------------------------------------------## - if "$isGNUtonFW" + ##----------------------------------------## + ## Modified by Martinski W. [2024-Jun-05] ## + ##----------------------------------------## + # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # + checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" + + if [ -z "$checksums" ] then - _CheckFirmwareMD5_ - retCode="$?" - else - _CheckFirmwareSHA256_ - retCode="$?" + Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website." + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ] + then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi fi - if [ "$retCode" -eq 1 ] + + if [ -f "$firmware_file" ] then - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" + # Extract the corresponding signature for the firmware file from the fetched checksums # + dl_sig="$(echo "$checksums" | grep "$(basename "$firmware_file")" | cut -d' ' -f1)" + if [ "$fw_sig" != "$dl_sig" ] + then + Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + if [ "$inMenuMode" = true ] + then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi + fi + else + Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!" + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ] + then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi fi ##----------------------------------------## @@ -5149,7 +4596,7 @@ Please manually update to version $minimum_supported_version or higher to use th if ! _WaitForYESorNO_ "Continue?" then Say "F/W Update was cancelled by user." - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + _DoCleanUp_ 1 "$keepZIPfile" return 1 fi fi @@ -5248,7 +4695,7 @@ Please manually update to version $minimum_supported_version or higher to use th 2. Update credentials by selecting \"Set Router Login Credentials\" from the Main Menu." _SendEMailNotification_ FAILED_FW_UPDATE_STATUS - _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" + _DoCleanUp_ 1 "$keepZIPfile" _EntwareServicesHandler_ start fi @@ -5650,8 +5097,7 @@ _ProcessMeshNodes_() } keepZIPfile=0 -keepWfile=0 -trap '_DoCleanUp_ 0 "$keepZIPfile" "$keepWfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM +trap '_DoCleanUp_ 0 "$keepZIPfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-28] ## @@ -6111,13 +5557,6 @@ _ShowMainMenu_() then notificationStr="${REDct}NOT SET${NOct}" else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}" fi - # Use the global variable - if "$isGNUtonFW" - then - FirmwareFlavor="${MAGENTAct}GNUton${NOct}" - else - FirmwareFlavor="${BLUEct}Merlin${NOct}" - fi printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] @@ -6128,7 +5567,6 @@ _ShowMainMenu_() fi printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide" printf "\n USB-Attached Storage Connected: $USBConnected" - printf "\n F/W Variant Configuration Found: $FirmwareFlavor" printf "\n F/W Version Currently Installed: $FW_InstalledVerStr" printf "\n F/W Update Version Available: $FW_NewUpdateVerStr" printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" @@ -6200,7 +5638,7 @@ _ShowMainMenu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## +## Modified by ExtremeFiretop [2024-Jun-03] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -6237,96 +5675,26 @@ _ShowAdvancedOptionsMenu_() fi fi - if "$isGNUtonFW" + if [ "$fwInstalledBaseVers" -le 3004 ] then - if [ "$fwInstalledBaseVers" -le 3004 ] - then - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "TUFBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="TUF Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" - else - current_build_type_menu="NOT SET" - fi - - if echo "$PRODUCT_ID" | grep -q "^TUF-" - then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menu" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" - fi - fi - elif [ "$fwInstalledBaseVers" -ge 3006 ] - then - # Retrieve the current build type setting - local current_build_typerog="$(Get_Custom_Setting "ROGBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_typerog" = "y" ]; then - current_build_type_menurog="ROG Build" - elif [ "$current_build_typerog" = "n" ]; then - current_build_type_menurog="Pure Build" - else - current_build_type_menurog="NOT SET" - fi - - if echo "$PRODUCT_ID" | grep -q "^GT-" - then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menurog" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menurog}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menurog}${NOct}]\n" - fi - fi - - # Retrieve the current build type setting - local current_build_typetuf="$(Get_Custom_Setting "TUFBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_typetuf" = "y" ]; then - current_build_type_menutuf="TUF Build" - elif [ "$current_build_typetuf" = "n" ]; then - current_build_type_menutuf="Pure Build" - else - current_build_type_menutuf="NOT SET" - fi + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="ROG Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi - if echo "$PRODUCT_ID" | grep -q "^TUF-" - then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menutuf" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menutuf}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menutuf}${NOct}]\n" - fi - fi - fi - else - if [ "$fwInstalledBaseVers" -le 3004 ] + if echo "$PRODUCT_ID" | grep -q "^GT-" then - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "ROGBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="ROG Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" - else - current_build_type_menu="NOT SET" - fi - - if echo "$PRODUCT_ID" | grep -q "^GT-" - then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menu" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" - fi + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" fi fi fi @@ -6464,12 +5832,7 @@ _AdvancedLogsOptions_() _InvalidMenuSelection_ fi ;; - cl) if "$isGNUtonFW" - then - _ManageChangelogGnuton_ "view" - else - _ManageChangelogMerlin_ "view" - fi + cl) _ManageChangelog_ "view" ;; e|exit) break ;; @@ -6480,7 +5843,7 @@ _AdvancedLogsOptions_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## +## Modified by ExtremeFiretop [2024-Jun-03] ## ##------------------------------------------## _advanced_options_menu_() { @@ -6493,7 +5856,7 @@ _advanced_options_menu_() case $advancedChoice in 1) _Set_FW_UpdateZIP_DirectoryPath_ ;; - 2) _Set_FW_UpdateCronSchedule_ + 2) _Set_FW_UpdateCronSchedule_ ;; 3) _Toggle_FW_UpdatesFromBeta_ ;; @@ -6502,14 +5865,9 @@ _advanced_options_menu_() else _InvalidMenuSelection_ fi ;; - bt) if echo "$PRODUCT_ID" | grep -q "^TUF-" - then _ChangeBuildType_TUF_ - elif [ "$fwInstalledBaseVers" -le 3004 ] && \ - echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_ROG_ - elif [ "$fwInstalledBaseVers" -ge 3006 ] && "$isGNUtonFW" && \ + bt) if [ "$fwInstalledBaseVers" -le 3004 ] && \ echo "$PRODUCT_ID" | grep -q "^GT-" - then _ChangeBuildType_ROG_ + then change_build_type else _InvalidMenuSelection_ fi ;; From fb58ec00d48ba937eecf859ab3c8662ea9d595d6 Mon Sep 17 00:00:00 2001 From: ExtremeFiretop Date: Thu, 20 Jun 2024 22:44:34 -0400 Subject: [PATCH 138/185] Revert "Update MerlinAU.sh" This reverts commit b3aa26fb12208d480bd5dedb5e4935c24a5b5c0d. --- MerlinAU.sh | 992 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 817 insertions(+), 175 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 17659e6c..e6de84dc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,11 +4,11 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-16 +# Last Modified: 2024-Jun-19 ################################################################### set -u -readonly SCRIPT_VERSION=1.2.3 +readonly SCRIPT_VERSION=1.3.0 readonly SCRIPT_NAME="MerlinAU" ##-------------------------------------## @@ -19,16 +19,17 @@ readonly SCRIPT_BRANCH="master" readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router/$SCRIPT_BRANCH" # Firmware URL Info # -readonly FW_URL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" -readonly FW_URL_RELEASE_SUFFIX="Release" +readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" +readonly FW_SFURL_RELEASE_SUFFIX="Release" +readonly FW_GITURL_RELEASE="https://api.github.com/repos/gnuton/asuswrt-merlin.ng/releases/latest" ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## # Changelog Info # -readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download" -readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download" -readonly CL_URL_3006="${FW_URL_BASE}/Documentation/Changelog-3006.txt/download" +readonly CL_URL_NG="${FW_SFURL_BASE}/Documentation/Changelog-NG.txt/download" +readonly CL_URL_386="${FW_SFURL_BASE}/Documentation/Changelog-386.txt/download" +readonly CL_URL_3006="${FW_SFURL_BASE}/Documentation/Changelog-3006.txt/download" readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended" @@ -405,6 +406,38 @@ _ScriptVersionStrToNum_() echo "$verNum" ; return 0 } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Jun-19] ## +##---------------------------------------## +_GetFirmwareVariantFromRouter_() +{ + ##DEFAULTS TO MERLIN## + local retCode=0 newVersionStr + + buildInfoStr="$(nvram get buildinfo)" + innerverStr="$(nvram get innerver)" + + ##FOR TESTING/DEBUG ONLY## + if false # Change to true for forcing GNUton flag + then + isGNUtonFW=true + else + # Check if innerver contains "gnuton" + if echo "$innerverStr" | grep -iq "gnuton" + then + isGNUtonFW=true + # if the version string contain "merlin" + elif echo "$buildInfoStr" | grep -iq "merlin" + then + isGNUtonFW=false + else + isGNUtonFW=false + fi + fi + + echo "$isGNUtonFW" ; return "$retCode" +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## @@ -493,7 +526,6 @@ readonly CRON_MONTH_NAMES="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)" readonly CRON_MONTH_RegEx="$CRON_MONTH_NAMES([\/,-]$CRON_MONTH_NAMES)*|([*1-9]|1[0-2])([\/,-]([1-9]|1[0-2]))*" readonly CRON_UNKNOWN_DATE="**ERROR**: UNKNOWN Date Found" - ##------------------------------------------## ## Modified by Martinski W. [2024-Jan-22] ## ##------------------------------------------## @@ -505,8 +537,12 @@ readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" readonly PRODUCT_ID="$(_GetRouterProductID_)" +##FOR TESTING/DEBUG ONLY## +#readonly PRODUCT_ID="TUF-AX3000_V2" +##FOR TESTING/DEBUG ONLY## readonly FW_FileName="${PRODUCT_ID}_firmware" -readonly FW_URL_RELEASE="${FW_URL_BASE}/${PRODUCT_ID}/${FW_URL_RELEASE_SUFFIX}/" +readonly FW_SFURL_RELEASE="${FW_SFURL_BASE}/${PRODUCT_ID}/${FW_SFURL_RELEASE_SUFFIX}/" +readonly isGNUtonFW=$(_GetFirmwareVariantFromRouter_) ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-21] ## @@ -561,6 +597,7 @@ ${REDct}v$SCRIPT_VERSION${NOct} --> ${GRNct}v$DLRepoVersion${NOct}" fi } + ##----------------------------------------## ## Modified by Martinski W. [2024-Jun-05] ## ##----------------------------------------## @@ -823,7 +860,8 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -895,7 +933,8 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -1159,6 +1198,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" echo "The directory path for the F/W ZIP file was updated successfully." + keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi return 0 @@ -1173,9 +1213,12 @@ _Init_Custom_Settings_Config_ # ROG upgrades to 3006 codebase should have # the ROG option deleted. #----------------------------------------------------------- -if [ "$fwInstalledBaseVers" -ge 3006 ] && grep -q "^ROGBuild" "$SETTINGSFILE" +if ! "$isGNUtonFW" then - Delete_Custom_Settings "ROGBuild" + if [ "$fwInstalledBaseVers" -ge 3006 ] && grep -q "^ROGBuild" "$SETTINGSFILE" + then + Delete_Custom_Settings "ROGBuild" + fi fi ##------------------------------------------## @@ -1314,8 +1357,8 @@ _CreateEMailContent_() fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - # Remove "_rog" suffix to avoid version comparison failures # - fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_rog$//')" + # Remove "_rog" or "_tuf" suffix to avoid version comparison failures + fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_\(rog\|tuf\)$//')" case "$1" in FW_UPDATE_TEST_EMAIL) @@ -1886,7 +1929,7 @@ _ShutDownNonCriticalServices_() ##------------------------------------------## _DoCleanUp_() { - local delBINfiles=false keepZIPfile=false moveZIPback=false + local delBINfiles=false keepZIPfile=false keepWfile=false local doTrace=false [ $# -gt 0 ] && [ "$1" -eq 0 ] && doTrace=false @@ -1898,20 +1941,35 @@ _DoCleanUp_() [ $# -gt 0 ] && [ "$1" -eq 1 ] && delBINfiles=true [ $# -gt 1 ] && [ "$2" -eq 1 ] && keepZIPfile=true + [ $# -gt 2 ] && [ "$3" -eq 1 ] && keepWfile=true # Stop the LEDs blinking # _Reset_LEDs_ 1 + # Check existence of files and preserve based on flags + local moveZIPback=false + local moveWback=false + # Move file temporarily to save it from deletion # - "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ] && \ - mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true + if "$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ]; then + mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true + fi + + if "$keepWfile" && [ -f "$FW_DL_FPATH" ]; then + mv -f "$FW_DL_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveWback=true + fi rm -f "${FW_ZIP_DIR}"/* "$delBINfiles" && rm -f "${FW_BIN_DIR}"/* - # Move file back to original location # - "$keepZIPfile" && "$moveZIPback" && \ - mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" + # Move files back to their original location if they were moved + if "$moveZIPback"; then + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.zip" "$FW_ZIP_FPATH" + fi + + if "$moveWback"; then + mv -f "${FW_ZIP_BASE_DIR}/${ScriptDirNameD}/${FW_FileName}.${extension}" "$FW_DL_FPATH" + fi if "$doTrace" then @@ -2015,7 +2073,7 @@ check_memory_and_prompt_reboot() # Restart Entware services # _EntwareServicesHandler_ start - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _DoExit_ 1 fi else @@ -2056,7 +2114,7 @@ check_version_support() check_model_support() { # List of unsupported models as a space-separated string - local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900" + local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900 DSL-AC68U" # Get the current model local current_model="$(_GetRouterProductID_)" @@ -2561,6 +2619,348 @@ _GetLatestFWUpdateVersionFromWebsite_() return 0 } +##---------------------------------------## +## Added by ExtremeFiretop [2024-Feb-23] ## +##---------------------------------------## +_GetLatestFWUpdateVersionFromGithub_() +{ + local url="$1" # GitHub API URL for the latest release + local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" + + local 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" = "pure" ]; then + search_type="pure\|squashfs\|ubi" + fi + + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + + # Construct the grep pattern based on search_type + local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\"" + + # Filter the JSON for the desired firmware using grep and head to fetch the URL + local download_url=$(echo "$release_data" | + grep -o "$grep_pattern" | + grep -o "https://[^ ]*\.\(w\|pkgtb\)" | + head -1) + + # Check if a URL was found + if [ -z "$download_url" ]; then + echo "**ERROR** **NO_GITHUB_URL**" + return 1 + else + # Extract the version from the download URL or release data + local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g") + echo "$version" + echo "$download_url" + return 0 + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-05] ## +##---------------------------------------## +GetLatestFirmwareMD5Url() { + local url="$1" # GitHub API URL for the latest release + local firmware_type="$2" # Type of firmware, e.g., "tuf", "rog" or "pure" + + local 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" = "pure" ]; then + search_type="pure\|squashfs\|ubi" + fi + + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + + # Construct the grep pattern based on search_type + local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.md5\"" + + # Filter the JSON for the desired firmware using grep and sed + local md5_url=$(echo "$release_data" | + grep -o "$grep_pattern" | + sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | + head -1) + + # Check if a URL was found and output result or error + if [ -z "$md5_url" ]; then + echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**" + return 1 + else + echo "$md5_url" + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-17] ## +##---------------------------------------## +GetLatestChangelogUrl() { + local url="$1" # GitHub API URL for the latest release + + # Fetch the latest release data from GitHub + local release_data=$(curl -s "$url") + + # Parse the release data to find the download URL of the CHANGELOG file + # Directly find the URL without matching a specific model number + local changelog_url=$(echo "$release_data" | grep -o "\"browser_download_url\": \".*CHANGELOG.*\"" | grep -o "https://[^ ]*\"" | tr -d '"' | head -1) + + # Check if the URL has been found + if [ -z "$changelog_url" ]; then + echo "**ERROR** **NO_CHANGELOG_FILE_URL_FOUND**" + return 1 + else + echo "$changelog_url" + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_DownloadForGnuton_() { + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$release_link") + + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + # Extract the file extension + extension="${sanitized_filename##*.}" + + # Combine path, custom file name, and extension before download + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + FW_MD5_GITHUB="${FW_ZIP_DIR}/${FW_FileName}.md5" + FW_Changelog_GITHUB="${FW_ZIP_DIR}/${FW_FileName}_Changelog.txt" + + # Download the firmware using the release link + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_DL_FPATH" "$release_link" + if [ ! -f "$FW_DL_FPATH" ]; then + return 1 + fi + + # Download the latest MD5 checksum + Say "Downloading latest MD5 checksum ${GRNct}${md5_url}${NOct}" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_MD5_GITHUB" "$md5_url" + if [ ! -f "$FW_MD5_GITHUB" ]; then + return 1 + fi + + # Download the latest changelog + Say "Downloading latest Changelog ${GRNct}${Gnuton_changelogurl}${NOct}" + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_Changelog_GITHUB" "$Gnuton_changelogurl" + if [ ! -f "$FW_Changelog_GITHUB" ]; then + return 1 + else + return 0 + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_DownloadForMerlin_() { + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_ZIP_FPATH" "$release_link" + + # Check if the file was downloaded successfully + if [ ! -f "$FW_ZIP_FPATH" ]; then + return 1 + else + return 0 + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_UnzipMerlin_() { + Say "-----------------------------------------------------------" + # List & log the contents of the ZIP file + unzip -l "$FW_ZIP_FPATH" 2>&1 | \ + while IFS= read -r uzLINE ; do Say "$uzLINE" ; done + Say "-----------------------------------------------------------" + + # Extracting the firmware binary image + if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ + while IFS= read -r line ; do Say "$line" ; done + then + Say "-----------------------------------------------------------" + #---------------------------------------------------------------# + # Check if ZIP file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# + if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # It's not on a USB drive, so it's safe to delete it + rm -f "$FW_ZIP_FPATH" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + -------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + return 1 + # Consider how to handle this error. For now, we'll not delete the ZIP file. + else + keepZIPfile=1 + fi + else + #------------------------------------------------------------# + # Remove ZIP file here because it may have been corrupted. + # Better to download it again and start all over, instead + # of trying to figure out why uncompressing it failed. + #------------------------------------------------------------# + rm -f "$FW_ZIP_FPATH" + _SendEMailNotification_ FAILED_FW_UNZIP_STATUS + Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." + _return 1 + fi + return 0 +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_CopyGnutonFiles_() { + +Say "Checking if file management is required" + +local copy_success=0 +local copy_attempted=1 + +# Check and copy the firmware file if different from destination +if [ "$FW_DL_FPATH" != "${FW_BIN_DIR}/${FW_FileName}.${extension}" ]; then + Say "File management is required" + copy_attempted=0 + cp "$FW_DL_FPATH" "$FW_BIN_DIR" && Say "Copying firmware file..." || copy_success=1 +else + Say "File management is not required" +fi + +# Check and copy the MD5 file if different from destination +if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then + copy_attempted=0 + mv -f "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Moving MD5 file..." || copy_success=1 +fi + +# Check and copy the Changelog file if different from destination +if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then + copy_attempted=0 + mv -f "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Moving changelog file..." || copy_success=1 +fi + +if [ $copy_attempted -eq 0 ] && [ $copy_success -eq 0 ] +then + #---------------------------------------------------------------# + # Check if Gntuon file was downloaded to a USB-attached drive. + # Take into account special case for Entware "/opt/" paths. + #---------------------------------------------------------------# + if ! echo "$FW_DL_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" + then + # It's not on a USB drive, so it's safe to delete it + rm -f "$FW_DL_FPATH" + rm -f "$FW_Changelog_GITHUB" + rm -f "$FW_MD5_GITHUB" + elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 + then + -------------------------------------------------------------# + # This should not happen because we already checked for it + # at the very beginning of this function, but just in case + # it does (drive going bad suddenly?) we'll report it here. + #-------------------------------------------------------------# + Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." + Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." + return 1 + # Consider how to handle this error. For now, we'll not delete the firmware file. + else + keepWfile=1 + fi +fi +return 0 +} + +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-05] ## +##----------------------------------------## +_CheckFirmwareSHA256_() { + # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # + checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" + + if [ -z "$checksums" ] + then + Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website." + _DoCleanUp_ 1 + if [ "$inMenuMode" = true ] + then + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + # Assume non-interactive mode; perform exit. + _DoExit_ 1 + fi + fi + + if [ -f "$firmware_file" ] + then + fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" + # Extract the corresponding signature for the firmware file from the fetched checksums # + dl_sig="$(echo "$checksums" | grep "$(basename "$firmware_file")" | cut -d' ' -f1)" + if [ "$fw_sig" != "$dl_sig" ] + then + Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + return 1 + fi + else + Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!" + _DoCleanUp_ 1 + return 1 + fi +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Apr-18] ## +##---------------------------------------## +_CheckFirmwareMD5_() { + # Check if both the MD5 checksum file and the firmware file exist + if [ -f "${FW_BIN_DIR}/${FW_FileName}.md5" ] && [ -f "$firmware_file" ]; then + # Extract the MD5 checksum from the downloaded .md5 file + # Assuming the .md5 file contains a single line with the checksum followed by the filename + local md5_expected=$(cut -d' ' -f1 "${FW_BIN_DIR}/${FW_FileName}.md5") + + # Calculate the MD5 checksum of the firmware file + local md5_actual=$(md5sum "$firmware_file" | cut -d' ' -f1) + + # Compare the calculated MD5 checksum with the expected MD5 checksum + if [ "$md5_actual" != "$md5_expected" ]; then + Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the MD5 checksum!" + _DoCleanUp_ 1 + _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS + return 1 + else + Say "Firmware MD5 checksum verified successfully." + fi + else + Say "${REDct}**ERROR**${NOct}: MD5 checksum file not found or firmware file is missing!" + _DoCleanUp_ 1 + return 1 + fi +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-27] ## ##----------------------------------------## @@ -2664,7 +3064,67 @@ _Toggle_Auto_Backups_() ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Feb-18] ## ##------------------------------------------## -change_build_type() +_ChangeBuildType_TUF_() +{ + local doReturnToMenu buildtypechoice + printf "Changing Flash Build Type...\n" + + # Use Get_Custom_Setting to retrieve the previous choice + previous_choice="$(Get_Custom_Setting "TUFBuild")" + + # If the previous choice is not set, default to 'n' + if [ "$previous_choice" = "TBD" ]; then + previous_choice="n" + fi + + # Convert previous choice to a descriptive text + if [ "$previous_choice" = "y" ]; then + display_choice="TUF Build" + else + display_choice="Pure Build" + fi + + printf "\nCurrent Build Type: ${GRNct}$display_choice${NOct}.\n" + + doReturnToMenu=false + while true + do + printf "\n${SEPstr}" + printf "\nChoose your preferred option for the build type to flash:\n" + printf "\n ${GRNct}1${NOct}. Original ${REDct}TUF${NOct} themed user interface${NOct}\n" + printf "\n ${GRNct}2${NOct}. Pure ${GRNct}non-TUF${NOct} themed user interface ${GRNct}(Recommended)${NOct}\n" + printf "\n ${GRNct}e${NOct}. Exit to Advanced Menu\n" + printf "${SEPstr}\n" + printf "[$display_choice] Enter selection: " + read -r choice + + [ -z "$choice" ] && break + + if echo "$choice" | grep -qE "^(e|exit|Exit)$" + then doReturnToMenu=true ; break ; fi + + case $choice in + 1) buildtypechoice="y" ; break + ;; + 2) buildtypechoice="n" ; break + ;; + *) echo ; _InvalidMenuSelection_ + ;; + esac + done + + "$doReturnToMenu" && return 0 + + Update_Custom_Settings "TUFBuild" "$buildtypechoice" + printf "\nThe build type to flash was updated successfully.\n" + + _WaitForEnterKey_ "$advnMenuReturnPromptStr" +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Feb-18] ## +##------------------------------------------## +_ChangeBuildType_ROG_() { local doReturnToMenu buildtypechoice printf "Changing Flash Build Type...\n" @@ -3610,21 +4070,31 @@ _ChangelogVerificationCheck_() current_version="$(_GetCurrentFWInstalledLongVersion_)" release_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" - # Get the correct Changelog filename: "Changelog-[3006|386|NG].txt" # - if echo "$release_version" | grep -qE "^3006[.]" + if "$isGNUtonFW" then - changeLogTag="3006" - elif echo "$release_version" | grep -q "386[.]" - then - changeLogTag="386" + changeLogFile="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" else - changeLogTag="NG" + # Get the correct Changelog filename: "Changelog-[3006|386|NG].txt" # + if echo "$release_version" | grep -qE "^3006[.]" + then + changeLogTag="3006" + elif echo "$release_version" | grep -q "386[.]" + then + changeLogTag="386" + else + changeLogTag="NG" + fi + changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" fi - changeLogFile="$(/usr/bin/find -L "${FW_BIN_DIR}" -name "Changelog-${changeLogTag}.txt" -print)" if [ ! -f "$changeLogFile" ] then - Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + if "$isGNUtonFW" + then + Say "Changelog file [${FW_BIN_DIR}/${FW_FileName}_Changelog.txt] does NOT exist." + else + Say "Changelog file [${FW_BIN_DIR}/Changelog-${changeLogTag}.txt] does NOT exist." + fi _DoCleanUp_ return 1 else @@ -3665,16 +4135,20 @@ _ChangelogVerificationCheck_() release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)" - # Check if the current version is present in the changelog - if ! grep -Eq "$current_version_regex" "$changeLogFile" + if "$isGNUtonFW" then - Say "Current version NOT found in changelog file. Bypassing changelog verification for this run." - return 0 + # For Gnuton, the whole file is relevant as it only contains the current version # + changelog_contents="$(cat "$changeLogFile")" + else + if ! grep -Eq "$current_version_regex" "$changeLogFile"; then + Say "Current version NOT found in changelog file. Bypassing changelog verification for this run." + return 0 + else + # Extract log contents between two firmware versions for non-Gnuton changelogs # + changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" + fi fi - # Extract log contents between two firmware versions - changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")" - if [ "$mode" = "interactive" ] then if _high_risk_phrases_interactive_ "$changelog_contents" @@ -3697,7 +4171,7 @@ _ChangelogVerificationCheck_() ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## -_ManageChangelog_() +_ManageChangelogMerlin_() { if [ $# -eq 0 ] || [ -z "$1" ] then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi @@ -3773,6 +4247,59 @@ _ManageChangelog_() return 0 } +_ManageChangelogGnuton_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] + then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi + + local mode="$1" # Mode should be 'download' or 'view' # + local newUpdateVerStr="" + local wgetLogFile changeLogFile changeLogTag changeLogURL + + # Create directory to download changelog if missing + if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi + + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + + # Follow redirects and capture the effective URL + local effective_url=$(curl -Ls -o /dev/null -w %{url_effective} "$Gnuton_changelogurl") + + # Use the effective URL to capture the Content-Disposition header + local original_filename=$(curl -sI "$effective_url" | grep -i content-disposition | sed -n 's/.*filename=["]*\([^";]*\).*/\1/p') + + # Sanitize filename by removing problematic characters + local sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + + FW_Changelog_GITHUB="${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" + + wgetLogFile="${FW_BIN_DIR}/${ScriptFNameTag}.WGET.LOG" + printf "\nRetrieving ${GRNct}${FW_Changelog_GITHUB}${NOct} ...\n" + + wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ + -O "$FW_Changelog_GITHUB" -o "$wgetLogFile" "${Gnuton_changelogurl}" + + if [ ! -f "$FW_Changelog_GITHUB" ] + then + Say "Changelog file [$FW_Changelog_GITHUB] does NOT exist." + echo ; [ -f "$wgetLogFile" ] && cat "$wgetLogFile" + else + if [ "$mode" = "download" ] + then + _ChangelogVerificationCheck_ "auto" + elif [ "$mode" = "view" ] + then + clear + printf "\n${GRNct}Changelog file is ready to review!${NOct}\n" + printf "\nPress '${REDct}q${NOct}' to quit when finished.\n" + dos2unix "$FW_Changelog_GITHUB" + _WaitForEnterKey_ + less "$FW_Changelog_GITHUB" + fi + fi + rm -f "$FW_Changelog_GITHUB" "$wgetLogFile" + return 1 +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## @@ -3815,7 +4342,12 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - _ManageChangelog_ "download" "$fwNewUpdateNotificationVers" + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" + else + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + fi fi fi @@ -3828,7 +4360,12 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - _ManageChangelog_ "download" "$fwNewUpdateNotificationVers" + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" + else + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + fi fi fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" @@ -4216,18 +4753,96 @@ Please manually update to version $minimum_supported_version or higher to use th return 1 fi - # Use set to read the output of the function into variables - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") - if [ $? -eq 0 ] && [ $# -eq 2 ] && \ + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apr-18] ## + ##------------------------------------------## + if "$isGNUtonFW" + then + Say "Using release information for Gnuton Firmware." + # Check if PRODUCT_ID is for a TUF model and requires user choice + if echo "$PRODUCT_ID" | grep -q "^TUF-"; then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "TUFBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found TUF build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the TUF build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + Update_Custom_Settings "TUFBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + elif echo "$PRODUCT_ID" | grep -q "^GT-" + then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "ROGBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found ROG build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the ROG build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + Update_Custom_Settings "ROGBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi + else + # If not a TUF model, process as usual + firmware_choice="pure" + fi + md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE" "$firmware_choice") + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") + retCode="$?" + else + Say "Using release information for Merlin Firmware." + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + retCode="$?" + fi + + if [ "$retCode" -eq 0 ] && [ "$#" -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] - then + then release_version="$1" release_link="$2" - else + else Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 - fi + fi # Extracting the F/W Update codebase number to use in the curl # fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)" @@ -4352,22 +4967,27 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Downloading ${GRNct}${release_link}${NOct}" echo - ##----------------------------------------## - ## Modified by Martinski W. [2024-Feb-28] ## - ##----------------------------------------## + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apl-24] ## + ##------------------------------------------## # Avoid error message about HSTS database # wgetHstsFile="/tmp/home/root/.wget-hsts" [ -f "$wgetHstsFile" ] && chmod 0644 "$wgetHstsFile" - wget --timeout=5 --tries=4 --waitretry=5 --retry-connrefused \ - -O "$FW_ZIP_FPATH" "$release_link" - fi - - if [ ! -f "$FW_ZIP_FPATH" ] - then - Say "${REDct}**ERROR**${NOct}: Firmware ZIP file [$FW_ZIP_FPATH] was not downloaded." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if "$isGNUtonFW" + then + _DownloadForGnuton_ + retCode="$?" + else + _DownloadForMerlin_ + retCode="$?" + fi + if [ "$retCode" -eq 1 ] + then + Say "${REDct}**ERROR**${NOct}: Firmware files were not downloaded successfully." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi fi ##------------------------------------------## @@ -4379,50 +4999,18 @@ Please manually update to version $minimum_supported_version or higher to use th check_memory_and_prompt_reboot "$requiredRAM_kb" "$availableRAM_kb" ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Mar-19] ## + ## Modified by ExtremeFiretop [2024-Apr-21] ## ##------------------------------------------## - Say "-----------------------------------------------------------" - # List & log the contents of the ZIP file # - unzip -l "$FW_ZIP_FPATH" 2>&1 | \ - while IFS= read -r uzLINE ; do Say "$uzLINE" ; done - Say "-----------------------------------------------------------" - - # Extracting the firmware binary image # - if unzip -o "$FW_ZIP_FPATH" -d "$FW_BIN_DIR" -x README* 2>&1 | \ - while IFS= read -r line ; do Say "$line" ; done + if "$isGNUtonFW" then - Say "-----------------------------------------------------------" - #---------------------------------------------------------------# - # Check if ZIP file was downloaded to a USB-attached drive. - # Take into account special case for Entware "/opt/" paths. - #---------------------------------------------------------------# - if ! echo "$FW_ZIP_FPATH" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" - then - # It's not on a USB drive, so it's safe to delete it # - rm -f "$FW_ZIP_FPATH" - elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 - then - #-------------------------------------------------------------# - # This should not happen because we already checked for it - # at the very beginning of this function, but just in case - # it does (drive going bad suddenly?) we'll report it here. - #-------------------------------------------------------------# - Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." - Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ - # Consider how to handle this error. For now, we'll not delete the ZIP file. - else - keepZIPfile=1 - fi + _CopyGnutonFiles_ + retCode="$?" else - #------------------------------------------------------------# - # Remove ZIP file here because it may have been corrupted. - # Better to download it again and start all over, instead - # of trying to figure out why uncompressing it failed. - #------------------------------------------------------------# - rm -f "$FW_ZIP_FPATH" - _SendEMailNotification_ FAILED_FW_UNZIP_STATUS - Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]." + _UnzipMerlin_ + retCode="$?" + fi + if [ "$retCode" -eq 1 ] + then "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi @@ -4525,56 +5113,21 @@ Please manually update to version $minimum_supported_version or higher to use th firmware_file="$pure_file" fi - ##----------------------------------------## - ## Modified by Martinski W. [2024-Jun-05] ## - ##----------------------------------------## - # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # - checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" - - if [ -z "$checksums" ] + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apr-25] ## + ##------------------------------------------## + if "$isGNUtonFW" then - Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website." - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ] - then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi + _CheckFirmwareMD5_ + retCode="$?" + else + _CheckFirmwareSHA256_ + retCode="$?" fi - - if [ -f "$firmware_file" ] + if [ "$retCode" -eq 1 ] then - fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)" - # Extract the corresponding signature for the firmware file from the fetched checksums # - dl_sig="$(echo "$checksums" | grep "$(basename "$firmware_file")" | cut -d' ' -f1)" - if [ "$fw_sig" != "$dl_sig" ] - then - Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website." - _DoCleanUp_ 1 - _SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS - if [ "$inMenuMode" = true ] - then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi - fi - else - Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!" - _DoCleanUp_ 1 - if [ "$inMenuMode" = true ] - then - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - # Assume non-interactive mode; perform exit. - _DoExit_ 1 - fi + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 fi ##----------------------------------------## @@ -4596,7 +5149,7 @@ Please manually update to version $minimum_supported_version or higher to use th if ! _WaitForYESorNO_ "Continue?" then Say "F/W Update was cancelled by user." - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" return 1 fi fi @@ -4695,7 +5248,7 @@ Please manually update to version $minimum_supported_version or higher to use th 2. Update credentials by selecting \"Set Router Login Credentials\" from the Main Menu." _SendEMailNotification_ FAILED_FW_UPDATE_STATUS - _DoCleanUp_ 1 "$keepZIPfile" + _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _EntwareServicesHandler_ start fi @@ -5097,7 +5650,8 @@ _ProcessMeshNodes_() } keepZIPfile=0 -trap '_DoCleanUp_ 0 "$keepZIPfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM +keepWfile=0 +trap '_DoCleanUp_ 0 "$keepZIPfile" "$keepWfile" ; _DoExit_ 0' HUP INT QUIT ABRT TERM ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-28] ## @@ -5557,6 +6111,13 @@ _ShowMainMenu_() then notificationStr="${REDct}NOT SET${NOct}" else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}" fi + # Use the global variable + if "$isGNUtonFW" + then + FirmwareFlavor="${MAGENTAct}GNUton${NOct}" + else + FirmwareFlavor="${BLUEct}Merlin${NOct}" + fi printf "${SEPstr}" if [ "$HIDE_ROUTER_SECTION" = "false" ] @@ -5567,6 +6128,7 @@ _ShowMainMenu_() fi printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide" printf "\n USB-Attached Storage Connected: $USBConnected" + printf "\n F/W Variant Configuration Found: $FirmwareFlavor" printf "\n F/W Version Currently Installed: $FW_InstalledVerStr" printf "\n F/W Update Version Available: $FW_NewUpdateVerStr" printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime" @@ -5638,7 +6200,7 @@ _ShowMainMenu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -5675,26 +6237,96 @@ _ShowAdvancedOptionsMenu_() fi fi - if [ "$fwInstalledBaseVers" -le 3004 ] + if "$isGNUtonFW" then - # Retrieve the current build type setting - local current_build_type="$(Get_Custom_Setting "ROGBuild")" - - # Convert the setting to a descriptive text - if [ "$current_build_type" = "y" ]; then - current_build_type_menu="ROG Build" - elif [ "$current_build_type" = "n" ]; then - current_build_type_menu="Pure Build" - else - current_build_type_menu="NOT SET" - fi + if [ "$fwInstalledBaseVers" -le 3004 ] + then + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "TUFBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="TUF Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi + + if echo "$PRODUCT_ID" | grep -q "^TUF-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + fi + fi + elif [ "$fwInstalledBaseVers" -ge 3006 ] + then + # Retrieve the current build type setting + local current_build_typerog="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_typerog" = "y" ]; then + current_build_type_menurog="ROG Build" + elif [ "$current_build_typerog" = "n" ]; then + current_build_type_menurog="Pure Build" + else + current_build_type_menurog="NOT SET" + fi + + if echo "$PRODUCT_ID" | grep -q "^GT-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menurog" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menurog}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menurog}${NOct}]\n" + fi + fi + + # Retrieve the current build type setting + local current_build_typetuf="$(Get_Custom_Setting "TUFBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_typetuf" = "y" ]; then + current_build_type_menutuf="TUF Build" + elif [ "$current_build_typetuf" = "n" ]; then + current_build_type_menutuf="Pure Build" + else + current_build_type_menutuf="NOT SET" + fi - if echo "$PRODUCT_ID" | grep -q "^GT-" + if echo "$PRODUCT_ID" | grep -q "^TUF-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menutuf" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menutuf}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menutuf}${NOct}]\n" + fi + fi + fi + else + if [ "$fwInstalledBaseVers" -le 3004 ] then - printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" - if [ "$current_build_type_menu" = "NOT SET" ] - then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" - else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + # Retrieve the current build type setting + local current_build_type="$(Get_Custom_Setting "ROGBuild")" + + # Convert the setting to a descriptive text + if [ "$current_build_type" = "y" ]; then + current_build_type_menu="ROG Build" + elif [ "$current_build_type" = "n" ]; then + current_build_type_menu="Pure Build" + else + current_build_type_menu="NOT SET" + fi + + if echo "$PRODUCT_ID" | grep -q "^GT-" + then + printf "\n ${GRNct}bt${NOct}. Toggle F/W Build Type" + if [ "$current_build_type_menu" = "NOT SET" ] + then printf "\n${padStr}[Current Build Type: ${REDct}${current_build_type_menu}${NOct}]\n" + else printf "\n${padStr}[Current Build Type: ${GRNct}${current_build_type_menu}${NOct}]\n" + fi fi fi fi @@ -5832,7 +6464,12 @@ _AdvancedLogsOptions_() _InvalidMenuSelection_ fi ;; - cl) _ManageChangelog_ "view" + cl) if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "view" + else + _ManageChangelogMerlin_ "view" + fi ;; e|exit) break ;; @@ -5843,7 +6480,7 @@ _AdvancedLogsOptions_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-03] ## +## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## _advanced_options_menu_() { @@ -5856,7 +6493,7 @@ _advanced_options_menu_() case $advancedChoice in 1) _Set_FW_UpdateZIP_DirectoryPath_ ;; - 2) _Set_FW_UpdateCronSchedule_ + 2) _Set_FW_UpdateCronSchedule_ ;; 3) _Toggle_FW_UpdatesFromBeta_ ;; @@ -5865,9 +6502,14 @@ _advanced_options_menu_() else _InvalidMenuSelection_ fi ;; - bt) if [ "$fwInstalledBaseVers" -le 3004 ] && \ + bt) if echo "$PRODUCT_ID" | grep -q "^TUF-" + then _ChangeBuildType_TUF_ + elif [ "$fwInstalledBaseVers" -le 3004 ] && \ + echo "$PRODUCT_ID" | grep -q "^GT-" + then _ChangeBuildType_ROG_ + elif [ "$fwInstalledBaseVers" -ge 3006 ] && "$isGNUtonFW" && \ echo "$PRODUCT_ID" | grep -q "^GT-" - then change_build_type + then _ChangeBuildType_ROG_ else _InvalidMenuSelection_ fi ;; From d404d679aba3383ba78f74a876725a690f8c207c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 20 Jun 2024 22:44:50 -0400 Subject: [PATCH 139/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e6de84dc..7b8a18a9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2805,7 +2805,7 @@ _UnzipMerlin_() { rm -f "$FW_ZIP_FPATH" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then - -------------------------------------------------------------# + #-------------------------------------------------------------# # This should not happen because we already checked for it # at the very beginning of this function, but just in case # it does (drive going bad suddenly?) we'll report it here. @@ -2876,7 +2876,7 @@ then rm -f "$FW_MD5_GITHUB" elif ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then - -------------------------------------------------------------# + #-------------------------------------------------------------# # This should not happen because we already checked for it # at the very beginning of this function, but just in case # it does (drive going bad suddenly?) we'll report it here. From f8a345d913fd8648cdd59fe4c1ab69f16f086eb6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 20 Jun 2024 23:07:12 -0400 Subject: [PATCH 140/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 7b8a18a9..c0b82821 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2652,7 +2652,7 @@ _GetLatestFWUpdateVersionFromGithub_() return 1 else # Extract the version from the download URL or release data - local version=$(echo "$download_url" | grep -oE "$PRODUCT_ID[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g") + local version=$(echo "$download_url" | grep -oE "${PRODUCT_ID}[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g") echo "$version" echo "$download_url" return 0 From 721a7a94d7fdafb7238185fbee479ebbbc5dcbda Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 21 Jun 2024 03:41:28 -0400 Subject: [PATCH 141/185] Update MerlinAU.sh --- MerlinAU.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c0b82821..f7ae8389 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -422,8 +422,9 @@ _GetFirmwareVariantFromRouter_() then isGNUtonFW=true else - # Check if innerver contains "gnuton" - if echo "$innerverStr" | grep -iq "gnuton" + # Check if innerver and fwInstalledExtendNum contains "gnuton" + if echo "$innerverStr" | grep -iq "gnuton" || \ + echo "$fwInstalledExtendNum" | grep -iq "gnuton" then isGNUtonFW=true # if the version string contain "merlin" @@ -1796,7 +1797,7 @@ _GetCurrentFWInstalledLongVersion_() { ##FOR TESTING/DEBUG ONLY## -if false ; then echo "3004.388.6.2" ; return 0 ; fi +if true ; then echo "3004.388.6.2" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum From f3a671045632bd21da036ac50719ffc5bdfb9d19 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 21 Jun 2024 03:42:06 -0400 Subject: [PATCH 142/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f7ae8389..9e68b1b2 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1797,7 +1797,7 @@ _GetCurrentFWInstalledLongVersion_() { ##FOR TESTING/DEBUG ONLY## -if true ; then echo "3004.388.6.2" ; return 0 ; fi +if false ; then echo "3004.388.6.2" ; return 0 ; fi ##FOR TESTING/DEBUG ONLY## local theVersionStr extVersNum From 55154e7d903a2f01b266165d251bd206e329579c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 24 Jun 2024 09:49:28 -0400 Subject: [PATCH 143/185] Update MerlinAU.sh --- MerlinAU.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9e68b1b2..cad5e68b 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-19 +# Last Modified: 2024-Jun-24 ################################################################### set -u @@ -94,6 +94,7 @@ fi ##----------------------------------------## inMenuMode=true isInteractive=false +FlashStarted=false readonly mainLAN_IPaddr="$(nvram get lan_ipaddr)" readonly fwInstalledBaseVers="$(nvram get firmver | sed 's/\.//g')" @@ -4343,11 +4344,14 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - if "$isGNUtonFW" + if ! "$FlashStarted" then - _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" - else - _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" + else + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + fi fi fi fi @@ -4361,11 +4365,14 @@ _CheckNewUpdateFirmwareNotification_() then _SendEMailNotification_ NEW_FW_UPDATE_STATUS fi - if "$isGNUtonFW" + if ! "$FlashStarted" then - _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" - else - _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + if "$isGNUtonFW" + then + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" + else + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + fi fi fi @@ -4679,6 +4686,7 @@ Please manually update to version $minimum_supported_version or higher to use th Say "${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" Say "Running the update task now... Checking for F/W updates..." + FlashStarted=true #---------------------------------------------------------------# # Check if an expected USB-attached drive is still mounted. From adff3cc0c5ae7964411674e00febef14fe224888 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 26 Jun 2024 10:56:03 -0400 Subject: [PATCH 144/185] Update MerlinAU.sh --- MerlinAU.sh | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index cad5e68b..c643dc6a 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-24 +# Last Modified: 2024-Jun-26 ################################################################### set -u @@ -4600,9 +4600,9 @@ _Toggle_FW_UpdateCheckSetting_() _WaitForEnterKey_ "$mainMenuReturnPromptStr" } -##----------------------------------------## -## Modified by Martinski W. [2024-Jun-16] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jun-26] ## +##------------------------------------------## _EntwareServicesHandler_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi @@ -4610,6 +4610,7 @@ _EntwareServicesHandler_() local actionStr="" divAction="" local serviceStr serviceCnt=0 local entwOPT_init entwOPT_unslung + local skipServices="tailscale" # space " " separated list # case "$1" in stop) actionStr="Stopping" ; divAction="unmount" ;; @@ -4631,6 +4632,15 @@ _EntwareServicesHandler_() then return 0 ; fi ## Entware is NOT found ## serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")" + + # Filter out services to skip and add a skip message + for skipService in $skipServices; do + if echo "$serviceStr" | /bin/grep -q "$skipService"; then + Say "Skipping $skipService $actionStr..." + fi + serviceStr=$(echo "$serviceStr" | /bin/grep -v "$skipService") + done + [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" [ "$serviceCnt" -eq 0 ] && return 0 @@ -4641,8 +4651,22 @@ _EntwareServicesHandler_() echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done Say "-----------------------------------------------------------" - $entwOPT_unslung "$1" ; sleep 5 - "$isInteractive" && printf "\nDone.\n" + # Stop or start each service individually + echo "$serviceStr" | while IFS= read -r servLine; do + serviceName=$(basename "$servLine") + if [ "$1" = "stop" ]; then + Say "Stopping $serviceName..." + "$servLine" stop + sleep 1 + else + Say "Starting $serviceName..." + "$servLine" start + sleep 1 + fi + done + + "$isInteractive" && printf "\nDone.\n" + sleep 5 } ##----------------------------------------## From 82636719a0dde806ea3a0658fd8df2fcd3ede085 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 26 Jun 2024 11:00:04 -0400 Subject: [PATCH 145/185] Update MerlinAU.sh --- MerlinAU.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index c643dc6a..798db39d 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -266,12 +266,12 @@ FW_UpdateCheckScript="/usr/sbin/webs_update.sh" #---------------------------------------------------------# _GetDefaultUSBMountPoint_() { - local mounPointPath retCode=0 + local mountPointPath retCode=0 local mountPointRegExp="^/dev/sd.* /tmp/mnt/.*" - mounPointPath="$(grep -m1 "$mountPointRegExp" /proc/mounts | awk -F ' ' '{print $2}')" - [ -z "$mounPointPath" ] && retCode=1 - echo "$mounPointPath" ; return "$retCode" + mountPointPath="$(grep -m1 "$mountPointRegExp" /proc/mounts | awk -F ' ' '{print $2}')" + [ -z "$mountPointPath" ] && retCode=1 + echo "$mountPointPath" ; return "$retCode" } ##----------------------------------------## @@ -1121,7 +1121,7 @@ _Set_FW_UpdateLOG_DirectoryPath_() # Move any existing log files to new directory # mv -f "${FW_LOG_DIR}"/*.log "$newLogFileDirPath" 2>/dev/null # Remove now the obsolete directory path # - rm -fr "$FW_LOG_DIR" + rm -fr "${FW_LOG_DIR:?}" # Update the log directory path after validation # Update_Custom_Settings FW_New_Update_LOG_Directory_Path "$newLogBaseDirPath" Update_Custom_Settings FW_New_Update_LOG_Preferred_Path "$newLogBaseDirPath" @@ -1196,7 +1196,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() return 1 fi # Remove now the obsolete directory path # - rm -fr "$FW_ZIP_DIR" + rm -fr "${FW_LOG_DIR:?}" rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" echo "The directory path for the F/W ZIP file was updated successfully." @@ -1318,7 +1318,7 @@ if echo "$UserPreferredLogPath" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" && \ [ "$UserPreferredLogPath" != "$FW_LOG_BASE_DIR" ] then mv -f "${FW_LOG_DIR}"/*.log "${UserPreferredLogPath}/$FW_LOG_SUBDIR" 2>/dev/null - rm -fr "$FW_LOG_DIR" + rm -fr "${FW_LOG_DIR:?}" Update_Custom_Settings FW_New_Update_LOG_Directory_Path "$UserPreferredLogPath" fi @@ -1961,8 +1961,8 @@ _DoCleanUp_() mv -f "$FW_DL_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveWback=true fi - rm -f "${FW_ZIP_DIR}"/* - "$delBINfiles" && rm -f "${FW_BIN_DIR}"/* + rm -f "${FW_ZIP_DIR:?}"/* + "$delBINfiles" && rm -f "${FW_BIN_DIR:?}"/* # Move files back to their original location if they were moved if "$moveZIPback"; then @@ -2502,7 +2502,9 @@ _GetNodeInfo_() --cookie-jar '/tmp/nodecookies.txt' \ --max-time 2 > /tmp/login_response.txt 2>&1 - if [ $? -ne 0 ]; then + if [ $? -ne 0 ] + then + printf "\n${REDct}Login failed for AiMesh Node [$NodeIP_Address].${NOct}\n" return 1 fi @@ -2518,7 +2520,9 @@ _GetNodeInfo_() --cookie '/tmp/nodecookies.txt' \ --max-time 2 2>&1)" - if [ $? -ne 0 ]; then + if [ $? -ne 0 ] + then + printf "\n${REDct}Failed to get information for AiMesh Node [$NodeIP_Address].${NOct}\n" return 1 fi @@ -6599,6 +6603,7 @@ do fi ;; 1) _RunFirmwareUpdateNow_ + FlashStarted=false ;; 2) _GetLoginCredentials_ ;; From 1c62b1ad4a5680b0b0198b445eca754032746b33 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 26 Jun 2024 11:02:55 -0400 Subject: [PATCH 146/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 798db39d..cfb30f38 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2520,7 +2520,7 @@ _GetNodeInfo_() --cookie '/tmp/nodecookies.txt' \ --max-time 2 2>&1)" - if [ $? -ne 0 ] + if [ $? -ne 0 ] || [ -z "$htmlContent" ] then printf "\n${REDct}Failed to get information for AiMesh Node [$NodeIP_Address].${NOct}\n" return 1 From b700ccc2bce89442981f5ab6659333bec05f770f Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 27 Jun 2024 10:10:14 -0400 Subject: [PATCH 147/185] Update MerlinAU.sh --- MerlinAU.sh | 140 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 103 insertions(+), 37 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index cfb30f38..0c4a8a4a 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-26 +# Last Modified: 2024-Jun-27 ################################################################### set -u @@ -751,7 +751,7 @@ else fi ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## _Init_Custom_Settings_Config_() { @@ -772,6 +772,7 @@ _Init_Custom_Settings_Config_() echo "FW_New_Update_EMail_CC_Name=TBD" echo "FW_New_Update_EMail_CC_Address=TBD" echo "CheckChangeLog ENABLED" + echo "Allow_Updates_OverVPN DISABLED" echo "FW_New_Update_Changelog_Approval=TBD" echo "FW_Allow_Beta_Production_Up ENABLED" echo "FW_Auto_Backupmon ENABLED" @@ -831,6 +832,11 @@ _Init_Custom_Settings_Config_() sed -i "10 i CheckChangeLog ENABLED" "$SETTINGSFILE" retCode=1 fi + if ! grep -q "^Allow_Updates_OverVPN " "$SETTINGSFILE" + then + sed -i "10 i Allow_Updates_OverVPN DISABLED" "$SETTINGSFILE" + retCode=1 + fi if ! grep -q "^FW_Allow_Beta_Production_Up " "$SETTINGSFILE" then sed -i "11 i FW_Allow_Beta_Production_Up ENABLED" "$SETTINGSFILE" @@ -850,7 +856,7 @@ _Init_Custom_Settings_Config_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-06] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## Get_Custom_Setting() { @@ -862,8 +868,8 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "Allow_Updates_OverVPN" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -922,7 +928,7 @@ _GetAllNodeSettings_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-06] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## Update_Custom_Settings() { @@ -935,8 +941,8 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "TUFBuild" | "credentials_base64" | \ - "CheckChangeLog" | \ + "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "Allow_Updates_OverVPN" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ "FW_New_Update_Notification_Date" | \ @@ -3001,6 +3007,41 @@ _toggle_change_log_check_() _WaitForEnterKey_ } +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jun-27] ## +##------------------------------------------## +_Toggle_VPN_Access_() +{ + local currentSetting="$(Get_Custom_Setting "Allow_Updates_OverVPN")" + + if [ "$currentSetting" = "ENABLED" ] + then + printf "${REDct}*WARNING*${NOct}\n" + printf "Disabling this feature means MerlinAU will shutdown Wireguard and Tailscale VPN access while updating.\n" + printf "The advice is to proceed only if you do not require the VPN access to stay alive while updating.\n" + + if _WaitForYESorNO_ "\nProceed to ${REDct}DISABLE${NOct}?" + then + Update_Custom_Settings "Allow_Updates_OverVPN" "DISABLED" + printf "VPN Access will now be ${REDct}DISABLED.${NOct}\n" + else + printf "VPN Access while updating remains ${GRNct}ENABLED.${NOct}\n" + fi + else + printf "${REDct}*WARNING*${NOct}\n" + printf "Enabling this feature means MerlinAU will keep Wireguard and Tailscale VPN access alive while updating.\n" + printf "The advice is to proceed only if you do require the VPN access to stay alive while updating.\n" + if _WaitForYESorNO_ "\nProceed to ${GRNct}ENABLE${NOct}?" + then + Update_Custom_Settings "Allow_Updates_OverVPN" "ENABLED" + printf "VPN Access will now be ${GRNct}ENABLED.${NOct}\n" + else + printf "VPN Access while updating remains ${REDct}DISABLED.${NOct}\n" + fi + fi + _WaitForEnterKey_ +} + ##----------------------------------------## ## Modified by Martinski W. [2024-May-27] ## ##----------------------------------------## @@ -4605,11 +4646,12 @@ _Toggle_FW_UpdateCheckSetting_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-26] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## _EntwareServicesHandler_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi + AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" local actionStr="" divAction="" local serviceStr serviceCnt=0 @@ -4622,11 +4664,14 @@ _EntwareServicesHandler_() *) return 1 ;; esac - if [ -f /opt/bin/diversion ] + if [ "$AllowVPN" = "DISABLED" ] then - Say "${actionStr} Diversion service..." - /opt/bin/diversion "$divAction" & - sleep 3 + if [ -f /opt/bin/diversion ] + then + Say "${actionStr} Diversion service..." + /opt/bin/diversion "$divAction" & + sleep 3 + fi fi entwOPT_init="/opt/etc/init.d" @@ -4637,13 +4682,16 @@ _EntwareServicesHandler_() serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")" - # Filter out services to skip and add a skip message - for skipService in $skipServices; do - if echo "$serviceStr" | /bin/grep -q "$skipService"; then - Say "Skipping $skipService $actionStr..." - fi - serviceStr=$(echo "$serviceStr" | /bin/grep -v "$skipService") - done + if [ "$AllowVPN" = "ENABLED" ] + then + # Filter out services to skip and add a skip message + for skipService in $skipServices; do + if echo "$serviceStr" | /bin/grep -q "$skipService"; then + Say "Skipping $skipService $actionStr..." + fi + serviceStr=$(echo "$serviceStr" | /bin/grep -v "$skipService") + done + fi [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" [ "$serviceCnt" -eq 0 ] && return 0 @@ -4655,22 +4703,28 @@ _EntwareServicesHandler_() echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done Say "-----------------------------------------------------------" - # Stop or start each service individually - echo "$serviceStr" | while IFS= read -r servLine; do - serviceName=$(basename "$servLine") - if [ "$1" = "stop" ]; then - Say "Stopping $serviceName..." - "$servLine" stop - sleep 1 - else - Say "Starting $serviceName..." - "$servLine" start - sleep 1 - fi - done + # Stop or start each service individually + echo "$serviceStr" | while IFS= read -r servLine ; do + case "$servLine" in + S* | *.sh ) + echo "Sourcing shell script: $servLine" + if [ -x "$servLine" ]; then + trap "" INT QUIT TSTP EXIT + . "$servLine" "$1" 2>&1 | tee -a /tmp/service_debug.log + fi + ;; + *) + echo "Forking subprocess for: $servLine" + if [ -x "$servLine" ]; then + "$servLine" "$1" 2>&1 | tee -a /tmp/service_debug.log + fi + ;; + esac + sleep 1 + done - "$isInteractive" && printf "\nDone.\n" - sleep 5 + "$isInteractive" && printf "\nDone.\n" + sleep 5 } ##----------------------------------------## @@ -6237,7 +6291,7 @@ _ShowMainMenu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -6262,6 +6316,16 @@ _ShowAdvancedOptionsMenu_() printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi + local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")" + if [ "$VPNAccess" = "DISABLED" ] + then + printf "\n ${GRNct}4${NOct}. Toggle VPN Access While Updating" + printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" + else + printf "\n ${GRNct}4${NOct}. Toggle VPN Access While Updating" + printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" + fi + if [ -f "/jffs/scripts/backupmon.sh" ] then # Retrieve the current backup settings @@ -6517,7 +6581,7 @@ _AdvancedLogsOptions_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-25] ## +## Modified by ExtremeFiretop [2024-Jun-27] ## ##------------------------------------------## _advanced_options_menu_() { @@ -6534,6 +6598,8 @@ _advanced_options_menu_() ;; 3) _Toggle_FW_UpdatesFromBeta_ ;; + 4) _Toggle_VPN_Access_ + ;; ab) if [ -f "/jffs/scripts/backupmon.sh" ] then _Toggle_Auto_Backups_ else _InvalidMenuSelection_ From 8fa591442c473f1a734f3c558aed2ec75fd44a0c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 27 Jun 2024 10:12:46 -0400 Subject: [PATCH 148/185] Update MerlinAU.sh --- MerlinAU.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 0c4a8a4a..f3f1ecdc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -868,7 +868,8 @@ Get_Custom_Setting() if [ -f "$SETTINGSFILE" ]; then case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "Allow_Updates_OverVPN" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ @@ -941,7 +942,8 @@ Update_Custom_Settings() [ ! -d "$SETTINGS_DIR" ] && mkdir -m 755 -p "$SETTINGS_DIR" case "$setting_type" in - "ROGBuild" | "credentials_base64" | "CheckChangeLog" | \ + "ROGBuild" | "TUFBuild" | "credentials_base64" | \ + "CheckChangeLog" | \ "Allow_Updates_OverVPN" | \ "FW_Allow_Beta_Production_Up" | \ "FW_Auto_Backupmon" | \ From 0e6ca6fc591ab8ad92aac057c112260402da9c40 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 27 Jun 2024 16:54:30 -0400 Subject: [PATCH 149/185] Update MerlinAU.sh --- MerlinAU.sh | 61 +++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f3f1ecdc..120b3015 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4653,12 +4653,14 @@ _Toggle_FW_UpdateCheckSetting_() _EntwareServicesHandler_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi - AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" + local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" local actionStr="" divAction="" local serviceStr serviceCnt=0 local entwOPT_init entwOPT_unslung - local skipServices="tailscale" # space " " separated list # + # space-delimited list # + local skipServiceList="tailscaled" + local skippedService skippedServiceFile skippedServiceList="" case "$1" in stop) actionStr="Stopping" ; divAction="unmount" ;; @@ -4684,20 +4686,28 @@ _EntwareServicesHandler_() serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")" + # Filter out services to skip and add a skip message # if [ "$AllowVPN" = "ENABLED" ] then - # Filter out services to skip and add a skip message - for skipService in $skipServices; do - if echo "$serviceStr" | /bin/grep -q "$skipService"; then - Say "Skipping $skipService $actionStr..." + for skipService in $skipServiceList + do + skippedService="$(echo "$serviceStr" | /bin/grep -E "S[0-9]+.*${skipService}$")" + if [ -n "$skippedService" ] + then + skippedServiceFile="$(basename "$skippedService")" + Say "Skipping $skippedServiceFile $1 call..." + # Rename service file so it's skipped by Entware # + if mv -f "${entwOPT_init}/$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" + then + [ -z "$skippedServiceList" ] && \ + skippedServiceList="$skippedServiceFile" || \ + skippedServiceList="$skippedServiceList $skippedServiceFile" + serviceStr="$(echo "$serviceStr" | /bin/grep -vE "S[0-9]+.*${skipService}$")" + fi fi - serviceStr=$(echo "$serviceStr" | /bin/grep -v "$skipService") done fi - [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" - [ "$serviceCnt" -eq 0 ] && return 0 - Say "${actionStr} Entware services..." "$isInteractive" && printf "Please wait.\n" Say "-----------------------------------------------------------" @@ -4705,28 +4715,19 @@ _EntwareServicesHandler_() echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done Say "-----------------------------------------------------------" - # Stop or start each service individually - echo "$serviceStr" | while IFS= read -r servLine ; do - case "$servLine" in - S* | *.sh ) - echo "Sourcing shell script: $servLine" - if [ -x "$servLine" ]; then - trap "" INT QUIT TSTP EXIT - . "$servLine" "$1" 2>&1 | tee -a /tmp/service_debug.log - fi - ;; - *) - echo "Forking subprocess for: $servLine" - if [ -x "$servLine" ]; then - "$servLine" "$1" 2>&1 | tee -a /tmp/service_debug.log - fi - ;; - esac - sleep 1 - done + $entwOPT_unslung "$1" ; sleep 5 + if [ -n "$skippedServiceList" ] + then + for skippedServiceFile in $skippedServiceList + do # Rename service file back to original state # + if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile" + then + Say "Skipped $skippedServiceFile $1 call." + fi + done + fi "$isInteractive" && printf "\nDone.\n" - sleep 5 } ##----------------------------------------## From 2d5e4254654e6d1a40a1591f834f5039a7ca8daf Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 27 Jun 2024 20:15:54 -0400 Subject: [PATCH 150/185] Update MerlinAU.sh --- MerlinAU.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 120b3015..a2e778bc 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3019,26 +3019,26 @@ _Toggle_VPN_Access_() if [ "$currentSetting" = "ENABLED" ] then printf "${REDct}*WARNING*${NOct}\n" - printf "Disabling this feature means MerlinAU will shutdown Wireguard and Tailscale VPN access while updating.\n" - printf "The advice is to proceed only if you do not require the VPN access to stay alive while updating.\n" + printf "Disabling this feature will shut down Diversion, Tailscale, and Wireguard VPN access during updates.\n" + printf "Proceed only if you do not need VPN access during updates.\n" - if _WaitForYESorNO_ "\nProceed to ${REDct}DISABLE${NOct}?" + if _WaitForYESorNO_ "\nProceed to ${GRNct}DISABLE${NOct}?" then Update_Custom_Settings "Allow_Updates_OverVPN" "DISABLED" - printf "VPN Access will now be ${REDct}DISABLED.${NOct}\n" + printf "VPN access will now be ${GRNct}DISABLED.${NOct}\n" else - printf "VPN Access while updating remains ${GRNct}ENABLED.${NOct}\n" + printf "VPN access during updates remains ${REDct}ENABLED.${NOct}\n" fi else printf "${REDct}*WARNING*${NOct}\n" - printf "Enabling this feature means MerlinAU will keep Wireguard and Tailscale VPN access alive while updating.\n" - printf "The advice is to proceed only if you do require the VPN access to stay alive while updating.\n" - if _WaitForYESorNO_ "\nProceed to ${GRNct}ENABLE${NOct}?" + printf "Enabling this feature will keep Diversion, Tailscale, and Wireguard VPN access active during updates.\n" + printf "Proceed only if you need VPN access during updates.\n" + if _WaitForYESorNO_ "\nProceed to ${REDct}ENABLE${NOct}?" then Update_Custom_Settings "Allow_Updates_OverVPN" "ENABLED" - printf "VPN Access will now be ${GRNct}ENABLED.${NOct}\n" + printf "VPN access will now be ${REDct}ENABLED.${NOct}\n" else - printf "VPN Access while updating remains ${REDct}DISABLED.${NOct}\n" + printf "VPN access during updates remains ${GRNct}DISABLED.${NOct}\n" fi fi _WaitForEnterKey_ @@ -6310,23 +6310,21 @@ _ShowAdvancedOptionsMenu_() printf "\n${padStr}[Current Schedule: ${GRNct}${FW_UpdateCronJobSchedule}${NOct}]\n" local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" + printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates" if [ "$BetaProductionSetting" = "DISABLED" ] then - printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates" printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates" printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" fi local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")" + printf "\n ${GRNct}4${NOct}. Toggle VPN Service During Updates" if [ "$VPNAccess" = "DISABLED" ] then - printf "\n ${GRNct}4${NOct}. Toggle VPN Access While Updating" - printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n" + printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n" else - printf "\n ${GRNct}4${NOct}. Toggle VPN Access While Updating" - printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n" + printf "\n${padStr}[Currently ${REDct}ENABLED${NOct}]\n" fi if [ -f "/jffs/scripts/backupmon.sh" ] From 4701fbe7cb7b27d53491f10fd3cf9c1790fb6f7a Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 05:57:24 -0400 Subject: [PATCH 151/185] Update MerlinAU.sh --- MerlinAU.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a2e778bc..ab5edfc6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -3019,7 +3019,7 @@ _Toggle_VPN_Access_() if [ "$currentSetting" = "ENABLED" ] then printf "${REDct}*WARNING*${NOct}\n" - printf "Disabling this feature will shut down Diversion, Tailscale, and Wireguard VPN access during updates.\n" + printf "Disabling this feature will shut down Diversion and Tailscale VPN access during updates.\n" printf "Proceed only if you do not need VPN access during updates.\n" if _WaitForYESorNO_ "\nProceed to ${GRNct}DISABLE${NOct}?" @@ -3031,7 +3031,7 @@ _Toggle_VPN_Access_() fi else printf "${REDct}*WARNING*${NOct}\n" - printf "Enabling this feature will keep Diversion, Tailscale, and Wireguard VPN access active during updates.\n" + printf "Enabling this feature will keep Diversion and Tailscale VPN access active during updates.\n" printf "Proceed only if you need VPN access during updates.\n" if _WaitForYESorNO_ "\nProceed to ${REDct}ENABLE${NOct}?" then @@ -4672,9 +4672,11 @@ _EntwareServicesHandler_() then if [ -f /opt/bin/diversion ] then + # Diversion unmount command also unloads entware services # Say "${actionStr} Diversion service..." - /opt/bin/diversion "$divAction" & - sleep 3 + /opt/bin/diversion "$divAction" >/dev/null + sleep 5 + return 0 fi fi From 1d9a4153300a1a2de7c47e9ac1ef95d801153b79 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 07:10:46 -0400 Subject: [PATCH 152/185] Update MerlinAU.sh --- MerlinAU.sh | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index ab5edfc6..f2bf7a3a 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4655,31 +4655,12 @@ _EntwareServicesHandler_() if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" - local actionStr="" divAction="" local serviceStr serviceCnt=0 local entwOPT_init entwOPT_unslung # space-delimited list # local skipServiceList="tailscaled" local skippedService skippedServiceFile skippedServiceList="" - case "$1" in - stop) actionStr="Stopping" ; divAction="unmount" ;; - start) actionStr="Restarting" ; divAction="mount" ;; - *) return 1 ;; - esac - - if [ "$AllowVPN" = "DISABLED" ] - then - if [ -f /opt/bin/diversion ] - then - # Diversion unmount command also unloads entware services # - Say "${actionStr} Diversion service..." - /opt/bin/diversion "$divAction" >/dev/null - sleep 5 - return 0 - fi - fi - entwOPT_init="/opt/etc/init.d" entwOPT_unslung="${entwOPT_init}/rc.unslung" @@ -5289,6 +5270,18 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Flashing ${GRNct}${firmware_file}${NOct}... ${REDct}Please wait for reboot in about 4 minutes or less.${NOct}" echo + local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" + if [ "$AllowVPN" = "DISABLED" ] + then + if [ -f /opt/bin/diversion ] + then + # Diversion unmount command also unloads entware services # + Say "Stopping Diversion service..." + /opt/bin/diversion unmount >/dev/null + sleep 5 + fi + fi + # *WARNING*: No more logging at this point & beyond # /sbin/ejusb -1 0 -u 1 From 081e5cecabd2d24e05a5ceae495e754f3ec5c93b Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 07:11:54 -0400 Subject: [PATCH 153/185] Update MerlinAU.sh --- MerlinAU.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/MerlinAU.sh b/MerlinAU.sh index f2bf7a3a..949349d4 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5339,6 +5339,7 @@ Please manually update to version $minimum_supported_version or higher to use th _SendEMailNotification_ FAILED_FW_UPDATE_STATUS _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _EntwareServicesHandler_ start + # /opt/bin/diversion mount >/dev/null #Does not work temporarily fi "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" From 076acf9d55b2c8134390d118016a49b90c4ab7e7 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 07:32:05 -0400 Subject: [PATCH 154/185] Update MerlinAU.sh --- MerlinAU.sh | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 949349d4..df14a3a7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-27 +# Last Modified: 2024-Jun-28 ################################################################### set -u @@ -4647,9 +4647,9 @@ _Toggle_FW_UpdateCheckSetting_() _WaitForEnterKey_ "$mainMenuReturnPromptStr" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-27] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jun-28] ## +##----------------------------------------## _EntwareServicesHandler_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi @@ -4664,17 +4664,36 @@ _EntwareServicesHandler_() entwOPT_init="/opt/etc/init.d" entwOPT_unslung="${entwOPT_init}/rc.unslung" + case "$1" in + stop) actionStr="Stopping" ;; + start) actionStr="Restarting" ;; + *) return 1 ;; + esac + + _RenameSkippedService_() + { + [ -z "$skippedServiceList" ] && return 1 + for skippedServiceFile in $skippedServiceList + do # Rename service file back to original state # + if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile" + then Say "Skipped $skippedServiceFile $1 call." ; fi + done + return 0 + } + if [ ! -x /opt/bin/opkg ] || [ ! -x "$entwOPT_unslung" ] then return 0 ; fi ## Entware is NOT found ## - serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")" + serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")" + + [ -n "$serviceStr" ] && Say "Looking for Entware services..." # Filter out services to skip and add a skip message # if [ "$AllowVPN" = "ENABLED" ] then for skipService in $skipServiceList do - skippedService="$(echo "$serviceStr" | /bin/grep -E "S[0-9]+.*${skipService}$")" + skippedService="$(echo "$serviceStr" | /bin/grep -E "/S[0-9]+.*${skipService}$")" if [ -n "$skippedService" ] then skippedServiceFile="$(basename "$skippedService")" @@ -4685,12 +4704,19 @@ _EntwareServicesHandler_() [ -z "$skippedServiceList" ] && \ skippedServiceList="$skippedServiceFile" || \ skippedServiceList="$skippedServiceList $skippedServiceFile" - serviceStr="$(echo "$serviceStr" | /bin/grep -vE "S[0-9]+.*${skipService}$")" + serviceStr="$(echo "$serviceStr" | /bin/grep -vE "/S[0-9]+.*${skipService}$")" fi fi done fi + [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" + if [ "$serviceCnt" -eq 0 ] + then + _RenameSkippedService_ "$1" && echo + return 0 + fi + Say "${actionStr} Entware services..." "$isInteractive" && printf "Please wait.\n" Say "-----------------------------------------------------------" @@ -4699,17 +4725,7 @@ _EntwareServicesHandler_() Say "-----------------------------------------------------------" $entwOPT_unslung "$1" ; sleep 5 - - if [ -n "$skippedServiceList" ] - then - for skippedServiceFile in $skippedServiceList - do # Rename service file back to original state # - if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile" - then - Say "Skipped $skippedServiceFile $1 call." - fi - done - fi + _RenameSkippedService_ "$1" && echo "$isInteractive" && printf "\nDone.\n" } From 783a4a6e65fee3e67df5511aa0b436b0e2c147a6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 08:01:30 -0400 Subject: [PATCH 155/185] Update MerlinAU.sh --- MerlinAU.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index df14a3a7..f1b15db1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4655,6 +4655,7 @@ _EntwareServicesHandler_() if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" + local actionStr="" local serviceStr serviceCnt=0 local entwOPT_init entwOPT_unslung # space-delimited list # @@ -5293,7 +5294,7 @@ Please manually update to version $minimum_supported_version or higher to use th then # Diversion unmount command also unloads entware services # Say "Stopping Diversion service..." - /opt/bin/diversion unmount >/dev/null + /opt/bin/diversion unmount & sleep 5 fi fi From c68ff03e570d9defaf59212b31ff7b771f037f3e Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 28 Jun 2024 09:02:00 -0400 Subject: [PATCH 156/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f1b15db1..cb794aa5 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -6332,7 +6332,7 @@ _ShowAdvancedOptionsMenu_() fi local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")" - printf "\n ${GRNct}4${NOct}. Toggle VPN Service During Updates" + printf "\n ${GRNct}4${NOct}. Toggle Tailscale During Updates" if [ "$VPNAccess" = "DISABLED" ] then printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n" From af2571e1c17021c70514f13b98cac1aae0cc00c2 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 1 Jul 2024 03:42:08 -0400 Subject: [PATCH 157/185] Update MerlinAU.sh --- MerlinAU.sh | 92 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index cb794aa5..6c7304d9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-28 +# Last Modified: 2024-Jun-30 ################################################################### set -u @@ -2911,7 +2911,10 @@ return 0 ##----------------------------------------## _CheckFirmwareSHA256_() { # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # - checksums="$(curl -Ls --retry 4 --retry-delay 5 https://www.asuswrt-merlin.net/download | sed -n '/
/,/
/p' | sed -e 's/<[^>]*>//g')" + checksums="$(curl -Ls --retry 4 --retry-delay 5 --retry-connrefused \ + https://www.asuswrt-merlin.net/download | \ + sed -n '/<.*>SHA256 signatures:<\/.*>/,/<\/pre>/p' | \ + sed -n '/].*>/,/<\/pre>/p' | sed -e 's/<[^>].*>//g')" if [ -z "$checksums" ] then @@ -3019,7 +3022,7 @@ _Toggle_VPN_Access_() if [ "$currentSetting" = "ENABLED" ] then printf "${REDct}*WARNING*${NOct}\n" - printf "Disabling this feature will shut down Diversion and Tailscale VPN access during updates.\n" + printf "Disabling this feature will shut down Tailscale VPN access during updates.\n" printf "Proceed only if you do not need VPN access during updates.\n" if _WaitForYESorNO_ "\nProceed to ${GRNct}DISABLE${NOct}?" @@ -3031,7 +3034,7 @@ _Toggle_VPN_Access_() fi else printf "${REDct}*WARNING*${NOct}\n" - printf "Enabling this feature will keep Diversion and Tailscale VPN access active during updates.\n" + printf "Enabling this feature will keep Tailscale VPN access active during updates.\n" printf "Proceed only if you need VPN access during updates.\n" if _WaitForYESorNO_ "\nProceed to ${REDct}ENABLE${NOct}?" then @@ -4802,7 +4805,10 @@ Please manually update to version $minimum_supported_version or higher to use th FW_ZIP_FPATH="${FW_ZIP_DIR}/${FW_FileName}.zip" fi - _ProcessMeshNodes_ 0 + if ! node_online_status="$(_NodeActiveStatus_)" + then node_online_status="" + else _ProcessMeshNodes_ 0 + fi local credsBase64="" local currentVersionNum="" releaseVersionNum="" @@ -4991,10 +4997,10 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$current_backup_settings" = "ENABLED" ] then # Extract version number from backupmon.sh - BM_VERSION="$(grep "^Version=" /jffs/scripts/backupmon.sh | awk -F'"' '{print $2}')" + local BM_VERSION="$(grep "^Version=" /jffs/scripts/backupmon.sh | awk -F'"' '{print $2}')" # Adjust version format from 1.46 to 1.4.6 if needed - DOT_COUNT="$(echo "$BM_VERSION" | tr -cd '.' | wc -c)" + local DOT_COUNT="$(echo "$BM_VERSION" | tr -cd '.' | wc -c)" if [ "$DOT_COUNT" -eq 0 ]; then # If there's no dot, it's a simple version like "1" (unlikely but let's handle it) BM_VERSION="${BM_VERSION}.0.0" @@ -5263,7 +5269,7 @@ Please manually update to version $minimum_supported_version or higher to use th _EntwareServicesHandler_ stop ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Mar-15] ## + ## Modified by ExtremeFiretop [2024-Jun-30] ## ##------------------------------------------## curl_response="$(curl -k "${routerURLstr}/login.cgi" \ @@ -5284,21 +5290,49 @@ Please manually update to version $minimum_supported_version or higher to use th then _SendEMailNotification_ POST_REBOOT_FW_UPDATE_SETUP - Say "Flashing ${GRNct}${firmware_file}${NOct}... ${REDct}Please wait for reboot in about 4 minutes or less.${NOct}" - echo - - local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" - if [ "$AllowVPN" = "DISABLED" ] + if [ -f /opt/bin/diversion ] then - if [ -f /opt/bin/diversion ] - then - # Diversion unmount command also unloads entware services # - Say "Stopping Diversion service..." - /opt/bin/diversion unmount & - sleep 5 - fi + # Extract version number from Diversion + local DIVER_VERSION="$(grep "^VERSION=" /opt/bin/diversion | awk -F'=' '{print $2}' | tr -d ' ')" + + # Adjust version format from 1.46 to 1.4.6 if needed + local DDOT_COUNT="$(echo "$DIVER_VERSION" | tr -cd '.' | wc -c)" + if [ "$DDOT_COUNT" -eq 0 ]; then + # If there's no dot, it's a simple version like "1" (unlikely but let's handle it) + DIVER_VERSION="${DIVER_VERSION}.0.0" + elif [ "$DDOT_COUNT" -eq 1 ]; then + # Check if there is only one character after the dot + if echo "$DIVER_VERSION" | grep -qE '^[0-9]+\.[0-9]{1}$'; then + # If the version is like 5.2, convert it to 5.2.0 + DIVER_VERSION="${DIVER_VERSION}.0" + else + # For versions like 5.26, insert a dot between the last two digits + DIVER_VERSION="$(echo "$DIVER_VERSION" | sed 's/\.\([0-9]\)\([0-9]\)/.\1.\2/')" + fi + fi + + # Convert version strings to comparable numbers + local currentDIVER_version="$(_ScriptVersionStrToNum_ "$DIVER_VERSION")" + local requiredDIVER_version="$(_ScriptVersionStrToNum_ "5.2.0")" + + # Diversion unmount command also unloads entware services # + Say "Stopping Diversion service..." + if [ "$currentDIVER_version" -ge "$requiredDIVER_version" ] + then + /opt/bin/diversion temp_disable & + else + local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" + if [ "$AllowVPN" = "DISABLED" ] + then + /opt/bin/diversion unmount & + fi + fi + sleep 5 fi + Say "Flashing ${GRNct}${firmware_file}${NOct}... ${REDct}Please wait for reboot in about 4 minutes or less.${NOct}" + echo + # *WARNING*: No more logging at this point & beyond # /sbin/ejusb -1 0 -u 1 @@ -5356,7 +5390,21 @@ Please manually update to version $minimum_supported_version or higher to use th _SendEMailNotification_ FAILED_FW_UPDATE_STATUS _DoCleanUp_ 1 "$keepZIPfile" "$keepWfile" _EntwareServicesHandler_ start - # /opt/bin/diversion mount >/dev/null #Does not work temporarily + if [ -f /opt/bin/diversion ] + then + Say "Restarting Diversion service..." + if [ "$currentDIVER_version" -ge "$requiredDIVER_version" ] + then + /opt/bin/diversion enable & + else + AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" + if [ "$AllowVPN" = "DISABLED" ] + then + Say "Unable to Restart Diversion. Please reboot to restart entware services." + fi + fi + sleep 5 + fi fi "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" @@ -6332,7 +6380,7 @@ _ShowAdvancedOptionsMenu_() fi local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")" - printf "\n ${GRNct}4${NOct}. Toggle Tailscale During Updates" + printf "\n ${GRNct}4${NOct}. Toggle Tailscale Access During Updates" if [ "$VPNAccess" = "DISABLED" ] then printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n" From ddfd14866a9a342364d4a1458233ebc5525c3b25 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Mon, 1 Jul 2024 03:47:20 -0400 Subject: [PATCH 158/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 6c7304d9..1dbbf950 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2907,7 +2907,7 @@ return 0 } ##----------------------------------------## -## Modified by Martinski W. [2024-Jun-05] ## +## Modified by Martinski W. [2024-Jun-30] ## ##----------------------------------------## _CheckFirmwareSHA256_() { # Fetch the latest SHA256 checksums from ASUSWRT-Merlin website # From a3dd4551e6c9f3f9731d91396b0000f6e539bfc7 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 5 Jul 2024 09:22:37 -0400 Subject: [PATCH 159/185] Update MerlinAU.sh --- MerlinAU.sh | 223 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 162 insertions(+), 61 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 1dbbf950..a71c3f23 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,19 +4,22 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jun-30 +# Last Modified: 2024-Jul-05 ################################################################### set -u readonly SCRIPT_VERSION=1.3.0 readonly SCRIPT_NAME="MerlinAU" -##-------------------------------------## -## Added by Martinski W. [2023-Dec-01] ## -##-------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-03] ## +##----------------------------------------## # Script URL Info # -readonly SCRIPT_BRANCH="master" -readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router/$SCRIPT_BRANCH" + +## Set to "master" for Production Releases ## +SCRIPT_BRANCH="dev" +readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router" +SCRIPT_URL_REPO="${SCRIPT_URL_BASE}/$SCRIPT_BRANCH" # Firmware URL Info # readonly FW_SFURL_BASE="https://sourceforge.net/projects/asuswrt-merlin/files" @@ -234,6 +237,66 @@ _DoExit_() _ReleaseLock_ ; exit "$exitCode" } +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-21] ## +##------------------------------------------## +logo() { + echo -e "${YLWct}" + echo -e " __ __ _ _ _ _ " + echo -e " | \/ | | (_) /\ | | | |" + echo -e " | \ / | ___ _ __| |_ _ __ / \ | | | |" + echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |" + echo -e " | | | | __| | | | | | | |/ ____ | |__| |" + echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}" + echo -e "${NOct}" +} + +##---------------------------------------## +## Added by ExtremeFiretop [2024-Jul-03] ## +##---------------------------------------## +_ShowAbout_() +{ + logo + cat < ${GRNct}v${DLRepoVersion}${NOct}" Say "$(date +'%b %d %Y %X') $(nvram get lan_hostname) ${ScriptFNameTag}_[$$] - INFO: A new script update (v$DLRepoVersion) is available to download." else scriptUpdateNotify=0 @@ -601,22 +650,54 @@ ${REDct}v$SCRIPT_VERSION${NOct} --> ${GRNct}v$DLRepoVersion${NOct}" ##----------------------------------------## -## Modified by Martinski W. [2024-Jun-05] ## +## Modified by Martinski W. [2024-Jul-03] ## ##----------------------------------------## -#a function that provides a UI to check for script updates and allows you to install the latest version... _SCRIPTUPDATE_() { - local ScriptFileDL="${ScriptFilePath}.DL" + local scriptVers ScriptFileDL="${ScriptFilePath}.DL" _CheckForNewScriptUpdates_ + + _DownloadScriptFiles_() + { + local retCode + + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_REPO}/version.txt" -o "$SCRIPTVERPATH" + curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_REPO}/${SCRIPT_NAME}.sh" -o "$ScriptFileDL" + + if [ $? -eq 0 ] && [ -s "$ScriptFileDL" ] + then + mv -f "$ScriptFileDL" "$ScriptFilePath" + chmod 755 "$ScriptFilePath" + retCode=0 + else + rm -f "$ScriptFileDL" + printf "\n${REDct}Download failed.${NOct}\n" + retCode=1 + fi + return "$retCode" + } + + if [ $# -gt 0 ] && [ "$1" = "force" ] + then + echo -e "${CYANct}Force downloading latest version...${NOct}" + scriptVers="$(/usr/sbin/curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_REPO}/version.txt")" + echo -e "${CYANct}Downloading latest version ($scriptVers) of ${SCRIPT_NAME}${NOct}" + + if _DownloadScriptFiles_ + then + echo -e "${CYANct}$SCRIPT_NAME successfully updated.${NOct}" + _ReleaseLock_ + exec "$ScriptFilePath" + fi + return + fi + clear logo - echo - echo -e "${YLWct}Update Utility${NOct}" - echo - echo -e "${CYANct}Current Version: ${YLWct}${SCRIPT_VERSION}${NOct}" - echo -e "${CYANct}Updated Version: ${YLWct}${DLRepoVersion}${NOct}" - echo + printf "\n${YLWct}Script Update Utility${NOct}\n\n" + printf "${CYANct}Version Currently Installed: ${YLWct}${SCRIPT_VERSION}${NOct}\n" + printf "${CYANct}Update Version Available Now: ${YLWct}${DLRepoVersion}${NOct}\n\n" if [ "$SCRIPT_VERSION" = "$DLRepoVersion" ] then @@ -624,29 +705,21 @@ _SCRIPTUPDATE_() echo -e "${CYANct}This will overwrite your currently installed version.${NOct}" if _WaitForYESorNO_ then - echo ; echo - echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v$DLRepoVersion${NOct}" - curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" - curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "$ScriptFileDL" + printf "\n\n" + echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v${DLRepoVersion}${NOct}" - if [ $? -eq 0 ] && [ -s "$ScriptFileDL" ] + if _DownloadScriptFiles_ then - mv -f "$ScriptFileDL" "$ScriptFilePath" - chmod 755 "$ScriptFilePath" echo echo -e "${CYANct}Download successful!${NOct}" echo -e "$(date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion" echo - else - rm -f "$ScriptFileDL" - echo - echo -e "${REDct}Download failed.${NOct}" fi _WaitForEnterKey_ return else - echo ; echo - echo -e "${GRNct}Exiting Update Utility...${NOct}" + printf "\n\n" + echo -e "${GRNct}Exiting Script Update Utility...${NOct}" sleep 1 return fi @@ -655,15 +728,11 @@ _SCRIPTUPDATE_() echo -e "${CYANct}Bingo! New version available! Would you like to update now?${NOct}" if _WaitForYESorNO_ then - echo ; echo - echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v$DLRepoVersion${NOct}" - curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/version.txt" -o "$SCRIPTVERPATH" - curl -LSs --retry 4 --retry-delay 5 "${SCRIPT_URL_BASE}/${SCRIPT_NAME}.sh" -o "$ScriptFileDL" + printf "\n\n" + echo -e "${CYANct}Downloading $SCRIPT_NAME ${CYANct}v${DLRepoVersion}${NOct}" - if [ $? -eq 0 ] && [ -s "$ScriptFileDL" ] + if _DownloadScriptFiles_ then - mv -f "$ScriptFileDL" "$ScriptFilePath" - chmod 755 "$ScriptFilePath" echo echo -e "$(date) - $SCRIPT_NAME - Successfully downloaded $SCRIPT_NAME v$DLRepoVersion" echo -e "${CYANct}Update successful! Restarting script...${NOct}" @@ -671,21 +740,40 @@ _SCRIPTUPDATE_() exec "$ScriptFilePath" # Re-execute the updated script # exit 0 # This line will not be executed due to above exec # else - rm -f "$ScriptFileDL" - echo - echo -e "${REDct}Download failed.${NOct}" _WaitForEnterKey_ return fi else - echo ; echo - echo -e "${GRNct}Exiting Update Utility...${NOct}" + printf "\n\n" + echo -e "${GRNct}Exiting Script Update Utility...${NOct}" sleep 1 return fi fi } +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-03] ## +##----------------------------------------## +_ChangeToDev_() +{ + SCRIPT_BRANCH="dev" + SCRIPT_URL_REPO="${SCRIPT_URL_BASE}/$SCRIPT_BRANCH" + _SCRIPTUPDATE_ force + _DoExit_ 0 +} + +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-03] ## +##----------------------------------------## +_ChangeToStable_() +{ + SCRIPT_BRANCH="master" + SCRIPT_URL_REPO="${SCRIPT_URL_BASE}/$SCRIPT_BRANCH" + _SCRIPTUPDATE_ force + _DoExit_ 0 +} + ##----------------------------------------## ## Modified by Martinski W. [2024-Mar-14] ## ##----------------------------------------## @@ -5833,9 +5921,9 @@ check_version_support ##-------------------------------------## _CheckEMailConfigFileFromAMTM_ 0 -##----------------------------------------## -## Modified by Martinski W. [2024-Jan-24] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jul-03] ## +##------------------------------------------## if [ $# -gt 0 ] then inMenuMode=false @@ -5850,6 +5938,16 @@ then ;; postUpdateEmail) _PostUpdateEmailNotification_ ;; + about) _ShowAbout_ + ;; + help) _ShowHelp_ + ;; + forceupdate) _SCRIPTUPDATE_ force + ;; + develop) _ChangeToDev_ + ;; + stable) _ChangeToStable_ + ;; uninstall) _DoUninstall_ ;; *) printf "${REDct}INVALID Parameter.${NOct}\n" @@ -6335,8 +6433,11 @@ _ShowMainMenu_() # Check for new script updates # if [ "$scriptUpdateNotify" != "0" ] then - printf "\n ${GRNct}up${NOct}. Update $SCRIPT_NAME Script Now" - printf "\n${padStr}[Version: ${GRNct}${DLRepoVersion}${NOct} Available for Download]\n" + printf "\n ${GRNct}up${NOct}. Update $SCRIPT_NAME Script" + printf "\n${padStr}[Version ${GRNct}${DLRepoVersion}${NOct} Available for Download]\n" + else + printf "\n ${GRNct}up${NOct}. Force Update $SCRIPT_NAME Script" + printf "\n${padStr}[No Update Available]\n" fi # Add selection for "Advanced Options" sub-menu # From e1f6e034906db24702cb690af0bf00b06d11d224 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 5 Jul 2024 14:18:39 -0400 Subject: [PATCH 160/185] Update MerlinAU.sh --- MerlinAU.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 6aaa4427..af422f68 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5829,9 +5829,9 @@ _SetSecondaryEMailAddress_() } # RegExp for IPv4 address # -readonly IPv4octet_RegEx="([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])" -readonly IPv4addrs_RegEx="((${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx})" -readonly IPv4privt_RegEx="((^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.))" +readonly IPv4octet_RegEx="(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])" +readonly IPv4addrs_RegEx="(${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx}" +readonly IPv4privt_RegEx="(^10\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168\.)" ##----------------------------------------## ## Modified by Martinski W. [2024-Apr-06] ## @@ -6317,7 +6317,7 @@ _InvalidMenuSelection_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Jul-03] ## +## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## _ShowMainMenu_() { From 4e6b0222554a4ca0e5f3294d7aacd2532459b8ea Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 5 Jul 2024 14:19:30 -0400 Subject: [PATCH 161/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index af422f68..235f1f57 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -6317,7 +6317,7 @@ _InvalidMenuSelection_() } ##----------------------------------------## -## Modified by Martinski W. [2024-May-31] ## +## Modified by Martinski W. [2024-Jul-03] ## ##----------------------------------------## _ShowMainMenu_() { From 08eb63a2bec201905f5e46d879ce7341e7359d2e Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 6 Jul 2024 10:37:56 -0400 Subject: [PATCH 162/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 235f1f57..7e9362c7 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5829,7 +5829,7 @@ _SetSecondaryEMailAddress_() } # RegExp for IPv4 address # -readonly IPv4octet_RegEx="(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])" +readonly IPv4octet_RegEx="([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" readonly IPv4addrs_RegEx="(${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx}" readonly IPv4privt_RegEx="(^10\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168\.)" From 7afe01fba3920742b6eb6ee8a7f95cbc3bcf2930 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 25 Jul 2024 10:12:09 -0400 Subject: [PATCH 163/185] Update MerlinAU.sh --- MerlinAU.sh | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 2b2af0bf..a9ef66fb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jul-05 +# Last Modified: 2024-Jul-24 ################################################################### set -u @@ -17,7 +17,7 @@ readonly SCRIPT_NAME="MerlinAU" # Script URL Info # ## Set to "master" for Production Releases ## -SCRIPT_BRANCH="master" +SCRIPT_BRANCH="dev" readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router" SCRIPT_URL_REPO="${SCRIPT_URL_BASE}/$SCRIPT_BRANCH" @@ -276,22 +276,22 @@ EOF _DoExit_ 0 } -##---------------------------------------## -## Added by ExtremeFiretop [2024-Jul-03] ## -##---------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-23] ## +##----------------------------------------## _ShowHelp_() { logo cat < Date: Sun, 28 Jul 2024 15:59:20 -0400 Subject: [PATCH 164/185] Update MerlinAU.sh --- MerlinAU.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a9ef66fb..19974b2c 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2139,7 +2139,7 @@ check_memory_and_prompt_reboot() # Attempt to clear clears pagecache, dentries, and inodes after shutting down services Say "Attempting to free up memory once more even more aggressively..." - # Stop Entware services before F/W flash # + # Stop Entware services to free some memory # _EntwareServicesHandler_ stop _ShutDownNonCriticalServices_ @@ -4734,7 +4734,7 @@ _Toggle_FW_UpdateCheckSetting_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Jun-28] ## +## Modified by Martinski W. [2024-Jul-24] ## ##----------------------------------------## _EntwareServicesHandler_() { @@ -4757,6 +4757,9 @@ _EntwareServicesHandler_() *) return 1 ;; esac + # Check if *NOT* skipping any services # + [ $# -gt 1 ] && [ "$2" = "-noskip" ] && skipServiceList="" + _RenameSkippedService_() { [ -z "$skippedServiceList" ] && return 1 @@ -4775,8 +4778,8 @@ _EntwareServicesHandler_() [ -n "$serviceStr" ] && Say "Looking for Entware services..." - # Filter out services to skip and add a skip message # - if [ "$AllowVPN" = "ENABLED" ] + # Filter out services to skip and add a "skip message" # + if [ "$AllowVPN" = "ENABLED" ] && [ -n "$skipServiceList" ] then for skipService in $skipServiceList do @@ -5348,9 +5351,6 @@ Please manually update to version $minimum_supported_version or higher to use th # Send last email notification before F/W flash # _SendEMailNotification_ START_FW_UPDATE_STATUS - # Stop Entware services before F/W flash # - _EntwareServicesHandler_ stop - ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jun-30] ## ##------------------------------------------## @@ -5416,15 +5416,24 @@ Please manually update to version $minimum_supported_version or higher to use th Say "Flashing ${GRNct}${firmware_file}${NOct}... ${REDct}Please wait for reboot in about 4 minutes or less.${NOct}" echo - # *WARNING*: No more logging at this point & beyond # - /sbin/ejusb -1 0 -u 1 - #------------------------------------------------------- # Stop toggling LEDs during the F/W flash to avoid # modifying NVRAM during the actual flash process. #------------------------------------------------------- _Reset_LEDs_ + ##----------------------------------------## + ## Modified by Martinski W. [2024-Jul-24] ## + ##----------------------------------------## + # Remove SIGHUP to allow script to continue # + trap '' HUP + + # Stop Entware services WITHOUT exceptions BEFORE the F/W flash # + _EntwareServicesHandler_ stop -noskip + + # *WARNING*: NO MORE logging at this point & beyond # + /sbin/ejusb -1 0 -u 1 + nohup curl -k "${routerURLstr}/upgrade.cgi" \ --referer "${routerURLstr}/Advanced_FirmwareUpgrade_Content.asp" \ --user-agent 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' \ @@ -5464,6 +5473,7 @@ Please manually update to version $minimum_supported_version or higher to use th # reboot by itself after the process returns, do it now. #----------------------------------------------------------# sleep 180 + _ReleaseLock_ /sbin/service reboot else Say "${REDct}**ERROR**${NOct}: Login failed. Please try the following: From 5b7c15ca077ee8819137a3a12acf618935c4a360 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 4 Aug 2024 04:11:56 -0400 Subject: [PATCH 165/185] Update MerlinAU.sh --- MerlinAU.sh | 642 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 493 insertions(+), 149 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 19974b2c..88a80196 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Jul-24 +# Last Modified: 2024-Aug-04 ################################################################### set -u @@ -40,9 +40,29 @@ readonly high_risk_terms="factory default reset|features are disabled|break back DLRepoVersion="" scriptUpdateNotify=0 -# For supported version and model checks # -MinFirmwareCheckFailed=0 -ModelCheckFailed=0 +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-29] ## +##----------------------------------------## +# For minimum supported firmware version check # +MinFirmwareVerCheckFailed=false +MinSupportedFirmwareVers="3004.386.12.0" + +# For router model check # +routerModelCheckFailed=false +offlineUpdateTrigger=false + +##--------------------------------------------## +## Modified by ExtremeFiretop [2023-Nov-26] ## +##--------------------------------------------## +readonly NOct="\e[0m" +readonly REDct="\e[1;31m" +readonly GRNct="\e[1;32m" +readonly BLKct="\e[1;30m" +readonly YLWct="\e[1;33m" +readonly BLUEct="\e[1;34m" +readonly MAGENTAct="\e[1;35m" +readonly CYANct="\e[1;36m" +readonly WHITEct="\e[1;37m" readonly ScriptFileName="${0##*/}" readonly ScriptFNameTag="${ScriptFileName%%.*}" @@ -112,6 +132,13 @@ fi readonly mainMenuReturnPromptStr="Press to return to the Main Menu..." readonly advnMenuReturnPromptStr="Press to return to the Advanced Options Menu..." readonly logsMenuReturnPromptStr="Press to return to the Log Options Menu..." +theMenuReturnPromptMsg="$mainMenuReturnPromptStr" + +# menu setup variables # +theExitStr="${GRNct}e${NOct}=Exit to Main Menu" +theMUExitStr="${GRNct}e${NOct}=Exit" +theADExitStr="${GRNct}e${NOct}=Exit to Advanced Options Menu" +theLGExitStr="${GRNct}e${NOct}=Exit to Log Options Menu" [ -t 0 ] && ! tty | grep -qwi "NOT" && isInteractive=true @@ -256,6 +283,7 @@ logo() { ##---------------------------------------## _ShowAbout_() { + clear logo cat </dev/null)" ] + then + printf "\nNo ZIP files found in the directory. Exiting.\n" + printf "\n---------------------------------------------------\n" + return 1 + fi + + while true + do + printf "\nAvailable ZIP files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" + + zipFileList="$(ls -A1 "$FW_ZIP_DIR"/*.zip 2>/dev/null)" + fileCount=1 + for zipFile in $zipFileList + do + printf "${GRNct}%d${NOct}) %s\n" "$fileCount" "$zipFile" + fileCount="$((fileCount + 1))" + done + + # Prompt user to select a ZIP file # + printf "\n---------------------------------------------------\n" + printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: " + read -r selection + + if [ -z "$selection" ] + then + printf "\n${REDct}Invalid selection${NOct}. Please try again.\n" + _WaitForEnterKey_ + clear + continue + fi + + if echo "$selection" | grep -qE "^(e|E|exit|Exit)$" + then + printf "Update process was cancelled. Exiting.\n" + return 1 + fi + + # Validate selection # + selected_file="$(echo "$zipFileList" | awk "NR==$selection")" + if [ -z "$selected_file" ] + then + printf "\n${REDct}Invalid selection${NOct}. Please try again.\n" + _WaitForEnterKey_ + clear + continue + else + clear + printf "\n---------------------------------------------------\n" + printf "\nYou have selected:\n${GRNct}$selected_file${NOct}\n" + break + fi + done + + # Extract or prompt for firmware version # + _GetOfflineFirmwareVersion_ "$selected_file" + + # Confirm the selection + if _WaitForYESorNO_ "\nDo you want to continue with the selected ZIP file?" + then + printf "\n---------------------------------------------------\n" + printf "\nStarting firmware update with the selected ZIP file.\n" + # Rename the selected ZIP file # + new_file_name="${PRODUCT_ID}_firmware.zip" + mv -f "$selected_file" "${FW_ZIP_DIR}/$new_file_name" + if [ $? -eq 0 ] + then + printf "\nFile packaged to ${GRNct}${new_file_name}${NOct}" + printf "\nRelease version: ${GRNct}${release_version}${NOct}\n" + printf "\n---------------------------------------------------\n" + _WaitForEnterKey_ + clear + return 0 + else + printf "\nFailed to rename the ZIP file. Exiting.\n" + return 1 + fi + else + printf "Operation was cancelled by user. Exiting.\n" + return 1 + fi +} + +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Jul-23] ## +##------------------------------------------## +_RunBackupmon_() +{ + # Check for the presence of backupmon.sh script + if [ -f "/jffs/scripts/backupmon.sh" ] + then + local current_backup_settings="$(Get_Custom_Setting "FW_Auto_Backupmon")" + if [ "$current_backup_settings" = "ENABLED" ] + then + # Extract version number from backupmon.sh + local BM_VERSION="$(grep "^Version=" /jffs/scripts/backupmon.sh | awk -F'"' '{print $2}')" + + # Adjust version format from 1.46 to 1.4.6 if needed + local DOT_COUNT="$(echo "$BM_VERSION" | tr -cd '.' | wc -c)" + if [ "$DOT_COUNT" -eq 0 ]; then + # If there's no dot, it's a simple version like "1" (unlikely but let's handle it) + BM_VERSION="${BM_VERSION}.0.0" + elif [ "$DOT_COUNT" -eq 1 ]; then + # For versions like 1.46, insert a dot before the last two digits + BM_VERSION="$(echo "$BM_VERSION" | sed 's/\.\([0-9]\)\([0-9]\)/.\1.\2/')" + fi + + # Convert version strings to comparable numbers + local currentBM_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")" + local requiredBM_version="$(_ScriptVersionStrToNum_ "1.5.3")" + + # Check if BACKUPMON version is greater than or equal to 1.5.3 + if [ "$currentBM_version" -ge "$requiredBM_version" ]; then + # Execute the backup script if it exists # + echo "" + Say "Backup Started (by BACKUPMON)" + sh /jffs/scripts/backupmon.sh -backup >/dev/null + BE=$? + Say "Backup Finished" + echo "" + if [ $BE -eq 0 ]; then + Say "Backup Completed Successfully" + echo "" + else + Say "Backup Failed" + echo "" + _SendEMailNotification_ NEW_BM_BACKUP_FAILED + _DoCleanUp_ 1 + if "$isInteractive" + then + printf "\n${REDct}**IMPORTANT NOTICE**:${NOct}\n" + printf "The firmware flash has been ${REDct}CANCELLED${NOct} due to a failed backup from BACKUPMON.\n" + printf "Please fix the BACKUPMON configuration, or consider uninstalling it to proceed flash.\n" + printf "Resolving the BACKUPMON configuration is HIGHLY recommended for safety of the upgrade.\n" + _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + else + _DoExit_ 1 + fi + fi + else + # BACKUPMON version is not sufficient + echo "" + Say "${REDct}**IMPORTANT NOTICE**:${NOct}" + echo "" + Say "Backup script (BACKUPMON) is installed; but version $BM_VERSION does not meet the minimum required version of 1.5.3." + Say "Skipping backup. Please update your version of BACKUPMON." + echo "" + fi + else + Say "Backup script (BACKUPMON) is disabled in the advanced options. Skipping backup." + echo "" + fi + else + Say "Backup script (BACKUPMON) is not installed. Skipping backup." + echo "" + fi + return 0 +} + +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-31] ## +##----------------------------------------## +_RunOfflineUpdateNow_() +{ + local offlineConfigFile="${SETTINGS_DIR}/offline_updates.txt" + + _ClearOfflineUpdateState_() + { + offlineUpdateTrigger=false + theMenuReturnPromptMsg="$mainMenuReturnPromptStr" + if [ $# -eq 0 ] || [ -z "$1" ] ; then return 0 ; fi + [ "$1" != "1" ] && printf "$1" + _WaitForEnterKey_ "$advnMenuReturnPromptStr" + } + + [ ! -s "$offlineConfigFile" ] && return 2 + + # Source the configuration file # + . "$offlineConfigFile" + + # Check required parameter # + if [ -z "${FW_OFFLINE_UPDATE_IS_ALLOWED:+xSETx}" ] || \ + [ "$FW_OFFLINE_UPDATE_IS_ALLOWED" != "true" ] + then return 2 ; fi + + # Reset FW_OFFLINE_UPDATE_ACCEPT_RISK to false # + if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" + then + sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"/" "$offlineConfigFile" + fi + + clear + printf "\n${REDct}***WARNING***${NOct}" + printf "\nYou are about to initiate an ${REDct}offline${NOct} firmware update." + printf "\nThe firmware image to be flashed is ${REDct}unvetted${NOct} and of ${REDct}unknown${NOct} origin.\n" + printf "\n1. This feature is intended for developers and advanced users only." + printf "\n2. No support will be offered when flashing firmware offline." + printf "\n3. This offline feature is excluded from documentation on purpose.\n" + printf "\nDo you acknowledge the risk and wish to proceed?" + printf "\nYou must type '${REDct}YES${NOct}' to continue.\n" + + read -r response + if [ "$response" = "YES" ] + then + # Add or update the setting to true # + if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" + then + sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"true\"/" "$offlineConfigFile" + else + # Ensure the new setting is added on a new line + echo "" >> "$offlineConfigFile" + echo "FW_OFFLINE_UPDATE_ACCEPT_RISK=\"true\"" >> "$offlineConfigFile" + fi + else + # Add or update the setting to false # + if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" + then + sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"/" "$offlineConfigFile" + else + # Ensure the new setting is added on a new line # + echo "" >> "$offlineConfigFile" + echo "FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"" >> "$offlineConfigFile" + fi + _ClearOfflineUpdateState_ "Offline update was aborted. Exiting.\n" + return 1 + fi + clear + logo + printf "\n---------------------------------------------------\n" + + offlineUpdateTrigger=true + theMenuReturnPromptMsg="$advnMenuReturnPromptStr" + + if _Set_FW_UpdateZIP_DirectoryPath_ + then + clear + # Create directory for downloading & extracting firmware # + if ! _CreateDirectory_ "$FW_ZIP_DIR" + then + _ClearOfflineUpdateState_ 1 ; return 1 + fi + printf "\n---------------------------------------------------\n" + printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:" + printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" + printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" + printf "\n---------------------------------------------------\n" + if _WaitForYESorNO_ + then + clear + printf "\n---------------------------------------------------\n" + printf "\nContinuing to the ZIP file selection process.\n" + if _SelectOfflineZipFile_ + then + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + if [ $? -eq 0 ] && [ $# -eq 2 ] && \ + [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] + then + release_link="$2" + _RunFirmwareUpdateNow_ + _ClearOfflineUpdateState_ + else + Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." + _ClearOfflineUpdateState_ 1 + return 1 + fi + else + _ClearOfflineUpdateState_ 1 + return 1 + fi + else + _ClearOfflineUpdateState_ "Offline update process was cancelled. Exiting.\n" + return 1 + fi + else + _ClearOfflineUpdateState_ "Offline update process was cancelled. Exiting.\n" + return 1 + fi +} + ##----------------------------------------## ## Modified by Martinski W. [2024-Jan-25] ## ##----------------------------------------## @@ -4851,14 +5249,14 @@ _RunFirmwareUpdateNow_() _DoExit_ 1 fi fi - if [ "$MinFirmwareCheckFailed" != "0" ]; then + if [ "$MinFirmwareCheckFailed" != "0" ] && [ "$ManualUpdateTrigger" = "1" ]; then Say "${REDct}WARNING:${NOct} The current firmware version is below the minimum supported. Please manually update to version $minimum_supported_version or higher to use this script.\n" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi - Say "${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" + Say "\n${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" Say "Running the update task now... Checking for F/W updates..." FlashStarted=true @@ -4898,7 +5296,7 @@ Please manually update to version $minimum_supported_version or higher to use th local credsBase64="" local currentVersionNum="" releaseVersionNum="" - local current_version="" release_version="" + local current_version="" # Create directory for downloading & extracting firmware # if ! _CreateDirectory_ "$FW_ZIP_DIR" ; then return 1 ; fi @@ -4918,25 +5316,48 @@ Please manually update to version $minimum_supported_version or higher to use th # is that the user wants to do a MANUAL Update Check # regardless of the state of the "F/W Update Check." #---------------------------------------------------------# - FW_UpdateCheckState="$(nvram get firmware_check_enable)" - [ -z "$FW_UpdateCheckState" ] && FW_UpdateCheckState=0 - if [ "$FW_UpdateCheckState" -eq 0 ] + if ! "$offlineUpdateTrigger" then - Say "Firmware update check is currently disabled." - "$inMenuMode" && _WaitForEnterKey_ || return 1 - fi + FW_UpdateCheckState="$(nvram get firmware_check_enable)" + [ -z "$FW_UpdateCheckState" ] && FW_UpdateCheckState=0 - #------------------------------------------------------ - # If the "New F/W Update" flag has been set get the - # "New F/W Release Version" from the router itself. - # If no new F/W version update is available return. - #------------------------------------------------------ - if ! release_version="$(_GetLatestFWUpdateVersionFromRouter_)" || \ - ! _CheckNewUpdateFirmwareNotification_ "$current_version" "$release_version" - then - Say "No new firmware version update is found for [$PRODUCT_ID] router model." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 + if [ "$FW_UpdateCheckState" -eq 0 ] + then + Say "Firmware update check is currently disabled." + "$inMenuMode" && _WaitForEnterKey_ || return 1 + fi + + #------------------------------------------------------ + # If the "New F/W Update" flag has been set get the + # "New F/W Release Version" from the router itself. + # If no new F/W version update is available return. + #------------------------------------------------------ + if ! release_version="$(_GetLatestFWUpdateVersionFromRouter_)" || \ + ! _CheckNewUpdateFirmwareNotification_ "$current_version" "$release_version" + then + Say "No new firmware version update is found for [$PRODUCT_ID] router model." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi + + # Use set to read the output of the function into variables + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + if [ $? -eq 0 ] && [ $# -eq 2 ] && \ + [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] + then + release_version="$1" + release_link="$2" + else + Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 1 + fi + + if ! _CheckTimeToUpdateFirmware_ "$current_version" "$release_version" + then + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + return 0 + fi fi ##------------------------------------------## @@ -5035,12 +5456,6 @@ Please manually update to version $minimum_supported_version or higher to use th # Inserting dots between each number dottedVersion="$(echo "$fwUpdateBaseNum" | sed 's/./&./g' | sed 's/.$//')" - if ! _CheckTimeToUpdateFirmware_ "$current_version" "$release_version" - then - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 0 - fi - ## Check for Login Credentials ## credsBase64="$(Get_Custom_Setting credentials_base64)" if [ -z "$credsBase64" ] || [ "$credsBase64" = "TBD" ] @@ -5070,85 +5485,17 @@ Please manually update to version $minimum_supported_version or higher to use th 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" - # Compare versions before deciding to download - if [ "$releaseVersionNum" -gt "$currentVersionNum" ] - then - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Mar-20] ## - ##------------------------------------------## - # Check for the presence of backupmon.sh script - if [ -f "/jffs/scripts/backupmon.sh" ] - then - local current_backup_settings="$(Get_Custom_Setting "FW_Auto_Backupmon")" - if [ "$current_backup_settings" = "ENABLED" ] - then - # Extract version number from backupmon.sh - local BM_VERSION="$(grep "^Version=" /jffs/scripts/backupmon.sh | awk -F'"' '{print $2}')" - - # Adjust version format from 1.46 to 1.4.6 if needed - local DOT_COUNT="$(echo "$BM_VERSION" | tr -cd '.' | wc -c)" - if [ "$DOT_COUNT" -eq 0 ]; then - # If there's no dot, it's a simple version like "1" (unlikely but let's handle it) - BM_VERSION="${BM_VERSION}.0.0" - elif [ "$DOT_COUNT" -eq 1 ]; then - # For versions like 1.46, insert a dot before the last two digits - BM_VERSION="$(echo "$BM_VERSION" | sed 's/\.\([0-9]\)\([0-9]\)/.\1.\2/')" - fi - - # Convert version strings to comparable numbers - local currentBM_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")" - local requiredBM_version="$(_ScriptVersionStrToNum_ "1.5.3")" - - # Check if BACKUPMON version is greater than or equal to 1.5.3 - if [ "$currentBM_version" -ge "$requiredBM_version" ]; then - # Execute the backup script if it exists # - echo "" - Say "Backup Started (by BACKUPMON)" - sh /jffs/scripts/backupmon.sh -backup >/dev/null - BE=$? - Say "Backup Finished" - echo "" - if [ $BE -eq 0 ]; then - Say "Backup Completed Successfully" - echo "" - else - Say "Backup Failed" - echo "" - _SendEMailNotification_ NEW_BM_BACKUP_FAILED - _DoCleanUp_ 1 - if "$isInteractive" - then - printf "\n${REDct}**IMPORTANT NOTICE**:${NOct}\n" - printf "The firmware flash has been ${REDct}CANCELLED${NOct} due to a failed backup from BACKUPMON.\n" - printf "Please fix the BACKUPMON configuration, or consider uninstalling it to proceed flash.\n" - printf "Resolving the BACKUPMON configuration is HIGHLY recommended for safety of the upgrade.\n" - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoExit_ 1 - fi - fi - else - # BACKUPMON version is not sufficient - echo "" - Say "${REDct}**IMPORTANT NOTICE**:${NOct}" - echo "" - Say "Backup script (BACKUPMON) is installed; but version $BM_VERSION does not meet the minimum required version of 1.5.3." - Say "Skipping backup. Please update your version of BACKUPMON." - echo "" - fi - else - Say "Backup script (BACKUPMON) is disabled in the advanced options. Skipping backup." - echo "" - fi - else - Say "Backup script (BACKUPMON) is not installed. Skipping backup." - echo "" - fi - - # Background function to create a blinking LED effect # - Toggle_LEDs 2 & Toggle_LEDs_PID=$! + ##----------------------------------------## + ## Modified by Martinski W. [2024-Jul-29] ## + ##----------------------------------------## + _RunBackupmon_ + # Background function to create a blinking LED effect # + _Toggle_LEDs_ 2 & Toggle_LEDs_PID=$! + # Compare versions before deciding to download # + if ! "$offlineUpdateTrigger" && \ + [ "$releaseVersionNum" -gt "$currentVersionNum" ] + then Say "Latest release version is ${GRNct}${release_version}${NOct}." Say "Downloading ${GRNct}${release_link}${NOct}" echo @@ -5307,7 +5654,7 @@ Please manually update to version $minimum_supported_version or higher to use th _CheckFirmwareMD5_ retCode="$?" else - _CheckFirmwareSHA256_ + _CheckOnlineFirmwareSHA256_ retCode="$?" fi if [ "$retCode" -eq 1 ] @@ -5752,8 +6099,10 @@ _SetSecondaryEMailAddress_() if ! echo "$userInput" | grep -qE ".+[@].+" then - printf "${REDct}INVALID input.${NOct} " + printf "\n${REDct}INVALID input.${NOct} " printf "No ampersand character [${GRNct}@${NOct}] is found.\n" + _WaitForEnterKey_ + clear continue fi @@ -6012,11 +6361,6 @@ then _WaitForEnterKey_ fi -# menu setup variables # -theExitStr="${GRNct}e${NOct}=Exit to Main Menu" -theADExitStr="${GRNct}e${NOct}=Exit to Advanced Options Menu" -theLGExitStr="${GRNct}e${NOct}=Exit to Log Options Menu" - padStr=" " SEPstr="----------------------------------------------------------" @@ -6461,7 +6805,7 @@ _ShowMainMenu_() } ##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-27] ## +## Modified by ExtremeFiretop [2024-Jul-23] ## ##------------------------------------------## _ShowAdvancedOptionsMenu_() { @@ -6473,7 +6817,7 @@ _ShowAdvancedOptionsMenu_() printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" - printf "\n ${GRNct}2${NOct}. Set F/W Update Check Schedule" + printf "\n ${GRNct}2${NOct}. Set F/W Update Cron Schedule" printf "\n${padStr}[Current Schedule: ${GRNct}${FW_UpdateCronJobSchedule}${NOct}]\n" local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")" From 1b018f140f828f42064610e07213a41e4a872833 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 4 Aug 2024 04:40:18 -0400 Subject: [PATCH 166/185] Update MerlinAU.sh --- MerlinAU.sh | 81 +++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 88a80196..acf6da4e 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1247,9 +1247,9 @@ _Set_FW_UpdateLOG_DirectoryPath_() return 0 } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jul-23] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-29] ## +##----------------------------------------## _Set_FW_UpdateZIP_DirectoryPath_() { local newZIP_BaseDirPath="$FW_ZIP_BASE_DIR" newZIP_FileDirPath="" @@ -1257,20 +1257,18 @@ _Set_FW_UpdateZIP_DirectoryPath_() while true do printf "\nEnter the directory path where the ZIP subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" - printf "Default directory for 'USB' storage is: [${GRNct}/tmp/mnt/${REDct}USBLABEL${NOct}${GRNct}/${NOct}].\n" - printf "Default directory for 'Local' storage is: [${GRNct}/home/root/${NOct}].\n" - if [ "$ManualUpdateTrigger" = "0" ] + if [ -n "$USBMountPoint" ] && _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" then - printf "\n[${theMUExitStr}] [CURRENT: ${GRNct}${FW_ZIP_BASE_DIR}${NOct}]: " + printf "Default directory for USB-attached drive: [${GRNct}${FW_ZIP_BASE_DIR}${NOct}]\n" else - printf "\n[${theADExitStr}] [CURRENT: ${GRNct}${FW_ZIP_BASE_DIR}${NOct}]: " + printf "Default directory for 'Local' storage is: [${GRNct}/home/root${NOct}]\n" fi + printf "\n[${theADExitStr}] [CURRENT: ${GRNct}${FW_ZIP_BASE_DIR}${NOct}]: " + read -r userInput - if [ -z "$userInput" ] - then break ; fi - if echo "$userInput" | grep -qE "^(e|E|exit|Exit)$" - then return 1 ; fi + if [ -z "$userInput" ] ; then break ; fi + if echo "$userInput" | grep -qE "^(e|E|exit|Exit)$" ; then return 1 ; fi if echo "$userInput" | grep -q '/$' then userInput="${userInput%/*}" ; fi @@ -1808,7 +1806,7 @@ _CreateDirectory_() "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi - if [ $ManualUpdateTrigger = "1" ] + if ! "$offlineUpdateTrigger" then # Clear directory in case any previous files still exist # rm -f "${1}"/* @@ -2225,38 +2223,32 @@ check_memory_and_prompt_reboot() ##----------------------------------------## ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## -# Function to check if the current router model is supported check_version_support() { local numOfFields current_version numCurrentVers numMinimumVers - # Minimum supported firmware version # - minimum_supported_version="3004.386.12.0" - current_version="$(_GetCurrentFWInstalledLongVersion_)" numOfFields="$(echo "$current_version" | awk -F '.' '{print NF}')" numCurrentVers="$(_FWVersionStrToNum_ "$current_version" "$numOfFields")" - numMinimumVers="$(_FWVersionStrToNum_ "$minimum_supported_version" "$numOfFields")" + numMinimumVers="$(_FWVersionStrToNum_ "$MinSupportedFirmwareVers" "$numOfFields")" # If the current firmware version is lower than the minimum supported firmware version, exit. if [ "$numCurrentVers" -lt "$numMinimumVers" ] - then - MinFirmwareCheckFailed="1" - fi + then MinFirmwareVerCheckFailed=true ; fi } -check_model_support() { +check_model_support() +{ # List of unsupported models as a space-separated string local unsupported_models="RT-AC87U RT-AC56U RT-AC66U RT-AC3200 RT-N66U RT-AC88U RT-AC5300 RT-AC3100 RT-AC68U RT-AC66U_B1 RT-AC1900 DSL-AC68U" # Get the current model local current_model="$(_GetRouterProductID_)" - # Check if the current model is in the list of unsupported models - if echo "$unsupported_models" | grep -wq "$current_model"; then - ModelCheckFailed="1" - fi + # Check if the current model is in the list of unsupported models # + if echo "$unsupported_models" | grep -wq "$current_model" + then routerModelCheckFailed=true ; fi } ##---------------------------------------## @@ -5232,11 +5224,14 @@ _RunFirmwareUpdateNow_() # Check if the router model is supported OR if # it has the minimum firmware version supported. - if [ "$ModelCheckFailed" != "0" ]; then + if "$routerModelCheckFailed" + then Say "${REDct}WARNING:${NOct} The current router model is not supported by this script." - if "$inMenuMode"; then + if "$inMenuMode" + then printf "\nWould you like to uninstall the script now?" - if _WaitForYESorNO_; then + if _WaitForYESorNO_ + then _DoUninstall_ return 0 else @@ -5249,9 +5244,10 @@ _RunFirmwareUpdateNow_() _DoExit_ 1 fi fi - if [ "$MinFirmwareCheckFailed" != "0" ] && [ "$ManualUpdateTrigger" = "1" ]; then + if "$MinFirmwareVerCheckFailed" && ! "$offlineUpdateTrigger" + then Say "${REDct}WARNING:${NOct} The current firmware version is below the minimum supported. -Please manually update to version $minimum_supported_version or higher to use this script.\n" +Please manually update to version $MinSupportedFirmwareVers or higher to use this script.\n" "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" return 1 fi @@ -5649,7 +5645,14 @@ Please manually update to version $minimum_supported_version or higher to use th ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Apr-25] ## ##------------------------------------------## - if "$isGNUtonFW" + if "$offlineUpdateTrigger" + then + if ! "$isGNUtonFW" + then + _CheckOfflineFirmwareSHA256_ + retCode="$?" + fi + elif "$isGNUtonFW" then _CheckFirmwareMD5_ retCode="$?" @@ -5660,6 +5663,7 @@ Please manually update to version $minimum_supported_version or higher to use th if [ "$retCode" -eq 1 ] then "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + _Reset_LEDs_ return 1 fi @@ -6689,17 +6693,20 @@ _ShowMainMenu_() Say "${REDct}WARNING:${NOct} ${scriptUpdateNotify}${NOct}\n" fi - # Unsupported Model Checks # - if [ "$ModelCheckFailed" != "0" ]; then + # Unsupported Model Check # + if "$routerModelCheckFailed" + then Say "${REDct}WARNING:${NOct} The current router model is not supported by this script. Please uninstall.\n" fi - if [ "$MinFirmwareCheckFailed" != "0" ]; then + if "$MinFirmwareVerCheckFailed" + then Say "${REDct}WARNING:${NOct} The current firmware version is below the minimum supported. - Please manually update to version $minimum_supported_version or higher to use this script.\n" +Please manually update to version $MinSupportedFirmwareVers or higher to use this script.\n" fi - if ! _HasRouterMoreThan256MBtotalRAM_ && ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR"; then + if ! _HasRouterMoreThan256MBtotalRAM_ && ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" + then Say "${REDct}WARNING:${NOct} Limited RAM detected (256MB). A USB drive is required for F/W updates.\n" fi From 2340cb3e5a8c6fb634c9de74abff2e72335a4b00 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 4 Aug 2024 04:57:46 -0400 Subject: [PATCH 167/185] Update MerlinAU.sh --- MerlinAU.sh | 307 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 232 insertions(+), 75 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index acf6da4e..01202874 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -370,7 +370,7 @@ _GetDefaultUSBMountPoint_() ## Modified by Martinski W. [2024-May-31] ## ##----------------------------------------## # Background function to create a blinking LED effect # -Toggle_LEDs() +_Toggle_LEDs_() { if [ -z "$LEDsToggleState" ] then @@ -1248,7 +1248,7 @@ _Set_FW_UpdateLOG_DirectoryPath_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Jul-29] ## +## Modified by Martinski W. [2024-Jul-31] ## ##----------------------------------------## _Set_FW_UpdateZIP_DirectoryPath_() { @@ -1263,7 +1263,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() else printf "Default directory for 'Local' storage is: [${GRNct}/home/root${NOct}]\n" fi - printf "\n[${theADExitStr}] [CURRENT: ${GRNct}${FW_ZIP_BASE_DIR}${NOct}]: " + printf "\n[${theADExitStr}] [CURRENT: ${GRNct}${FW_ZIP_BASE_DIR}${NOct}]: " read -r userInput @@ -1803,7 +1803,7 @@ _CreateDirectory_() if [ ! -d "$1" ] then Say "${REDct}**ERROR**${NOct}: Unable to create directory [$1] to download firmware." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 1 fi if ! "$offlineUpdateTrigger" @@ -2295,13 +2295,147 @@ _TestLoginCredentials_() } ##----------------------------------------## -## Modified by Martinski W. [2024-May-23] ## +## Modified by Martinski W. [2024-Jul-30] ## +##----------------------------------------## +_GetRawKeypress_() +{ + local savedSettings + savedSettings="$(stty -g)" + stty -echo raw + echo "$(dd count=1 2>/dev/null)" + stty "$savedSettings" +} + +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-31] ## +##----------------------------------------## +_GetKeypressInput_() +{ + local inputStrLenMAX=16 inputString promptStr + local charNum inputStrLen keypressCount + local theKeySeqCnt maxKeySeqCnt=4 retCode + local theKeySeqNum maxKeySeqNum="27251624" + local offlineModeFlag=false + + if [ -n "${offlineUpdateFlag:+xSETx}" ] + then offlineModeFlag=true ; fi + + if [ $# -eq 0 ] || [ -z "$1" ] + then + printf "\n**ERROR**: NO prompt string was provided.\n" + return 1 + fi + promptStr="$1" + + _ShowInputString_() + { printf "\r\033[0K${promptStr} %s" "$inputString" ; } + + _ClearKeySeqState_() + { + theKeySeqNum=0 ; theKeySeqCnt=0 + if "$offlineModeFlag" + then offlineUpdateFlag=false + else unset offlineUpdateFlag + fi + } + + charNum="" + inputString="" + inputStrLen=0 + keypressCount=0 + _ClearKeySeqState_ + _ShowInputString_ + + local savedIFS="$IFS" + while IFS='' theChar="$(_GetRawKeypress_)" + do + charNum="$(printf "%d" "'$theChar")" + + if [ "$charNum" -eq 0 ] || [ "$charNum" -eq 10 ] || [ "$charNum" -eq 13 ] + then + if [ "$inputStrLen" -gt 0 ] + then retCode=0 ; else retCode=1 ; fi + break + fi + + ## BACKSPACE keypress ## + if [ "$charNum" -eq 8 ] || [ "$charNum" -eq 127 ] + then + if [ "$inputStrLen" -gt 0 ] + then + inputString="${inputString%?}" + inputStrLen="${#inputString}" + _ShowInputString_ + fi + _ClearKeySeqState_ + continue + fi + + ## BACKSPACE ALL keypress ## + if [ "$charNum" -eq 21 ] + then + if [ "$inputStrLen" -gt 0 ] + then + inputString="" + inputStrLen=0 + _ShowInputString_ + fi + _ClearKeySeqState_ + continue + fi + + ## ONLY 7-bit ASCII printable characters are VALID ## + if [ "$charNum" -gt 31 ] && [ "$charNum" -lt 127 ] + then + if [ "$inputStrLen" -le "$inputStrLenMAX" ] + then + inputString="${inputString}${theChar}" + inputStrLen="${#inputString}" + fi + _ShowInputString_ + _ClearKeySeqState_ + continue + fi + + # Non-Printable ASCII Codes ## + if "$offlineModeFlag" && [ "$charNum" -gt 0 ] && [ "$charNum" -lt 32 ] + then + offlineUpdateFlag=false + theKeySeqCnt="$((theKeySeqCnt + 1))" + if [ "$theKeySeqCnt" -eq 1 ] + then theKeySeqNum="$charNum" + else theKeySeqNum="${theKeySeqNum}${charNum}" + fi + if [ "$theKeySeqCnt" -eq "$maxKeySeqCnt" ] && \ + [ "$theKeySeqNum" -eq "$maxKeySeqNum" ] + then + _ClearKeySeqState_ + if [ "$inputString" = "offline" ] + then offlineUpdateFlag=true ; fi + continue + fi + if [ "$theKeySeqCnt" -gt "$maxKeySeqCnt" ] || \ + { [ "$theKeySeqCnt" -eq "$maxKeySeqCnt" ] && \ + [ "$theKeySeqNum" -ne "$maxKeySeqNum" ] ; } + then _ClearKeySeqState_ ; fi + else + _ClearKeySeqState_ + fi + done + IFS="$savedIFS" + + theUserInputStr="$inputString" + return "$retCode" +} + +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-31] ## ##----------------------------------------## _GetPasswordInput_() { local PSWDstrLenMIN=1 PSWDstrLenMAX=64 - local PSWDstring PSWDtmpStr PSWDprompt - local retCode charNum pswdLength showPSWD + local newPSWDstring newPSWDtmpStr PSWDprompt + local retCode charNum newPSWDlength showPSWD # For more responsive TAB keypress debounce # local tabKeyDebounceSem="/tmp/var/tmp/${ScriptFNameTag}_TabKeySEM.txt" @@ -2312,15 +2446,6 @@ _GetPasswordInput_() fi PSWDprompt="$1" - _GetKeypress_() - { - local savedSettings - savedSettings="$(stty -g)" - stty -echo raw - echo "$(dd count=1 2>/dev/null)" - stty "$savedSettings" - } - _TabKeyDebounceWait_() { touch "$tabKeyDebounceSem" @@ -2339,41 +2464,41 @@ _GetPasswordInput_() _ShowPSWDPrompt_() { local pswdTemp LENct LENwd - [ "$showPSWD" = "1" ] && pswdTemp="$PSWDstring" || pswdTemp="$PSWDtmpStr" - if [ "$pswdLength" -lt "$PSWDstrLenMIN" ] || [ "$pswdLength" -gt "$PSWDstrLenMAX" ] + [ "$showPSWD" = "1" ] && pswdTemp="$newPSWDstring" || pswdTemp="$newPSWDtmpStr" + if [ "$newPSWDlength" -lt "$PSWDstrLenMIN" ] || [ "$newPSWDlength" -gt "$PSWDstrLenMAX" ] then LENct="$REDct" ; LENwd="" else LENct="$GRNct" ; LENwd="02" fi - printf "\r\033[0K$PSWDprompt [Length=${LENct}%${LENwd}d${NOct}]: %s" "$pswdLength" "$pswdTemp" + printf "\r\033[0K$PSWDprompt [Length=${LENct}%${LENwd}d${NOct}]: %s" "$newPSWDlength" "$pswdTemp" } showPSWD=0 charNum="" - PSWDstring="$pswdString" - pswdLength="${#PSWDstring}" - PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" + newPSWDstring="$thePWSDstring" + newPSWDlength="${#newPSWDstring}" + newPSWDtmpStr="$(_ShowAsterisks_ "$newPSWDlength")" echo ; _ShowPSWDPrompt_ local savedIFS="$IFS" - while IFS='' theChar="$(_GetKeypress_)" + while IFS='' theChar="$(_GetRawKeypress_)" do charNum="$(printf "%d" "'$theChar")" - if [ "$theChar" = "" ] || [ "$charNum" -eq 13 ] + if [ "$charNum" -eq 0 ] || [ "$charNum" -eq 10 ] || [ "$charNum" -eq 13 ] then - if [ "$pswdLength" -ge "$PSWDstrLenMIN" ] && [ "$pswdLength" -le "$PSWDstrLenMAX" ] + if [ "$newPSWDlength" -ge "$PSWDstrLenMIN" ] && [ "$newPSWDlength" -le "$PSWDstrLenMAX" ] then echo retCode=0 - elif [ "$pswdLength" -lt "$PSWDstrLenMIN" ] + elif [ "$newPSWDlength" -lt "$PSWDstrLenMIN" ] then - PSWDstring="" + newPSWDstring="" printf "\n${REDct}**ERROR**${NOct}: Password length is less than allowed minimum length " printf "[MIN=${GRNct}${PSWDstrLenMIN}${NOct}].\n" retCode=1 - elif [ "$pswdLength" -gt "$PSWDstrLenMAX" ] + elif [ "$newPSWDlength" -gt "$PSWDstrLenMAX" ] then - PSWDstring="" + newPSWDstring="" printf "\n${REDct}**ERROR**${NOct}: Password length is greater than allowed maximum length " printf "[MAX=${GRNct}${PSWDstrLenMAX}${NOct}].\n" retCode=1 @@ -2381,8 +2506,13 @@ _GetPasswordInput_() break fi - ## Ignore Escape Sequences ## - [ "$charNum" -eq 27 ] && continue + ## Keep same previous password string ## + if [ "$charNum" -eq 27 ] && [ -n "$thePWSDstring" ] + then + retCode=0 + newPSWDstring="$thePWSDstring" + break + fi ## TAB keypress as toggle with debounce ## if [ "$charNum" -eq 9 ] @@ -2399,41 +2529,55 @@ _GetPasswordInput_() ## BACKSPACE keypress ## if [ "$charNum" -eq 8 ] || [ "$charNum" -eq 127 ] then - if [ "$pswdLength" -gt 0 ] + if [ "$newPSWDlength" -gt 0 ] then - PSWDstring="${PSWDstring%?}" - pswdLength="${#PSWDstring}" - PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" + newPSWDstring="${newPSWDstring%?}" + newPSWDlength="${#newPSWDstring}" + newPSWDtmpStr="$(_ShowAsterisks_ "$newPSWDlength")" _ShowPSWDPrompt_ - continue fi + continue + fi + + ## BACKSPACE ALL keypress ## + if [ "$charNum" -eq 21 ] + then + if [ "$newPSWDlength" -gt 0 ] + then + newPSWDstring="" + newPSWDlength=0 + newPSWDtmpStr="$(_ShowAsterisks_ "$newPSWDlength")" + _ShowPSWDPrompt_ + fi + continue fi ## ONLY 7-bit ASCII printable characters are VALID ## if [ "$charNum" -gt 31 ] && [ "$charNum" -lt 127 ] then - if [ "$pswdLength" -le "$PSWDstrLenMAX" ] + if [ "$newPSWDlength" -le "$PSWDstrLenMAX" ] then - PSWDstring="${PSWDstring}${theChar}" - pswdLength="${#PSWDstring}" - PSWDtmpStr="$(_ShowAsterisks_ "$pswdLength")" - _ShowPSWDPrompt_ - continue + newPSWDstring="${newPSWDstring}${theChar}" + newPSWDlength="${#newPSWDstring}" + newPSWDtmpStr="$(_ShowAsterisks_ "$newPSWDlength")" fi + _ShowPSWDPrompt_ + continue fi done IFS="$savedIFS" - pswdString="$PSWDstring" + thePWSDstring="$newPSWDstring" return "$retCode" } ##----------------------------------------## -## Modified by Martinski W. [2024-Feb-29] ## +## Modified by Martinski W. [2024-Jul-30] ## ##----------------------------------------## _GetLoginCredentials_() { - local retry="yes" userName pswdString + local retry="yes" userName savedMsg + local oldPWSDstring thePWSDstring local loginCredsENC loginCredsDEC # Get the Username from NVRAM # @@ -2442,17 +2586,18 @@ _GetLoginCredentials_() loginCredsENC="$(Get_Custom_Setting credentials_base64)" if [ -z "$loginCredsENC" ] || [ "$loginCredsENC" = "TBD" ] then - pswdString="" + thePWSDstring="" else loginCredsDEC="$(echo "$loginCredsENC" | openssl base64 -d)" - pswdString="$(echo "$loginCredsDEC" | sed "s/${userName}://")" + thePWSDstring="$(echo "$loginCredsDEC" | sed "s/${userName}://")" fi + oldPWSDstring="$thePWSDstring" while [ "$retry" = "yes" ] do echo "=== Login Credentials ===" _GetPasswordInput_ "Enter password for user ${GRNct}${userName}${NOct}" - if [ -z "$pswdString" ] + if [ -z "$thePWSDstring" ] then printf "\nPassword string is ${REDct}NOT${NOct} valid. Credentials were not saved.\n" _WaitForEnterKey_ @@ -2460,12 +2605,16 @@ _GetLoginCredentials_() fi # Encode the Username and Password in Base64 # - loginCredsENC="$(echo -n "${userName}:${pswdString}" | openssl base64 -A)" + loginCredsENC="$(echo -n "${userName}:${thePWSDstring}" | openssl base64 -A)" # Save the credentials to the SETTINGSFILE # Update_Custom_Settings credentials_base64 "$loginCredsENC" - printf "\n${GRNct}Credentials saved.${NOct}\n" + if [ "$thePWSDstring" != "$oldPWSDstring" ] + then savedMsg="${GRNct}New credentials saved.${NOct}" + else savedMsg="${GRNct}Credentials remain unchanged.${NOct}" + fi + printf "\n${savedMsg}\n" printf "Encoded Credentials:\n" printf "${GRNct}$loginCredsENC${NOct}\n" @@ -5236,7 +5385,7 @@ _RunFirmwareUpdateNow_() return 0 else Say "Uninstallation cancelled. Exiting script." - _WaitForEnterKey_ "$mainMenuReturnPromptStr" + _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 0 fi else @@ -5248,11 +5397,12 @@ _RunFirmwareUpdateNow_() then Say "${REDct}WARNING:${NOct} The current firmware version is below the minimum supported. Please manually update to version $MinSupportedFirmwareVers or higher to use this script.\n" - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 1 fi - Say "\n${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" + echo + Say "${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" Say "Running the update task now... Checking for F/W updates..." FlashStarted=true @@ -5265,7 +5415,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi then Say "Expected directory path $FW_ZIP_BASE_DIR is NOT found." Say "${REDct}**ERROR**${NOct}: Required USB storage device is not connected or not mounted correctly." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 1 fi @@ -5457,7 +5607,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi if [ -z "$credsBase64" ] || [ "$credsBase64" = "TBD" ] then Say "${REDct}**ERROR**${NOct}: No login credentials have been saved. Use the Main Menu to save login credentials." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 1 fi @@ -5471,7 +5621,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi if ! _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" 1 then Say "${REDct}**ERROR**${NOct}: A USB drive is required for the F/W update due to limited RAM." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" return 1 fi fi @@ -5515,6 +5665,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi then Say "${REDct}**ERROR**${NOct}: Firmware files were not downloaded successfully." "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + _Reset_LEDs_ return 1 fi fi @@ -5540,7 +5691,8 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi if [ "$retCode" -eq 1 ] then - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" + _Reset_LEDs_ return 1 fi @@ -5560,7 +5712,8 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi if [ "$retCode" -eq 1 ] then - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" + _Reset_LEDs_ return 1 fi @@ -5662,7 +5815,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi if [ "$retCode" -eq 1 ] then - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" _Reset_LEDs_ return 1 fi @@ -5851,7 +6004,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi fi - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" } ##-------------------------------------## @@ -6279,9 +6432,9 @@ check_version_support ##-------------------------------------## _CheckEMailConfigFileFromAMTM_ 0 -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jul-03] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-31] ## +##----------------------------------------## if [ $# -gt 0 ] then inMenuMode=false @@ -6988,7 +7141,7 @@ _ShowAdvancedOptionsMenu_() printf "\n ${GRNct}un${NOct}. Uninstall\n" printf "\n ${GRNct}e${NOct}. Return to Main Menu\n" - printf "${SEPstr}" + printf "${SEPstr}\n" } ##---------------------------------------## @@ -7099,18 +7252,19 @@ _AdvancedLogsOptions_() done } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-27] ## -##------------------------------------------## -_advanced_options_menu_() +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-31] ## +##----------------------------------------## +_AdvancedOptionsMenu_() { + local theUserInputStr="" + local offlineUpdateFlag=false while true do _ShowAdvancedOptionsMenu_ - printf "\nEnter selection: " - read -r advancedChoice + _GetKeypressInput_ "Enter selection:" echo - case $advancedChoice in + case "$theUserInputStr" in 1) _Set_FW_UpdateZIP_DirectoryPath_ ;; 2) _Set_FW_UpdateCronSchedule_ @@ -7154,9 +7308,12 @@ _advanced_options_menu_() ;; un) _DoUninstall_ && _WaitForEnterKey_ ;; - e|exit) break + e|E|exit) break ;; - *) _InvalidMenuSelection_ + *) if [ -n "${offlineUpdateFlag:+OK}" ] && "$offlineUpdateFlag" + then _RunOfflineUpdateNow_ ; [ "$?" -eq 2 ] && _InvalidMenuSelection_ + else _InvalidMenuSelection_ + fi ;; esac done @@ -7205,7 +7362,7 @@ do ;; up) _SCRIPTUPDATE_ ;; - ad) _advanced_options_menu_ + ad) _AdvancedOptionsMenu_ ;; mn) if "$inRouterSWmode" && [ -n "$node_list" ] then _ShowNodesMenuOptions_ @@ -7214,7 +7371,7 @@ do ;; lo) _AdvancedLogsOptions_ ;; - e|exit) _DoExit_ 0 + e|E|exit) _DoExit_ 0 ;; *) _InvalidMenuSelection_ ;; From 9f03004dfa959deba362de4e2ad16979b120f327 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 4 Aug 2024 05:01:01 -0400 Subject: [PATCH 168/185] Update MerlinAU.sh --- MerlinAU.sh | 59 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 01202874..bf159cfb 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4943,7 +4943,7 @@ _Toggle_FW_UpdateCheckSetting_() } ##----------------------------------------## -## Modified by Martinski W. [2024-Jul-24] ## +## Modified by Martinski W. [2024-Aug-02] ## ##----------------------------------------## _EntwareServicesHandler_() { @@ -4951,11 +4951,12 @@ _EntwareServicesHandler_() local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)" local actionStr="" - local serviceStr serviceCnt=0 + local servicesList servicesCnt=0 local entwOPT_init entwOPT_unslung - # space-delimited list # - local skipServiceList="tailscaled" - local skippedService skippedServiceFile skippedServiceList="" + # space-delimited list of services to skip # + local skipServiceList="tailscaled zerotier-one sshd" + local skippedService skippedServiceFile skippedServiceName + local theSkippedServiceList="" entwOPT_init="/opt/etc/init.d" entwOPT_unslung="${entwOPT_init}/rc.unslung" @@ -4971,10 +4972,11 @@ _EntwareServicesHandler_() _RenameSkippedService_() { - [ -z "$skippedServiceList" ] && return 1 - for skippedServiceFile in $skippedServiceList + [ -z "$theSkippedServiceList" ] && return 1 + for skippedServiceName in $theSkippedServiceList do # Rename service file back to original state # - if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile" + skippedServiceFile="${entwOPT_init}/$skippedServiceName" + if mv -f "${entwOPT_init}/OFF.${skippedServiceName}.OFF" "$skippedServiceFile" then Say "Skipped $skippedServiceFile $1 call." ; fi done return 0 @@ -4983,35 +4985,40 @@ _EntwareServicesHandler_() if [ ! -x /opt/bin/opkg ] || [ ! -x "$entwOPT_unslung" ] then return 0 ; fi ## Entware is NOT found ## - serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")" + servicesList="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")" + [ -z "$servicesList" ] && return 0 - [ -n "$serviceStr" ] && Say "Looking for Entware services..." + Say "Searching for Entware services to ${1}..." # Filter out services to skip and add a "skip message" # if [ "$AllowVPN" = "ENABLED" ] && [ -n "$skipServiceList" ] then for skipService in $skipServiceList do - skippedService="$(echo "$serviceStr" | /bin/grep -E "/S[0-9]+.*${skipService}$")" + skippedService="$(echo "$servicesList" | /bin/grep -E "/S[0-9]+.*${skipService}([.]sh)?$")" if [ -n "$skippedService" ] then - skippedServiceFile="$(basename "$skippedService")" - Say "Skipping $skippedServiceFile $1 call..." - # Rename service file so it's skipped by Entware # - if mv -f "${entwOPT_init}/$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" - then - [ -z "$skippedServiceList" ] && \ - skippedServiceList="$skippedServiceFile" || \ - skippedServiceList="$skippedServiceList $skippedServiceFile" - serviceStr="$(echo "$serviceStr" | /bin/grep -vE "/S[0-9]+.*${skipService}$")" - fi + for skippedServiceFile in $skippedService + do + skippedServiceName="$(basename "$skippedServiceFile")" + Say "Skipping $skippedServiceFile $1 call..." + # Rename service file so it's skipped by Entware # + if mv -f "$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceName}.OFF" + then + [ -z "$theSkippedServiceList" ] && \ + theSkippedServiceList="$skippedServiceName" || \ + theSkippedServiceList="$theSkippedServiceList $skippedServiceName" + servicesList="$(echo "$servicesList" | /bin/grep -vE "${skippedServiceFile}$")" + fi + done fi done fi - [ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)" - if [ "$serviceCnt" -eq 0 ] + [ -n "$servicesList" ] && servicesCnt="$(echo "$servicesList" | wc -l)" + if [ "$servicesCnt" -eq 0 ] then + Say "No Entware services to ${1}." _RenameSkippedService_ "$1" && echo return 0 fi @@ -5019,8 +5026,8 @@ _EntwareServicesHandler_() Say "${actionStr} Entware services..." "$isInteractive" && printf "Please wait.\n" Say "-----------------------------------------------------------" - # List the Entware service scripts found # - echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done + # List the Entware services found to stop/start # + echo "$servicesList" | while IFS= read -r servLine ; do Say "$servLine" ; done Say "-----------------------------------------------------------" $entwOPT_unslung "$1" ; sleep 5 @@ -6990,7 +6997,7 @@ _ShowAdvancedOptionsMenu_() fi local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")" - printf "\n ${GRNct}4${NOct}. Toggle Tailscale Access During Updates" + printf "\n ${GRNct}4${NOct}. Toggle Tailscale/ZeroTier Access During Updates" if [ "$VPNAccess" = "DISABLED" ] then printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n" From 7a0601bcb97696f02359c31fa841d282f2bc39bd Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 4 Aug 2024 05:41:01 -0400 Subject: [PATCH 169/185] Update MerlinAU.sh --- MerlinAU.sh | 317 ---------------------------------------------------- 1 file changed, 317 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index e476db10..67877f7a 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5366,323 +5366,6 @@ _RunOfflineUpdateNow_() fi } -##----------------------------------------## -## Modified by Martinski W. [2024-Jan-25] ## -##----------------------------------------## -_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-9a-zA-Z]+' - local fwVersionFormat - - # Extract the version number using regex # - firmware_version="$(echo "$zip_file" | grep -oE "$extract_version_regex")" - - # Check if the router model is supported OR if - # it has the minimum firmware version supported. - if "$routerModelCheckFailed" - then - Say "${REDct}WARNING:${NOct} The current router model is not supported by this script." - if "$inMenuMode" - then - printf "\nWould you like to uninstall the script now?" - if _WaitForYESorNO_ - then - _DoUninstall_ - return 0 - else - Say "Uninstallation cancelled. Exiting script." - _WaitForEnterKey_ "$theMenuReturnPromptMsg" - return 0 - fi - else - Say "Exiting script due to unsupported router model." - _DoExit_ 1 - fi - fi - if "$MinFirmwareVerCheckFailed" && ! "$offlineUpdateTrigger" - then - Say "${REDct}WARNING:${NOct} The current firmware version is below the minimum supported. -Please manually update to version $MinSupportedFirmwareVers or higher to use this script.\n" - "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" - return 1 - fi - - echo - Say "${GRNct}MerlinAU${NOct} v$SCRIPT_VERSION" - Say "Running the update task now... Checking for F/W updates..." - FlashStarted=true - - zipFileList="$(ls -A1 "$FW_ZIP_DIR"/*.zip 2>/dev/null)" - fileCount=1 - for zipFile in $zipFileList - do - printf "${GRNct}%d${NOct}) %s\n" "$fileCount" "$zipFile" - fileCount="$((fileCount + 1))" - done - - # Prompt user to select a ZIP file # - printf "\n---------------------------------------------------\n" - printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: " - read -r selection - - if [ -z "$selection" ] - then - printf "\n${REDct}Invalid selection${NOct}. Please try again.\n" - _WaitForEnterKey_ - clear - continue - fi - - if echo "$selection" | grep -qE "^(e|E|exit|Exit)$" - then - printf "Update process was cancelled. Exiting.\n" - return 1 - fi - - # Validate selection # - selected_file="$(echo "$zipFileList" | awk "NR==$selection")" - if [ -z "$selected_file" ] - then - printf "\n${REDct}Invalid selection${NOct}. Please try again.\n" - _WaitForEnterKey_ - clear - continue - else - clear - printf "\n---------------------------------------------------\n" - printf "\nYou have selected:\n${GRNct}$selected_file${NOct}\n" - break - fi - done - - # Extract or prompt for firmware version # - _GetOfflineFirmwareVersion_ "$selected_file" - - # Confirm the selection - if _WaitForYESorNO_ "\nDo you want to continue with the selected ZIP file?" - then - printf "\n---------------------------------------------------\n" - printf "\nStarting firmware update with the selected ZIP file.\n" - # Rename the selected ZIP file # - new_file_name="${PRODUCT_ID}_firmware.zip" - mv -f "$selected_file" "${FW_ZIP_DIR}/$new_file_name" - if [ $? -eq 0 ] - then - printf "\nFile packaged to ${GRNct}${new_file_name}${NOct}" - printf "\nRelease version: ${GRNct}${release_version}${NOct}\n" - printf "\n---------------------------------------------------\n" - _WaitForEnterKey_ - clear - return 0 - else - printf "\nFailed to rename the ZIP file. Exiting.\n" - return 1 - fi - else - printf "Operation was cancelled by user. Exiting.\n" - return 1 - fi -} - -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jul-23] ## -##------------------------------------------## -_RunBackupmon_() -{ - # Check for the presence of backupmon.sh script - if [ -f "/jffs/scripts/backupmon.sh" ] - then - local current_backup_settings="$(Get_Custom_Setting "FW_Auto_Backupmon")" - if [ "$current_backup_settings" = "ENABLED" ] - then - # Extract version number from backupmon.sh - local BM_VERSION="$(grep "^Version=" /jffs/scripts/backupmon.sh | awk -F'"' '{print $2}')" - - # Adjust version format from 1.46 to 1.4.6 if needed - local DOT_COUNT="$(echo "$BM_VERSION" | tr -cd '.' | wc -c)" - if [ "$DOT_COUNT" -eq 0 ]; then - # If there's no dot, it's a simple version like "1" (unlikely but let's handle it) - BM_VERSION="${BM_VERSION}.0.0" - elif [ "$DOT_COUNT" -eq 1 ]; then - # For versions like 1.46, insert a dot before the last two digits - BM_VERSION="$(echo "$BM_VERSION" | sed 's/\.\([0-9]\)\([0-9]\)/.\1.\2/')" - fi - - # Convert version strings to comparable numbers - local currentBM_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")" - local requiredBM_version="$(_ScriptVersionStrToNum_ "1.5.3")" - - # Check if BACKUPMON version is greater than or equal to 1.5.3 - if [ "$currentBM_version" -ge "$requiredBM_version" ]; then - # Execute the backup script if it exists # - echo "" - Say "Backup Started (by BACKUPMON)" - sh /jffs/scripts/backupmon.sh -backup >/dev/null - BE=$? - Say "Backup Finished" - echo "" - if [ $BE -eq 0 ]; then - Say "Backup Completed Successfully" - echo "" - else - Say "Backup Failed" - echo "" - _SendEMailNotification_ NEW_BM_BACKUP_FAILED - _DoCleanUp_ 1 - if "$isInteractive" - then - printf "\n${REDct}**IMPORTANT NOTICE**:${NOct}\n" - printf "The firmware flash has been ${REDct}CANCELLED${NOct} due to a failed backup from BACKUPMON.\n" - printf "Please fix the BACKUPMON configuration, or consider uninstalling it to proceed flash.\n" - printf "Resolving the BACKUPMON configuration is HIGHLY recommended for safety of the upgrade.\n" - _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - else - _DoExit_ 1 - fi - fi - else - # BACKUPMON version is not sufficient - echo "" - Say "${REDct}**IMPORTANT NOTICE**:${NOct}" - echo "" - Say "Backup script (BACKUPMON) is installed; but version $BM_VERSION does not meet the minimum required version of 1.5.3." - Say "Skipping backup. Please update your version of BACKUPMON." - echo "" - fi - else - Say "Backup script (BACKUPMON) is disabled in the advanced options. Skipping backup." - echo "" - fi - else - Say "Backup script (BACKUPMON) is not installed. Skipping backup." - echo "" - fi - return 0 -} - -##----------------------------------------## -## Modified by Martinski W. [2024-Jul-31] ## -##----------------------------------------## -_RunOfflineUpdateNow_() -{ - local offlineConfigFile="${SETTINGS_DIR}/offline_updates.txt" - - _ClearOfflineUpdateState_() - { - offlineUpdateTrigger=false - theMenuReturnPromptMsg="$mainMenuReturnPromptStr" - if [ $# -eq 0 ] || [ -z "$1" ] ; then return 0 ; fi - [ "$1" != "1" ] && printf "$1" - _WaitForEnterKey_ "$advnMenuReturnPromptStr" - } - - [ ! -s "$offlineConfigFile" ] && return 2 - - # Source the configuration file # - . "$offlineConfigFile" - - # Check required parameter # - if [ -z "${FW_OFFLINE_UPDATE_IS_ALLOWED:+xSETx}" ] || \ - [ "$FW_OFFLINE_UPDATE_IS_ALLOWED" != "true" ] - then return 2 ; fi - - # Reset FW_OFFLINE_UPDATE_ACCEPT_RISK to false # - if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" - then - sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"/" "$offlineConfigFile" - fi - - clear - printf "\n${REDct}***WARNING***${NOct}" - printf "\nYou are about to initiate an ${REDct}offline${NOct} firmware update." - printf "\nThe firmware image to be flashed is ${REDct}unvetted${NOct} and of ${REDct}unknown${NOct} origin.\n" - printf "\n1. This feature is intended for developers and advanced users only." - printf "\n2. No support will be offered when flashing firmware offline." - printf "\n3. This offline feature is excluded from documentation on purpose.\n" - printf "\nDo you acknowledge the risk and wish to proceed?" - printf "\nYou must type '${REDct}YES${NOct}' to continue.\n" - - read -r response - if [ "$response" = "YES" ] - then - # Add or update the setting to true # - if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" - then - sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"true\"/" "$offlineConfigFile" - else - # Ensure the new setting is added on a new line - echo "" >> "$offlineConfigFile" - echo "FW_OFFLINE_UPDATE_ACCEPT_RISK=\"true\"" >> "$offlineConfigFile" - fi - else - # Add or update the setting to false # - if grep -q "^FW_OFFLINE_UPDATE_ACCEPT_RISK=" "$offlineConfigFile" - then - sed -i "s/^FW_OFFLINE_UPDATE_ACCEPT_RISK=.*/FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"/" "$offlineConfigFile" - else - # Ensure the new setting is added on a new line # - echo "" >> "$offlineConfigFile" - echo "FW_OFFLINE_UPDATE_ACCEPT_RISK=\"false\"" >> "$offlineConfigFile" - fi - _ClearOfflineUpdateState_ "Offline update was aborted. Exiting.\n" - return 1 - fi - clear - logo - printf "\n---------------------------------------------------\n" - - offlineUpdateTrigger=true - theMenuReturnPromptMsg="$advnMenuReturnPromptStr" - - if _Set_FW_UpdateZIP_DirectoryPath_ - then - clear - # Create directory for downloading & extracting firmware # - if ! _CreateDirectory_ "$FW_ZIP_DIR" - then - _ClearOfflineUpdateState_ 1 ; return 1 - fi - printf "\n---------------------------------------------------\n" - printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:" - printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" - printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" - printf "\n---------------------------------------------------\n" - if _WaitForYESorNO_ - then - clear - printf "\n---------------------------------------------------\n" - printf "\nContinuing to the ZIP file selection process.\n" - if _SelectOfflineZipFile_ - then - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") - if [ $? -eq 0 ] && [ $# -eq 2 ] && \ - [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] - then - release_link="$2" - _RunFirmwareUpdateNow_ - _ClearOfflineUpdateState_ - else - Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." - _ClearOfflineUpdateState_ 1 - return 1 - fi - else - _ClearOfflineUpdateState_ 1 - return 1 - fi - else - _ClearOfflineUpdateState_ "Offline update process was cancelled. Exiting.\n" - return 1 - fi - else - _ClearOfflineUpdateState_ "Offline update process was cancelled. Exiting.\n" - return 1 - fi -} - ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jul-31] ## ##------------------------------------------## From c63a57722605103b1f40f893fdbde20f0a92a970 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 6 Aug 2024 01:35:24 -0400 Subject: [PATCH 170/185] Update MerlinAU.sh --- MerlinAU.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 67877f7a..d5b82ce1 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1383,6 +1383,7 @@ readonly hookScriptTagStr="#Added by $ScriptFNameTag#" # Postponement Days for F/W Update Check # FW_UpdatePostponementDays="$(Get_Custom_Setting FW_New_Update_Postponement_Days)" +FW_UpdateExpectedRunDate="$(Get_Custom_Setting FW_New_Update_Expected_Run_Date)" ##----------------------------------------## ## Modified by Martinski W. [2024-Feb-18] ## @@ -1482,7 +1483,11 @@ _CreateEMailContent_() rm -f "$tempEMailContent" "$tempEMailBodyMsg" - subjectStr="F/W Update Status for $MODEL_ID" + if [ -s "$tempNodeEMailList" ]; then + subjectStr="F/W Update Status for $node_lan_hostname" + else + subjectStr="F/W Update Status for $MODEL_ID" + fi fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" @@ -1503,6 +1508,7 @@ _CreateEMailContent_() echo "A new F/W Update version ${fwNewUpdateVersion} is available for the ${MODEL_ID} router." printf "\nThe F/W version that is currently installed:\n${fwInstalledVersion}\n" printf "\nNumber of days to postpone flashing the new F/W Update version: ${FW_UpdatePostponementDays}\n" + printf "\nThe firmware update is expected to occur on: ${FW_UpdateDate}\n" } > "$tempEMailBodyMsg" ;; AGGREGATED_UPDATE_NOTIFICATION) @@ -4768,6 +4774,7 @@ _CheckNodeFWUpdateNotification_() nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" echo "" > "$tempNodeEMailList" echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" + echo "Automated update will be scheduled only if MerlinAU is installed on the node." >> "$tempNodeEMailList" fi fi @@ -4779,6 +4786,7 @@ _CheckNodeFWUpdateNotification_() nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" echo "" > "$tempNodeEMailList" echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" + echo "Automated update will be scheduled only if MerlinAU is installed on the node." >> "$tempNodeEMailList" fi return 0 } From 717c904b75d9e0c5ae6dcee7e691b5881bafca22 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 6 Aug 2024 01:43:15 -0400 Subject: [PATCH 171/185] Update MerlinAU.sh --- MerlinAU.sh | 68 +++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d5b82ce1..7d86d316 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Aug-04 +# Last Modified: 2024-Aug-05 ################################################################### set -u @@ -1032,9 +1032,9 @@ _GetAllNodeSettings_() echo "$setting_value" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-Jun-27] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Aug-04] ## +##----------------------------------------## Update_Custom_Settings() { if [ $# -lt 2 ] || [ -z "$1" ] || [ -z "$2" ] ; then return 1 ; fi @@ -1098,6 +1098,10 @@ Update_Custom_Settings() then FW_UpdatePostponementDays="$setting_value" # + elif [ "$setting_type" = "FW_New_Update_Expected_Run_Date" ] + then + FW_UpdateExpectedRunDate="$setting_value" + # elif [ "$setting_type" = "FW_New_Update_EMail_Notification" ] then sendEMailNotificationsFlag="$setting_value" @@ -1471,9 +1475,9 @@ _GetLatestFWUpdateVersionFromRouter_() echo "$newVersionStr" ; return "$retCode" } -##------------------------------------------## -## Modified by ExtremeFiretop [2024-May-03] ## -##------------------------------------------## +##----------------------------------------## +## Modified by Martinski W. [2024-Aug-04] ## +##----------------------------------------## _CreateEMailContent_() { if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi @@ -1483,11 +1487,9 @@ _CreateEMailContent_() rm -f "$tempEMailContent" "$tempEMailBodyMsg" - if [ -s "$tempNodeEMailList" ]; then - subjectStr="F/W Update Status for $node_lan_hostname" - else - subjectStr="F/W Update Status for $MODEL_ID" - fi + if [ -s "$tempNodeEMailList" ] + then subjectStr="F/W Update Status for $node_lan_hostname" + else subjectStr="F/W Update Status for $MODEL_ID" fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" @@ -1508,7 +1510,8 @@ _CreateEMailContent_() echo "A new F/W Update version ${fwNewUpdateVersion} is available for the ${MODEL_ID} router." printf "\nThe F/W version that is currently installed:\n${fwInstalledVersion}\n" printf "\nNumber of days to postpone flashing the new F/W Update version: ${FW_UpdatePostponementDays}\n" - printf "\nThe firmware update is expected to occur on: ${FW_UpdateDate}\n" + [ "$FW_UpdateExpectedRunDate" != "TBD" ] && \ + printf "\nThe firmware update is expected to occur on: ${FW_UpdateExpectedRunDate}\n" } > "$tempEMailBodyMsg" ;; AGGREGATED_UPDATE_NOTIFICATION) @@ -4652,7 +4655,7 @@ _ManageChangelogGnuton_() } ##----------------------------------------## -## Modified by Martinski W. [2024-May-31] ## +## Modified by Martinski W. [2024-Aug-05] ## ##----------------------------------------## _CheckNewUpdateFirmwareNotification_() { @@ -4660,6 +4663,7 @@ _CheckNewUpdateFirmwareNotification_() then echo "**ERROR** **NO_PARAMS**" ; return 1 ; fi local numOfFields fwNewUpdateVersNum + local sendNewUpdateStatusEmail=false local currentVersionStr="$1" releaseVersionStr="$2" numOfFields="$(echo "$currentVersionStr" | awk -F '.' '{print NF}')" @@ -4671,6 +4675,7 @@ _CheckNewUpdateFirmwareNotification_() Say "Current firmware version '${currentVersionStr}' is up to date." Update_Custom_Settings FW_New_Update_Notification_Date TBD Update_Custom_Settings FW_New_Update_Notification_Vers TBD + Update_Custom_Settings FW_New_Update_Expected_Run_Date TBD Update_Custom_Settings FW_New_Update_Changelog_Approval TBD return 1 fi @@ -4689,10 +4694,7 @@ _CheckNewUpdateFirmwareNotification_() fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Vers "$fwNewUpdateNotificationVers" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" - if "$inRouterSWmode" - then - _SendEMailNotification_ NEW_FW_UPDATE_STATUS - fi + "$inRouterSWmode" && sendNewUpdateStatusEmail=true if ! "$FlashStarted" then if "$isGNUtonFW" @@ -4710,9 +4712,7 @@ _CheckNewUpdateFirmwareNotification_() then fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" - if "$inRouterSWmode" - then - _SendEMailNotification_ NEW_FW_UPDATE_STATUS + "$inRouterSWmode" && sendNewUpdateStatusEmail=true fi if ! "$FlashStarted" then @@ -4728,12 +4728,12 @@ _CheckNewUpdateFirmwareNotification_() fwNewUpdateNotificationDate="$(Get_Custom_Setting FW_New_Update_Notification_Date)" upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")" nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")" + if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ] - then - Update_Custom_Settings FW_New_Update_Expected_Run_Date "TBD" - else - Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs" + then Update_Custom_Settings FW_New_Update_Expected_Run_Date TBD + else Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs" fi + "$sendNewUpdateStatusEmail" && _SendEMailNotification_ NEW_FW_UPDATE_STATUS return 0 } @@ -4772,9 +4772,12 @@ _CheckNodeFWUpdateNotification_() nodefwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" - echo "" > "$tempNodeEMailList" - echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" - echo "Automated update will be scheduled only if MerlinAU is installed on the node." >> "$tempNodeEMailList" + { + echo "" + echo "AiMesh Node ${nodefriendlyname} with MAC address ${node_label_mac} requires update from ${1} to ${2} version." + echo "(${1} --> ${2})" + echo "Automated update will be scheduled only if MerlinAU is installed on the node." + } > "$tempNodeEMailList" fi fi @@ -4784,9 +4787,12 @@ _CheckNodeFWUpdateNotification_() nodefwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" _Populate_Node_Settings_ "$node_label_mac" "$node_lan_hostname" "$nodefwNewUpdateNotificationDate" "$nodefwNewUpdateNotificationVers" "$uid" nodefriendlyname="$(_GetAllNodeSettings_ "$node_label_mac" "Model_NameID")" - echo "" > "$tempNodeEMailList" - echo "AiMesh Node $nodefriendlyname with MAC Address: $node_label_mac requires update from $1 to $2 ($1 --> $2)" >> "$tempNodeEMailList" - echo "Automated update will be scheduled only if MerlinAU is installed on the node." >> "$tempNodeEMailList" + { + echo "" + echo "AiMesh Node ${nodefriendlyname} with MAC address ${node_label_mac} requires update from ${1} to ${2} version." + echo "(${1} --> ${2})" + echo "Automated update will be scheduled only if MerlinAU is installed on the node." + } > "$tempNodeEMailList" fi return 0 } From ac73c106299fbb37e001932f6bdc9f7815ce6391 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 6 Aug 2024 08:03:17 -0400 Subject: [PATCH 172/185] Update MerlinAU.sh --- MerlinAU.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index bbe2b455..3b482e60 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4714,7 +4714,6 @@ _CheckNewUpdateFirmwareNotification_() fwNewUpdateNotificationDate="$(date +"$FW_UpdateNotificationDateFormat")" Update_Custom_Settings FW_New_Update_Notification_Date "$fwNewUpdateNotificationDate" "$inRouterSWmode" && sendNewUpdateStatusEmail=true - fi if ! "$FlashStarted" then if "$isGNUtonFW" From 0d966aedd3fa1f1af31c74acecf0dc6b957578cf Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 6 Aug 2024 09:51:08 -0400 Subject: [PATCH 173/185] Update MerlinAU.sh --- MerlinAU.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 3b482e60..b7863b5f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -608,12 +608,12 @@ readonly CRON_MONTH_RegEx="$CRON_MONTH_NAMES([\/,-]$CRON_MONTH_NAMES)*|([*1-9]|1 readonly CRON_UNKNOWN_DATE="**ERROR**: UNKNOWN Date Found" ##------------------------------------------## -## Modified by Martinski W. [2024-Jan-22] ## +## Modified by Martinski W. [2024-Aug-06] ## ##------------------------------------------## # To postpone a firmware update for a few days # readonly FW_UpdateMinimumPostponementDays=0 readonly FW_UpdateDefaultPostponementDays=15 -readonly FW_UpdateMaximumPostponementDays=60 +readonly FW_UpdateMaximumPostponementDays=199 readonly FW_UpdateNotificationDateFormat="%Y-%m-%d_%H:%M:00" readonly MODEL_ID="$(_GetRouterModelID_)" @@ -4001,9 +4001,9 @@ _Calculate_DST_() { local notifyTimeStrn notifyTimeSecs currentTimeSecs dstAdjustSecs dstAdjustDays local postponeTimeSecs fwNewUpdatePostponementDays - + notifyTimeStrn="$1" - + currentTimeSecs="$(date +%s)" notifyTimeSecs="$(date +%s -d "$notifyTimeStrn")" @@ -4139,7 +4139,7 @@ _CheckPostponementDays_() ##------------------------------------------## _Set_FW_UpdatePostponementDays_() { - local validNumRegExp="([0-9]|[1-9][0-9])" + local validNumRegExp="([0-9]|[1-9][0-9]|1[0-9][0-9])" local oldPostponementDays newPostponementDays postponeDaysStr userInput oldPostponementDays="$(Get_Custom_Setting FW_New_Update_Postponement_Days TBD)" From 6514ed041448f92c9e29406c833bf7eaa5f8c32c Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 00:16:53 -0400 Subject: [PATCH 174/185] Update MerlinAU.sh --- MerlinAU.sh | 293 +++++++++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 141 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8a9b9615..86be0707 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4,7 +4,7 @@ # # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 -# Last Modified: 2024-Aug-06 +# Last Modified: 2024-Aug-05 ################################################################### set -u @@ -1260,7 +1260,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() while true do - printf "\nEnter the directory path where the ZIP subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" + printf "\nEnter the directory path where the update file subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" if [ -n "$USBMountPoint" ] && _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" then printf "Default directory for USB-attached drive: [${GRNct}${FW_ZIP_BASE_DIR}${NOct}]\n" @@ -1330,7 +1330,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -fr "${FW_LOG_DIR:?}" rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" - echo "The directory path for the F/W ZIP file was updated successfully." + echo "The directory path for the F/W update file was updated successfully." keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi @@ -3138,16 +3138,19 @@ else Say "File management is not required" fi -# Check and copy the MD5 file if different from destination -if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then - copy_attempted=0 - mv -f "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Moving MD5 file..." || copy_success=1 -fi +if ! "$offlineUpdateTrigger" +then + # Check and copy the MD5 file if different from destination + if [ "$FW_MD5_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then + copy_attempted=0 + mv -f "$FW_MD5_GITHUB" "$FW_BIN_DIR" && Say "Moving MD5 file..." || copy_success=1 + fi -# Check and copy the Changelog file if different from destination -if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then - copy_attempted=0 - mv -f "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Moving changelog file..." || copy_success=1 + # Check and copy the Changelog file if different from destination + if [ "$FW_Changelog_GITHUB" != "${FW_BIN_DIR}/${FW_FileName}_Changelog.txt" ]; then + copy_attempted=0 + mv -f "$FW_Changelog_GITHUB" "$FW_BIN_DIR" && Say "Moving changelog file..." || copy_success=1 + fi fi if [ $copy_attempted -eq 0 ] && [ $copy_success -eq 0 ] @@ -4134,9 +4137,9 @@ _CheckPostponementDays_() return "$retCode" } -##----------------------------------------## -## Modified by Martinski W. [2024-Aug-06] ## -##----------------------------------------## +##------------------------------------------## +## Modified by ExtremeFiretop [2024-May-06] ## +##------------------------------------------## _Set_FW_UpdatePostponementDays_() { local validNumRegExp="([0-9]|[1-9][0-9]|1[0-9][0-9])" @@ -4700,9 +4703,9 @@ _CheckNewUpdateFirmwareNotification_() then if "$isGNUtonFW" then - _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" + _ManageChangelogGnuton_ "download" "$fwNewUpdateNotificationVers" else - _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" + _ManageChangelogMerlin_ "download" "$fwNewUpdateNotificationVers" fi fi fi @@ -5074,7 +5077,7 @@ _GetOfflineFirmwareVersion_() fwVersionFormat="${BLUEct}BASE${WHITEct}.${CYANct}MAJOR${WHITEct}.${MAGENTAct}MINOR${WHITEct}.${YLWct}PATCH${NOct}" # Prompt user for the firmware version if extraction fails # printf "\n${REDct}**WARNING**${NOct}\n" - printf "\nFailed to identify firmware version from the ZIP file name." + printf "\nFailed to identify firmware version from the update file name." printf "\nPlease enter the firmware version number in the format ${fwVersionFormat}\n" printf "\n(Examples: 3004.388.8.0 or 3004.388.8.beta1): " read -r formatted_version @@ -5093,36 +5096,36 @@ _GetOfflineFirmwareVersion_() export release_version="$formatted_version" } -##----------------------------------------## -## Modified by Martinski W. [2024-Jul-30] ## -##----------------------------------------## -_SelectOfflineZipFile_() +##------------------------------------------## +## Modified by ExtremeFiretop [2024-Aug-06] ## +##------------------------------------------## +_SelectOfflineUpdateFile_() { - local selection zipFileList fileCount + local selection fileList fileCount - # Check if the directory is empty or no ZIP files are found # - if [ -z "$(ls -A "$FW_ZIP_DIR"/*.zip 2>/dev/null)" ] + # Check if the directory is empty or no desired files are found # + if [ -z "$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb "$FW_ZIP_DIR"/*.zip 2>/dev/null)" ] then - printf "\nNo ZIP files found in the directory. Exiting.\n" + printf "\nNo valid files found in the directory. Exiting.\n" printf "\n---------------------------------------------------\n" return 1 fi while true do - printf "\nAvailable ZIP files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" + printf "\nAvailable files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" - zipFileList="$(ls -A1 "$FW_ZIP_DIR"/*.zip 2>/dev/null)" + fileList="$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb "$FW_ZIP_DIR"/*.zip 2>/dev/null)" fileCount=1 - for zipFile in $zipFileList + for file in $fileList do - printf "${GRNct}%d${NOct}) %s\n" "$fileCount" "$zipFile" + printf "${GRNct}%d${NOct}) %s\n" "$fileCount" "$file" fileCount="$((fileCount + 1))" done - # Prompt user to select a ZIP file # + # Prompt user to select a file # printf "\n---------------------------------------------------\n" - printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: " + printf "\n[${theMUExitStr}] Enter the number of the file you want to select: " read -r selection if [ -z "$selection" ] @@ -5140,7 +5143,7 @@ _SelectOfflineZipFile_() fi # Validate selection # - selected_file="$(echo "$zipFileList" | awk "NR==$selection")" + selected_file="$(echo "$fileList" | awk "NR==$selection")" if [ -z "$selected_file" ] then printf "\n${REDct}Invalid selection${NOct}. Please try again.\n" @@ -5159,12 +5162,12 @@ _SelectOfflineZipFile_() _GetOfflineFirmwareVersion_ "$selected_file" # Confirm the selection - if _WaitForYESorNO_ "\nDo you want to continue with the selected ZIP file?" + if _WaitForYESorNO_ "\nDo you want to continue with the selected file?" then printf "\n---------------------------------------------------\n" - printf "\nStarting firmware update with the selected ZIP file.\n" - # Rename the selected ZIP file # - new_file_name="${PRODUCT_ID}_firmware.zip" + printf "\nStarting firmware update with the selected file.\n" + # Rename the selected file # + new_file_name="${PRODUCT_ID}_firmware.${selected_file##*.}" mv -f "$selected_file" "${FW_ZIP_DIR}/$new_file_name" if [ $? -eq 0 ] then @@ -5175,7 +5178,7 @@ _SelectOfflineZipFile_() clear return 0 else - printf "\nFailed to rename the ZIP file. Exiting.\n" + printf "\nFailed to rename the file. Exiting.\n" return 1 fi else @@ -5184,6 +5187,78 @@ _SelectOfflineZipFile_() fi } +_GnutonBuildSelection_() +{ + ##------------------------------------------## + ## Modified by ExtremeFiretop [2024-Apr-18] ## + ##------------------------------------------## + # Check if PRODUCT_ID is for a TUF model and requires user choice + if echo "$PRODUCT_ID" | grep -q "^TUF-"; then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "TUFBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found TUF build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the TUF build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "TUF Build selected for flashing" + firmware_choice="tuf" + Update_Custom_Settings "TUFBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "TUFBuild" "n" + fi + elif echo "$PRODUCT_ID" | grep -q "^GT-" + then + # Fetch the previous choice from the settings file + local previous_choice="$(Get_Custom_Setting "ROGBuild")" + + if [ "$previous_choice" = "y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + elif [ "$previous_choice" = "n" ]; then + echo "Pure Build selected for flashing" + firmware_choice="pure" + elif [ "$inMenuMode" = true ]; then + printf "${REDct}Found ROG build for: $PRODUCT_ID.${NOct}\n" + printf "${REDct}Would you like to use the ROG build?${NOct}\n" + printf "Enter your choice (y/n): " + read -r choice + if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then + echo "ROG Build selected for flashing" + firmware_choice="rog" + Update_Custom_Settings "ROGBuild" "y" + else + echo "Pure Build selected for flashing" + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi + else + echo "Defaulting to Pure Build due to non-interactive mode." + firmware_choice="pure" + Update_Custom_Settings "ROGBuild" "n" + fi + else + # If not a TUF model, process as usual + firmware_choice="pure" + fi + return 0 +} + ##------------------------------------------## ## Modified by ExtremeFiretop [2024-Jul-23] ## ##------------------------------------------## @@ -5353,9 +5428,22 @@ _RunOfflineUpdateNow_() clear printf "\n---------------------------------------------------\n" printf "\nContinuing to the ZIP file selection process.\n" - if _SelectOfflineZipFile_ + if _SelectOfflineUpdateFile_ then - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + if "$isGNUtonFW" + then + # Extract the filename from the path + original_filename=$(basename "$selected_file") + # Sanitize filename by removing problematic characters (if necessary) + sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + # Extract the file extension + extension="${sanitized_filename##*.}" + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + _GnutonBuildSelection_ + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") + else + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + fi if [ $? -eq 0 ] && [ $# -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] then @@ -5509,8 +5597,20 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi # Use set to read the output of the function into variables - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") - if [ $? -eq 0 ] && [ $# -eq 2 ] && \ + if "$isGNUtonFW" + then + Say "Using release information for Gnuton Firmware." + _GnutonBuildSelection_ + md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE" "$firmware_choice") + Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") + retCode="$?" + else + Say "Using release information for Merlin Firmware." + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + retCode="$?" + fi + if [ "$retCode" -eq 0 ] && [ $# -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] then release_version="$1" @@ -5528,97 +5628,6 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi fi - ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-18] ## - ##------------------------------------------## - if "$isGNUtonFW" - then - Say "Using release information for Gnuton Firmware." - # Check if PRODUCT_ID is for a TUF model and requires user choice - if echo "$PRODUCT_ID" | grep -q "^TUF-"; then - # Fetch the previous choice from the settings file - local previous_choice="$(Get_Custom_Setting "TUFBuild")" - - if [ "$previous_choice" = "y" ]; then - echo "TUF Build selected for flashing" - firmware_choice="tuf" - elif [ "$previous_choice" = "n" ]; then - echo "Pure Build selected for flashing" - firmware_choice="pure" - elif [ "$inMenuMode" = true ]; then - printf "${REDct}Found TUF build for: $PRODUCT_ID.${NOct}\n" - printf "${REDct}Would you like to use the TUF build?${NOct}\n" - printf "Enter your choice (y/n): " - read -r choice - if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then - echo "TUF Build selected for flashing" - firmware_choice="tuf" - Update_Custom_Settings "TUFBuild" "y" - else - echo "Pure Build selected for flashing" - firmware_choice="pure" - Update_Custom_Settings "TUFBuild" "n" - fi - else - echo "Defaulting to Pure Build due to non-interactive mode." - firmware_choice="pure" - Update_Custom_Settings "TUFBuild" "n" - fi - elif echo "$PRODUCT_ID" | grep -q "^GT-" - then - # Fetch the previous choice from the settings file - local previous_choice="$(Get_Custom_Setting "ROGBuild")" - - if [ "$previous_choice" = "y" ]; then - echo "ROG Build selected for flashing" - firmware_choice="rog" - elif [ "$previous_choice" = "n" ]; then - echo "Pure Build selected for flashing" - firmware_choice="pure" - elif [ "$inMenuMode" = true ]; then - printf "${REDct}Found ROG build for: $PRODUCT_ID.${NOct}\n" - printf "${REDct}Would you like to use the ROG build?${NOct}\n" - printf "Enter your choice (y/n): " - read -r choice - if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then - echo "ROG Build selected for flashing" - firmware_choice="rog" - Update_Custom_Settings "ROGBuild" "y" - else - echo "Pure Build selected for flashing" - firmware_choice="pure" - Update_Custom_Settings "ROGBuild" "n" - fi - else - echo "Defaulting to Pure Build due to non-interactive mode." - firmware_choice="pure" - Update_Custom_Settings "ROGBuild" "n" - fi - else - # If not a TUF model, process as usual - firmware_choice="pure" - fi - md5_url=$(GetLatestFirmwareMD5Url "$FW_GITURL_RELEASE" "$firmware_choice") - Gnuton_changelogurl=$(GetLatestChangelogUrl "$FW_GITURL_RELEASE") - set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") - retCode="$?" - else - Say "Using release information for Merlin Firmware." - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - retCode="$?" - fi - - if [ "$retCode" -eq 0 ] && [ "$#" -eq 2 ] && \ - [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] - then - release_version="$1" - release_link="$2" - else - Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." - "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" - return 1 - fi - # Extracting the F/W Update codebase number to use in the curl # fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)" # Inserting dots between each number @@ -5729,14 +5738,16 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## - _ChangelogVerificationCheck_ "interactive" - retCode="$?" + if ! [[ "$isGNUtonFW" && "$offlineUpdateTrigger" ]]; then + _ChangelogVerificationCheck_ "interactive" + retCode="$?" - if [ "$retCode" -eq 1 ] - then - "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" - _Reset_LEDs_ - return 1 + if [ "$retCode" -eq 1 ] + then + "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" + _Reset_LEDs_ + return 1 + fi fi freeRAM_kb="$(_GetFreeRAM_KB_)" @@ -6998,7 +7009,7 @@ _ShowAdvancedOptionsMenu_() printf "================== Advanced Options Menu =================\n" printf "${SEPstr}\n" - printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File" + printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update File" printf "\n${padStr}[Current Path: ${GRNct}${FW_ZIP_DIR}${NOct}]\n" printf "\n ${GRNct}2${NOct}. Set F/W Update Cron Schedule" From 61e040802942618ddde323873d4a0835495bd469 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 00:46:22 -0400 Subject: [PATCH 175/185] Update MerlinAU.sh --- MerlinAU.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 86be0707..71147c00 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1492,7 +1492,12 @@ _CreateEMailContent_() else subjectStr="F/W Update Status for $MODEL_ID" fi fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" - fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + if ! "$offlineUpdateTrigger" + then + fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + else + fwNewUpdateVersion="$release_version" + fi # Remove "_rog" or "_tuf" suffix to avoid version comparison failures fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_\(rog\|tuf\)$//')" From ef97b76c3ebdd527048f2f1bc92c3b4e10964884 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 00:59:52 -0400 Subject: [PATCH 176/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 71147c00..94400092 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5432,7 +5432,7 @@ _RunOfflineUpdateNow_() then clear printf "\n---------------------------------------------------\n" - printf "\nContinuing to the ZIP file selection process.\n" + printf "\nContinuing to the update file selection process.\n" if _SelectOfflineUpdateFile_ then if "$isGNUtonFW" From 11b07de3a60f779b6f557ca9f20b88b7b9543b07 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 02:39:14 -0400 Subject: [PATCH 177/185] Update MerlinAU.sh --- MerlinAU.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 94400092..d0bf58cf 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1260,7 +1260,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() while true do - printf "\nEnter the directory path where the update file subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" + printf "\nEnter the directory path where the ZIP subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" if [ -n "$USBMountPoint" ] && _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" then printf "Default directory for USB-attached drive: [${GRNct}${FW_ZIP_BASE_DIR}${NOct}]\n" @@ -1330,7 +1330,7 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -fr "${FW_LOG_DIR:?}" rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" - echo "The directory path for the F/W update file was updated successfully." + echo "The directory path for the F/W ZIP file was updated successfully." keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi @@ -5082,7 +5082,7 @@ _GetOfflineFirmwareVersion_() fwVersionFormat="${BLUEct}BASE${WHITEct}.${CYANct}MAJOR${WHITEct}.${MAGENTAct}MINOR${WHITEct}.${YLWct}PATCH${NOct}" # Prompt user for the firmware version if extraction fails # printf "\n${REDct}**WARNING**${NOct}\n" - printf "\nFailed to identify firmware version from the update file name." + printf "\nFailed to identify firmware version from the ZIP file name." printf "\nPlease enter the firmware version number in the format ${fwVersionFormat}\n" printf "\n(Examples: 3004.388.8.0 or 3004.388.8.beta1): " read -r formatted_version @@ -5118,7 +5118,7 @@ _SelectOfflineUpdateFile_() while true do - printf "\nAvailable files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" + printf "\nAvailable ZIP files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" fileList="$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb "$FW_ZIP_DIR"/*.zip 2>/dev/null)" fileCount=1 @@ -5130,7 +5130,7 @@ _SelectOfflineUpdateFile_() # Prompt user to select a file # printf "\n---------------------------------------------------\n" - printf "\n[${theMUExitStr}] Enter the number of the file you want to select: " + printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: " read -r selection if [ -z "$selection" ] From 1e664df71e7059c87271e8f585e42780aad1108d Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 20:57:37 -0400 Subject: [PATCH 178/185] Update MerlinAU.sh --- MerlinAU.sh | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index d0bf58cf..74300352 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -1260,7 +1260,8 @@ _Set_FW_UpdateZIP_DirectoryPath_() while true do - printf "\nEnter the directory path where the ZIP subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" + if "$isGNUtonFW"; then printf "\nEnter the directory path where the update subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n" + else printf "\nEnter the directory path where the ZIP subdirectory [${GRNct}${FW_ZIP_SUBDIR}${NOct}] will be stored.\n"; fi if [ -n "$USBMountPoint" ] && _ValidateUSBMountPoint_ "$FW_ZIP_BASE_DIR" then printf "Default directory for USB-attached drive: [${GRNct}${FW_ZIP_BASE_DIR}${NOct}]\n" @@ -1330,7 +1331,8 @@ _Set_FW_UpdateZIP_DirectoryPath_() rm -fr "${FW_LOG_DIR:?}" rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256 Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath" - echo "The directory path for the F/W ZIP file was updated successfully." + if "$isGNUtonFW"; then echo "The directory path for the F/W update file was updated successfully." + else echo "The directory path for the F/W ZIP file was updated successfully."; fi keepWfile=0 _WaitForEnterKey_ "$advnMenuReturnPromptStr" fi @@ -1492,12 +1494,7 @@ _CreateEMailContent_() else subjectStr="F/W Update Status for $MODEL_ID" fi fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" - if ! "$offlineUpdateTrigger" - then - fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" - else - fwNewUpdateVersion="$release_version" - fi + fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" # Remove "_rog" or "_tuf" suffix to avoid version comparison failures fwInstalledVersion="$(echo "$fwInstalledVersion" | sed 's/_\(rog\|tuf\)$//')" @@ -5082,7 +5079,8 @@ _GetOfflineFirmwareVersion_() fwVersionFormat="${BLUEct}BASE${WHITEct}.${CYANct}MAJOR${WHITEct}.${MAGENTAct}MINOR${WHITEct}.${YLWct}PATCH${NOct}" # Prompt user for the firmware version if extraction fails # printf "\n${REDct}**WARNING**${NOct}\n" - printf "\nFailed to identify firmware version from the ZIP file name." + if "$isGNUtonFW"; then printf "\nFailed to identify firmware version from the update file name." + else 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.beta1): " read -r formatted_version @@ -5109,18 +5107,30 @@ _SelectOfflineUpdateFile_() local selection fileList fileCount # Check if the directory is empty or no desired files are found # - if [ -z "$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb "$FW_ZIP_DIR"/*.zip 2>/dev/null)" ] + if "$isGNUtonFW" then - printf "\nNo valid files found in the directory. Exiting.\n" - printf "\n---------------------------------------------------\n" - return 1 + if [ -z "$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb 2>/dev/null)" ] + then + printf "\nNo valid update files found in the directory. Exiting.\n" + printf "\n---------------------------------------------------\n" + return 1 + fi + else + if [ -z "$(ls -A "$FW_ZIP_DIR"/*.zip 2>/dev/null)" ] + then + printf "\nNo valid ZIP files found in the directory. Exiting.\n" + printf "\n---------------------------------------------------\n" + return 1 + fi fi while true do - printf "\nAvailable ZIP files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" + if "$isGNUtonFW"; then printf "\nAvailable update files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n" + else printf "\nAvailable ZIP files in the directory: [${GRNct}${FW_ZIP_DIR}${NOct}]:\n\n"; fi - fileList="$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb "$FW_ZIP_DIR"/*.zip 2>/dev/null)" + if "$isGNUtonFW"; then fileList="$(ls -A "$FW_ZIP_DIR"/*.w "$FW_ZIP_DIR"/*.pkgtb 2>/dev/null)" + else fileList="$(ls -A "$FW_ZIP_DIR"/*.zip 2>/dev/null)"; fi fileCount=1 for file in $fileList do @@ -5130,7 +5140,8 @@ _SelectOfflineUpdateFile_() # Prompt user to select a file # printf "\n---------------------------------------------------\n" - printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: " + if "$isGNUtonFW"; then printf "\n[${theMUExitStr}] Enter the number of the update file you want to select: " + else printf "\n[${theMUExitStr}] Enter the number of the ZIP file you want to select: "; fi read -r selection if [ -z "$selection" ] @@ -5424,7 +5435,8 @@ _RunOfflineUpdateNow_() _ClearOfflineUpdateState_ 1 ; return 1 fi printf "\n---------------------------------------------------\n" - printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:" + if "$isGNUtonFW"; then printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:" + else printf "\nPlease copy your firmware update file (.w or .pkgtb) (using the *original* update filename) to this directory:"; fi printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" printf "\n---------------------------------------------------\n" @@ -5913,7 +5925,10 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi if echo "$curl_response" | grep -Eq 'url=index\.asp|url=GameDashboard\.asp' then - _SendEMailNotification_ POST_REBOOT_FW_UPDATE_SETUP + if ! "$offlineUpdateTrigger" + then + _SendEMailNotification_ POST_REBOOT_FW_UPDATE_SETUP + fi if [ -f /opt/bin/diversion ] then From 66560373b50dcf0ea5a2aa13c25f3279c569df80 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Wed, 7 Aug 2024 20:59:45 -0400 Subject: [PATCH 179/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 74300352..a72f3b24 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5435,8 +5435,8 @@ _RunOfflineUpdateNow_() _ClearOfflineUpdateState_ 1 ; return 1 fi printf "\n---------------------------------------------------\n" - if "$isGNUtonFW"; then printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:" - else printf "\nPlease copy your firmware update file (.w or .pkgtb) (using the *original* update filename) to this directory:"; fi + if "$isGNUtonFW"; then printf "\nPlease copy your firmware update file (.w or .pkgtb) using the *original* ZIP filename to this directory:" + else printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:"; fi printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" printf "\n---------------------------------------------------\n" From f1e66adc107fb9429d902d45598719255cb553e8 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Thu, 8 Aug 2024 21:22:04 -0400 Subject: [PATCH 180/185] Update MerlinAU.sh --- MerlinAU.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index a72f3b24..ac1dc735 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -8,16 +8,16 @@ ################################################################### set -u +## Set version for each Production Release ## readonly SCRIPT_VERSION=1.3.0 readonly SCRIPT_NAME="MerlinAU" +## Set to "master" for Production Releases ## +SCRIPT_BRANCH="dev" ##----------------------------------------## ## Modified by Martinski W. [2024-Jul-03] ## ##----------------------------------------## # Script URL Info # - -## Set to "master" for Production Releases ## -SCRIPT_BRANCH="dev" readonly SCRIPT_URL_BASE="https://raw.githubusercontent.com/ExtremeFiretop/MerlinAutoUpdate-Router" SCRIPT_URL_REPO="${SCRIPT_URL_BASE}/$SCRIPT_BRANCH" From 451b09caf238d315b87a5dde76fda135f1169f28 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 9 Aug 2024 01:48:38 -0400 Subject: [PATCH 181/185] Update MerlinAU.sh --- MerlinAU.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 8f8075b0..ab6452e6 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -12,7 +12,7 @@ set -u readonly SCRIPT_VERSION=1.3.0 readonly SCRIPT_NAME="MerlinAU" ## Set to "master" for Production Releases ## -SCRIPT_BRANCH="master" +SCRIPT_BRANCH="dev" ##----------------------------------------## ## Modified by Martinski W. [2024-Jul-03] ## @@ -5459,7 +5459,7 @@ _RunOfflineUpdateNow_() _GnutonBuildSelection_ set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") else - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_URL_RELEASE") + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") fi if [ $? -eq 0 ] && [ $# -eq 2 ] && \ [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] From 6a773b91d43881fca64ffbebbcb51a6d7538cdbd Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Fri, 9 Aug 2024 04:44:18 -0400 Subject: [PATCH 182/185] Update MerlinAU.sh --- MerlinAU.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index ab6452e6..5ccd2a1c 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5755,7 +5755,7 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi ##------------------------------------------## ## Modified by ExtremeFiretop [2024-May-25] ## ##------------------------------------------## - if ! [[ "$isGNUtonFW" && "$offlineUpdateTrigger" ]]; then + if ! { "$isGNUtonFW" && "$offlineUpdateTrigger" ; } then _ChangelogVerificationCheck_ "interactive" retCode="$?" From 91dbcb4cfacb6628596cb1d457c75ce17c69c6ac Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sat, 10 Aug 2024 15:08:00 -0400 Subject: [PATCH 183/185] Update MerlinAU.sh --- MerlinAU.sh | 78 +++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 5ccd2a1c..9ce5a22f 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5426,58 +5426,52 @@ _RunOfflineUpdateNow_() offlineUpdateTrigger=true theMenuReturnPromptMsg="$advnMenuReturnPromptStr" - if _Set_FW_UpdateZIP_DirectoryPath_ + clear + # Create directory for downloading & extracting firmware # + if ! _CreateDirectory_ "$FW_ZIP_DIR" + then + _ClearOfflineUpdateState_ 1 ; return 1 + fi + printf "\n---------------------------------------------------\n" + if "$isGNUtonFW"; then printf "\nPlease copy your firmware update file (.w or .pkgtb) using the *original* ZIP filename to this directory:" + else printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:"; fi + printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" + printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" + printf "\n---------------------------------------------------\n" + if _WaitForYESorNO_ then clear - # Create directory for downloading & extracting firmware # - if ! _CreateDirectory_ "$FW_ZIP_DIR" - then - _ClearOfflineUpdateState_ 1 ; return 1 - fi - printf "\n---------------------------------------------------\n" - if "$isGNUtonFW"; then printf "\nPlease copy your firmware update file (.w or .pkgtb) using the *original* ZIP filename to this directory:" - else printf "\nPlease copy your firmware ZIP file (using the *original* ZIP filename) to this directory:"; fi - printf "\n[${GRNct}$FW_ZIP_DIR${NOct}]\n" - printf "\nPress '${GRNct}Y${NOct}' when completed, or '${REDct}N${NOct}' to cancel.\n" printf "\n---------------------------------------------------\n" - if _WaitForYESorNO_ + printf "\nContinuing to the update file selection process.\n" + if _SelectOfflineUpdateFile_ then - clear - printf "\n---------------------------------------------------\n" - printf "\nContinuing to the update file selection process.\n" - if _SelectOfflineUpdateFile_ + if "$isGNUtonFW" then - if "$isGNUtonFW" - then - # Extract the filename from the path - original_filename=$(basename "$selected_file") - # Sanitize filename by removing problematic characters (if necessary) - sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') - # Extract the file extension - extension="${sanitized_filename##*.}" - FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" - _GnutonBuildSelection_ - set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") - else - set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") - fi - if [ $? -eq 0 ] && [ $# -eq 2 ] && \ - [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] - then - release_link="$2" - _RunFirmwareUpdateNow_ - _ClearOfflineUpdateState_ - else - Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." - _ClearOfflineUpdateState_ 1 - return 1 - fi + # Extract the filename from the path + original_filename=$(basename "$selected_file") + # Sanitize filename by removing problematic characters (if necessary) + sanitized_filename=$(echo "$original_filename" | sed 's/[^a-zA-Z0-9._-]//g') + # Extract the file extension + extension="${sanitized_filename##*.}" + FW_DL_FPATH="${FW_ZIP_DIR}/${FW_FileName}.${extension}" + _GnutonBuildSelection_ + set -- $(_GetLatestFWUpdateVersionFromGithub_ "$FW_GITURL_RELEASE" "$firmware_choice") + else + set -- $(_GetLatestFWUpdateVersionFromWebsite_ "$FW_SFURL_RELEASE") + fi + if [ $? -eq 0 ] && [ $# -eq 2 ] && \ + [ "$1" != "**ERROR**" ] && [ "$2" != "**NO_URL**" ] + then + release_link="$2" + _RunFirmwareUpdateNow_ + _ClearOfflineUpdateState_ else + Say "${REDct}**ERROR**${NOct}: No firmware release URL was found for [$PRODUCT_ID] router model." _ClearOfflineUpdateState_ 1 return 1 fi else - _ClearOfflineUpdateState_ "Offline update process was cancelled. Exiting.\n" + _ClearOfflineUpdateState_ 1 return 1 fi else From a0af4e402e174083eca3eaafe0fa4c7f28fed167 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 11 Aug 2024 13:04:13 -0400 Subject: [PATCH 184/185] Update MerlinAU.sh --- MerlinAU.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index 9ce5a22f..cdcebb82 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5840,25 +5840,31 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi ##------------------------------------------## - ## Modified by ExtremeFiretop [2024-Apr-25] ## + ## Modified by ExtremeFiretop [2024-Aug-11] ## ##------------------------------------------## if "$offlineUpdateTrigger" then if ! "$isGNUtonFW" - then + then _CheckOfflineFirmwareSHA256_ retCode="$?" - fi - elif "$isGNUtonFW" - then - _CheckFirmwareMD5_ - retCode="$?" + elif [ -f "${FW_BIN_DIR}/${FW_FileName}.md5" ]; then + _CheckFirmwareMD5_ + retCode="$?" + else + retCode=0 # Skip if the MD5 file does not exist + fi else - _CheckOnlineFirmwareSHA256_ - retCode="$?" + if "$isGNUtonFW"; then + _CheckFirmwareMD5_ + retCode="$?" + else + _CheckOnlineFirmwareSHA256_ + retCode="$?" + fi fi - if [ "$retCode" -eq 1 ] - then + + if [ "$retCode" -eq 1 ]; then "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" _Reset_LEDs_ return 1 From fa55df84fd10778567ca27591b08e83842555eab Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Sun, 11 Aug 2024 13:05:17 -0400 Subject: [PATCH 185/185] Update MerlinAU.sh --- MerlinAU.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index cdcebb82..68c67fa9 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -5864,7 +5864,8 @@ Please manually update to version $MinSupportedFirmwareVers or higher to use thi fi fi - if [ "$retCode" -eq 1 ]; then + if [ "$retCode" -eq 1 ] + then "$inMenuMode" && _WaitForEnterKey_ "$theMenuReturnPromptMsg" _Reset_LEDs_ return 1