diff options
Diffstat (limited to '.local/bin/unmount-device')
-rwxr-xr-x | .local/bin/unmount-device | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/.local/bin/unmount-device b/.local/bin/unmount-device new file mode 100755 index 0000000..239663d --- /dev/null +++ b/.local/bin/unmount-device | |||
@@ -0,0 +1,28 @@ | |||
1 | #!/bin/sh | ||
2 | # Script for unmounting filesystems | ||
3 | |||
4 | # Set askpass program for authentication | ||
5 | #export SUDO_ASKPASS=/usr/bin/ssh-askpass | ||
6 | |||
7 | # Get list of unmountable filesystems excluding critical ones (/, /home, /boot, etc...) | ||
8 | exclude="\(/\|/boot\|/boot/efi\|/var\|/tmp\|/home\)$" | ||
9 | parts="$(lsblk -lp | grep "\(part\|crypt\)\s*/" | grep -v "$exclude" | awk '{print $7,"-",$4}')" | ||
10 | [ "$parts" = "" ] && exit 0 | ||
11 | |||
12 | # Get filesystem to unmount from user | ||
13 | crypt=0 | ||
14 | select="$(echo "$parts" | dmenu -i -p "Select filesystem to unmount" | cut -d ' ' -f 1)" | ||
15 | [ "$select" = "" ] && exit 0 | ||
16 | dev="$(lsblk -lp | grep "$select" | awk '{print $1}')" | ||
17 | [ "$(lsblk -no TYPE $dev)" = "crypt" ] && crypt=1 | ||
18 | |||
19 | # Unmount the filesystem | ||
20 | umount=0 | ||
21 | sudo 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 | |||