summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/dmnt
diff options
context:
space:
mode:
authorivan-boikov <ik.boikov.public@protonmail.com>2022-03-05 17:39:56 +0100
committerivan-boikov <ik.boikov.public@protonmail.com>2022-03-05 17:39:56 +0100
commite15bfb5ab86bb0adf1c375312a0bf0b72d65967e (patch)
treeebb4e3c745a0921b119ef4955c965721506392de /scripts/.local/bin/dmnt
parenta01dbe16dd247bfa445fd8bd6bd6f42bb192447d (diff)
dmnt:
handling LUKS-encrypted drives automatic killing of blocking processes dpass: more checks for faulty usage added echo mode fixed type mode set echo mode as default dunst: moved to bottomright automatic width remaps: don't kill x11 with a shortcut
Diffstat (limited to 'scripts/.local/bin/dmnt')
-rwxr-xr-xscripts/.local/bin/dmnt36
1 files changed, 32 insertions, 4 deletions
diff --git a/scripts/.local/bin/dmnt b/scripts/.local/bin/dmnt
index 2df5271..c6bad87 100755
--- a/scripts/.local/bin/dmnt
+++ b/scripts/.local/bin/dmnt
@@ -12,19 +12,34 @@ getmount() { \
mkdiryn=$(printf "No\\nYes" | "$dmenu" -i -p "$mp does not exist. Create it?") || exit 1
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
fi
- }
+}
mountusb() { \
- sudo -A mount "$1" 2>/dev/null && notify-send "USB mounting" "$1 mounted." && exit 0
+ # handle LUKS-encrypted drives
+ #case "$(lsblk -no FSTYPE $1)" in
+ # *crypto_LUKS*)
+ #;;
+ #esac
+ #sudo -A mount "$1" 2>/dev/null && notify-send "USB mounting" "$1 mounted." && exit 0
+ sudo -A mount "$1" 2>/dev/null && notify-send "$1 mounted" "" && exit 0
alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}')
getmount "/mnt /media -maxdepth 1 -type d $alreadymounted"
partitiontype="$(lsblk -no "fstype" "$1")"
case "$partitiontype" in
"vfat") sudo -A mount -t vfat "$1" "$mp" -o rw,umask=0000;;
"exfat") sudo -A mount "$1" "$mp" -o uid="$(id -u)",gid="$(id -g)";;
+ *crypto_LUKS*)
+ name="$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 16)"
+ mkfifo fifo
+ dpass > fifo &
+ sudo cryptsetup open --type luks "$1" "$name" --key-file fifo
+ rm fifo
+ device="/dev/mapper/$name"
+ sudo -A mount "$device" "$mp"
+ ;;
*) sudo -A mount "$1" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";;
esac
- notify-send "USB mounting" "$1 mounted to $mp."
+ notify-send "$1 mounted to $mp." ""
}
mountandroid() { \
@@ -39,8 +54,21 @@ unmountdev() {
result=$(sudo -A umount "$1" 2>&1)
if [ -z "$result" ]; then
notify-send "Unmount device" "$1 unmounted"
+ return
else
- notify-send -u critical -t 4000 "Unmount device" "$result"
+ processes=$(lsof "$1" | tail -n +2 | awk '{print $1 " " $2}' | uniq)
+ pids="$(echo "$processes" | awk '{print $2}')"
+ #notify-send -u critical "Unmount device" "$result\nPreparing list of processes blocking $1..."
+ notify-send -u critical "Unmount $1" "$result\nBlocking processes:\n$processes"
+ action=$(echo "nothing\nterminate\nkill" | $dmenu -p "What to do to processes blocking $1" -l 3)
+ case $action in
+ terminate) echo "$pids" | while IFS='\n' read -r pid ; do kill $pid; done ;;
+ kill) echo "$pids" | while IFS='\n' read -r pid ; do kill -9 $pid; done ;;
+ nothing)
+ notify-send -u critical "Unmount device" "Aborted, $1 is still mounted"
+ return ;;
+ esac
+ unmountdev "$1"
fi
}