From 4093ed20117e0204b6c4e8d4a4ac0b405638d0a6 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Mar 2025 04:34:16 -0400 Subject: [PATCH 1/2] Update MerlinAU.sh --- MerlinAU.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index f0696ee2..ec153660 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -2846,7 +2846,7 @@ _CreateEMailContent_() fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)" if ! "$offlineUpdateTrigger" then - fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_)" else fwNewUpdateVersion="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" fi @@ -8384,6 +8384,16 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or fi fi + if ! "$offlineUpdateTrigger" + then + NewUpdate_VersionVerify="$(_GetLatestFWUpdateVersionFromRouter_)" + if [ "$NewUpdate_VersionVerify" != "$release_version" ] + then + Say "WARNING: The release version found by MerlinAU [$release_version] does not match the F/W update version from the router [$NewUpdate_VersionVerify]." + "$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" || return 1 + fi + fi + # Extracting the F/W Update codebase number # fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)" # Inserting dots between each number # From f7bf7b48eaf1a9c5f9b22c6f16bb1d8fffb4e6a4 Mon Sep 17 00:00:00 2001 From: Joel Samson Date: Tue, 11 Mar 2025 05:54:57 -0400 Subject: [PATCH 2/2] Update MerlinAU.sh --- MerlinAU.sh | 85 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/MerlinAU.sh b/MerlinAU.sh index ec153660..a5b88138 100644 --- a/MerlinAU.sh +++ b/MerlinAU.sh @@ -4545,29 +4545,52 @@ _GetLatestFWUpdateVersionFromGithub_() search_type="pure\|squashfs\|ubi" fi + if ! "$offlineUpdateTrigger" + then + # Get the router version from the router itself + local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + else + # Get the router version from the router itself + local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" + fi + + if [ -z "$router_version" ]; then + echo "**ERROR** **NO_ROUTER_VERSION**" + return 1 + 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)" + # Extract all matched download URLs + local download_urls="$(echo "$release_data" | \ + grep -o "$grep_pattern" | \ + grep -o "https://[^ ]*\.\(w\|pkgtb\)")" # Check if a URL was found - if [ -z "$download_url" ] + if [ -z "$download_urls" ] 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 + # Loop through each matching URL and compare version to router_version + local url_item version + for url_item in $download_urls; do + # Extract the version portion from the URL + local version="$(echo "$url_item" \ + | grep -oE "${PRODUCT_ID}_[^ ]*\.(w|pkgtb)" \ + | sed "s/${PRODUCT_ID}_//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)" + + # If this URL’s version matches the router version, we're done + if [ "$version" = "$router_version" ]; then + echo "$version" + echo "$url_item" + return 0 + fi + done fi } @@ -4586,25 +4609,51 @@ GetLatestFirmwareMD5Url() search_type="pure\|squashfs\|ubi" fi + if ! "$offlineUpdateTrigger" + then + # Get the router version from the router itself + local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)" + else + # Get the router version from the router itself + local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")" + fi + + if [ -z "$router_version" ]; then + echo "**ERROR** **NO_ROUTER_VERSION**" + return 1 + 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" | + # Extract all matched download URLs + local md5_urls="$(echo "$release_data" | grep -o "$grep_pattern" | - sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' | - head -1)" + sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/')" # Check if a URL was found and output result or error - if [ -z "$md5_url" ] + if [ -z "$md5_urls" ] then - echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**" + echo "**ERROR** **NO_MD5_FILE_URL_FOUND**" return 1 else - echo "$md5_url" + # Loop through each matching URL and compare version to router_version + local url_item version + for url_item in $md5_urls; do + # Extract the version portion from the URL + local md5="$(echo "$url_item" \ + | grep -oE "${PRODUCT_ID}_[^ ]*\.(md5)" \ + | sed "s/${PRODUCT_ID}_//;s/.md5$//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)" + + # If this URL’s version matches the router version, we're done + if [ "$md5" = "$router_version" ]; then + echo "$md5" + return 0 + fi + done fi }