From 17e87f2b85d82f58e327ce2c7645f1fff555bc5b Mon Sep 17 00:00:00 2001 From: luddinho <76713238+luddinho@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:09:38 +0100 Subject: [PATCH 1/2] refactor: distinguish between disk e.g. sda and partition e.g. sda1; improvement of command for removing disk drom GUI list --- ui/execute.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ui/execute.sh b/ui/execute.sh index 1ef608b..14aee59 100755 --- a/ui/execute.sh +++ b/ui/execute.sh @@ -109,8 +109,11 @@ 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.*$::') + + # 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]\+$//') # Set device path to determine the mountpoint device="/dev/${par}" @@ -161,7 +164,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}" @@ -191,9 +194,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 @@ -210,7 +211,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 From 8fb2ab8457b95548b3b32e835baa268b7f385737 Mon Sep 17 00:00:00 2001 From: luddinho <76713238+luddinho@users.noreply.github.com> Date: Fri, 5 Jan 2024 13:16:40 +0100 Subject: [PATCH 2/2] refactor: distinguish between disk named usb1 or sda --- ui/execute.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/execute.sh b/ui/execute.sh index 14aee59..4c656b8 100755 --- a/ui/execute.sh +++ b/ui/execute.sh @@ -112,8 +112,14 @@ else # If ${par} has a device name like "usb1p1", then get the partition name from it, e.g. "usb1" part=$(echo "${par}" | sed 's:p.*$::') - # 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]\+$//') + # 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}"