44#
55# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7- # Last Modified: 2025-Aug-13
7+ # Last Modified: 2025-Sep-01
88# ##################################################################
99set -u
1010
1111# # Set version for each Production Release ##
12- readonly SCRIPT_VERSION=1.5.3
13- readonly SCRIPT_VERSTAG=" 25081319 "
12+ readonly SCRIPT_VERSION=1.5.4
13+ readonly SCRIPT_VERSTAG=" 25090123 "
1414readonly SCRIPT_NAME=" MerlinAU"
1515# # Set to "master" for Production Releases ##
16- SCRIPT_BRANCH=" master "
16+ SCRIPT_BRANCH=" dev "
1717
1818# #----------------------------------------##
1919# # Modified by Martinski W. [2024-Jul-03] ##
@@ -502,6 +502,12 @@ _AcquireLock_()
502502 return " $retCode "
503503}
504504
505+ # #-------------------------------------##
506+ # # Added by Martinski W. [2025-Sep-01] ##
507+ # #-------------------------------------##
508+ _EscapeChars_ ()
509+ { printf " %s" " $1 " | sed ' s/[][\/$.*^&-]/\\&/g' ; }
510+
505511# #-------------------------------------##
506512# # Added by Martinski W. [2023-Dec-26] ##
507513# #-------------------------------------##
@@ -2563,7 +2569,7 @@ _ActionsAfterNewConfigSettings_()
25632569# #----------------------------------------##
25642570_UpdateConfigFromWebUISettings_ ()
25652571{
2566- [ ! -f " $SHARED_SETTINGS_FILE " ] && return 1
2572+ [ ! -s " $SHARED_SETTINGS_FILE " ] && return 1
25672573
25682574 local settingsMergeOK=true logMsgTag=" with errors."
25692575 local oldLoginCredsENC doRouterLoginTest=false
@@ -6131,12 +6137,44 @@ _Calculate_NextRunTime_()
61316137 fi
61326138}
61336139
6140+ # #-------------------------------------##
6141+ # # Added by Martinski W. [2025-Sep-01] ##
6142+ # #-------------------------------------##
6143+ _CheckFWAutoUpdateCronJobExists_ ()
6144+ {
6145+ local fullCheck=true cronSchedule grepSchedStr
6146+
6147+ if [ $# -gt 0 ] && [ " $1 " = " ANY" ]
6148+ then fullCheck=false
6149+ fi
6150+
6151+ if ! " $fullCheck "
6152+ then
6153+ if eval $cronListCmd | grep -qE " $CRON_JOB_RUN #${CRON_JOB_TAG} #$"
6154+ then return 0
6155+ else return 1
6156+ fi
6157+ fi
6158+
6159+ cronSchedule=" $( Get_Custom_Setting FW_New_Update_Cron_Job_Schedule) "
6160+ if [ -z " $cronSchedule " ] || [ " $cronSchedule " = " TBD" ]
6161+ then
6162+ cronSchedule=" $FW_Update_CRON_DefaultSchedule "
6163+ fi
6164+ grepSchedStr=" $( _EscapeChars_ " $cronSchedule " ) "
6165+
6166+ if eval $cronListCmd | grep -qE " ^$grepSchedStr $CRON_JOB_RUN #${CRON_JOB_TAG} #$"
6167+ then return 0
6168+ else return 1
6169+ fi
6170+ }
6171+
61346172# #----------------------------------------##
6135- # # Modified by Martinski W. [2023-Nov-19 ] ##
6173+ # # Modified by Martinski W. [2025-Sep-01 ] ##
61366174# #----------------------------------------##
61376175_AddFWAutoUpdateCronJob_ ()
61386176{
6139- local newSchedule newSetting retCode=1
6177+ local newSchedule newSetting grepSchedStr retCode=1
61406178 if [ $# -gt 0 ] && [ -n " $1 " ]
61416179 then
61426180 newSetting=true
@@ -6147,16 +6185,24 @@ _AddFWAutoUpdateCronJob_()
61476185 fi
61486186 if [ -z " $newSchedule " ] || [ " $newSchedule " = " TBD" ]
61496187 then
6188+ newSetting=true
61506189 newSchedule=" $FW_Update_CRON_DefaultSchedule "
61516190 fi
6191+ grepSchedStr=" $( _EscapeChars_ " $newSchedule " ) "
6192+
6193+ if eval $cronListCmd | grep -qE " ^$grepSchedStr $CRON_JOB_RUN #${CRON_JOB_TAG} #$"
6194+ then
6195+ return 0 # Already exists#
6196+ fi
61526197
61536198 cru a " $CRON_JOB_TAG " " $newSchedule $CRON_JOB_RUN "
61546199 sleep 1
6155- if eval $cronListCmd | grep -qE " $CRON_JOB_RUN #${CRON_JOB_TAG} #$"
6200+ if eval $cronListCmd | grep -qE " ^ $grepSchedStr $CRON_JOB_RUN #${CRON_JOB_TAG} #$"
61566201 then
61576202 retCode=0
61586203 " $newSetting " && \
61596204 Update_Custom_Settings FW_New_Update_Cron_Job_Schedule " $newSchedule "
6205+ _Calculate_NextRunTime_ recal
61606206 fi
61616207 return " $retCode "
61626208}
@@ -6167,10 +6213,10 @@ _AddFWAutoUpdateCronJob_()
61676213_DelFWAutoUpdateCronJob_ ()
61686214{
61696215 local retCode
6170- if eval $cronListCmd | grep -qE " $CRON_JOB_RUN # ${CRON_JOB_TAG} #$ "
6216+ if _CheckFWAutoUpdateCronJobExists_ ANY
61716217 then
61726218 cru d " $CRON_JOB_TAG " ; sleep 1
6173- if eval $cronListCmd | grep -qE " $CRON_JOB_RUN # ${CRON_JOB_TAG} #$ "
6219+ if _CheckFWAutoUpdateCronJobExists_ ANY
61746220 then
61756221 retCode=1
61766222 printf " ${REDct} **ERROR**${NOct} : Failed to remove cron job [${GRNct}${CRON_JOB_TAG}${NOct} ].\n"
@@ -6238,21 +6284,27 @@ _GetScriptAutoUpdateCronSchedule_()
62386284}
62396285
62406286# #----------------------------------------##
6241- # # Modified by Martinski W. [2025-Feb-21 ] ##
6287+ # # Modified by Martinski W. [2025-Sep-01 ] ##
62426288# #----------------------------------------##
62436289_AddScriptAutoUpdateCronJob_ ()
62446290{
6245- local newSchedule retCode=1
6291+ local newSchedule grepSchedStr retCode=1
62466292
62476293 newSchedule=" $( _GetScriptAutoUpdateCronSchedule_) "
62486294 if [ -z " $newSchedule " ] || [ " $newSchedule " = " TBD" ]
62496295 then
62506296 newSchedule=" $ScriptAU_CRON_DefaultSchedule "
62516297 fi
6298+ grepSchedStr=" $( _EscapeChars_ " $newSchedule " ) "
6299+
6300+ if eval $cronListCmd | grep -qE " ^$grepSchedStr $SCRIPT_UP_CRON_JOB_RUN #${SCRIPT_UP_CRON_JOB_TAG} #$"
6301+ then
6302+ return 0 # Already exists#
6303+ fi
62526304
62536305 cru a " $SCRIPT_UP_CRON_JOB_TAG " " $newSchedule $SCRIPT_UP_CRON_JOB_RUN "
62546306 sleep 1
6255- if eval $cronListCmd | grep -qE " $SCRIPT_UP_CRON_JOB_RUN #${SCRIPT_UP_CRON_JOB_TAG} #$"
6307+ if eval $cronListCmd | grep -qE " ^ $grepSchedStr $SCRIPT_UP_CRON_JOB_RUN #${SCRIPT_UP_CRON_JOB_TAG} #$"
62566308 then
62576309 retCode=0
62586310 fi
@@ -6810,7 +6862,6 @@ _Set_FW_UpdateCronScheduleCustom_()
68106862 printf " Cron job '${GRNct}${CRON_JOB_TAG}${NOct} ' was updated successfully.\n"
68116863 current_schedule_english=" $( translate_schedule " $nextCronSchedule " ) "
68126864 printf " Job Schedule: ${GRNct}${current_schedule_english}${NOct} \n"
6813- _Calculate_NextRunTime_ recal
68146865 else
68156866 retCode=1
68166867 printf " ${REDct} **ERROR**${NOct} : Failed to add/update the cron job [${CRON_JOB_TAG} ].\n"
@@ -7211,14 +7262,13 @@ _Set_FW_UpdateCronScheduleGuided_()
72117262 printf " Updating '${GRNct}${CRON_JOB_TAG}${NOct} ' cron job...\n"
72127263 if _AddFWAutoUpdateCronJob_ " $nextCronSched "
72137264 then
7214- retCode=0
7215- printf " Cron job '${GRNct}${CRON_JOB_TAG}${NOct} ' was updated successfully.\n"
7216- cronSchedStrHR=" $( _TranslateCronSchedHR_ " $nextCronSched " ) "
7217- printf " Job Schedule: ${GRNct}${cronSchedStrHR}${NOct} \n"
7218- _Calculate_NextRunTime_ recal
7265+ retCode=0
7266+ printf " Cron job '${GRNct}${CRON_JOB_TAG}${NOct} ' was updated successfully.\n"
7267+ cronSchedStrHR=" $( _TranslateCronSchedHR_ " $nextCronSched " ) "
7268+ printf " Job Schedule: ${GRNct}${cronSchedStrHR}${NOct} \n"
72197269 else
7220- retCode=1
7221- printf " ${REDct} **ERROR**${NOct} : Failed to add/update the cron job [${CRON_JOB_TAG} ].\n"
7270+ retCode=1
7271+ printf " ${REDct} **ERROR**${NOct} : Failed to add/update the cron job [${CRON_JOB_TAG} ].\n"
72227272 fi
72237273 else
72247274 retCode=0
@@ -10035,7 +10085,7 @@ _EnableFWAutoUpdateChecks_()
1003510085}
1003610086
1003710087# #----------------------------------------##
10038- # # Modified by Martinski W. [2025-Apr-11 ] ##
10088+ # # Modified by Martinski W. [2025-Sep-01 ] ##
1003910089# #----------------------------------------##
1004010090_ConfirmCronJobForFWAutoUpdates_ ()
1004110091{
@@ -10046,7 +10096,8 @@ _ConfirmCronJobForFWAutoUpdates_()
1004610096 # Check if the PREVIOUS Cron Job ID already exists #
1004710097 if eval $cronListCmd | grep -qE " $CRON_JOB_RUN #${CRON_JOB_TAG_OLD} #$"
1004810098 then # If it exists, delete the OLD one & create a NEW one#
10049- cru d " $CRON_JOB_TAG_OLD " ; sleep 1 ; _AddFWAutoUpdateCronJob_
10099+ cru d " $CRON_JOB_TAG_OLD " ; sleep 1
10100+ _AddFWAutoUpdateCronJob_
1005010101 fi
1005110102
1005210103 # Retrieve custom setting for automatic F/W update checks #
@@ -10068,7 +10119,7 @@ _ConfirmCronJobForFWAutoUpdates_()
1006810119 # 1) "ENABLED": Automatically enable checks (no user prompt) #
1006910120 if [ " $fwUpdateCheckState " = " ENABLED" ]
1007010121 then
10071- if ! eval " $cronListCmd " | grep -qE " $CRON_JOB_RUN # ${CRON_JOB_TAG} #$ "
10122+ if ! _CheckFWAutoUpdateCronJobExists_
1007210123 then
1007310124 printf " Auto-enabling cron job '${GRNct}${CRON_JOB_TAG}${NOct} '...\n"
1007410125 if _AddFWAutoUpdateCronJob_
@@ -10087,7 +10138,7 @@ _ConfirmCronJobForFWAutoUpdates_()
1008710138 # 2) "TBD": Prompt the user (original behavior) #
1008810139 elif [ " $fwUpdateCheckState " = " TBD" ]
1008910140 then
10090- if ! eval $cronListCmd | grep -qE " $CRON_JOB_RUN # ${CRON_JOB_TAG} #$ "
10141+ if ! _CheckFWAutoUpdateCronJobExists_
1009110142 then
1009210143 _ShowLogo_
1009310144 printf " Do you want to enable automatic firmware update checks?\n"
@@ -10096,20 +10147,14 @@ _ConfirmCronJobForFWAutoUpdates_()
1009610147
1009710148 if _WaitForYESorNO_
1009810149 then
10099- # User said YES -> enable checks #
1010010150 printf " Adding '${GRNct}${CRON_JOB_TAG}${NOct} ' cron job...\n"
10101- if ! eval " $cronListCmd " | grep -qE " $CRON_JOB_RUN # ${CRON_JOB_TAG} #$ "
10151+ if _AddFWAutoUpdateCronJob_
1010210152 then
10103- if _AddFWAutoUpdateCronJob_
10104- then
10105- printf " Cron job '${GRNct}${CRON_JOB_TAG}${NOct} ' was added successfully.\n"
10106- cronSchedStrHR=" $( _TranslateCronSchedHR_ " $FW_UpdateCronJobSchedule " ) "
10107- printf " Job Schedule: ${GRNct}${cronSchedStrHR}${NOct} \n"
10108- else
10109- printf " ${REDct} **ERROR**${NOct} : Failed to add the cron job [${CRON_JOB_TAG} ].\n"
10110- fi
10153+ printf " Cron job '${GRNct}${CRON_JOB_TAG}${NOct} ' was added successfully.\n"
10154+ cronSchedStrHR=" $( _TranslateCronSchedHR_ " $FW_UpdateCronJobSchedule " ) "
10155+ printf " Job Schedule: ${GRNct}${cronSchedStrHR}${NOct} \n"
1011110156 else
10112- printf " Cron job ' ${GRNct}${CRON_JOB_TAG}${ NOct}' already exists .\n"
10157+ printf " ${REDct} **ERROR** ${ NOct}: Failed to add the cron job [ ${CRON_JOB_TAG} ] .\n"
1011310158 fi
1011410159 _EnableFWAutoUpdateChecks_
1011510160 else
0 commit comments