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-09
7+ # Last Modified: 2025-Nov-10
88# ##################################################################
99set -u
1010
1111# # Set version for each Production Release ##
1212readonly SCRIPT_VERSION=1.5.7
13- readonly SCRIPT_VERSTAG=" 25110922 "
13+ readonly SCRIPT_VERSTAG=" 25111002 "
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] ##
@@ -8777,27 +8777,55 @@ _RunOfflineUpdateNow_()
87778777# #-------------------------------------##
87788778_Unmount_Eject_USB_Drives_ ()
87798779{
8780- local eject_USB_OK=1 usbMountPoint=" "
8781- local curWaitDelaySecs=0
8782- local theWaitDelaySecs=5
8783- local maxWaitDelaySecs=180 # 3 mins enough time?? #
8780+ local maxWaitDelaySecs=240 # 4 mins#
8781+ local theWaitDelaySecs=5 curWaitDelaySecs=0
8782+ local ejectUSB_OK=false ejectUSB_PID=" " usbMountPoint=" "
87848783 local logMsg=" Unmount/Eject USB Drive"
87858784
87868785 _MsgToSysLog_ () { logger -st " ${SCRIPT_NAME} _[$$ ]" -p 4 " $1 " ; }
87878786
87888787 _MsgToSysLog_ " START of ${logMsg} ..."
87898788
8789+ /sbin/ejusb -1 0 -u 1 2> /dev/null & ejectUSB_PID=$!
8790+
87908791 while [ " $curWaitDelaySecs " -lt " $maxWaitDelaySecs " ]
87918792 do
8792- if /sbin/ejusb -1 0 -u 1 2> /dev/null
8793+ # # If unmount succeeded, then exit loop ##
8794+ if [ -n " $ejectUSB_PID " ] && \
8795+ ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8796+ ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
87938797 then
8794- eject_USB_OK=0 ; break
8798+ ejectUSB_OK=true ; break
87958799 fi
8800+
8801+ # # If USB drive is no longer mounted, exit loop ##
87968802 if ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
87978803 then
8798- _MsgToSysLog_ " ${logMsg} . No USB-attached drives were found."
8799- eject_USB_OK=0 ; break
8804+ _MsgToSysLog_ " ${logMsg} : No USB drives are mounted."
8805+ ejectUSB_OK=true ; break
8806+ fi
8807+
8808+ # # If timeout was reached, check again and exit loop ##
8809+ if [ -n " $ejectUSB_PID " ] && \
8810+ [ " $curWaitDelaySecs " -ge " $maxWaitDelaySecs " ]
8811+ then
8812+ if ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8813+ ! usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8814+ then
8815+ ejectUSB_OK=true ; break
8816+ fi
8817+ kill -KILL " $ejectUSB_PID " 2> /dev/null
8818+ wait $ejectUSB_PID ; break
8819+ fi
8820+
8821+ # # If USB drive is still mounted, try again ##
8822+ if [ -n " $ejectUSB_PID " ] && \
8823+ ! kill -EXIT " $ejectUSB_PID " 2> /dev/null && \
8824+ usbMountPoint=" $( _GetDefaultUSBMountPoint_) "
8825+ then
8826+ /sbin/ejusb -1 0 -u 1 2> /dev/null & ejectUSB_PID=$!
88008827 fi
8828+
88018829 if [ " $curWaitDelaySecs " -gt 0 ] && \
88028830 [ " $(( curWaitDelaySecs % 10 )) " -eq 0 ]
88038831 then _MsgToSysLog_ " $logMsg Wait Timeout [$curWaitDelaySecs secs]..."
@@ -8807,18 +8835,17 @@ _Unmount_Eject_USB_Drives_()
88078835 curWaitDelaySecs=" $(( curWaitDelaySecs + theWaitDelaySecs)) "
88088836 done
88098837
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- if [ " $eject_USB_OK " -ne 0 ]
8838+ if " $ejectUSB_OK " || \
8839+ [ " $curWaitDelaySecs " -lt " $maxWaitDelaySecs " ]
88168840 then
8841+ _MsgToSysLog_ " $logMsg succeeded [$curWaitDelaySecs secs]"
8842+ else
8843+ _MsgToSysLog_ " $logMsg Wait Timeout [$maxWaitDelaySecs secs] expired."
88178844 _MsgToSysLog_ " Unable to unmount USB drive. Device is likely busy."
88188845 fi
8819-
88208846 _MsgToSysLog_ " END of ${logMsg} ."
8821- return " $eject_USB_OK "
8847+
8848+ " $ejectUSB_OK " && return 0 || return 1
88228849}
88238850
88248851# #----------------------------------------##
0 commit comments