Skip to content

Commit ecb5774

Browse files
Update MerlinAU.sh
1 parent 96f4f4c commit ecb5774

File tree

1 file changed

+114
-45
lines changed

1 file changed

+114
-45
lines changed

MerlinAU.sh

Lines changed: 114 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2025-Feb-17
7+
# Last Modified: 2025-March-25
88
###################################################################
99
set -u
1010

1111
## Set version for each Production Release ##
12-
readonly SCRIPT_VERSION=1.3.10
12+
readonly SCRIPT_VERSION=1.3.11
1313
readonly SCRIPT_NAME="MerlinAU"
1414
## Set to "master" for Production Releases ##
1515
SCRIPT_BRANCH="master"
@@ -414,50 +414,56 @@ logo() {
414414
echo -e "${NOct}"
415415
}
416416

417-
##---------------------------------------##
418-
## Added by ExtremeFiretop [2024-Jul-03] ##
419-
##---------------------------------------##
417+
##----------------------------------------##
418+
## Modified by Martinski W. [2025-Feb-22] ##
419+
##----------------------------------------##
420420
_ShowAbout_()
421421
{
422422
clear
423423
logo
424424
cat <<EOF
425-
About
426-
$SCRIPT_NAME is a tool for automating firmware updates on AsusWRT Merlin,
427-
ensuring your router stays up-to-date with the latest features and security
428-
patches. It simplifies the update process by automatically checking for,
429-
downloading, and applying new firmware versions.
430-
Developed by ExtremeFiretop and Martinski W.
425+
$SCRIPT_NAME is a tool for automating firmware updates on AsusWRT-Merlin,
426+
ensuring your router stays up-to-date with the latest features and
427+
security patches. It greatly simplifies the firmware update process
428+
by automatically checking for, downloading, and applying the latest
429+
firmware version update that is currently available.
430+
[Developed by ExtremeFiretop and Martinski W.]
431431
License
432432
$SCRIPT_NAME is free to use under the GNU General Public License
433433
version 3 (GPL-3.0) https://opensource.org/licenses/GPL-3.0
434434
Help & Support
435435
https://www.snbforums.com/threads/merlinau-the-ultimate-firmware-auto-updater-addon.88577/
436+
Wiki page:
437+
https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/wiki
436438
Source code
437439
https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router
438440
EOF
439441
printf "\n"
440442
_DoExit_ 0
441443
}
442444

443-
##------------------------------------------##
444-
## Modified by ExtremeFiretop [2024-Nov-18] ##
445-
##------------------------------------------##
445+
##----------------------------------------##
446+
## Modified by Martinski W. [2025-Feb-22] ##
447+
##----------------------------------------##
446448
_ShowHelp_()
447449
{
448450
clear
449451
logo
450452
cat <<EOF
451453
Available commands:
452-
${SCRIPT_NAME}.sh about explains functionality
453-
${SCRIPT_NAME}.sh help display available commands
454-
${SCRIPT_NAME}.sh checkupdates check for available MerlinAU script updates
455-
${SCRIPT_NAME}.sh forceupdate updates to latest version (force update)
456-
${SCRIPT_NAME}.sh run_now run update process on router
457-
${SCRIPT_NAME}.sh processNodes run update check on nodes
458-
${SCRIPT_NAME}.sh develop switch to development branch
459-
${SCRIPT_NAME}.sh stable switch to stable branch
460-
${SCRIPT_NAME}.sh uninstall uninstalls script
454+
${SCRIPT_NAME}.sh about describe add-on functionality
455+
${SCRIPT_NAME}.sh help show available commands & Wiki URL
456+
${SCRIPT_NAME}.sh checkupdates check for available MerlinAU updates
457+
${SCRIPT_NAME}.sh forceupdate update to latest MerlinAU version
458+
${SCRIPT_NAME}.sh run_now run F/W update process
459+
${SCRIPT_NAME}.sh processNodes run update check on nodes
460+
${SCRIPT_NAME}.sh develop switch to development branch
461+
${SCRIPT_NAME}.sh stable switch to stable master branch
462+
${SCRIPT_NAME}.sh startup run startup initialization actions
463+
${SCRIPT_NAME}.sh install install MerlinAU files
464+
${SCRIPT_NAME}.sh uninstall uninstall MerlinAU files
465+
Wiki page:
466+
https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/wiki
461467
EOF
462468
printf "\n"
463469
_DoExit_ 0
@@ -1741,7 +1747,7 @@ _CreateEMailContent_()
17411747
fwInstalledVersion="$(_GetCurrentFWInstalledLongVersion_)"
17421748
if ! "$offlineUpdateTrigger"
17431749
then
1744-
fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
1750+
fwNewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_)"
17451751
else
17461752
fwNewUpdateVersion="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
17471753
fi
@@ -3308,29 +3314,52 @@ _GetLatestFWUpdateVersionFromGithub_()
33083314
search_type="pure\|squashfs\|ubi"
33093315
fi
33103316

