Skip to content

Commit d177828

Browse files
Merge pull request #216 from ExtremeFiretop/dev
Dev 1.1.4 as Next Stable Release
2 parents 17b6482 + 745904b commit d177828

File tree

3 files changed

+116
-78
lines changed

3 files changed

+116
-78
lines changed

MerlinAU.sh

Lines changed: 109 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2024-May-18
7+
# Last Modified: 2024-May-23
88
###################################################################
99
set -u
1010

11-
readonly SCRIPT_VERSION=1.1.3
11+
readonly SCRIPT_VERSION=1.1.4
1212
readonly SCRIPT_NAME="MerlinAU"
1313

1414
##-------------------------------------##
@@ -25,9 +25,10 @@ readonly FW_URL_RELEASE_SUFFIX="Release"
2525
##---------------------------------------##
2626
## Added by ExtremeFiretop [2024-May-03] ##
2727
##---------------------------------------##
28-
# Changelog URL Info #
28+
# Changelog Info #
2929
readonly CL_URL_NG="${FW_URL_BASE}/Documentation/Changelog-NG.txt/download"
3030
readonly CL_URL_386="${FW_URL_BASE}/Documentation/Changelog-386.txt/download"
31+
readonly high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended"
3132

3233
# For new script version updates from source repository #
3334
UpdateNotify=0
@@ -98,8 +99,9 @@ then inRouterSWmode=true
9899
else inRouterSWmode=false
99100
fi
100101

101-
mainMenuReturnPromptStr="Press <Enter> to return to the Main Menu..."
102-
advnMenuReturnPromptStr="Press <Enter> to return to the Advanced Menu..."
102+
readonly mainMenuReturnPromptStr="Press <Enter> to return to the Main Menu..."
103+
readonly advnMenuReturnPromptStr="Press <Enter> to return to the Advanced Menu..."
104+
readonly logsMenuReturnPromptStr="Press <Enter> to return to the Logs Menu..."
103105

104106
[ -t 0 ] && ! tty | grep -qwi "NOT" && isInteractive=true
105107

@@ -201,10 +203,10 @@ _AcquireLock_()
201203
then
202204
Say "Stale lock found (older than $LockFileMaxSecs secs.) Reset lock file."
203205
oldPID="$(cat "$LockFilePath")"
204-
if [ -n "$oldPID" ] && kill -EXIT $oldPID 2>/dev/null && \
205-
echo "$(pidof "$ScriptFileName")" | grep -qow "$oldPID"
206+
if [ -n "$oldPID" ] && kill -EXIT "$oldPID" 2>/dev/null && \
207+
pidof "$ScriptFileName" | grep -qow "$oldPID"
206208
then
207-
kill -TERM $oldPID ; wait $oldPID
209+
kill -TERM "$oldPID" ; wait "$oldPID"
208210
fi
209211
rm -f "$LockFilePath"
210212
echo "$$" > "$LockFilePath"
@@ -496,17 +498,17 @@ readonly FW_FileName="${PRODUCT_ID}_firmware"
496498
readonly FW_URL_RELEASE="${FW_URL_BASE}/${PRODUCT_ID}/${FW_URL_RELEASE_SUFFIX}/"
497499

498500
##------------------------------------------##
499-
## Modified by ExtremeFiretop [2024-Feb-01] ##
501+
## Modified by ExtremeFiretop [2024-May-21] ##
500502
##------------------------------------------##
501503
logo() {
502504
echo -e "${YLWct}"
503-
echo -e " __ __ _ _ _ _ "
504-
echo -e " | \/ | | (_) /\ | | | |"
505-
echo -e " | \ / | ___ _ __| |_ _ __ / \ | | | |"
506-
echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |"
507-
echo -e " | | | | __| | | | | | | |/ ____ | |__| |"
508-
echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}"
509-
echo -e " ${NOct}"
505+
echo -e " __ __ _ _ _ _ "
506+
echo -e " | \/ | | (_) /\ | | | |"
507+
echo -e " | \ / | ___ _ __| |_ _ __ / \ | | | |"
508+
echo -e " | |\/| |/ _ | '__| | | '_ \ / /\ \| | | |"
509+
echo -e " | | | | __| | | | | | | |/ ____ | |__| |"
510+
echo -e " |_| |_|\___|_| |_|_|_| |_/_/ \_\____/ ${GRNct}v${SCRIPT_VERSION}"
511+
echo -e "${NOct}"
510512
}
511513

