diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-06-11 07:56:17 -0400 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-06-11 07:56:17 -0400 |
commit | 9e82c96713989a7565eadac505b36e3dbe91cd5a (patch) | |
tree | 7c2f998cc9d06f97bfe10ce1ee844121b662f595 /.local/bin/mount-device | |
parent | 3adcf542289a0883924ae9b9be8b898c36702c95 (diff) |
Added, removed, renamed scripts
Diffstat (limited to '.local/bin/mount-device')
-rwxr-xr-x | .local/bin/mount-device | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/.local/bin/mount-device b/.local/bin/mount-device new file mode 100755 index 0000000..6b644df --- /dev/null +++ b/.local/bin/mount-device | |||
@@ -0,0 +1,39 @@ | |||
1 | #!/bin/sh | ||
2 | # Script for mounting block devices | ||
3 | |||
4 | # Set askpass program for authentication | ||
5 | #export SUDO_ASKPASS=/usr/bin/ssh-askpass | ||
6 | |||
7 | # Check for and get device to mount from user | ||
8 | devs="$(lsblk -lpo NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep "part\s*$\|crypto_LUKS" | awk '{print $1,"-",$3}')" | ||
9 | [ "$devs" = "" ] && exit 0 | ||
10 | dev="$(echo "$devs" | dmenu -i -p "Select device" | cut -d ' ' -f 1)" | ||
11 | [ "$dev" = "" ] && exit 1 | ||
12 | |||
13 | # Open and map drive if it is encrypted | ||
14 | crypt=0 | ||
15 | [ "$(lsblk -no FSTYPE $dev)" = "crypto_LUKS" ] && crypt=1 && \ | ||
16 | mapname="$(echo -n "" | dmenu -i -p "Enter device mapper name")" && \ | ||
17 | sudo cryptsetup open $dev $mapname | ||
18 | |||
19 | # Attempt to mount without mountpoint for devices in /etc/fstab | ||
20 | sudo mount "$dev" 2>/dev/null && exit 0 | ||
21 | |||
22 | # Get mountpoint from user | ||
23 | mntpnt="$(find /mnt -maxdepth 3 -type d 2>/dev/null | dmenu -i -p "Select mountpoint")" | ||
24 | [ "$mntpnt" = "" ] && exit 1 | ||
25 | |||
26 | # If selected mountpoint does not exist ask to create it | ||
27 | # If user decides not to create non-existent drive, exit | ||
28 | [ ! -d $mntpnt ] && create="$(echo "No\nYes" | \ | ||
29 | dmenu -i -p "$mntpnt does not exist, would you like to create it?")" && \ | ||
30 | ([ "$create" = "Yes" ] && sudo -A mkdir -p $mntpnt || exit 0) | ||
31 | |||
32 | # Mount the device | ||
33 | if [ $crypt -eq 1 ]; then | ||
34 | sudo -A mount /dev/mapper/$mapname $mntpnt && pgrep -x dunst && \ | ||
35 | notify-send "$dev mounted to $mntpnt" | ||
36 | else | ||
37 | sudo -A mount $dev $mntpnt && pgrep -x dunst && \ | ||
38 | notify-send "$dev mounted to $mntpnt" | ||
39 | fi | ||