|
4 | 4 | # |
5 | 5 | # Original Creation Date: 2023-Oct-01 by @ExtremeFiretop. |
6 | 6 | # Official Co-Author: @Martinski W. - Date: 2023-Nov-01 |
7 | | -# Last Modified: 2025-Jun-08 |
| 7 | +# Last Modified: 2025-Jun-17 |
8 | 8 | ################################################################### |
9 | 9 | set -u |
10 | 10 |
|
11 | 11 | ## Set version for each Production Release ## |
12 | | -readonly SCRIPT_VERSION=1.4.8 |
| 12 | +readonly SCRIPT_VERSION=1.4.9 |
13 | 13 | readonly SCRIPT_NAME="MerlinAU" |
14 | 14 | ## Set to "master" for Production Releases ## |
15 | 15 | SCRIPT_BRANCH="master" |
@@ -3033,9 +3033,9 @@ _GetLatestFWUpdateVersionFromRouter_() |
3033 | 3033 | echo "$newVersionStr" ; return "$retCode" |
3034 | 3034 | } |
3035 | 3035 |
|
3036 | | -##----------------------------------------## |
3037 | | -## Modified by Martinski W. [2024-Apr-14] ## |
3038 | | -##----------------------------------------## |
| 3036 | +##------------------------------------------## |
| 3037 | +## Modified by ExtremeFiretop [2025-Jun-17] ## |
| 3038 | +##------------------------------------------## |
3039 | 3039 | _CreateEMailContent_() |
3040 | 3040 | { |
3041 | 3041 | if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi |
@@ -3136,35 +3136,34 @@ _CreateEMailContent_() |
3136 | 3136 | ;; |
3137 | 3137 | STOP_FW_UPDATE_APPROVAL) |
3138 | 3138 | emailBodyTitle="WARNING" |
| 3139 | + high_risk_regex=$(printf '%s\n' "$high_risk_terms" | sed 's/ /[[:space:]]+/g') |
3139 | 3140 | if "$isEMailFormatHTML" |
3140 | 3141 | then |
3141 | 3142 | # Highlight high-risk terms using HTML with a yellow background # |
3142 | | - highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/<span style='background-color:yellow;'>\1<\/span>/gi")" |
| 3143 | + highlighted_changelog_contents="$( |
| 3144 | + printf '%s\n' "$changelog_contents" | |
| 3145 | + sed -E ":a;N;\$!ba; \ |
| 3146 | + s/(${high_risk_regex})/<span style='background-color:yellow;'>\\1<\\/span>/Ig" |
| 3147 | + )" |
3143 | 3148 | else |
3144 | 3149 | # Step 1: Enclose matched terms with unique markers that don't conflict with '>' and '<' |
3145 | | - highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/\[\[UPPER\]\]\1\[\[ENDUPPER\]\]/gi")" |
3146 | | - |
3147 | | - # Step 2: Modify the awk script with correct marker lengths |
3148 | | - highlighted_changelog_contents="$(echo "$highlighted_changelog_contents" | awk ' |
3149 | | - BEGIN { |
3150 | | - upper_marker = "[[UPPER]]" |
3151 | | - endupper_marker = "[[ENDUPPER]]" |
3152 | | - upper_marker_length = length(upper_marker) |
3153 | | - endupper_marker_length = length(endupper_marker) |
3154 | | - } |
3155 | | - { |
3156 | | - while (match($0, /\[\[UPPER\]\][^\[]*\[\[ENDUPPER\]\]/)) { |
3157 | | - prefix = substr($0, 1, RSTART - 1) |
3158 | | - match_text_start = RSTART + upper_marker_length |
3159 | | - match_text_length = RLENGTH - upper_marker_length - endupper_marker_length |
3160 | | - match_text = substr($0, match_text_start, match_text_length) |
3161 | | - suffix = substr($0, RSTART + RLENGTH) |
3162 | | - match_text_upper = toupper(match_text) |
3163 | | - $0 = prefix ">" match_text_upper "<" suffix |
3164 | | - } |
3165 | | - print |
3166 | | - } |
3167 | | - ')" |
| 3150 | + highlighted_changelog_contents="$( |
| 3151 | + printf '%s\n' "$changelog_contents" | |
| 3152 | + awk -v regex="$high_risk_regex" ' |
| 3153 | + BEGIN { IGNORECASE = 1 } |
| 3154 | + { buf = buf $0 ORS } # slurp into buf |
| 3155 | + END { |
| 3156 | + out = "" |
| 3157 | + while (match(buf, regex)) { |
| 3158 | + pre = substr(buf, 1, RSTART - 1) |
| 3159 | + hit = substr(buf, RSTART, RLENGTH) |
| 3160 | + buf = substr(buf, RSTART + RLENGTH) # delete hit + prefix |
| 3161 | + out = out pre ">" toupper(hit) "<" # grow output |
| 3162 | + } |
| 3163 | + out = out buf # tail with no more matches |
| 3164 | + printf "%s", out |
| 3165 | + }' |
| 3166 | + )" |
3168 | 3167 | fi |
3169 | 3168 | { |
3170 | 3169 | echo "Found high-risk phrases in the changelog file while Auto-Updating to version <b>${fwNewUpdateVersion}</b> on the <b>${MODEL_ID}</b> router." |
|
0 commit comments