512514
##-----------------------------------------------##
@@ -1286,11 +1288,19 @@ _CreateEMailContent_()
12861288
;;
12871289
STOP_FW_UPDATE_APPROVAL)
12881290
emailBodyTitle="WARNING"
1291+
if $isEMailFormatHTML
1292+
then
1293+
# Highlight high-risk terms using HTML with a yellow background #
1294+
highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/<span style='background-color:yellow;'>\1<\/span>/gi")
1295+
else
1296+
# Highlight high-risk terms in plain text using asterisks #
1297+
highlighted_changelog_contents=$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/*\1*/gi")
1298+
fi
12891299
{
1290-
echo "Found high-risk phrases in the change-logs while Auto-Updating to version <b>${fwNewUpdateVersion}</b> on the <b>${MODEL_ID}</b> router."
1291-
echo "Changelog contents include the following changes:"
1292-
echo "$changelog_contents"
1293-
printf "\nPlease run script interactively to approve this F/W Update from current version:\n<b>${fwInstalledVersion}</b>\n"
1300+
echo "Found high-risk phrases in the change-logs while Auto-Updating to version <b>${fwNewUpdateVersion}</b> on the <b>${MODEL_ID}</b> router."
1301+
echo "Changelog contents include the following changes:"
1302+
echo "$highlighted_changelog_contents"
1303+
printf "\nPlease run script interactively to approve this F/W Update from current version:\n<b>${fwInstalledVersion}</b>\n"
12941304
} > "$tempEMailBodyMsg"
12951305
;;
12961306
NEW_BM_BACKUP_FAILED)
@@ -2044,15 +2054,15 @@ _TestLoginCredentials_()
20442054
}
20452055

