commit a711989f461c93441c36b17d41081ea2bc89f27b
parent 31abf611a9b7c0fa5ea64094cf4165f74163d0d1
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Fri, 21 May 2021 00:09:26 -0400
Fix mount and unmount scripts
Diffstat:
4 files changed, 98 insertions(+), 84 deletions(-)
diff --git a/.local/bin/mntdev b/.local/bin/mntdev
@@ -0,0 +1,49 @@
+#!/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>.
+# Requires `permit nopass <user> cmd <full_path_to_this_script>` in doas.conf.
+# 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
diff --git a/.local/bin/mount_device_openbsd b/.local/bin/mount_device_openbsd
@@ -1,42 +0,0 @@
-#!/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.
-# Requires `permit nopass <user> cmd <full_path_to_this_script>` in doas.conf
-
-disks=$(sysctl hw.disknames | cut -d= -f2 | tr ',' ' ')
-for entry in $disks; do
- disk="$(echo "$entry" | cut -d: -f1)"
- devices=$(disklabel -p G "$disk" | tail -n +19 | \
- awk -v d=$disk '$9=="" {printf "%s%s %s (%s)\n", d, $1, $4, $2}')
-done
-
-choice="$(echo "$devices" | dmenu -i -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 "Failed to Mount" "$choice not mounted. Is it already mounted?"
- exit 1
-fi
-
-exit 0
diff --git a/.local/bin/umntdev b/.local/bin/umntdev
@@ -0,0 +1,49 @@
+#!/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 mounted devices and umount the
+# selected device.
+# Requires `permit nopass <user> cmd <full_path_to_this_script>` in doas.conf
+# 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!~/\/boot|\/home$|\/usr|\/var/ {printf "%s%s (%s)\n", d, $1, $2}')"
+done
+
+devices=$(echo "$devices" | sed '/^$/d')
+choice="$(echo "$devices" | dmenu -i -l 20 -p "Unmount:")" || exit 1
+choice="$(echo "$choice" | awk '{print $1}' | tr -d ':')"
+
+umount /mnt/"$choice" && notify-send "Unounted Drive" \
+ "$choice from /mnt/$choice" && unmounted=1
+
+# Clean up after successful unmount
+if [ "$unmounted" ]; then
+ rmdir /mnt/"$choice"
+ exit 0
+else
+ notify-send -u critical "Failed to Unmount" \
+ "Could not unmount $choice: device is busy or not mounted."
+ exit 1
+fi
diff --git a/.local/bin/unmount_device_openbsd b/.local/bin/unmount_device_openbsd
@@ -1,42 +0,0 @@
-#!/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 mounted devices and umount the
-# selected device.
-# Requires `permit nopass <user> cmd <full_path_to_this_script>` in doas.conf
-
-disks=$(sysctl hw.disknames | cut -d= -f2 | tr ',' ' ')
-for entry in $disks; do
- disk="$(echo "$entry" | cut -d: -f1)"
- devices=$(disklabel -p G "$disk" | tail -n +19 | \
- awk -v d=$disk '$9!~/\/boot|\/home$|\/usr|\/var/ {printf "%s%s (%s)\n", d, $1, $2}')
-done
-
-choice="$(echo "$devices" | dmenu -i -p "Unmount:")" || exit 1
-choice="$(echo "$choice" | awk '{print $1}' | tr -d ':')"
-
-umount /mnt/"$choice" && notify-send "Unounted Drive" \
- "$choice from /mnt/$choice" && unmounted=1
-
-# Clean up after successful unmount
-if [ "$unmounted" ]; then
- rmdir /mnt/"$choice"
- exit 0
-else
- notify-send "Failed to Unmount" \
- "Could not unmount $choice: device not mounted or busy."
- exit 1
-fi