From 9e82c96713989a7565eadac505b36e3dbe91cd5a Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 11 Jun 2023 07:56:17 -0400 Subject: Added, removed, renamed scripts --- .local/bin/unmount-device | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 .local/bin/unmount-device (limited to '.local/bin/unmount-device') diff --git a/.local/bin/unmount-device b/.local/bin/unmount-device new file mode 100755 index 0000000..239663d --- /dev/null +++ b/.local/bin/unmount-device @@ -0,0 +1,28 @@ +#!/bin/sh +# Script for unmounting filesystems + +# Set askpass program for authentication +#export SUDO_ASKPASS=/usr/bin/ssh-askpass + +# Get list of unmountable filesystems excluding critical ones (/, /home, /boot, etc...) +exclude="\(/\|/boot\|/boot/efi\|/var\|/tmp\|/home\)$" +parts="$(lsblk -lp | grep "\(part\|crypt\)\s*/" | grep -v "$exclude" | awk '{print $7,"-",$4}')" +[ "$parts" = "" ] && exit 0 + +# Get filesystem to unmount from user +crypt=0 +select="$(echo "$parts" | dmenu -i -p "Select filesystem to unmount" | cut -d ' ' -f 1)" +[ "$select" = "" ] && exit 0 +dev="$(lsblk -lp | grep "$select" | awk '{print $1}')" +[ "$(lsblk -no TYPE $dev)" = "crypt" ] && crypt=1 + +# Unmount the filesystem +umount=0 +sudo umount $select && pgrep -x dunst && \ + notify-send "Unmounted $select ($dev)" && umount=1 \ + || notify-send "Error: unable to unmount $select" "Are you in it?" + +[ $crypt -eq 1 -a $umount -eq 1 ] && sudo cryptsetup close $dev && pgrep -x dunst && \ + notify-send "Unmapped $dev" && exit 14 + + -- cgit v1.2.3