diff options
author | 2025-02-13 14:13:49 +0530 | |
---|---|---|
committer | 2025-02-13 14:13:49 +0530 | |
commit | 8a2e1006b3b272126332aa064f3ad95387129544 (patch) | |
tree | 944c80ac612a65980d94a54ba11b6c7102037ecf /.local/bin/unmounter | |
parent | dcbb16d8b08ff5956abef5e6478b59df2e93ad35 (diff) | |
download | dotfiles-8a2e1006b3b272126332aa064f3ad95387129544.tar.gz dotfiles-8a2e1006b3b272126332aa064f3ad95387129544.tar.bz2 dotfiles-8a2e1006b3b272126332aa064f3ad95387129544.zip |
Diffstat (limited to '.local/bin/unmounter')
-rwxr-xr-x | .local/bin/unmounter | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/.local/bin/unmounter b/.local/bin/unmounter new file mode 100755 index 0000000..7f1dbf5 --- /dev/null +++ b/.local/bin/unmounter @@ -0,0 +1,28 @@ +#!/bin/sh + +# Unmount USB drives or Android phones. Replaces the older `dmenuumount`. Fewer +# prompt and also de-decrypts LUKS drives that are unmounted. + +set -e + +mounteddroids="$(grep simple-mtpfs /etc/mtab | awk '{print "📱" $2}')" +lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")" +mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "💾%s (%s)\n",$4,$3}')" + +allunmountable="$(echo "$mounteddroids +$mounteddrives" | sed "/^$/d;s/ *$//")" +test -n "$allunmountable" + +chosen="$(echo "$allunmountable" | dmenu -i -p "Unmount which drive?")" +chosen="${chosen%% *}" +test -n "$chosen" + +sudo -A umount -l "/${chosen#*/}" +notify-send "Device unmounted." "$chosen has been unmounted." + +# Close the chosen drive if decrypted. +cryptid="$(echo "$lsblkoutput" | grep "/${chosen#*/}$")" +cryptid="${cryptid%% *}" +test -b /dev/mapper/"${cryptid##*/}" +sudo -A cryptsetup close "$cryptid" +notify-send "🔒Device dencryption closed." "Drive is now securely locked again." |