3317+
if ! "$offlineUpdateTrigger"
3318+
then
3319+
# Get the router version from the router itself
3320+
local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
3321+
else
3322+
# Get the router version from the router itself
3323+
local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
3324+
fi
3325+
3326+
if [ -z "$router_version" ]; then
3327+
echo "**ERROR** **NO_ROUTER_VERSION**"
3328+
return 1
3329+
fi
3330+
33113331
# Fetch the latest release data from GitHub #
33123332
local release_data="$(curl -s "$url")"
33133333

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

3317-
# Filter the JSON for the desired firmware using grep and head to fetch the URL
3318-
local download_url="$(echo "$release_data" |
3319-
grep -o "$grep_pattern" |
3320-
grep -o "https://[^ ]*\.\(w\|pkgtb\)" |
3321-
head -1)"
3337+
# Extract all matched download URLs
3338+
local download_urls="$(echo "$release_data" | \
3339+
grep -o "$grep_pattern" | \
3340+
grep -o "https://[^ ]*\.\(w\|pkgtb\)")"
33223341

33233342
# Check if a URL was found
3324-
if [ -z "$download_url" ]
3343+
if [ -z "$download_urls" ]
33253344
then
33263345
echo "**ERROR** **NO_GITHUB_URL**"
33273346
return 1
33283347
else
3329-
# Extract the version from the download URL or release data
3330-
local version="$(echo "$download_url" | grep -oE "${PRODUCT_ID}[_-][0-9.]+[^/]*" | sed "s/${PRODUCT_ID}[_-]//;s/.w$//;s/_/./g")"
3331-
echo "$version"
3332-
echo "$download_url"
3333-
return 0
3348+
# Loop through each matching URL and compare version to router_version
3349+
local url_item version
3350+
for url_item in $download_urls; do
3351+
# Extract the version portion from the URL
3352+
local version="$(echo "$url_item" \
3353+
| grep -oE "${PRODUCT_ID}_[^ ]*\.(w|pkgtb)" \
3354+
| sed "s/${PRODUCT_ID}_//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)"
3355+
3356+
# If this URL’s version matches the router version, we're done
3357+
if [ "$version" = "$router_version" ]; then
3358+
echo "$version"
3359+
echo "$url_item"
3360+
return 0
3361+
fi
3362+
done
33343363
fi
33353364
}
33363365

@@ -3349,25 +3378,51 @@ GetLatestFirmwareMD5Url()
33493378
search_type="pure\|squashfs\|ubi"
33503379
fi
33513380

3381+
if ! "$offlineUpdateTrigger"
3382+
then
3383+
# Get the router version from the router itself
3384+
local router_version="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
3385+
else
3386+
# Get the router version from the router itself
3387+
local router_version="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
3388+
fi
3389+
3390+
if [ -z "$router_version" ]; then
3391+
echo "**ERROR** **NO_ROUTER_VERSION**"
3392+
return 1
3393+
fi
3394+
33523395
# Fetch the latest release data from GitHub
33533396
local release_data="$(curl -s "$url")"
33543397

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

