Skip to content

Commit 9bb7d26

Browse files
authored
Merge pull request #9 from luddinho/feature/issue-8/improvement-of-unmount-and-removing-disk-from-gui
refactor: Unmount and eject disk after script execution
2 parents 1d8818a + 8fb2ab8 commit 9bb7d26

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

ui/execute.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,17 @@ else
109109
# If ${par} starts with /dev/, then delete /dev/
110110
par=$(echo "${par}" | sed 's:^/dev/::')
111111

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
114123

115124
# Set device path to determine the mountpoint
116125
device="/dev/${par}"
@@ -161,7 +170,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
161170
echo "${txt_line_separator}" >> "${log}"
162171
echo "$(timestamp) - AutoPilot Version ${app_version} ${txt_autopilot_starts}" >> "${log}"
163172
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}"
165174
echo "${txt_device_detected}: ${device}" >> "${log}"
166175
echo "${txt_mountpoint}: ${mountpoint}" >> "${log}"
167176
echo "${txt_volume_id}: ${uuid}" >> "${log}"
@@ -191,9 +200,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
191200
if [[ "${disconnect}" == "auto" ]] || [[ "${disconnect}" == "manual" ]]; then
192201

193202
# 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
197204

198205
# Write RAM buffer back to disk
199206
sync
@@ -210,7 +217,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
210217
sleep 10
211218

212219
# 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}")
214221

215222
# If disk has been ejected
216223
if [ -z "${unmount_check}" ]; then

0 commit comments

Comments
 (0)