~jbauer/dotfiles

ref: daebf07b03e1fe9fe376eb75d5dd061c8fa047d3 dotfiles/.local/bin/mntdev -rwxr-xr-x 1.7 KiB
daebf07bJake Bauer Update README 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

# Copyright (C) 2021  Jake Bauer
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Present the user with a dmenu prompt of devices to mount and mount the
# selected device to /mnt/<dev>.
# This script must be run with root privs.

if [ "$(id -u)" -ne 0 ]
	then echo "You must run this script with root privileges."
	exit 1
fi

disks=$(sysctl hw.disknames | cut -d= -f2 | tr ',' ' ')
for entry in $disks; do
	disk="$(echo "$entry" | cut -d: -f1)"
	devices="$devices
$(disklabel -p G "$disk" | tail -n +19 | awk -v d=$disk '$9=="" {printf "%s%s %s (%s)\n", d, $1, $4, $2}')"
done

devices=$(echo "$devices" | sed '/^$/d')
choice="$(echo "$devices" | dmenu -i -l 20 -p "Mount:")" || exit 1
choice="$(echo "$choice" | awk '{print $1}' | tr -d ':')"

mkdir -p /mnt/"$choice"
mount /dev/"$choice" /mnt/"$choice" && notify-send "Mounted Drive" \
	"$choice mounted to\n/mnt/$choice" && mounted=1

# Clean up if unsuccessful mount
if [ -z "$mounted" ]; then
	rmdir /mnt/"$choice"
	notify-send -u critical "Failed to Mount" "$choice not mounted."
	exit 1
fi

exit 0