3358-
# Filter the JSON for the desired firmware using grep and sed
3359-
local md5_url="$(echo "$release_data" |
3401+
# Extract all matched download URLs
3402+
local md5_urls="$(echo "$release_data" |
33603403
grep -o "$grep_pattern" |
3361-
sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/' |
3362-
head -1)"
3404+
sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/')"
33633405

33643406
# Check if a URL was found and output result or error
3365-
if [ -z "$md5_url" ]
3407+
if [ -z "$md5_urls" ]
33663408
then
3367-
echo "**ERROR** **NO_FIRMWARE_FILE_URL_FOUND**"
3409+
echo "**ERROR** **NO_MD5_FILE_URL_FOUND**"
33683410
return 1
33693411
else
3370-
echo "$md5_url"
3412+
# Loop through each matching URL and compare version to router_version
3413+
local url_item version
3414+
for url_item in $md5_urls; do
3415+
# Extract the version portion from the URL
3416+
local md5="$(echo "$url_item" \
3417+
| grep -oE "${PRODUCT_ID}_[^ ]*\.(md5)" \
3418+
| sed "s/${PRODUCT_ID}_//;s/.md5$//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1)"
3419+
3420+
# If this URL’s version matches the router version, we're done
3421+
if [ "$md5" = "$router_version" ]; then
3422+
echo "$md5"
3423+
return 0
3424+
fi
3425+
done
33713426
fi
33723427
}
33733428

@@ -3502,7 +3557,7 @@ _UnzipMerlin_()
35023557
rm -f "$FW_ZIP_FPATH"
35033558
_SendEMailNotification_ FAILED_FW_UNZIP_STATUS
35043559
Say "${REDct}**ERROR**${NOct}: Unable to decompress the firmware ZIP file [$FW_ZIP_FPATH]."
3505-
_return 1
3560+
return 1
35063561
fi
35073562
return 0
35083563
}
@@ -6356,7 +6411,7 @@ _Toggle_FW_UpdateCheckSetting_()
63566411
}
63576412

63586413
##----------------------------------------##
6359-
## Modified by Martinski W. [2024-Oct-04] ##
6414+
## Modified by Martinski W. [2025-Feb-22] ##
63606415
##----------------------------------------##
63616416
_RemoveCronJobsFromAddOns_()
63626417
{
@@ -6397,7 +6452,10 @@ _RemoveCronJobsFromAddOns_()
63976452
Say "Cron jobs [$cronJobCount] from 3rd-party add-ons were found."
63986453
Say "---------------------------------------------------------------"
63996454

6400-
sleep 5
6455+
"$isInteractive" && \
6456+
printf "\nPlease wait to allow already started cron jobs to complete execution..."
6457+
sleep 15
6458+
"$isInteractive" && printf "\nDone.\n"
64016459
return 0
64026460
}
64036461

@@ -7129,6 +7187,16 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
71297187
fi
71307188
fi
71317189

7190+
if ! "$offlineUpdateTrigger"
7191+
then
7192+
NewUpdate_VersionVerify="$(_GetLatestFWUpdateVersionFromRouter_)"
7193+
if [ "$NewUpdate_VersionVerify" != "$release_version" ]
7194+
then
7195+
Say "WARNING: The release version found by MerlinAU [$release_version] does not match the F/W update version from the router [$NewUpdate_VersionVerify]."
7196+
"$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr" || return 1
7197+
fi
7198+
fi
7199+
71327200
# Extracting the F/W Update codebase number #
71337201
fwUpdateBaseNum="$(echo "$release_version" | cut -d'.' -f1)"
71347202
# Inserting dots between each number #
@@ -7490,6 +7558,7 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
74907558
echo
74917559

74927560
# *WARNING*: NO MORE logging at this point & beyond #
7561+
sync ; sleep 2 ; echo 3 > /proc/sys/vm/drop_caches ; sleep 3
74937562
/sbin/ejusb -1 0 -u 1 2>/dev/null
74947563

74957564
#----------------------------------------------------------------------------------#

0 commit comments

Comments
 (0)