Commit a671ba3a authored by Robert Labudda's avatar Robert Labudda
Browse files

smount tool

parent 9a0826db
......@@ -27,6 +27,32 @@ ask you for it.
Requirements: bash, gpg, pinentry
smount
------
A wrapper around `udisksctl` for mounting volumes without `sudo`. The script
understands three commands:
* `mount`
* `umount`
* no parameter lists all connected devices (a leading `*`) indicates that it
is mounted
`mount` and `umount` accept either the block device name or the name of the
volume (usually the label). It matches the given name case-insensitive.
$ smount
* data /dev/sdb1
usb-stick /dev/sdc
$ smount umount data
Unmounted /dev/sdb1
$ smount
data /dev/sdb1
usb-stick /dev/sdc3
$ smount mount sdc
Mounted /dev/sdc3 at /run/media/baldrick/usb-stick.
sshmount
--------
......
#!/bin/bash
COMMAND="$1"
DEVICES=$(udisksctl dump | grep PreferredDevice | cut -c 33-)
shopt -qs nocasematch
for i in $DEVICES
do
LABEL=$(udisksctl info -b $i | grep IdLabel | cut -c 33-)
MOUNTPOINT=$(udisksctl info -b $i | grep MountPoints | cut -c 25-)
MOUNTED=" "
if [ -n "$MOUNTPOINT" ]
then
MOUNTED="* "
fi
if [ -n "$LABEL" ]
then
if [[ "$COMMAND" = "umount" && ("$i" =~ "$2" || "$LABEL" =~ "$2") ]]
then
if [ -n "$MOUNTPOINT" ]
then
udisksctl unmount -b $i
exit 0
else
echo "$i is not mounted"
exit -1
fi
elif [[ "$COMMAND" = "mount" && ("$i" =~ "$2" || "$LABEL" =~ "$2") ]]
then
if [ -z "$MOUNTPOINT" ]
then
udisksctl mount -b $i
exit 0
else
echo "$i is already mounted"
exit -1
fi
elif [ -z "$COMMAND" ]
then
echo -e "$MOUNTED$LABEL\t$i"
fi
fi
done
if [ -n "$COMMAND" ]
then
if [[ "$COMMAND" =~ "^(umount|mount)$" ]]
then
echo "Unknown command."
else
echo "'$2' not found"
fi
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment