Commit 8be4a22b authored by R's avatar R
Browse files

smount: support luks encrypted devices

parent 797a672d
......@@ -49,6 +49,33 @@ filesystem). Matches are performed case-insensitive.
$ smount sdc
Mounted /dev/sdc3 at /run/media/baldrick/usb-stick.
Encrypted devices are listed with a NerdFont lock icon. To either lock or
unlock the device call smount with the command 'lock' or 'unlock' (really
doesn’t matter which one you use).
When unlocking an encrypted device it will be mounted in the same step. If
you umount an unlocked and encrypted device it will not immediately be locked
again.
$ smount
# /dev/sdc1
$ smount unlock sdc1
Unlocking /dev/sdc1.
Passphrase:
Unlocked /dev/sdc1 as /dev/dm-0.
Mounted /dev/dm-0 at /run/media/baldrick/secure-data.
$ smount
* secure-data /dev/mapper/luks-49a1a923-d417-4fdc-8279-6fc584f09e84
$ smount data
Unmounted /dev/dm-0
$ smount
secure-data /dev/mapper/luks-49a1a923-d417-4fdc-8279-6fc584f09e84
# /dev/sdc1
$ smount lock sdc1
Locked /dev/sdc1
$ smount
# /dev/sdc1
sshmount
--------
......
#!/bin/bash
TARGET="$1"
UNLOCKTARGET="$2"
DEVICES=$(udisksctl dump | grep PreferredDevice | cut -c 33-)
shopt -qs nocasematch
......@@ -9,17 +10,52 @@ 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-)
ENCRYPTED=$(udisksctl info -b $i | grep IdType | grep crypto_LUKS)
MOUNTED=" "
if [ -n "$MOUNTPOINT" ]
then
MOUNTED="* "
fi
if [ -n "$ENCRYPTED" ]
then
LOCKPOINT=$(udisksctl info -b $i | grep CleartextDevice | cut -c 33-)
LOCKPOINT=${LOCKPOINT//\'/}
UNLOCKEDDEVICE=$(udisksctl dump | grep -A 5 "$LOCKPOINT:" | grep " Device:" | cut -c 33-)
UNLOCKMOUNTPOINT=$(udisksctl info -b $UNLOCKEDDEVICE 2>/dev/null | grep MountPoints | cut -c 25-)
if [[ -z "$TARGET" && "$LOCKPOINT" = "/" ]]
then
echo -e "\uf023 $i"
elif [[ -z "$TARGET" && "$LOCKPOINT" != "/" && -z "$UNLOCKMOUNTPOINT" ]]
then
echo -e "\uf09c $i"
elif [[ ("$TARGET" = "lock" || "$TARGET" = "unlock") && "$i" =~ "$UNLOCKTARGET" ]]
then
if [[ "$LOCKPOINT" = "/" ]]
then
echo "Unlocking $i."
udisksctl unlock -b "$i" && \
LOCKPOINT=$(udisksctl info -b $i | grep CleartextDevice | cut -c 33-) && \
LOCKPOINT=${LOCKPOINT//\'/} && \
UNLOCKEDDEVICE=$(udisksctl dump | grep -A 5 "$LOCKPOINT:" | grep " Device:" | cut -c 33-) && \
udisksctl mount -b "$UNLOCKEDDEVICE"
exit 0
else
udisksctl lock -b "$i"
exit 0
fi
fi
fi
if [ -n "$LABEL" ]
then
if [ -z "$TARGET" ]
if [[ -z "$TARGET" ]]
then
echo -e "$MOUNTED$LABEL\t$i"
if [ -z "$ENCRYPTED" ]
then
echo -e "$MOUNTED$LABEL\t$i"
fi
elif [[ "$i" =~ "$TARGET" || "$LABEL" =~ "$TARGET" ]]
then
if [ -n "$MOUNTPOINT" ]
......
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