Skip to content

Commit 8873880

Browse files
Merge pull request #111 from ExtremeFiretop/dev
Dev 1.0.1 as next master release
2 parents 82e42c9 + 67a6b1b commit 8873880

File tree

1 file changed

+93
-67
lines changed

1 file changed

+93
-67
lines changed

MerlinAU.sh

Lines changed: 93 additions & 67 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: 2024-Jan-28
7+
# Last Modified: 2024-Jan-31
88
###################################################################
99
set -u
1010

1111
#For AMTM versioning:
12-
readonly SCRIPT_VERSION=1.0.0
12+
readonly SCRIPT_VERSION=1.0.1
1313
readonly SCRIPT_NAME="MerlinAU"
1414

1515
##-------------------------------------##
@@ -258,7 +258,7 @@ Toggle_LEDs()
258258
do
259259
LED_ToggleState="$((! LED_ToggleState))"
260260
nvram set led_disable="$LED_ToggleState"
261-
service restart_leds > /dev/null 2>&1
261+
/sbin/service restart_leds > /dev/null 2>&1
262262
sleep "$blinkRateSecs"
263263
done
264264
return 0
@@ -285,7 +285,7 @@ _Reset_LEDs_()
285285
wait $Toggle_LEDs_PID
286286
# Set LEDs to their "initial state" #
287287
nvram set led_disable="$LED_InitState"
288-
service restart_leds >/dev/null 2>&1
288+
/sbin/service restart_leds >/dev/null 2>&1
289289
sleep 2
290290
fi
291291
Toggle_LEDs_PID=""
@@ -388,7 +388,7 @@ _FWVersionStrToNum_()
388388
then
389389
nonProductionVersionWeight=-100
390390
# Remove 'alpha/beta' and any following numbers #
391-
verStr="$(echo "$verStr" | sed 's/[Aa]lpha[0-9]*// ; s/[Bb]eta[0-9]*//')"
391+
verStr="$(echo "$verStr" | sed 's/[._-]\?[Aa]lpha[0-9]*// ; s/[._-]\?[Bb]eta[0-9]*//')"
392392
fi
393393

394394
numFields="$(echo "$verStr" | awk -F '.' '{print NF}')"
@@ -815,9 +815,9 @@ Update_Custom_Settings()
815815
}
816816

