diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2023-05-15 00:17:12 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2023-05-15 00:17:12 +0200 |
commit | d8a759b0bb0e510e1ea037a3f10e42a61fc4e618 (patch) | |
tree | 97f11adb53c42d2709a717ba7d5292f187e75952 /.local/bin/umounter | |
parent | 12d18871a0beb202589a8faea1856664d9beba69 (diff) |
Fix ext drive mounters
Diffstat (limited to '.local/bin/umounter')
-rwxr-xr-x | .local/bin/umounter | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/.local/bin/umounter b/.local/bin/umounter new file mode 100755 index 0000000..126f1b8 --- /dev/null +++ b/.local/bin/umounter @@ -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" + +doas 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##*/}" +doas cryptsetup close "$cryptid" +notify-send "🔒Device dencryption closed." "Drive is now securely locked again." |