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"
read -r dev
while [ -n "$dev" ]
do
while [ -n "$dev" ]; do
if [ "$dev" = "l" ]; then
lsblk
elif [ "$dev" = "q" ]; then
exit
else
if grep -qs "$dev " /proc/mounts; then
sync
if pumount "$dev"
then
echo "$dev" unmounted.
if udisksctl power-off -b /dev/"$dev"
then
echo "$dev" ejected.
sync "$(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")"
if pumount "/dev/$dev"; then
echo "/dev/$dev unmounted."
if udisksctl power-off -b "/dev/$dev" --no-user-interaction; then
echo "/dev/$dev ejected."
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
pmount "$dev"
echo "$dev" mounted to "$(lsblk -n /dev/"$dev" | rev | cut -d' ' -f1 | rev)".
echo "/dev/$dev does not exist or is not a block device."
fi
fi