sudo
This commit is contained in:
parent
036d4600fe
commit
99bfbaafc9
@ -3,16 +3,18 @@ set -e
|
|||||||
|
|
||||||
DEV="/dev"
|
DEV="/dev"
|
||||||
MNT="/mnt"
|
MNT="/mnt"
|
||||||
|
# will not be split when used
|
||||||
|
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: %b [device in %b/]\n" "$0" "$DEV" >>/dev/stderr \
|
||||||
&& exit 1 \
|
&& exit 1 \
|
||||||
|| true
|
|| true
|
||||||
|
|
||||||
|
# no need to priviledge escalate if we're already root
|
||||||
! [ "$(id -u)" = 0 ] \
|
! [ "$(id -u)" = 0 ] \
|
||||||
&& printf "%b: This script must be run as root.\n" "$0" >>/dev/stderr \
|
|| SUDO=""
|
||||||
&& exit 1 \
|
|
||||||
|| true
|
|
||||||
|
|
||||||
# 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" ] \
|
||||||
@ -21,7 +23,7 @@ MNT="/mnt"
|
|||||||
|| true
|
|| true
|
||||||
[ -d "$MNT/$1" ] \
|
[ -d "$MNT/$1" ] \
|
||||||
|| mkdir "$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 \
|
&& printf "%b: '%b/%b' is a directory, but isn't empty.\n" "$0" "$MNT" "$1" >>/dev/stderr \
|
||||||
&& exit 1 \
|
&& exit 1 \
|
||||||
|| true
|
|| true
|
||||||
@ -31,4 +33,4 @@ MNT="/mnt"
|
|||||||
|| true
|
|| true
|
||||||
|
|
||||||
# ok, we're safe
|
# ok, we're safe
|
||||||
mount "$DEV/$1" "$MNT/$1"
|
"$SUDO" mount "$DEV/$1" "$MNT/$1"
|
||||||
|
Loading…
Reference in New Issue
Block a user