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"
MNT="/mnt"
# will not be split when used
SUDO="doas"
[ -n "$SUDO" ] || SUDO="doas"
# preliminary checks
[ -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 \
|| 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
! [ -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 \
|| true
[ -d "$MNT/$1" ] \
|| mkdir "$MNT/$1"
! [ "$(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 \
|| true
! [ -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 \
|| true