This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/dmenumount

45 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
2020-05-06 03:20:19 +02:00
######################################################################
2021-02-14 19:07:45 +01:00
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
# @file : dmenumount
# @license : GPLv3
2021-02-14 19:07:45 +01:00
# @created : Wednesday May 20, 2020 18:05:31 CEST
#
2021-02-14 19:07:45 +01:00
# @description : dmenu prompt to mount unmounted drives
######################################################################
2020-05-06 03:20:19 +02:00
getmount() { \
[ -z "$chosen" ] && exit 1
mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")"
[ "$mp" = "" ] && exit 1
if [ ! -d "$mp" ]; then
mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?")
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
fi
}
mountusb() { \
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $1}')"
alreadymounted=$(lsblk -nrpo "name,type,mountpoint" \
| awk '$2=="part"&&$3!~/\/efi|\/home$|SWAP/&&length($3)>1\{printf "-not \\( -path *%s -prune \\) \\ \n",$3}')
getmount "/mnt /media /mount /home -maxdepth 2 -type d $alreadymounted"
2020-05-06 03:20:19 +02:00
partitiontype="$(lsblk -no "fstype" "$chosen")"
case "$partitiontype" in
"vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;;
*) sudo -A mount "$chosen" "$mp"; user="$(whoami)";
2020-09-29 00:38:24 +02:00
sudo -A chown "$user":"$user" "$mp";;
2020-05-06 03:20:19 +02:00
esac
2020-09-06 21:49:21 +02:00
notify-send " USB mounting" "$chosen mounted to $mp."
2020-05-06 03:20:19 +02:00
}
usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | awk '$2=="part"&&$4==""{printf "%s (%s)\n",$1,$3}')"
if [ -z "$usbdrives" ]; then
2020-09-06 21:49:21 +02:00
notify-send -u "critical" -t 3000 " USB ERROR" "No drive to mount."
2020-05-06 03:20:19 +02:00
else
notify-send "USB drive(s) detected."
mountusb
fi