summaryrefslogtreecommitdiff
path: root/.local/bin/dmenu
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2022-06-16 21:11:00 -0400
committerSam Chudnick <sam@chudnick.com>2022-06-16 21:11:00 -0400
commit38ccd88ced5790dc941157fed56c5ac4756acd7f (patch)
tree730f10aa756359347008753c84a375f93c312da2 /.local/bin/dmenu
parent6b0dadd3b736655836a40fe458268c615020f5bb (diff)
Added support for LUKS devices
Added support for LUKS devices to mount and unmount scripts. Scripts will now detect if a device or partition is LUKS encrypted and automatically map and mount the device.
Diffstat (limited to '.local/bin/dmenu')
-rwxr-xr-x.local/bin/dmenu/mount-device24
-rwxr-xr-x.local/bin/dmenu/unmount-device17
2 files changed, 31 insertions, 10 deletions
diff --git a/.local/bin/dmenu/mount-device b/.local/bin/dmenu/mount-device
index e325a65..c2decd5 100755
--- a/.local/bin/dmenu/mount-device
+++ b/.local/bin/dmenu/mount-device
@@ -2,16 +2,22 @@
2# Script for mounting block devices 2# Script for mounting block devices
3 3
4# Set askpass program for authentication 4# Set askpass program for authentication
5export SUDO_ASKPASS=/usr/bin/ssh-askpass 5#export SUDO_ASKPASS=/usr/bin/ssh-askpass
6 6
7# Check for and get device to mount from user 7# Check for and get device to mount from user
8devs="$(lsblk -lp | grep "part $" | awk '{print $1,"-",$4}')" 8devs="$(lsblk -lpo NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep "part\s*$\|crypto_LUKS" | awk '{print $1,"-",$3}')"
9[ "$devs" = "" ] && exit 0 9[ "$devs" = "" ] && exit 0
10dev="$(echo $devs | dmenu -i -p "Select device" | cut -d ' ' -f 1)" 10dev="$(echo "$devs" | dmenu -i -p "Select device" | cut -d ' ' -f 1)"
11[ "$dev" = "" ] && exit 0 11[ "$dev" = "" ] && exit 0
12 12
13# Open and map drive if it is encrypted
14crypt=0
15[ "$(lsblk -no FSTYPE $dev)" = "crypto_LUKS" ] && crypt=1 && \
16 mapname="$(echo -n "" | dmenu -i -p "Enter device mapper name")" && \
17 sudo cryptsetup open $dev $mapname
18
13# Attempt to mount without mountpoint for devices in /etc/fstab 19# Attempt to mount without mountpoint for devices in /etc/fstab
14sudo -A mount "$dev" 2>/dev/null && exit 0 20sudo mount "$dev" 2>/dev/null && exit 0
15 21
16# Get mountpoint from user 22# Get mountpoint from user
17mntpnt="$(find /mnt -maxdepth 3 -type d 2>/dev/null | dmenu -i -p "Select mountpoint")" 23mntpnt="$(find /mnt -maxdepth 3 -type d 2>/dev/null | dmenu -i -p "Select mountpoint")"
@@ -23,5 +29,11 @@ mntpnt="$(find /mnt -maxdepth 3 -type d 2>/dev/null | dmenu -i -p "Select mountp
23 dmenu -i -p "$mntpnt does not exist, would you like to create it?")" && \ 29 dmenu -i -p "$mntpnt does not exist, would you like to create it?")" && \
24 ([ "$create" = "Yes" ] && sudo -A mkdir -p $mntpnt || exit 0) 30 ([ "$create" = "Yes" ] && sudo -A mkdir -p $mntpnt || exit 0)
25 31
26sudo -A mount $dev $mntpnt && pgrep -x dunst && notify-send "$dev mounted to $mntpnt" 32# Mount the device
27 33if [ $crypt -eq 1 ]; then
34 sudo -A mount /dev/mapper/$mapname $mntpnt && pgrep -x dunst && \
35 notify-send "$dev mounted to $mntpnt"
36else
37 sudo -A mount $dev $mntpnt && pgrep -x dunst && \
38 notify-send "$dev mounted to $mntpnt"
39fi
diff --git a/.local/bin/dmenu/unmount-device b/.local/bin/dmenu/unmount-device
index 75cb10f..239663d 100755
--- a/.local/bin/dmenu/unmount-device
+++ b/.local/bin/dmenu/unmount-device
@@ -2,18 +2,27 @@
2# Script for unmounting filesystems 2# Script for unmounting filesystems
3 3
4# Set askpass program for authentication 4# Set askpass program for authentication
5export SUDO_ASKPASS=/usr/bin/ssh-askpass 5#export SUDO_ASKPASS=/usr/bin/ssh-askpass
6 6
7# Get list of unmountable filesystems excluding critical ones (/, /home, /boot, etc...) 7# Get list of unmountable filesystems excluding critical ones (/, /home, /boot, etc...)
8exclude="\(/\|/boot\|/boot/efi\|/var\|/tmp\|/home\)$" 8exclude="\(/\|/boot\|/boot/efi\|/var\|/tmp\|/home\)$"
9parts="$(lsblk -lp | grep "part /" | grep -v "$exclude" | awk '{print $7,"-",$4}')" 9parts="$(lsblk -lp | grep "\(part\|crypt\)\s*/" | grep -v "$exclude" | awk '{print $7,"-",$4}')"
10[ "$parts" = "" ] && exit 0 10[ "$parts" = "" ] && exit 0
11 11
12# Get filesystem to unmount from user 12# Get filesystem to unmount from user
13crypt=0
13select="$(echo "$parts" | dmenu -i -p "Select filesystem to unmount" | cut -d ' ' -f 1)" 14select="$(echo "$parts" | dmenu -i -p "Select filesystem to unmount" | cut -d ' ' -f 1)"
14[ "$select" = "" ] && exit 0 15[ "$select" = "" ] && exit 0
15dev="$(lsblk -lp | grep "$select" | awk '{print $1}')" 16dev="$(lsblk -lp | grep "$select" | awk '{print $1}')"
17[ "$(lsblk -no TYPE $dev)" = "crypt" ] && crypt=1
16 18
17# Unmount the filesystem 19# Unmount the filesystem
18sudo -A umount $select && pgrep -x dunst && notify-send "Unmounted $select ($dev)" \ 20umount=0
19 || notify-send "Error: unable to unmount $select" "Are you in it?" 21sudo umount $select && pgrep -x dunst && \
22 notify-send "Unmounted $select ($dev)" && umount=1 \
23 || notify-send "Error: unable to unmount $select" "Are you in it?"
24
25[ $crypt -eq 1 -a $umount -eq 1 ] && sudo cryptsetup close $dev && pgrep -x dunst && \
26 notify-send "Unmapped $dev" && exit 14
27
28