1
0
This commit is contained in:
dtb 2021-08-19 08:32:27 -04:00
parent 036d4600fe
commit 99bfbaafc9

View File

@ -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"