aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/unmounter
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/unmounter')
-rwxr-xr-x.local/bin/unmounter25
1 files changed, 25 insertions, 0 deletions
diff --git a/.local/bin/unmounter b/.local/bin/unmounter
new file mode 100755
index 0000000..fe1d01a
--- /dev/null
+++ b/.local/bin/unmounter
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+set -e
+
+mounteddroids="$(rg 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" | mew -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" | rg "/${chosen#*/}$")"
+cryptid="${cryptid%% *}"
+test -b /dev/mapper/"${cryptid##*/}"
+doas_askpass cryptsetup close "$cryptid"
+notify-send "🔒Device decryption closed." "Drive is now securely locked again."