Skip to content

Commit 6e5b682

Browse files
Merge pull request #367 from ExtremeFiretop/ExtremeFiretop-Fixes
Fixes: Cron Schedule Calculations, Changelog Verification, Post-Update Version Comparison
2 parents b7c1b50 + 2c70b4c commit 6e5b682

File tree

1 file changed

+117
-23
lines changed

1 file changed

+117
-23
lines changed

MerlinAU.sh

Lines changed: 117 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ _GetLatestFWUpdateVersionFromRouter_()
16391639
}
16401640

16411641
##------------------------------------------##
1642-
## Modified by ExtremeFiretop [2024-Nov-16] ##
1642+
## Modified by ExtremeFiretop [2024-Nov-26] ##
16431643
##------------------------------------------##
16441644
_CreateEMailContent_()
16451645
{
@@ -1662,8 +1662,8 @@ _CreateEMailContent_()
16621662
fwNewUpdateVersion="$(Get_Custom_Setting "FW_New_Update_Notification_Vers")"
16631663
fi
16641664

1665-
# Remove "_rog" or "_tuf" or -gHASHVALUES suffix to avoid version comparison failures #
1666-
fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/(_(rog|tuf)|-g[0-9a-f]{10})$//')"
1665+
# Remove any suffix starting with "-" or "_" to avoid version comparison failures
1666+
fwInstalledVersion="$(echo "$fwInstalledVersion" | sed -E 's/[-_].*$//')"
16671667

16681668
case "$1" in
16691669
FW_UPDATE_TEST_EMAIL)
@@ -1679,6 +1679,13 @@ _CreateEMailContent_()
16791679
echo "A new F/W Update version <b>${fwNewUpdateVersion}</b> is available for the <b>${MODEL_ID}</b> router."
16801680
printf "\nThe F/W version that is currently installed:\n<b>${fwInstalledVersion}</b>\n"
16811681
printf "\nNumber of days to postpone flashing the new F/W Update version: <b>${FW_UpdatePostponementDays}</b>\n"
1682+
printf "\nPlease click here to review the changelog:\n"
1683+
if "$isGNUtonFW"
1684+
then
1685+
printf "${Gnuton_changelogurl}\n"
1686+
else
1687+
printf "${changeLogURL}\n"
1688+
fi
16821689
[ "$FW_UpdateExpectedRunDate" != "TBD" ] && \
16831690
printf "\nThe firmware update is expected to occur on: <b>${FW_UpdateExpectedRunDate}</b>\n"
16841691
} > "$tempEMailBodyMsg"
@@ -1713,8 +1720,30 @@ _CreateEMailContent_()
17131720
# Highlight high-risk terms using HTML with a yellow background #
17141721
highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/<span style='background-color:yellow;'>\1<\/span>/gi")"
17151722
else
1716-
# Highlight high-risk terms in plain text using asterisks #
1717-
highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/*\1*/gi")"
1723+
# Step 1: Enclose matched terms with unique markers that don't conflict with '>' and '<'
1724+
highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/\[\[UPPER\]\]\1\[\[ENDUPPER\]\]/gi")"
1725+
1726+
# Step 2: Modify the awk script with correct marker lengths
1727+
highlighted_changelog_contents="$(echo "$highlighted_changelog_contents" | awk '
1728+
BEGIN {
1729+
upper_marker = "[[UPPER]]"
1730+
endupper_marker = "[[ENDUPPER]]"
1731+
upper_marker_length = length(upper_marker)
1732+
endupper_marker_length = length(endupper_marker)
1733+
}
1734+
{
1735+
while (match($0, /\[\[UPPER\]\][^\[]*\[\[ENDUPPER\]\]/)) {
1736+
prefix = substr($0, 1, RSTART - 1)
1737+
match_text_start = RSTART + upper_marker_length
1738+
match_text_length = RLENGTH - upper_marker_length - endupper_marker_length
1739+
match_text = substr($0, match_text_start, match_text_length)
1740+
suffix = substr($0, RSTART + RLENGTH)
1741+
match_text_upper = toupper(match_text)
1742+
$0 = prefix ">" match_text_upper "<" suffix
1743+
}
1744+
print
1745+
}
1746+
')"
17181747
fi
17191748
{
17201749
echo "Found high-risk phrases in the changelog file while Auto-Updating to version <b>${fwNewUpdateVersion}</b> on the <b>${MODEL_ID}</b> router."
@@ -3031,6 +3060,7 @@ _GetNodeInfo_()
30313060
node_build_name="Unreachable"
30323061
node_lan_hostname="Unreachable"
30333062
node_label_mac="Unreachable"
3063+
NodeGNUtonFW=false
30343064

30353065
## Check for Login Credentials ##
30363066
credsBase64="$(Get_Custom_Setting credentials_base64)"
@@ -3093,6 +3123,9 @@ _GetNodeInfo_()
30933123
node_lan_hostname="$(echo "$htmlContent" | grep -o '"lan_hostname":"[^"]*' | sed 's/"lan_hostname":"//')"
30943124
node_label_mac="$(echo "$htmlContent" | grep -o '"label_mac":"[^"]*' | sed 's/"label_mac":"//')"
30953125

3126+
# Check if installed F/W NVRAM vars contain "gnuton" #
3127+
if echo "$node_extendno" | grep -iq "gnuton"
3128+
then NodeGNUtonFW=true ; fi
30963129
# Combine extracted information into one string #
30973130
Node_combinedVer="${node_firmver}.${node_buildno}.$node_extendno"
30983131

@@ -3985,18 +4018,29 @@ _IncrementDay_()
39854018
echo "$day $month $year"
39864019
}
39874020

3988-
##----------------------------------------##
3989-
## Modified by Martinski W. [2024-May-18] ##
3990-
##----------------------------------------##
4021+
##------------------------------------------##
4022+
## Modified by ExtremeFiretop [2024-Nov-26] ##
4023+
##------------------------------------------##
39914024
matches_day_of_month()
39924025
{
39934026
local curr_dom="$1"
39944027
local dom_expr="$2"
3995-
local domStart domEnd
4028+
local domStart domEnd expanded_days
39964029

39974030
if [ "$dom_expr" = "*" ]
39984031
then # Matches any day of the month #
39994032
return 0
4033+
elif echo "$dom_expr" | grep -q '/'
4034+
then
4035+
# Handle step values like */5 or 1-15/3
4036+
expanded_days=$(expand_cron_field "$dom_expr" 1 31)
4037+
for day in $expanded_days
4038+
do
4039+
if [ "$day" -eq "$curr_dom" ]
4040+
then # Current day matches one in the expanded list #
4041+
return 0
4042+
fi
4043+
done
40004044
elif echo "$dom_expr" | grep -q '-'
40014045
then
40024046
domStart="$(echo "$dom_expr" | cut -d'-' -f1)"
@@ -4081,14 +4125,14 @@ matches_month()
40814125
return 1 # No match #
40824126
}
40834127

4084-
##----------------------------------------##
4085-
## Modified by Martinski W. [2024-May-18] ##
4086-
##----------------------------------------##
4128+
##------------------------------------------##
4129+
## Modified by ExtremeFiretop [2024-Nov-26] ##
4130+
##------------------------------------------##
40874131
matches_day_of_week()
40884132
{
40894133
local curr_dow="$1"
40904134
local dow_expr="$2"
4091-
local dowStart dowEnd dowStartNum dowEndNum
4135+
local dowStart dowEnd expanded_dows
40924136

40934137
_DayOfWeekNameToNumber_()
40944138
{
@@ -4112,12 +4156,24 @@ matches_day_of_week()
41124156
if [ "$dow_expr" = "*" ]
41134157
then # Matches any day of the week #
41144158
return 0
4159+
elif echo "$dow_expr" | grep -q '/'
4160+
then
4161+
# Handle step values like */2 or 1-5/2
4162+
expanded_dows=$(expand_cron_field "$dow_expr" 0 6)
4163+
for dow in $expanded_dows
4164+
do
4165+
if [ "$dow" -eq "$curr_dow" ]
4166+
then # Current day of the week matches one in the expanded list #
4167+
return 0
4168+
fi
4169+
done
41154170
elif echo "$dow_expr" | grep -q '-'
41164171
then
41174172
dowStart="$(echo "$dow_expr" | cut -d'-' -f1)"
41184173
dowEnd="$(echo "$dow_expr" | cut -d'-' -f2)"
41194174
dowStartNum="$(_DayOfWeekNameToNumber_ "$dowStart")"
41204175
dowEndNum="$(_DayOfWeekNameToNumber_ "$dowEnd")"
4176+
41214177
if [ "$dowStartNum" -gt "$dowEndNum" ]
41224178
then
41234179
dow_expr="$dowStartNum"
@@ -5565,9 +5621,9 @@ _high_risk_phrases_nointeractive_()
55655621
fi
55665622
}
55675623

5568-
##----------------------------------------##
5569-
## Modified by Martinski W. [2024-Aug-11] ##
5570-
##----------------------------------------##
5624+
##-------------------------------------==---##
5625+
## Modified by ExtremeFiretop [2024-Nov-24] ##
5626+
##-------------------------------------==---##
55715627
_ChangelogVerificationCheck_()
55725628
{
55735629
local mode="$1" # Mode should be 'auto' or 'interactive' #
@@ -5609,10 +5665,14 @@ _ChangelogVerificationCheck_()
56095665
# Use awk to format the version based on the number of initial digits
56105666
formatted_current_version=$(echo "$current_version" | awk -F. '{
56115667
if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix
5612-
if (NF == 4 && $4 == "0") {
5613-
printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0
5614-
} else if (NF == 4) {
5615-
printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit
5668+
if (NF == 4) {
5669+
# Remove any non-digit characters from the fourth field
5670+
sub(/[^0-9].*/, "", $4)
5671+
if ($4 == "0") {
5672+
printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0
5673+
} else {
5674+
printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit
5675+
}
56165676
}
56175677
} else if (NF == 3) { # For version without a four-digit prefix
56185678
if ($3 == "0") {
@@ -5640,8 +5700,8 @@ _ChangelogVerificationCheck_()
56405700
}')
56415701

56425702
# Define regex patterns for both versions
5643-
release_version_regex="$formatted_release_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
5644-
current_version_regex="$formatted_current_version \([0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\)"
5703+
release_version_regex="${formatted_release_version//./[._]}\s*\([0-9]{1,2}-[A-Za-z]+-[0-9]{4}\)"
5704+
current_version_regex="${formatted_current_version//./[._]}\s*\([0-9]{1,2}-[A-Za-z]+-[0-9]{4}\)"
56455705

56465706
if "$isGNUtonFW"
56475707
then
@@ -5686,7 +5746,7 @@ _ManageChangelogMerlin_()
56865746

56875747
local mode="$1" # Mode should be 'download' or 'view' #
56885748
local newUpdateVerStr=""
5689-
local wgetLogFile changeLogFile changeLogTag changeLogURL
5749+
local wgetLogFile changeLogFile changeLogTag
56905750

56915751
# Create directory to download changelog if missing
56925752
if ! _CreateDirectory_ "$FW_BIN_DIR" ; then return 1 ; fi
@@ -5936,6 +5996,23 @@ _CheckNodeFWUpdateNotification_()
59365996
echo ""
59375997
echo "AiMesh Node <b>${nodefriendlyname}</b> with MAC address <b>${node_label_mac}</b> requires update from <b>${1}</b> to <b>${2}</b> version."
59385998
echo "(<b>${1}</b> --> <b>${2}</b>)"
5999+
echo "Please click here to review the latest changelog:"
6000+
if "$NodeGNUtonFW"
6001+
then
6002+
Gnuton_changelogurl="$(GetLatestChangelogUrl "$FW_GITURL_RELEASE")"
6003+
echo "$Gnuton_changelogurl"
6004+
else
6005+
if [ "$node_firmver" -eq 3006 ]
6006+
then
6007+
changeLogURL="${CL_URL_3006}"
6008+
elif echo "$node_firmver" | grep -qE "^386[.]"
6009+
then
6010+
changeLogURL="${CL_URL_386}"
6011+
else
6012+
changeLogURL="${CL_URL_NG}"
6013+
fi
6014+
echo "$changeLogURL"
6015+
fi
59396016
echo "Automated update will be scheduled <b>only if</b> MerlinAU is installed on the node."
59406017
} > "$tempNodeEMailList"
59416018
fi
@@ -5951,6 +6028,23 @@ _CheckNodeFWUpdateNotification_()
59516028
echo ""
59526029
echo "AiMesh Node <b>${nodefriendlyname}</b> with MAC address <b>${node_label_mac}</b> requires update from <b>${1}</b> to <b>${2}</b> version."
59536030
echo "(<b>${1}</b> --> <b>${2}</b>)"
6031+
echo "Please click here to review the latest changelog:"
6032+
if "$NodeGNUtonFW"
6033+
then
6034+
Gnuton_changelogurl="$(GetLatestChangelogUrl "$FW_GITURL_RELEASE")"
6035+
echo "$Gnuton_changelogurl"
6036+
else
6037+
if [ "$node_firmver" -eq 3006 ]
6038+
then
6039+
changeLogURL="${CL_URL_3006}"
6040+
elif echo "$node_firmver" | grep -qE "^386[.]"
6041+
then
6042+
changeLogURL="${CL_URL_386}"
6043+
else
6044+
changeLogURL="${CL_URL_NG}"
6045+
fi
6046+
echo "$changeLogURL"
6047+
fi
59546048
echo "Automated update will be scheduled <b>only if</b> MerlinAU is installed on the node."
59556049
} > "$tempNodeEMailList"
59566050
fi

0 commit comments

Comments
 (0)