Miscellaneous improvements to nmount plugin (#1547)

* plugins/nmount: keep `while` & `do` on one line for consistency

* plugins/nmount: sync only that device, which user wants to unmount

* plugins/nmount: replace all instances of `$dev` with `/dev/$dev`

* plugins/nmount: add `--no-user-interaction` option to `udisksctl`

Otherwise the user will be asked for authentication each time he wants
to unmount, say, HDD, since `udisksctl` will try to power it off.

* plugins/nmount: try to mount only existing block devices

* plugins/nmount: do not invoke `lsblk` immediately after mounting

Sometimes `lsblk` fails to provide mountpoint in such a short time frame.

* plugins/nmount: simplify pipe

* plugins/nmount: keep `echo` arguments in a single pair of quotes

* plugins/nmount: report mountpoint only if mounting was successful
This commit is contained in:
8B411 2022-12-21 19:44:28 +02:00 committed by GitHub
parent e236bd0b3a
commit a51437ff16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,26 +26,27 @@ printf "\nEnsure you aren't still in the mounted device.\n"
printf "%s" "$prompt" printf "%s" "$prompt"
read -r dev read -r dev
while [ -n "$dev" ] while [ -n "$dev" ]; do
do
if [ "$dev" = "l" ]; then if [ "$dev" = "l" ]; then
lsblk lsblk
elif [ "$dev" = "q" ]; then elif [ "$dev" = "q" ]; then
exit exit
else else
if grep -qs "$dev " /proc/mounts; then if grep -qs "$dev " /proc/mounts; then
sync sync "$(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")"
if pumount "$dev" if pumount "/dev/$dev"; then
then echo "/dev/$dev unmounted."
echo "$dev" unmounted. if udisksctl power-off -b "/dev/$dev" --no-user-interaction; then
if udisksctl power-off -b /dev/"$dev" echo "/dev/$dev ejected."
then
echo "$dev" ejected.
fi fi
fi fi
elif [ -b "/dev/$dev" ]; then
if pmount "/dev/$dev"; then
sleep 1
echo "/dev/$dev mounted to $(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")."
fi
else else
pmount "$dev" echo "/dev/$dev does not exist or is not a block device."
echo "$dev" mounted to "$(lsblk -n /dev/"$dev" | rev | cut -d' ' -f1 | rev)".
fi fi
fi fi