swaydots

my dotfiles
git clone https://git.awy.one/swaydots.git
Log | Files | Refs | README | LICENSE

unmounter (882B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 mounteddroids="$(rg simple-mtpfs /etc/mtab | awk '{print "📱" $2}')"
      6 lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")"
      7 mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "💾%s (%s)\n",$4,$3}')"
      8 
      9 allunmountable="$(echo "$mounteddroids
     10 $mounteddrives" | sed "/^$/d;s/ *$//")"
     11 test -n "$allunmountable"
     12 
     13 chosen="$(echo "$allunmountable" | mew -i -p "Unmount which drive?")"
     14 chosen="${chosen%% *}"
     15 test -n "$chosen"
     16 
     17 doas umount -l "/${chosen#*/}"
     18 notify-send "Device unmounted." "$chosen has been unmounted."
     19 
     20 # Close the chosen drive if decrypted.
     21 cryptid="$(echo "$lsblkoutput" | rg "/${chosen#*/}$")"
     22 cryptid="${cryptid%% *}"
     23 test -b /dev/mapper/"${cryptid##*/}"
     24 doas_askpass cryptsetup close "$cryptid"
     25 notify-send "🔒Device decryption closed." "Drive is now securely locked again."