1
0

fix for linux standard heirarchy, fix stderr redir

This commit is contained in:
dtb 2022-06-26 16:29:30 -04:00
parent a81ee1d982
commit b1bdf665b6

14
bin/mnt
View File

@ -2,12 +2,13 @@
set -e set -e
DEV="/dev" DEV="/dev"
MNT="/mnt" MNT="/media"
[ -n "$SUDO" ] || SUDO="doas" [ -n "$SUDO" ] || SUDO="doas"
# preliminary checks # preliminary checks
[ -n "$2" ] || [ -z "$1" ] \ [ -n "$2" ] || [ -z "$1" ] \
&& printf "Usage: %s [device in %s/]\n" "$0" "$DEV" >>/dev/stderr \ && printf "Usage: %s [device in %s/]\n" \
"$0" "$DEV" 1>&2 \
&& exit 1 \ && exit 1 \
|| true || true
@ -17,17 +18,20 @@ MNT="/mnt"
# 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 "%s: '%s/%s' 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" 1>&2 \
&& 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 "%s: '%s/%s' 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" 1>&2 \
&& exit 1 \ && exit 1 \
|| true || true
! [ -e "/dev/$1" ] \ ! [ -e "/dev/$1" ] \
&& printf "%s: '%s/%s' doesn't exist.\n" "$0" "$DEV" "$1" >>/dev/stderr \ && printf "%s: '%s/%s' doesn't exist.\n" \
"$0" "$DEV" "$1" 1>&2 \
&& exit 1 \ && exit 1 \
|| true || true