20462056
##----------------------------------------##
2047-
## Modified by Martinski W. [2024-Apr-15] ##
2057+
## Modified by Martinski W. [2024-May-23] ##
20482058
##----------------------------------------##
20492059
_GetPasswordInput_()
20502060
{
20512061
local PSWDstrLenMIN=1 PSWDstrLenMAX=64
20522062
local PSWDstring PSWDtmpStr PSWDprompt
20532063
local retCode charNum pswdLength showPSWD
2054-
# Added for TAB keypress debounce #
2055-
local lastTabTime=0 currentTime
2064+
# For more responsive TAB keypress debounce #
2065+
local tabKeyDebounceSem="/tmp/var/tmp/${ScriptFNameTag}_TabKeySEM.txt"
20562066

20572067
if [ $# -eq 0 ] || [ -z "$1" ]
20582068
then
@@ -2070,6 +2080,13 @@ _GetPasswordInput_()
20702080
stty "$savedSettings"
20712081
}
20722082

2083+
_TabKeyDebounceWait_()
2084+
{
2085+
touch "$tabKeyDebounceSem"
2086+
usleep 300000 #0.3 sec#
2087+
rm -f "$tabKeyDebounceSem"
2088+
}
2089+
20732090
_ShowAsterisks_()
20742091
{
20752092
if [ $# -eq 0 ] || [ "$1" -eq 0 ]
@@ -2129,12 +2146,11 @@ _GetPasswordInput_()
21292146
## TAB keypress as toggle with debounce ##
21302147
if [ "$charNum" -eq 9 ]
21312148
then
2132-
currentTime="$(date +%s)"
2133-
if [ "$((currentTime - lastTabTime))" -gt 0 ]
2149+
if [ ! -f "$tabKeyDebounceSem" ]
21342150
then
21352151
showPSWD="$((! showPSWD))"
2136-
lastTabTime="$currentTime" # Update TAB keypress time #
21372152
_ShowPSWDPrompt_
2153+
_TabKeyDebounceWait_ &
21382154
fi
21392155
continue
21402156
fi
@@ -3632,7 +3648,7 @@ _Toggle_FW_UpdateEmailNotifications_()
36323648

36333649
if ! _WaitForYESorNO_ "Do you want to ${emailNotificationNewStateStr} F/W Update email notifications?"
36343650
then
3635-
_RunEMailNotificationTest_ && _WaitForEnterKey_ "$mainMenuReturnPromptStr"
3651+
_RunEMailNotificationTest_ && _WaitForEnterKey_ "$advnMenuReturnPromptStr"
36363652
return 1
36373653
fi
36383654

@@ -3649,7 +3665,7 @@ _Toggle_FW_UpdateEmailNotifications_()
36493665
printf "F/W Update email notifications are now ${emailNotificationNewStateStr}.\n"
36503666

36513667
_RunEMailNotificationTest_
3652-
_WaitForEnterKey_ "$mainMenuReturnPromptStr"
3668+
_WaitForEnterKey_ "$advnMenuReturnPromptStr"
36533669
}
36543670

36553671
##------------------------------------------##
@@ -3936,11 +3952,11 @@ Please manually update to version $minimum_supported_version or higher to use th
39363952
fi
39373953

39383954
# Convert version strings to comparable numbers
3939-
current_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")"
3940-
required_version="$(_ScriptVersionStrToNum_ "1.5.3")"
3955+
local currentBM_version="$(_ScriptVersionStrToNum_ "$BM_VERSION")"
3956+
local requiredBM_version="$(_ScriptVersionStrToNum_ "1.5.3")"
39413957

39423958
# Check if BACKUPMON version is greater than or equal to 1.5.3
3943-
if [ "$current_version" -ge "$required_version" ]; then
3959+
if [ "$currentBM_version" -ge "$requiredBM_version" ]; then
39443960
# Execute the backup script if it exists #
39453961
echo ""
39463962
Say "Backup Started (by BACKUPMON)"
@@ -4135,26 +4151,26 @@ Please manually update to version $minimum_supported_version or higher to use th
41354151
release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
41364152
current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
41374153

4138-
# Check if the current version is present in the changelog
4154+
# Check if the current version is present in the changelog #
41394155
if ! grep -Eq "$current_version_regex" "$changeLogFile"; then
41404156
Say "Current version not found in change-log. Bypassing change-log verification for this run."
41414157
else
4142-
# Extract log contents between two firmware versions
4158+
# Extract log contents between two firmware versions #
41434159
changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFile")"
4144-
# Define high-risk terms as a single string separated by '|'
4145-
high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended"
41464160

4147-
# Search for high-risk terms in the extracted log contents
4148-
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then
4149-
if [ "$inMenuMode" = true ]; then
4150-
printf "\n ${REDct}Warning: Found high-risk phrases in the change-log.${NOct}"
4161+
# Search for high-risk terms in the extracted log contents #
4162+
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"
4163+
then
4164+
if [ "$inMenuMode" = true ]
4165+
then
4166+
printf "\n ${REDct}*WARNING*: Found high-risk phrases in the change-log.${NOct}"
41514167
printf "\n ${REDct}Would you like to continue anyways?${NOct}"
41524168
if ! _WaitForYESorNO_ ; then
41534169
Say "Exiting for change-log review."
41544170
_DoCleanUp_ 1 ; return 1
41554171
fi
41564172
else
4157-
Say "Warning: Found high-risk phrases in the change-log."
4173+
Say "*WARNING*: Found high-risk phrases in the change-log."
41584174
Say "Please run script interactively to approve the upgrade."
41594175
_SendEMailNotification_ STOP_FW_UPDATE_APPROVAL
41604176
_DoCleanUp_ 1
@@ -4217,28 +4233,50 @@ Please manually update to version $minimum_supported_version or higher to use th
42174233
firmware_file="$pure_file"
42184234
fi
42194235

4220-
##------------------------------------------##
4221-
## Modified by ExtremeFiretop [2024-Feb-03] ##
4222-
##------------------------------------------##
4223-
if [ -f "sha256sum.sha256" ] && [ -f "$firmware_file" ]; then
4236+
##----------------------------------------##
4237+
## Modified by Martinski W. [2024-May-23] ##
4238+
##----------------------------------------##
4239+
# Fetch the latest SHA256 checksums from ASUSWRT-Merlin website #
4240+
checksums="$(curl --silent --connect-timeout 10 --retry 4 --max-time 12 https://www.asuswrt-merlin.net/download | sed -n '/<pre>/,/</pre>/p' | sed -e 's/<[^>]*>//g')"
4241+
4242+
if [ -z "$checksums" ]
4243+
then
4244+
Say "${REDct}**ERROR**${NOct}: Could not download the firmware SHA256 signatures from the website."
4245+
_DoCleanUp_ 1
4246+
if [ "$inMenuMode" = true ]
4247+
then
4248+
_WaitForEnterKey_ "$mainMenuReturnPromptStr"
4249+
return 1
4250+
else
4251+
# Assume non-interactive mode; perform exit.
4252+
_DoExit_ 1
4253+
fi
4254+
fi
4255+
4256+
if [ -f "$firmware_file" ]
4257+
then
42244258
fw_sig="$(openssl sha256 "$firmware_file" | cut -d' ' -f2)"
4225-
dl_sig="$(grep "$firmware_file" sha256sum.sha256 | cut -d' ' -f1)"
4226-
if [ "$fw_sig" != "$dl_sig" ]; then
4227-
Say "${REDct}**ERROR**${NOct}: Extracted firmware does not match the SHA256 signature!"
4259+
# Extract the corresponding signature for the firmware file from the fetched checksums #
4260+
dl_sig="$(echo "$checksums" | grep "$(basename $firmware_file)" | cut -d' ' -f1)"
4261+
if [ "$fw_sig" != "$dl_sig" ]
4262+
then
4263+
Say "${REDct}**ERROR**${NOct}: SHA256 signature from extracted firmware file does not match the SHA256 signature from the website."
42284264
_DoCleanUp_ 1
42294265
_SendEMailNotification_ FAILED_FW_CHECKSUM_STATUS
4230-
if [ "$inMenuMode" = true ]; then
4266+
if [ "$inMenuMode" = true ]
4267+
then
42314268
_WaitForEnterKey_ "$mainMenuReturnPromptStr"
42324269
return 1
42334270
else
4234-
# Assume non-interactive mode; perform exit.
4235-
_DoExit_ 1
4271+
# Assume non-interactive mode; perform exit.
4272+
_DoExit_ 1
42364273
fi
42374274
fi
42384275
else
4239-
Say "${REDct}**ERROR**${NOct}: SHA256 signature file not found!"
4276+
Say "${REDct}**ERROR**${NOct}: Firmware image file NOT found!"
42404277
_DoCleanUp_ 1
4241-
if [ "$inMenuMode" = true ]; then
4278+
if [ "$inMenuMode" = true ]
4279+
then
42424280
_WaitForEnterKey_ "$mainMenuReturnPromptStr"
42434281
return 1
42444282
else
@@ -4872,8 +4910,10 @@ fi
48724910
# menu setup variables #
48734911
theExitStr="${GRNct}e${NOct}=Exit to Main Menu"
48744912
theADExitStr="${GRNct}e${NOct}=Exit to Advanced Menu"
4913+
theLGExitStr="${GRNct}e${NOct}=Exit to Logs Menu"
4914+
48754915
padStr=" "
4876-
SEPstr="-----------------------------------------------------"
4916+
SEPstr="----------------------------------------------------------"
48774917

48784918
FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}"
48794919
if [ "$PRODUCT_ID" = "$MODEL_ID" ]
@@ -4917,10 +4957,10 @@ _GetFileSelectionIndex_()
49174957
if [ $# -lt 2 ] || [ "$2" != "-MULTIOK" ]
49184958
then
49194959
multiIndexListOK=false
4920-
promptStr="Enter selection [${selectStr}] [${theExitStr}]?"
4960+
promptStr="Enter selection [${selectStr}] [${theLGExitStr}]?"
49214961
else
49224962
multiIndexListOK=true
4923-
promptStr="Enter selection [${selectStr} | ${theAllStr}] [${theExitStr}]?"
4963+
promptStr="Enter selection [${selectStr} | ${theAllStr}] [${theLGExitStr}]?"
49244964
fi
49254965
fileIndex=0 multiIndex=false
49264966
numRegEx="([1-9]|[1-9][0-9])"
@@ -5188,7 +5228,7 @@ _ShowMainMenu_()
51885228

51895229
clear
51905230
logo
5191-
printf "${YLWct}========= By ExtremeFiretop & Martinski W. ==========${NOct}\n\n"
5231+
printf "${YLWct}============ By ExtremeFiretop & Martinski W. ============${NOct}\n\n"
51925232

51935233
# New Script Update Notification #
51945234
if [ "$UpdateNotify" != "0" ]; then
@@ -5220,25 +5260,24 @@ _ShowMainMenu_()
52205260
else notificationStr="${GRNct}$(_SimpleNotificationDate_ "$notifyDate")${NOct}"
52215261
fi
52225262

5223-
##------------------------------------------##
5224-
## Modified by ExtremeFiretop [2024-Mar-27] ##
5225-
##------------------------------------------##
5263+
##----------------------------------------##
5264+
## Modified by Martinski W. [2024-May-19] ##
5265+
##----------------------------------------##
52265266
printf "${SEPstr}"
52275267
if [ "$HIDE_ROUTER_SECTION" = "false" ]
52285268
then
52295269
if ! FW_NewUpdateVersion="$(_GetLatestFWUpdateVersionFromRouter_ 1)"
52305270
then FW_NewUpdateVersion="${REDct}NONE FOUND${NOct}"
52315271
else FW_NewUpdateVersion="${GRNct}${FW_NewUpdateVersion}${NOct}$arrowStr"
52325272
fi
5233-
printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(H)ide"
5234-
printf "\n${padStr}USB Storage Connected: $USBConnected"
5235-
printf "\n${padStr}F/W Version Installed: $FW_InstalledVersion"
5236-
printf "\n${padStr}F/W Update Available: $FW_NewUpdateVersion"
5237-
printf "\n${padStr}F/W Upd Expected ETA: $ExpectedFWUpdateRuntime"
5273+
printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(H)ide"
5274+
printf "\n USB-Attached Storage Connected: $USBConnected"
5275+
printf "\n F/W Version Currently Installed: $FW_InstalledVersion"
5276+
printf "\n F/W Update Version Available: $FW_NewUpdateVersion"
5277+
printf "\n F/W Update Estimated Run Date: $ExpectedFWUpdateRuntime"
52385278
else
5239-
printf "\n${padStr}F/W Product/Model ID: $FW_RouterModelID ${padStr}(S)how"
5279+
printf "\n Router's Product Name/Model ID: ${FW_RouterModelID}${padStr}(S)how"
52405280
fi
5241-
52425281
printf "\n${SEPstr}"
52435282

52445283
printf "\n ${GRNct}1${NOct}. Run F/W Update Check Now\n"
@@ -5292,7 +5331,7 @@ _ShowAdvancedOptionsMenu_()
52925331
{
52935332
clear
52945333
logo
5295-
printf "=============== Advanced Options Menu ===============\n"
5334+
printf "================== Advanced Options Menu =================\n"
52965335
printf "${SEPstr}\n"
52975336

52985337
printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update ZIP File"
@@ -5397,7 +5436,7 @@ _ShowNodesMenu_()
53975436
{
53985437
clear
53995438
logo
5400-
printf "============== AiMesh Node(s) Info Menu ==============\n"
5439+
printf "================= AiMesh Node(s) Info Menu ================\n"
54015440
printf "${SEPstr}\n"
54025441

54035442
if ! node_online_status="$(_NodeActiveStatus_)"
@@ -5473,7 +5512,7 @@ _DownloadChangelogs_()
54735512
less "$changeLogFile"
54745513
fi
54755514
rm -f "$changeLogFile" "$wgetLogFile"
5476-
"$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr"
5515+
"$inMenuMode" && _WaitForEnterKey_ "$logsMenuReturnPromptStr"
54775516
return 1
54785517
}
54795518

@@ -5484,7 +5523,7 @@ _ShowLogsMenu_()
54845523
{
54855524
clear
54865525
logo
5487-
printf "===================== Logs Menu =====================\n"
5526+
printf "======================== Logs Menu =======================\n"
54885527
printf "${SEPstr}\n"
54895528

54905529
printf "\n ${GRNct}1${NOct}. Set Directory for F/W Update Log Files"

0 commit comments

Comments
 (0)