From 99bfbaafc920010782dc9f5d17d0958e5005adcb Mon Sep 17 00:00:00 2001 From: Deven Blake Date: Thu, 19 Aug 2021 08:32:27 -0400 Subject: [PATCH] sudo --- dotfiles-old/bin/mnt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dotfiles-old/bin/mnt b/dotfiles-old/bin/mnt index dfc27f5..2e6359c 100755 --- a/dotfiles-old/bin/mnt +++ b/dotfiles-old/bin/mnt @@ -3,16 +3,18 @@ set -e DEV="/dev" MNT="/mnt" +# will not be split when used +SUDO="doas" # preliminary checks [ -n "$2" ] || [ -z "$1" ] \ && printf "Usage: %b [device in %b/]\n" "$0" "$DEV" >>/dev/stderr \ && exit 1 \ || true + +# no need to priviledge escalate if we're already root ! [ "$(id -u)" = 0 ] \ - && printf "%b: This script must be run as root.\n" "$0" >>/dev/stderr \ - && exit 1 \ - || true + || SUDO="" # exhaustive checks to ensure $DEV/$1 exists and that $MNT/$1 can be safely used as a mountpoint ! [ -d "$MNT/$1" ] && [ -a "$MNT/$1" ] \ @@ -21,7 +23,7 @@ MNT="/mnt" || true [ -d "$MNT/$1" ] \ || mkdir "$MNT/$1" -! [ "$(ls -A "$MNT/$1" | wc -c)" = 0 ] \ +! [ "$(ls -A "$MNT/$1" | wc -l | xargs echo)" = 0 ] \ && printf "%b: '%b/%b' is a directory, but isn't empty.\n" "$0" "$MNT" "$1" >>/dev/stderr \ && exit 1 \ || true @@ -31,4 +33,4 @@ MNT="/mnt" || true # ok, we're safe -mount "$DEV/$1" "$MNT/$1" +"$SUDO" mount "$DEV/$1" "$MNT/$1"