@@ -109,8 +109,17 @@ else
109
109
# If ${par} starts with /dev/, then delete /dev/
110
110
par=$( echo " ${par} " | sed ' s:^/dev/::' )
111
111
112
- # If ${par} has a device name like "usb1p1", then get the disk name from it, e.g. "usb1"
113
- disk=$( echo " ${par} " | sed ' s:p.*$::' )
112
+ # If ${par} has a device name like "usb1p1", then get the partition name from it, e.g. "usb1"
113
+ part=$( echo " ${par} " | sed ' s:p.*$::' )
114
+
115
+ # Check if variable $part is named usb[x] (e.g. usb1) ? assign $part to $disk : remove trailing number from $part (e.g. sda1 --> sda)
116
+ if [[ " ${part} " =~ ^[uU][sS][bB] ]]; then
117
+ # keep the identified partition as disk, because usb1 is the disk itself
118
+ disk=" ${part} "
119
+ else
120
+ # remove the number from the partition to identify the disk itself, e.g. partition is sda1 --> disk is sda
121
+ disk=$( echo " ${part} " | sed ' s/[0-9]\+$//' )
122
+ fi
114
123
115
124
# Set device path to determine the mountpoint
116
125
device=" /dev/${par} "
@@ -161,7 +170,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
161
170
echo " ${txt_line_separator} " >> " ${log} "
162
171
echo " $( timestamp) - AutoPilot Version ${app_version} ${txt_autopilot_starts} " >> " ${log} "
163
172
echo " ${txt_line_separator} " >> " ${log} "
164
- echo " ${txt_ext_detected_step_1} ${disk } ${txt_ext_detected_step_2} " >> " ${log} "
173
+ echo " ${txt_ext_detected_step_1} ${part } ${txt_ext_detected_step_2} " >> " ${log} "
165
174
echo " ${txt_device_detected} : ${device} " >> " ${log} "
166
175
echo " ${txt_mountpoint} : ${mountpoint} " >> " ${log} "
167
176
echo " ${txt_volume_id} : ${uuid} " >> " ${log} "
@@ -191,9 +200,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
191
200
if [[ " ${disconnect} " == " auto" ]] || [[ " ${disconnect} " == " manual" ]]; then
192
201
193
202
# Remove disk from the GUI list
194
- cp /tmp/usbtab /tmp/usbtab.old
195
- grep -v " ${disk} " /tmp/usbtab.old > /tmp/usbtab
196
- rm -f /tmp/usbtab.old
203
+ sed -i " /^" " ${disk} " " /d" /tmp/usbtab
197
204
198
205
# Write RAM buffer back to disk
199
206
sync
@@ -210,7 +217,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
210
217
sleep 10
211
218
212
219
# Check if unmount was successful
213
- unmount_check=$( /usr/syno/bin/synousbdisk -enum | grep " $disk " )
220
+ unmount_check=$( /usr/syno/bin/synousbdisk -enum | grep " ${ disk} " )
214
221
215
222
# If disk has been ejected
216
223
if [ -z " ${unmount_check} " ]; then
0 commit comments