Skip to content

Commit 9116e0b

Browse files
Merge pull request #423 from ExtremeFiretop/ExtremeFiretop-patch-1
Minor Fixes
2 parents d3ca507 + f7bf7b4 commit 9116e0b

File tree

1 file changed

+78
-19
lines changed

1 file changed

+78
-19
lines changed

MerlinAU.sh

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ _CreateEMailContent_()
28462846
fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)"
28472847
if ! "$offlineUpdateTrigger"
28482848
then
2849-
fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
2849+
fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_)"
28502850
else
28512851
fwNewUpdateVersion="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
28522852
fi
@@ -4545,29 +4545,52 @@ _GetLatestFWUpdateVersionFromGithub_()
45454545
search_type="pure\|squashfs\|ubi"
45464546
fi
45474547

4548+
if ! "$offlineUpdateTrigger"
4549+
then
4550+
# Get the router version from the router itself
4551+
local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
4552+
else
4553+
# Get the router version from the router itself
4554+
local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
4555+
fi
4556+
4557+
if [ -z "$router_version" ]; then
4558+
echo "**ERROR** **NO_ROUTER_VERSION**"
4559+
return 1
4560+
fi
4561+
45484562
# Fetch the latest release data from GitHub #
45494563
local release_data="$(curl -s "$url")"
45504564

45514565
# Construct the grep pattern based on search_type #
45524566
local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\""
45534567

4554-
# Filter the JSON for the desired firmware using grep and head to fetch the URL
4555-
local download_url="$(echo "$release_data" |
4556-
grep -o "$grep_pattern" |
4557-
grep -o "https://[^ ]*\.\(w\|pkgtb\)" |
4558-
head -1)"
4568+
# Extract all matched download URLs
4569+
local download_urls="$(echo "$release_data" | \
4570+
grep -o "$grep_pattern" | \
4571+
grep -o "https://[^ ]*\.\(w\|pkgtb\)")"
45594572

45604573
# Check if a URL was found
4561-
if [ -z "$download_url" ]
4574+
if [ -z "$download_urls" ]
45624575
then
45634576
echo "**ERROR** **NO_GITHUB_URL**"
45644577
return 1
45654578
else
4566-
# Extract the version from the download URL or release data
4567-
local version="$(echo "$download_url" | grep -oE "${PRODUCT_ID}[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g")"
4568-
echo "$version"
4569-
echo "$download_url"
4570-
return 0
4579+
# Loop through each matching URL and compare version to router_version
4580+
local url_item version
4581+
for url_item in $download_urls; do
4582+
# Extract the version portion from the URL
4583+
local version="$(echo "$url_item" \
4584+
| grep -oE "${PRODUCT_ID}_[^ ]*\.(w|pkgtb)" \
4585+
| sed "s/${PRODUCT_ID}_//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)"
4586+
4587+
# If this URL’s version matches the router version, we're done
4588+
if [ "$version" = "$router_version" ]; then
4589+
echo "$version"
4590+
echo "$url_item"
4591+
return 0
4592+
fi
4593+
done
45714594
fi
45724595
}
45734596

@@ -4586,25 +4609,51 @@ GetLatestFirmwareMD5Url()
45864609
search_type="pure\|squashfs\|ubi"
45874610
fi
45884611

4612+
if ! "$offlineUpdateTrigger"
4613+
then
4614+
# Get the router version from the router itself
4615+
local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
4616+
else
4617+
# Get the router version from the router itself
4618+
local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
4619+
fi
4620+
4621+
if [ -z "$router_version" ]; then
4622+
echo "**ERROR** **NO_ROUTER_VERSION**"
4623+
return 1
4624+
fi
4625+
45894626
# Fetch the latest release data from GitHub
45904627
local release_data="$(curl -s "$url")"
45914628

45924629
# Construct the grep pattern based on search_type
45934630
local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.md5\""
45944631

4595-
# Filter the JSON for the desired firmware using grep and sed
4596-
local md5_url="$(echo "$release_data" |
4632+
# Extract all matched download URLs
4633+
local md5_urls="$(echo "$release_data" |
45974634
grep -o "$grep_pattern" |
4598-
sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' |
4599-
head -1)"
4635+
sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/')"
46004636

46014637
# Check if a URL was found and output result or error
4602-
if [ -z "$md5_url" ]
4638+
if [ -z "$md5_urls" ]
46034639
then
4604-
echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**"
4640+
echo "**ERROR** **NO_MD5_FILE_URL_FOUND**"
46054641
return 1
46064642
else
4607-
echo "$md5_url"
4643+
# Loop through each matching URL and compare version to router_version
4644+
local url_item version
4645+
for url_item in $md5_urls; do
4646+
# Extract the version portion from the URL
4647+
local md5="$(echo "$url_item" \
4648+
| grep -oE "${PRODUCT_ID}_[^ ]*\.(md5)" \
4649+
| sed "s/${PRODUCT_ID}_//;s/.md5$//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)"
4650+
4651+
# If this URL’s version matches the router version, we're done
4652+
if [ "$md5" = "$router_version" ]; then
4653+
echo "$md5"
4654+
return 0
4655+
fi
4656+
done
46084657
fi
46094658
}
46104659

@@ -8384,6 +8433,16 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
83848433
fi
83858434
fi
83868435

8436+
if ! "$offlineUpdateTrigger"
8437+
then
8438+
NewUpdate_VersionVerify="$(_GetLatestFWUpdateVersionFromRouter_)"
8439+
if [ "$NewUpdate_VersionVerify" != "$release_version" ]
8440+
then
8441+
Say "WARNING: The release version found by MerlinAU [$release_version] does not match the F/W update version from the router [$NewUpdate_VersionVerify]."
8442+
"$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" || return 1
8443+
fi
8444+
fi
8445+
83878446
# Extracting the F/W Update codebase number #
83888447
fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)"
83898448
# Inserting dots between each number #

0 commit comments

Comments
 (0)