Skip to content

Commit 8ecda77

Browse files
Improved Code to Unmount USB Drives
- Improved/modified code that tries to unmount the USB-attached drives before flashing the F/W. If any USB drive is "busy" the code waits until it becomes idle, up to a maximum of 150 secs (2.5 minutes).
1 parent 1ff8d7a commit 8ecda77

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

MerlinAU.sh

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
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-09
88
###################################################################
99
set -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="25110922"
1414
readonly SCRIPT_NAME="MerlinAU"
1515
## Set to "master" for Production Releases ##
1616
SCRIPT_BRANCH="dev"
@@ -8772,8 +8772,52 @@ _RunOfflineUpdateNow_()
87728772
fi
87738773
}
87748774

8775+
##-------------------------------------##
8776+
## Added by Martinski W. [2025-Nov-09] ##
8777+
##-------------------------------------##
8778+
_Unmount_Eject_USB_Drives_()
8779+
{
8780+
local eject_USB_OK=1 usbMountPoint=""
8781+
local curWaitDelaySecs=0
8782+
local theWaitDelaySecs=5
8783+
local maxWaitDelaySecs=150 # Enough time?? #
8784+
local logMsg="Unmount/Eject USB Drives"
8785+
8786+
_MsgToSysLog_() { logger -st "${SCRIPT_NAME}_[$$]" -p 4 "$1" ; }
8787+
8788+
_MsgToSysLog_ "START of ${logMsg}..."
8789+
8790+
while [ "$curWaitDelaySecs" -lt "$maxWaitDelaySecs" ]
8791+
do
8792+
if /sbin/ejusb -1 0 -u 1 2>/dev/null
8793+
then
8794+
eject_USB_OK=0 ; break
8795+
fi
8796+
if ! usbMountPoint="$(_GetDefaultUSBMountPoint_)"
8797+
then
8798+
_MsgToSysLog_ "${logMsg}. No USB-attached drives were found."
8799+
eject_USB_OK=0 ; break
8800+
fi
8801+
if [ "$curWaitDelaySecs" -gt 0 ] && \
8802+
[ "$((curWaitDelaySecs % 10))" -eq 0 ]
8803+
then _MsgToSysLog_ "$logMsg Wait Timeout [$curWaitDelaySecs secs]..."
8804+
fi
8805+
8806+
sleep "$theWaitDelaySecs"
8807+
curWaitDelaySecs="$((curWaitDelaySecs + theWaitDelaySecs))"
8808+
done
8809+
8810+
if [ "$curWaitDelaySecs" -lt "$maxWaitDelaySecs" ]
8811+
then _MsgToSysLog_ "$logMsg [$curWaitDelaySecs secs] succeeded."
8812+
else _MsgToSysLog_ "$logMsg Wait Timeout [$maxWaitDelaySecs secs] expired."
8813+
fi
8814+
8815+
_MsgToSysLog_ "END of ${logMsg}."
8816+
return "$eject_USB_OK"
8817+
}
8818+
87758819
##----------------------------------------##
8776-
## Modified by Martinski W. [2025-Nov-05] ##
8820+
## Modified by Martinski W. [2025-Nov-09] ##
87778821
##----------------------------------------##
87788822
_RunFirmwareUpdateNow_()
87798823
{
@@ -9339,7 +9383,13 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
93399383

93409384
# *WARNING*: NO MORE logging at this point & beyond #
93419385
sync ; sleep 2 ; echo 3 > /proc/sys/vm/drop_caches ; sleep 3
9342-
/sbin/ejusb -1 0 -u 1 2>/dev/null
9386+
9387+
##-------------------------------------##
9388+
## Added by Martinski W. [2025-Nov-09] ##
9389+
##-------------------------------------##
9390+
# Unmount the USB drives. If "busy" let's wait until "idle" state. #
9391+
#------------------------------------------------------------------#
9392+
_Unmount_Eject_USB_Drives_
93439393

93449394
#----------------------------------------------------------------------------------#
93459395
# **IMPORTANT NOTE**:
@@ -9450,7 +9500,7 @@ _PostUpdateEmailNotification_()
94509500
then break ; fi
94519501

94529502
if [ "$curWaitDelaySecs" -gt 0 ] && \
9453-
[ "$((curWaitDelaySecs % 60))" -eq 0 ]
9503+
[ "$((curWaitDelaySecs % 30))" -eq 0 ]
94549504
then Say "$logMsg [$curWaitDelaySecs secs.]..." ; fi
94559505

94569506
sleep $theWaitDelaySecs
@@ -9462,7 +9512,7 @@ _PostUpdateEmailNotification_()
94629512
else Say "$logMsg [$maxWaitDelaySecs sec.] expired."
94639513
fi
94649514

9465-
Say "END of $logMsg [$$curWaitDelaySecs sec.]"
9515+
Say "END of $logMsg [$curWaitDelaySecs sec.]"
94669516
sleep 20 ## Let's wait a bit & proceed ##
94679517
_SendEMailNotification_ POST_REBOOT_FW_UPDATE_STATUS
94689518
}
@@ -9494,7 +9544,7 @@ _PostRebootRunNow_()
94949544
then break ; fi
94959545

94969546
if [ "$curWaitDelaySecs" -gt 0 ] && \
9497-
[ "$((curWaitDelaySecs % 60))" -eq 0 ]
9547+
[ "$((curWaitDelaySecs % 30))" -eq 0 ]
94989548
then Say "$logMsg [$curWaitDelaySecs secs.]..." ; fi
94999549

95009550
sleep $theWaitDelaySecs
@@ -9506,7 +9556,7 @@ _PostRebootRunNow_()
95069556
else Say "$logMsg [$maxWaitDelaySecs sec.] expired."
95079557
fi
95089558

9509-
Say "END of $logMsg [$$curWaitDelaySecs sec.]"
9559+
Say "END of $logMsg [$curWaitDelaySecs sec.]"
95109560
sleep 30 ## Let's wait a bit & proceed ##
95119561
if _AcquireLock_ cliFileLock
95129562
then

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MerlinAU - AsusWRT-Merlin Firmware Auto Updater
22

3-
## v1.5.6
4-
## 2025-Nov-07
3+
## v1.5.7
4+
## 2025-Nov-09
55

66
## WebUI:
77
![image](https://github.com/user-attachments/assets/9c1dff99-9c13-491b-a7fa-aff924d5f02e)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.6
1+
1.5.7

0 commit comments

Comments
 (0)