Skip to content

Commit 6d16cd4

Browse files
Code Improvements
Some code improvements and fine-tuning.
1 parent a0f5f85 commit 6d16cd4

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

MerlinAU.sh

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2025-Jul-29
7+
# Last Modified: 2025-Aug-02
88
###################################################################
99
set -u
1010

@@ -4854,22 +4854,26 @@ _GetLatestFWUpdateVersionFromWebsite_()
48544854
return 0
48554855
}
48564856

4857-
##------------------------------------------##
4858-
## Modified by ExtremeFiretop [2024-May-05] ##
4859-
##------------------------------------------##
4857+
##----------------------------------------##
4858+
## Modified by Martinski W. [2025-Aug-02] ##
4859+
##----------------------------------------##
48604860
_GetLatestFWUpdateVersionFromGitHub_()
48614861
{
4862-
local routerVersion search_type release_data
4863-
local gitURL="$1" # GitHub URL for the latest release #
4862+
local routerVersion searchType releaseData
4863+
local theGitURL="$1" # GitHub URL for the latest F/W release #
48644864
local firmware_type="$2" # "tuf", "rog" or "pure" #
4865-
local grep_pattern downloadURLs theURL urlVersion
4865+
local grepPattern theFW_URLs fw_URL urlVersion
4866+
local FW_FileExtRegExp FW_BinTypeRegExp
4867+
4868+
FW_FileExtRegExp="(w|pkgtb)"
4869+
FW_BinTypeRegExp="(nand_squashfs|puresqubi|pureubi|ubi|squashfs|pure)"
48664870

4867-
search_type="$firmware_type" # Default to the input firmware_type #
4871+
searchType="$firmware_type" # Default to the input firmware_type #
48684872

4869-
# If firmware_type is "pure", set search_type to include "squashfs" as well #
4873+
# If firmware_type is "pure", include all F/W image types #
48704874
if [ "$firmware_type" = "pure" ]
48714875
then
4872-
search_type="pure\|squashfs\|ubi"
4876+
searchType="$FW_BinTypeRegExp"
48734877
fi
48744878

48754879
if ! "$offlineUpdateTrigger"
@@ -4885,53 +4889,56 @@ _GetLatestFWUpdateVersionFromGitHub_()
48854889
fi
48864890

48874891
# Fetch the latest release data from GitHub #
4888-
release_data="$(curl -s "$gitURL")"
4892+
releaseData="$(curl -s "$theGitURL")"
48894893

4890-
# Construct the grep pattern based on search_type #
4891-
grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.\(w\|pkgtb\)\""
4894+
# grep search pattern #
4895+
grepPattern="\"browser_download_url\": \".*${PRODUCT_ID}.*${searchType}.*\.${FW_FileExtRegExp}\""
48924896

48934897
# Extract all matched download URLs #
4894-
downloadURLs="$(echo "$release_data" | \
4895-
grep -o "$grep_pattern" | \
4896-
grep -o "https://[^ ]*\.\(w\|pkgtb\)")"
4898+
theFW_URLs="$(echo "$releaseData" | grep -oE "$grepPattern" | \
4899+
grep -oE "https://[^ ]*\.${FW_FileExtRegExp}")"
48974900

4898-
if [ -z "$downloadURLs" ]
4901+
if [ -z "$theFW_URLs" ]
48994902
then
49004903
echo "**ERROR** **NO_GITHUB_URL**"
49014904
return 1
49024905
else
4903-
for theURL in $downloadURLs
4906+
for fw_URL in $theFW_URLs
49044907
do
49054908
# Extract the version portion from the URL #
4906-
urlVersion="$(echo "$theURL" \
4907-
| grep -oE "${PRODUCT_ID}_[^ ]*\.(w|pkgtb)" \
4908-
| sed "s/${PRODUCT_ID}_//;s/\\.w$//;s/\\.pkgtb$//;s/_\\(ubi\\|puresqubi\\|nand_squashfs\\)$//;s/_/./g" | head -n1)"
4909+
urlVersion="$(echo "$fw_URL" | grep -oE "${PRODUCT_ID}_[^ ]*\.${FW_FileExtRegExp}" | \
4910+
sed -E "s/${PRODUCT_ID}_//;s/\.${FW_FileExtRegExp}$//;s/_${FW_BinTypeRegExp}$//;s/_/./g" | head -n1)"
49094911

49104912
if [ "$urlVersion" = "$routerVersion" ]
49114913
then
49124914
echo "$urlVersion"
4913-
echo "$theURL"
4915+
echo "$fw_URL"
49144916
return 0
49154917
fi
49164918
done
49174919
fi
49184920
}
49194921

