1
0
This commit is contained in:
dtb 2022-05-18 17:50:16 -04:00
parent c889962c6c
commit 7afa559ff4

11
bin/mnt
View File

@ -3,12 +3,11 @@ set -e
DEV="/dev" DEV="/dev"
MNT="/mnt" MNT="/mnt"
# will not be split when used [ -n "$SUDO" ] || SUDO="doas"
SUDO="doas"
# preliminary checks # preliminary checks
[ -n "$2" ] || [ -z "$1" ] \ [ -n "$2" ] || [ -z "$1" ] \
&& printf "Usage: %b [device in %b/]\n" "$0" "$DEV" >>/dev/stderr \ && printf "Usage: %s [device in %s/]\n" "$0" "$DEV" >>/dev/stderr \
&& exit 1 \ && exit 1 \
|| true || true
@ -18,17 +17,17 @@ SUDO="doas"
# exhaustive checks to ensure $DEV/$1 exists and that $MNT/$1 can be safely used as a mountpoint # exhaustive checks to ensure $DEV/$1 exists and that $MNT/$1 can be safely used as a mountpoint
! [ -d "$MNT/$1" ] && [ -a "$MNT/$1" ] \ ! [ -d "$MNT/$1" ] && [ -a "$MNT/$1" ] \
&& printf "%b: '%b/%b' already exists, but isn't a directory.\n" "$0" "$MNT" "$1" >>/dev/stderr \ && printf "%s: '%s/%s' already exists, but isn't a directory.\n" "$0" "$MNT" "$1" >>/dev/stderr \
&& exit 1 \ && exit 1 \
|| true || true
[ -d "$MNT/$1" ] \ [ -d "$MNT/$1" ] \
|| mkdir "$MNT/$1" || mkdir "$MNT/$1"
! [ "$(ls -A "$MNT/$1" | wc -l | xargs echo)" = 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 \ && printf "%s: '%s/%s' is a directory, but isn't empty.\n" "$0" "$MNT" "$1" >>/dev/stderr \
&& exit 1 \ && exit 1 \
|| true || true
! [ -e "/dev/$1" ] \ ! [ -e "/dev/$1" ] \
&& printf "%b: '%b/%b' doesn't exist.\n" "$0" "$DEV" "$1" >>/dev/stderr \ && printf "%s: '%s/%s' doesn't exist.\n" "$0" "$DEV" "$1" >>/dev/stderr \
&& exit 1 \ && exit 1 \
|| true || true