summaryrefslogtreecommitdiff
path: root/.local/bin/mount-device
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/mount-device')
-rwxr-xr-x.local/bin/mount-device39
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
8devs="$(lsblk -lpo NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep "part\s*$\|crypto_LUKS" | awk '{print $1,"-",$3}')"
9[ "$devs" = "" ] && exit 0
10dev="$(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
14crypt=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
20sudo mount "$dev" 2>/dev/null && exit 0
21
22# Get mountpoint from user
23mntpnt="$(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
33if [ $crypt -eq 1 ]; then
34 sudo -A mount /dev/mapper/$mapname $mntpnt && pgrep -x dunst && \
35 notify-send "$dev mounted to $mntpnt"
36else
37 sudo -A mount $dev $mntpnt && pgrep -x dunst && \
38 notify-send "$dev mounted to $mntpnt"
39fi