817817
##------------------------------------------##
818-
## Modified by ExtremeFiretop [2024-Jan-26] ##
818+
## Modified by ExtremeFiretop [2024-Jan-30] ##
819819
##------------------------------------------##
820-
_migrate_settings_() {
820+
_migrate_settings_move() {
821821
local USBMountPoint="$(Get_Custom_Setting FW_New_Update_LOG_Directory_Path)"
822822
local old_settings_dir="${ADDONS_PATH}/$ScriptFNameTag"
823823
local new_settings_dir="${ADDONS_PATH}/$ScriptDirNameD"
@@ -830,7 +830,13 @@ _migrate_settings_() {
830830
if [ -d "$old_settings_dir" ]; then
831831
# Check if the new SETTINGS directory already exists
832832
if [ -d "$new_settings_dir" ]; then
833-
echo "The new SETTINGS directory already exists. Migration is not required."
833+
# Remove the old SETTINGS directory since the new one exists
834+
rm -rf "$old_settings_dir"
835+
if [ $? -eq 0 ]; then
836+
echo "The new SETTINGS directory already exists. Removed the old SETTINGS directory."
837+
else
838+
echo "Error occurred while removing the old SETTINGS directory."
839+
fi
834840
else
835841
# Move the old SETTINGS directory to the new location
836842
mv "$old_settings_dir" "$new_settings_dir"
@@ -846,7 +852,13 @@ _migrate_settings_() {
846852
if [ -d "$old_bin_dir" ]; then
847853
# Check if the new BIN directory already exists
848854
if [ -d "$new_bin_dir" ]; then
849-
echo "The new BIN directory already exists. Migration is not required."
855+
# Remove the old BIN directory since the new one exists
856+
rm -rf "$old_bin_dir"
857+
if [ $? -eq 0 ]; then
858+
echo "The new BIN directory already exists. Removed the old BIN directory."
859+
else
860+
echo "Error occurred while removing the old BIN directory."
861+
fi
850862
else
851863
# Move the old BIN directory to the new location
852864
mv "$old_bin_dir" "$new_bin_dir"
@@ -862,7 +874,13 @@ _migrate_settings_() {
862874
if [ -d "$old_log_dir" ]; then
863875
# Check if the new LOG directory already exists
864876
if [ -d "$new_log_dir" ]; then
865-
echo "The new LOG directory already exists. Migration is not required."
877+
# Remove the old LOG directory since the new one exists
878+
rm -rf "$old_log_dir"
879+
if [ $? -eq 0 ]; then
880+
echo "The new LOG directory already exists. Removed the old LOG directory."
881+
else
882+
echo "Error occurred while removing the old LOG directory."
883+
fi
866884
else
867885
# Move the old LOG directory to the new location
868886
mv "$old_log_dir" "$new_log_dir"
@@ -875,7 +893,7 @@ _migrate_settings_() {
875893
fi
876894
}
877895

878-
_migrate_settings_
896+
_migrate_settings_move
879897

880898
##------------------------------------------##
881899
## Modified by ExtremeFiretop [2024-Jan-24] ##
@@ -1519,13 +1537,20 @@ _GetCurrentFWInstalledLongVersion_()
15191537
##----------------------------------------##
15201538
_GetCurrentFWInstalledShortVersion_()
15211539
{
1540+
##FOR DEBUG ONLY##
1541+
if true
1542+
then
15221543
local theVersionStr extVersNum
15231544

15241545
extVersNum="$(nvram get extendno | awk -F '-' '{print $1}')"
15251546
[ -z "$extVersNum" ] && extVersNum=0
15261547

15271548
theVersionStr="$(nvram get buildno).$extVersNum"
15281549
echo "$theVersionStr"
1550+
else
1551+
##FOR DEBUG ONLY##
1552+
echo "388.5.0"
1553+
fi
15291554
}
15301555

15311556
##-------------------------------------##
@@ -1816,7 +1841,7 @@ _toggle_beta_updates_() {
18161841

18171842
if [ "$currentSetting" = "ENABLED" ]; then
18181843
printf "${REDct}*WARNING*:${NOct}\n"
1819-
printf "Disabling updates from beta to release firmware may limit access to new features and fixes.\n"
1844+
printf "Disabling updates from beta to release firmware may limit access to new features and fixes.\n"
18201845
printf "Keep this enabled if you prefer to stay up-to-date with the latest releases.\n"
18211846
printf "\nProceed to disable? [y/N]: "
18221847
read -r response
@@ -2305,31 +2330,13 @@ _EntwareServicesHandler_()
23052330

23062331
if [ -n "$actionStr" ]
23072332
then
2333+
"$isInteractive" && \
23082334
printf "\n${actionStr} Entware services... Please wait.\n"
23092335
$entwOPT_unslung $1 ; sleep 5
23102336
printf "\nDone.\n"
23112337
fi
23122338
}
23132339

2314-
##-------------------------------------##
2315-
## Added by Martinski W. [2024-Jan-28] ##
2316-
##-------------------------------------##
2317-
_UnmountUSBDrives_()
2318-
{
2319-
local theDevice mountPointRegExp="^/dev/sd[a-z][0-9]+.* /tmp/mnt/.*"
2320-
2321-
mountedDevices="$(grep -E "$mountPointRegExp" /proc/mounts | awk -F ' ' '{print $1}')"
2322-
[ -z "$mountedDevices" ] && return 1
2323-
2324-
"$isInteractive" && \
2325-
printf "\nUnmounting USB-attached drives. Please wait...\n"
2326-
2327-
for theDevice in $mountedDevices
2328-
do umount -f "$theDevice" 2>/dev/null; sleep 2 ; done
2329-
2330-
printf "\nDone.\n"
2331-
}
2332-
23332340
##----------------------------------------##
23342341
## Modified by Martinski W. [2024-Jan-25] ##
23352342
##----------------------------------------##
@@ -2413,7 +2420,6 @@ Please manually update to version $minimum_supported_version or higher to use th
24132420

24142421
# Get current firmware version #
24152422
current_version="$(_GetCurrentFWInstalledShortVersion_)"
2416-
##FOR DEBUG ONLY##current_version="388.5.0"
24172423

24182424
#---------------------------------------------------------#
24192425
# If the "F/W Update Check" in the WebGUI is disabled
@@ -2563,7 +2569,7 @@ Please manually update to version $minimum_supported_version or higher to use th
25632569
cd "$FW_BIN_DIR"
25642570

25652571
##------------------------------------------##
2566-
## Modified by ExtremeFiretop [2024-Jan-25] ##
2572+
## Modified by ExtremeFiretop [2024-Jan-30] ##
25672573
##------------------------------------------##
25682574
local checkChangeLogSetting="$(Get_Custom_Setting "CheckChangeLog")"
25692575

@@ -2578,42 +2584,62 @@ Please manually update to version $minimum_supported_version or higher to use th
25782584
"$inMenuMode" && _WaitForEnterKey_ "$menuReturnPromptStr"
25792585
return 1
25802586
else
2581-
# Format current_version by removing the last '.0'
2582-
formatted_current_version=$(echo $current_version | awk -F. '{print $1"."$2}')
2587+
# Use awk to format the version based on the number of initial digits
2588+
formatted_current_version=$(echo "$current_version" | awk -F. '{
2589+
if (length($1) == 4 && NF >= 3) {
2590+
# For version starting with four digits like 3004.388.5.0
2591+
# Format as the next two fields (388.5)
2592+
printf "%s.%s", $2, $3
2593+
} else if (NF >= 2) {
2594+
# For version with three initial digits like 388.5.0
2595+
# Format as the first two fields (388.5)
2596+
printf "%s.%s", $1, $2
2597+
}
2598+
}')
25832599

25842600
# Format release_version by removing the prefix '3004.' and the last '.0'
25852601
formatted_release_version=$(echo $release_version | awk -F. '{print $2"."$3}')
25862602

2587-
# Extract log contents between two firmware versions
2588-
changelog_contents=$(awk "/$formatted_release_version/,/$formatted_current_version/" "$changelog_file")
2603+
# Define regex patterns for both versions
2604+
release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
2605+
current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
25892606

2590-
# Define high-risk terms as a single string separated by '|'
2591-
high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended"
25922607

2593-
# Search for high-risk terms in the extracted log contents
2594-
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then
2595-
if [ "$inMenuMode" = true ]; then
2596-
printf "\n ${REDct}Warning: Found high-risk phrases in the change-logs.${NOct}"
2597-
printf "\n ${REDct}Would you like to continue anyways?${NOct}"
2598-
if ! _WaitForYESorNO_ ; then
2599-
Say "Exiting for change-log review."
2600-
_DoCleanUp_ 1 ; return 1
2608+
# Check if the current version is present in the changelog
2609+
if ! grep -Eq "$current_version_regex" "$changelog_file"; then
2610+
Say "Current version not found in change-log. Bypassing change-log verification for this run."
2611+
else
2612+
# Extract log contents between two firmware versions
2613+
changelog_contents=$(awk "/$release_version_regex/,/$current_version_regex/" "$changelog_file")
2614+
# Define high-risk terms as a single string separated by '|'
2615+
high_risk_terms="factory default reset|features are disabled|break backward compatibility|must be manually|strongly recommended"
2616+
2617+
# Search for high-risk terms in the extracted log contents
2618+
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"; then
2619+
if [ "$inMenuMode" = true ]; then
2620+
printf "\n ${REDct}Warning: Found high-risk phrases in the change-logs.${NOct}"
2621+
printf "\n ${REDct}Would you like to continue anyways?${NOct}"
2622+
if ! _WaitForYESorNO_ ; then
2623+
Say "Exiting for change-log review."
2624+
_DoCleanUp_ 1 ; return 1
2625+
fi
2626+
else
2627+
Say "Warning: Found high-risk phrases in the change-logs."
2628+
Say "Please run script interactively to approve the upgrade."
2629+
_SendEMailNotification_ STOP_FW_UPDATE_APPROVAL
2630+
_DoCleanUp 1
2631+
_DoExit_ 1
26012632
fi
26022633
else
2603-
Say "Warning: Found high-risk phrases in the change-logs."
2604-
Say "Please run script interactively to approve the upgrade."
2605-
_SendEMailNotification_ STOP_FW_UPDATE_APPROVAL
2606-
_DoCleanUp 1
2607-
_DoExit_ 1
2634+
Say "No high-risk phrases found in the change-logs."
26082635
fi
2609-
else
2610-
Say "No high-risk phrases found in the change-logs."
26112636
fi
26122637
fi
26132638
else
26142639
Say "Change-logs check disabled."
26152640
fi
26162641

2642+
rog_file=""
26172643
# Detect ROG and pure firmware files
26182644
rog_file="$(ls | grep -i '_rog_')"
26192645
pure_file="$(ls -1 | grep -iE '.*[.](w|pkgtb)$' | grep -iv 'rog')"
@@ -2744,10 +2770,10 @@ Please manually update to version $minimum_supported_version or higher to use th
27442770
# so that the F/W Update can start without interruptions.
27452771
#------------------------------------------------------------#
27462772
"$isInteractive" && printf "\nRestarting web server... Please wait.\n"
2747-
/sbin/service restart_httpd &
2773+
/sbin/service restart_httpd >/dev/null 2>&1 &
27482774
sleep 5
27492775

2750-
# Send last email notification before flash #
2776+
# Send last email notification before F/W flash #
27512777
_SendEMailNotification_ START_FW_UPDATE_STATUS
27522778

27532779
# Check if '/opt/bin/diversion' exists #
@@ -2757,7 +2783,7 @@ Please manually update to version $minimum_supported_version or higher to use th
27572783
/opt/bin/diversion unmount
27582784
fi
27592785

2760-
# Stop entware services before flash #
2786+
# Stop entware services before F/W flash #
27612787
_EntwareServicesHandler_ stop
27622788

27632789
curl_response="$(curl "${routerURLstr}/login.cgi" \
@@ -2782,7 +2808,13 @@ Please manually update to version $minimum_supported_version or higher to use th
27822808
echo
27832809

27842810
# *WARNING*: No more logging at this point & beyond #
2785-
_UnmountUSBDrives_
2811+
/sbin/ejusb -1 0 -u 1
2812+
2813+
#-------------------------------------------------------
2814+
# Stop toggling LEDs during the F/W flash to avoid
2815+
# modifying NVRAM during the actual flash process.
2816+
#-------------------------------------------------------
2817+
_Reset_LEDs_
27862818

27872819
nohup curl "${routerURLstr}/upgrade.cgi" \
27882820
--referer ${routerURLstr}/Advanced_FirmwareUpgrade_Content.asp \
@@ -2799,6 +2831,7 @@ Please manually update to version $minimum_supported_version or higher to use th
27992831
-F "file=@${firmware_file}" \
28002832
--cookie /tmp/cookie.txt > /tmp/upload_response.txt 2>&1 &
28012833
curlPID=$!
2834+
28022835
#----------------------------------------------------------#
28032836
# In the rare case that the F/W Update gets "stuck" for
28042837
# some reason & the "curl" cmd never returns, we create
@@ -2820,10 +2853,8 @@ Please manually update to version $minimum_supported_version or higher to use th
28202853
#----------------------------------------------------------#
28212854
# Let's wait for 3 minutes here. If the router does not
28222855
# reboot by itself after the process returns, do it now.
2823-
# Restart the LEDs with a "slower" blinking rate.
28242856
#----------------------------------------------------------#
2825-
_Reset_LEDs_ ; Toggle_LEDs 3 & Toggle_LEDs_PID=$!
2826-
sleep 180 ; _Reset_LEDs_ 1
2857+
sleep 180
28272858
/sbin/service reboot
28282859
else
28292860
Say "${REDct}**ERROR**${NOct}: Login failed. Please try the following:
@@ -3064,9 +3095,9 @@ then
30643095
printf "Automatic firmware update checks will be DISABLED.\n"
30653096
printf "You can enable this feature later through the menu.\n"
30663097
FW_UpdateCheckState=0
3098+
runfwUpdateCheck=false
30673099
nvram set firmware_check_enable="$FW_UpdateCheckState"
30683100
nvram commit
3069-
runfwUpdateCheck=false
30703101
fi
30713102
else
30723103
printf "Cron job '${GRNct}${CRON_JOB_TAG}${NOct}' already exists.\n"
@@ -3078,8 +3109,6 @@ then
30783109
_WaitForEnterKey_
30793110
fi
30803111

3081-
rog_file=""
3082-
30833112
FW_RouterProductID="${GRNct}${PRODUCT_ID}${NOct}"
30843113
if [ "$PRODUCT_ID" = "$MODEL_ID" ]
30853114
then FW_RouterModelID="${FW_RouterProductID}"
@@ -3291,14 +3320,11 @@ theExitStr="${GRNct}e${NOct}=Exit to main menu"
32913320

32923321
while true
32933322
do
3294-
local_choice_set="$(Get_Custom_Setting "ROGBuild")"
32953323
show_menu
32963324

32973325
# Check if the directory exists again before attempting to navigate to it
32983326
if [ -d "$FW_BIN_DIR" ]; then
32993327
cd "$FW_BIN_DIR"
3300-
# Check for the presence of "rog" in filenames in the directory again
3301-
rog_file="$(ls | grep -i '_rog_')"
33023328
fi
33033329

33043330
printf "Enter selection: " ; read -r userChoice

0 commit comments

Comments
 (0)