44#
55# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7- # Last Modified: 2025-Nov-05
7+ # Last Modified: 2025-Nov-16
88# ##################################################################
99set -u
1010
1111# # Set version for each Production Release ##
12- readonly SCRIPT_VERSION=1.5.6
13- readonly SCRIPT_VERSTAG=" 25110520 "
12+ readonly SCRIPT_VERSION=1.5.7
13+ readonly SCRIPT_VERSTAG=" 25111620 "
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] ##
@@ -2544,9 +2544,9 @@ _WebUI_SetEmailConfigFileFromAMTM_()
25442544 _WriteVarDefToHelperJSFile_ " isEMailConfigEnabledInAMTM" " $isEMailConfigEnabledInAMTM " true
25452545}
25462546
2547- # #------------------------------------------ ##
2548- # # Modified by ExtremeFiretop [2025-May-21 ] ##
2549- # #------------------------------------------ ##
2547+ # #----------------------------------------##
2548+ # # Modified by Martinski W. [2025-Nov-16 ] ##
2549+ # #----------------------------------------##
25502550_ActionsAfterNewConfigSettings_ ()
25512551{
25522552 if [ ! -s " ${CONFIG_FILE} .bak" ] || \
@@ -2555,7 +2555,7 @@ _ActionsAfterNewConfigSettings_()
25552555
25562556 _ConfigOptionChanged_ ()
25572557 {
2558- if diff " $CONFIG_FILE " " ${CONFIG_FILE} .bak" | grep -q " $1 "
2558+ if diff -U0 " $CONFIG_FILE " " ${CONFIG_FILE} .bak" | grep -q " $1 "
25592559 then return 0
25602560 else return 1
25612561 fi
@@ -3000,9 +3000,9 @@ _GetLatestFWUpdateVersionFromRouter_()
30003000 echo " $newVersionStr " ; return " $retCode "
30013001}
30023002
3003- # #------------------------------------------ ##
3004- # # Modified by ExtremeFiretop [2025-Jun-17 ] ##
3005- # #------------------------------------------ ##
3003+ # #----------------------------------------##
3004+ # # Modified by Martinski W. [2025-Nov-10 ] ##
3005+ # #----------------------------------------##
30063006_CreateEMailContent_ ()
30073007{
30083008 if [ $# -eq 0 ] || [ -z " $1 " ] ; then return 1 ; fi
@@ -3080,6 +3080,13 @@ _CreateEMailContent_()
30803080 printf " \nThe F/W version that is currently installed:\n<b>${fwInstalledVersion} </b>\n"
30813081 } > " $tempEMailBodyMsg "
30823082 ;;
3083+ FAILED_USB_DRIVE_UNMOUNT)
3084+ emailBodyTitle=" USB Drive Unmount Failed"
3085+ {
3086+ echo " Unable to unmount the USB-attached drive before the F/W Update flash was started on the <b>${MODEL_ID} </b> router."
3087+ printf " \nThe USB drive was likely in a busy state.\n"
3088+ } > " $tempEMailBodyMsg "
3089+ ;;
30833090 SUCCESS_SCRIPT_UPDATE_STATUS)
30843091 if [ -s " $SCRIPT_VERPATH " ]
30853092 then
@@ -8772,8 +8779,85 @@ _RunOfflineUpdateNow_()
87728779 fi
87738780}
87748781
8782+ # #-------------------------------------##
8783+ # # Added by Martinski W. [2025-Nov-09] ##
8784+ # #-------------------------------------##
8785+ _Unmount_Eject_USB_Drives_ ()
8786+ {
8787+ local maxWaitDelaySecs=240 # 4 mins#
8788+ local theWaitDelaySecs=5 curWaitDelaySecs=0
8789+ local ejectUSB_OK=false ejectUSB_PID=" " usbMountPoint=" "
8790+ local logMsg=" Unmount/Eject USB Drive"
8791+
8792+ _MsgToSysLog_ () { logger -st " ${SCRIPT_NAME} _[$$ ]" -p 4 " $1 " ; }
8793+
8794+ _MsgToSysLog_ " START of ${logMsg} ..."
8795+
8796+ /sbin/ejusb -1 0 -u 1 2> /dev/null & ejectUSB_PID=$!
8797+
8798+ while [ " $curWaitDelaySecs " -lt " $maxWaitDelaySecs " ]
8799+ do
8800+ # # If unmount succeeded, then exit loop ##
8801+ if [ -n " $ejectUSB_PID " ] && \
8802+ ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8803+ ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8804+ then
8805+ ejectUSB_OK=true ; break
8806+ fi
8807+
8808+ # # If USB drive is no longer mounted, exit loop ##
8809+ if ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8810+ then
8811+ _MsgToSysLog_ " ${logMsg} : No USB drives are mounted."
8812+ ejectUSB_OK=true ; break
8813+ fi
8814+
8815+ # # If timeout was reached, check again and exit loop ##
8816+ if [ -n " $ejectUSB_PID " ] && \
8817+ [ " $curWaitDelaySecs " -ge " $maxWaitDelaySecs " ]
8818+ then
8819+ if ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8820+ ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8821+ then
8822+ ejectUSB_OK=true ; break
8823+ fi
8824+ kill -KILL " $ejectUSB_PID " 2> /dev/null
8825+ wait $ejectUSB_PID ; break
8826+ fi
8827+
8828+ # # If USB drive is still mounted, try again ##
8829+ if [ -n " $ejectUSB_PID " ] && \
8830+ ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8831+ usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8832+ then
8833+ /sbin/ejusb -1 0 -u 1 2> /dev/null & ejectUSB_PID=$!
8834+ fi
8835+
8836+ if [ " $curWaitDelaySecs " -gt 0 ] && \
8837+ [ " $(( curWaitDelaySecs % 10 )) " -eq 0 ]
8838+ then _MsgToSysLog_ " $logMsg Wait Timeout [$curWaitDelaySecs secs]..."
8839+ fi
8840+
8841+ sleep " $theWaitDelaySecs "
8842+ curWaitDelaySecs=" $(( curWaitDelaySecs + theWaitDelaySecs)) "
8843+ done
8844+
8845+ if " $ejectUSB_OK " || \
8846+ [ " $curWaitDelaySecs " -lt " $maxWaitDelaySecs " ]
8847+ then
8848+ _MsgToSysLog_ " $logMsg succeeded [$curWaitDelaySecs secs]"
8849+ else
8850+ _MsgToSysLog_ " $logMsg Wait Timeout [$maxWaitDelaySecs secs] expired."
8851+ _MsgToSysLog_ " Unable to unmount USB drive. Device is likely busy."
8852+ _SendEMailNotification_ FAILED_USB_DRIVE_UNMOUNT
8853+ fi
8854+ _MsgToSysLog_ " END of ${logMsg} ."
8855+
8856+ " $ejectUSB_OK " && return 0 || return 1
8857+ }
8858+
87758859# #----------------------------------------##
8776- # # Modified by Martinski W. [2025-Nov-05 ] ##
8860+ # # Modified by Martinski W. [2025-Nov-09 ] ##
87778861# #----------------------------------------##
87788862_RunFirmwareUpdateNow_ ()
87798863{
@@ -9339,7 +9423,13 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
93399423
93409424 # *WARNING*: NO MORE logging at this point & beyond #
93419425 sync ; sleep 2 ; echo 3 > /proc/sys/vm/drop_caches ; sleep 3
9342- /sbin/ejusb -1 0 -u 1 2> /dev/null
9426+
9427+ # #-------------------------------------##
9428+ # # Added by Martinski W. [2025-Nov-09] ##
9429+ # #-------------------------------------##
9430+ # Unmount the USB drives. If "busy" let's wait until "idle" state. #
9431+ # ------------------------------------------------------------------#
9432+ _Unmount_Eject_USB_Drives_
93439433
93449434 # ----------------------------------------------------------------------------------#
93459435 # **IMPORTANT NOTE**:
@@ -9450,7 +9540,7 @@ _PostUpdateEmailNotification_()
94509540 then break ; fi
94519541
94529542 if [ " $curWaitDelaySecs " -gt 0 ] && \
9453- [ " $(( curWaitDelaySecs % 60 )) " -eq 0 ]
9543+ [ " $(( curWaitDelaySecs % 30 )) " -eq 0 ]
94549544 then Say " $logMsg [$curWaitDelaySecs secs.]..." ; fi
94559545
94569546 sleep $theWaitDelaySecs
@@ -9462,7 +9552,7 @@ _PostUpdateEmailNotification_()
94629552 else Say " $logMsg [$maxWaitDelaySecs sec.] expired."
94639553 fi
94649554
9465- Say " END of $logMsg [$$ curWaitDelaySecs sec.]"
9555+ Say " END of $logMsg [$curWaitDelaySecs sec.]"
94669556 sleep 20 # # Let's wait a bit & proceed ##
94679557 _SendEMailNotification_ POST_REBOOT_FW_UPDATE_STATUS
94689558}
@@ -9494,7 +9584,7 @@ _PostRebootRunNow_()
94949584 then break ; fi
94959585
94969586 if [ " $curWaitDelaySecs " -gt 0 ] && \
9497- [ " $(( curWaitDelaySecs % 60 )) " -eq 0 ]
9587+ [ " $(( curWaitDelaySecs % 30 )) " -eq 0 ]
94989588 then Say " $logMsg [$curWaitDelaySecs secs.]..." ; fi
94999589
95009590 sleep $theWaitDelaySecs
@@ -9506,7 +9596,7 @@ _PostRebootRunNow_()
95069596 else Say " $logMsg [$maxWaitDelaySecs sec.] expired."
95079597 fi
95089598
9509- Say " END of $logMsg [$$ curWaitDelaySecs sec.]"
9599+ Say " END of $logMsg [$curWaitDelaySecs sec.]"
95109600 sleep 30 # # Let's wait a bit & proceed ##
95119601 if _AcquireLock_ cliFileLock
95129602 then
@@ -11243,7 +11333,7 @@ _Gnuton_Check_Webs_Update_Script_()
1124311333
1124411334 # (Re)bind/mount only if remote is newer version OR files differ #
1124511335 if [ " $remoteVersTag " -gt " $localVersTag " ] || \
11246- ! diff " $FW_UpdateCheckScript " " $dwnldGnutonWebsUpdateFilePath " > /dev/null 2>&1
11336+ ! diff -q " $FW_UpdateCheckScript " " $dwnldGnutonWebsUpdateFilePath " > /dev/null 2>&1
1124711337 then
1124811338 umount " $FW_UpdateCheckScript " 2> /dev/null
1124911339 mv -f " $dwnldGnutonWebsUpdateFilePath " " $fixedGnutonWebsUpdateFilePath "
0 commit comments