Recently Written · git

dmenu-scripts

Ask for things

git clone https://github.com/equwal/dmenu-scripts

Log | Files | Refs


dunmount (1030 bytes)

1 #!/bin/sh
2 
3 # Unmount USB drives or Android phones. Replaces the older `dmenuumount`. Fewer
4 # prompt and also de-decrypts LUKS drives that are unmounted.
5 
6 set -e
7 
8 mounteddroids="$(grep simple-mtpfs /etc/mtab | awk '{print "📱" $2}')"
9 lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")"
10 mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "💾%s (%s)\n",$4,$3}')"
11 
12 allunmountable="$(echo "$mounteddroids
13 $mounteddrives" | sed "/^$/d;s/ *$//")"
14 test -n "$allunmountable"
15 
16 chosen="$(echo "$allunmountable" | dmenu -i -p "Unmount which drive?")"
17 chosen="${chosen%% *}"
18 test -n "$chosen"
19 
20 sudo -A umount -l "/${chosen#*/}"
21 notify-send "Device unmounted." "$chosen has been unmounted."
22 
23 # Close the chosen drive if decrypted.
24 cryptid="$(echo "$lsblkoutput" | grep "/${chosen#*/}$")"
25 cryptid="${cryptid%% *}"
26 test -b /dev/mapper/"${cryptid##*/}"
27 sudo -A cryptsetup close "$cryptid"
28 notify-send "🔒Device dencryption closed." "Drive is now securely locked again."