4920-
##------------------------------------------##
4921-
## Modified by ExtremeFiretop [2024-May-05] ##
4922-
##------------------------------------------##
4922+
##----------------------------------------##
4923+
## Modified by Martinski W. [2025-Aug-02] ##
4924+
##----------------------------------------##
49234925
GetLatestFirmwareMD5URL()
49244926
{
4925-
local routerVersion
4926-
local gitURL="$1" # GitHub URL for the latest release #
4927+
local routerVersion searchType releaseData
4928+
local theGitURL="$1" # GitHub URL for the latest F/W release #
49274929
local firmware_type="$2" # "tuf", "rog" or "pure" #
4930+
local grepPattern theMD5_URLs md5_URL md5Version
4931+
local FW_FileExtRegExp FW_BinTypeRegExp
4932+
4933+
FW_FileExtRegExp="(w|pkgtb)"
4934+
FW_BinTypeRegExp="(nand_squashfs|puresqubi|pureubi|ubi|squashfs|pure)"
49284935

4929-
local search_type="$firmware_type" # Default to the input firmware_type #
4936+
searchType="$firmware_type" # Default to the input firmware_type #
49304937

4931-
# If firmware_type is "pure", set search_type to include "squashfs" as well
4938+
# If firmware_type is "pure", include all F/W image types #
49324939
if [ "$firmware_type" = "pure" ]
49334940
then
4934-
search_type="pure\|squashfs\|ubi"
4941+
searchType="$FW_BinTypeRegExp"
49354942
fi
49364943

49374944
if ! "$offlineUpdateTrigger"
@@ -4947,32 +4954,29 @@ GetLatestFirmwareMD5URL()
49474954
fi
49484955

49494956
# Fetch the latest release data from GitHub #
4950-
local release_data="$(curl -s "$gitURL")"
4957+
releaseData="$(curl -s "$theGitURL")"
49514958

4952-
# Construct the grep pattern based on search_type #
4953-
local grep_pattern="\"browser_download_url\": \".*${PRODUCT_ID}.*\(${search_type}\).*\.md5\""
4959+
# grep search pattern #
4960+
grepPattern="\"browser_download_url\": \".*${PRODUCT_ID}.*${searchType}.*\.${FW_FileExtRegExp}\.md5\""
49544961

49554962
# Extract all matched download URLs #
4956-
local md5_URLs="$(echo "$release_data" |
4957-
grep -o "$grep_pattern" |
4958-
sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/')"
4963+
theMD5_URLs="$(echo "$releaseData" | grep -oE "$grepPattern" | \
4964+
grep -oE "https://[^ ]*\.${FW_FileExtRegExp}\.md5")"
49594965

4960-
if [ -z "$md5_URLs" ]
4966+
if [ -z "$theMD5_URLs" ]
49614967
then
49624968
echo "**ERROR** **NO_MD5_FILE_URL_FOUND**"
49634969
return 1
49644970
else
4965-
local theURL md5Version
4966-
for theURL in $md5_URLs
4971+
for md5_URL in $theMD5_URLs
49674972
do
49684973
# Extract the version portion from the URL #
4969-
md5Version="$(echo "$theURL" \
4970-
| grep -oE "${PRODUCT_ID}_[^ ]*\.(md5)" \
4971-
| sed "s/${PRODUCT_ID}_//;s/\\.md5$//;s/\\.w$//;s/\\.pkgtb$//;s/_\\(ubi\\|puresqubi\\|nand_squashfs\\)$//;s/_/./g" | head -n1)"
4974+
md5Version="$(echo "$md5_URL" | grep -oE "${PRODUCT_ID}_[^ ]*\.${FW_FileExtRegExp}\.md5" | \
4975+
sed -E "s/${PRODUCT_ID}_//;s/\.${FW_FileExtRegExp}\.md5$//;s/_${FW_BinTypeRegExp}$//;s/_/./g" | head -n1)"
49724976

49734977
if [ "$md5Version" = "$routerVersion" ]
49744978
then
4975-
echo "$theURL"
4979+
echo "$md5_URL"
49764980
return 0
49774981
fi
49784982
done
@@ -4984,15 +4988,15 @@ GetLatestFirmwareMD5URL()
49844988
##----------------------------------------##
49854989
GetLatestChangelogURL()
49864990
{
4987-
local gitURL="$1" # GitHub URL for the latest release #
4991+
local theGitURL="$1" # GitHub URL for the latest F/W release #
49884992
local changelogURL
49894993

49904994
# Fetch the latest release data from GitHub #
4991-
local release_data="$(curl -s "$gitURL")"
4995+
local releaseData="$(curl -s "$theGitURL")"
49924996

49934997
# Parse the release data to find the download URL of the CHANGELOG file
49944998
# Directly find the URL without matching a specific model number
4995-
changelogURL="$(echo "$release_data" | grep -o "\"browser_download_url\": \".*CHANGELOG.*\"" | grep -o "https://[^ ]*\"" | tr -d '"' | head -n1)"
4999+
changelogURL="$(echo "$releaseData" | grep -o "\"browser_download_url\": \".*CHANGELOG.*\"" | grep -o "https://[^ ]*\"" | tr -d '"' | head -n1)"
49965000

49975001
if [ -z "$changelogURL" ]
49985002
then

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MerlinAU - AsusWRT-Merlin Firmware Auto Updater
22
## v1.5.1
3-
## 2025-Jul-29
3+
## 2025-Aug-02
44

55
## WebUI:
66
![image](https://github.com/user-attachments/assets/9c1dff99-9c13-491b-a7fa-aff924d5f02e)

0 commit comments

Comments
 (0)