Skip to content

Commit

Permalink
Merge pull request #9 from luddinho/feature/issue-8/improvement-of-un…
Browse files Browse the repository at this point in the history
…mount-and-removing-disk-from-gui

refactor: Unmount and eject disk after script execution
  • Loading branch information
toafez authored Jan 6, 2024
2 parents 1d8818a + 8fb2ab8 commit 9bb7d26
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ui/execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ else
# If ${par} starts with /dev/, then delete /dev/
par=$(echo "${par}" | sed 's:^/dev/::')

# If ${par} has a device name like "usb1p1", then get the disk name from it, e.g. "usb1"
disk=$(echo "${par}" | sed 's:p.*$::')
# If ${par} has a device name like "usb1p1", then get the partition name from it, e.g. "usb1"
part=$(echo "${par}" | sed 's:p.*$::')

# Check if variable $part is named usb[x] (e.g. usb1) ? assign $part to $disk : remove trailing number from $part (e.g. sda1 --> sda)
if [[ "${part}" =~ ^[uU][sS][bB] ]]; then
# keep the identified partition as disk, because usb1 is the disk itself
disk="${part}"
else
# remove the number from the partition to identify the disk itself, e.g. partition is sda1 --> disk is sda
disk=$(echo "${part}" | sed 's/[0-9]\+$//')
fi

# Set device path to determine the mountpoint
device="/dev/${par}"
Expand Down Expand Up @@ -161,7 +170,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
echo "${txt_line_separator}" >> "${log}"
echo "$(timestamp) - AutoPilot Version ${app_version} ${txt_autopilot_starts}" >> "${log}"
echo "${txt_line_separator}" >> "${log}"
echo "${txt_ext_detected_step_1} ${disk} ${txt_ext_detected_step_2}" >> "${log}"
echo "${txt_ext_detected_step_1} ${part} ${txt_ext_detected_step_2}" >> "${log}"
echo "${txt_device_detected}: ${device}" >> "${log}"
echo "${txt_mountpoint}: ${mountpoint}" >> "${log}"
echo "${txt_volume_id}: ${uuid}" >> "${log}"
Expand Down Expand Up @@ -191,9 +200,7 @@ if [[ "${connect}" == "true" ]] && [ -n "${mountpoint}" ]; then
if [[ "${disconnect}" == "auto" ]] || [[ "${disconnect}" == "manual" ]]; then

# Remove disk from the GUI list
cp /tmp/usbtab /tmp/usbtab.old
grep -v "${disk}" /tmp/usbtab.old > /tmp/usbtab
rm -f /tmp/usbtab.old
sed -i "/^""${disk}""/d" /tmp/usbtab

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

# Check if unmount was successful
unmount_check=$(/usr/syno/bin/synousbdisk -enum | grep "$disk")
unmount_check=$(/usr/syno/bin/synousbdisk -enum | grep "${disk}")

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

0 comments on commit 9bb7d26

Please sign in to comment.