Improvements

This commit is contained in:
Gal Szkolnik 2022-10-05 21:49:54 -04:00
parent d8e37c1fdf
commit d6a9f59544
6 changed files with 48 additions and 12 deletions

View file

@ -1,15 +1,28 @@
ANSI_Print() { printf "\E[${ANSI_Code}m%s\E[0m" "$@"; }
ANSI_Red() { ANSI_Code=31 ANSI_Print "$@"; }
ANSI_Green() { ANSI_Code=32 ANSI_Print "$@"; }
ANSI_Yellow() { ANSI_Code=33 ANSI_Print "$@"; }
ANSI_Blue() { ANSI_Code=34 ANSI_Print "$@"; }
ANSI_Indiego() { ANSI_Code=35 ANSI_Print "$@"; }
ANSI_Cyan() { ANSI_Code=36 ANSI_Print "$@"; }
warn() {
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
(>&2 printf '%s %s\n' $(ANSI_Yellow 'WARNING:') "$(echo "$@")" )
}
# The way to call this is:
# eval $(error 1 "message") || exit $?
# where 1 is the return/exit code and "message" is the message to be
# displayed
error() {
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
printf "(>&2 \
printf '%%s %%b' '$(ANSI_Red 'ERROR:')' '$(printf "%b " "${@:2}")') \
&& echo '' && return ${1} 2>/dev/null || exit ${1}"
}
require_root() {
if [[ $EUID -ne 0 ]]; then
error "This script should only be run using sudo or as the root user"
exit 1
eval $(error 1 "This script should only be run using sudo or as the root user")
fi
}
@ -22,9 +35,14 @@ recommend_root() {
function setacl() {
if [[ $# -lt 4 ]]; then
error "setacl missing arguments, called with '$1' ${@:2}"
printf "%s\n" "Usage:" "\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]"
return 1
eval $(error 1 \
"setacl missing arguments, called with '$1' ${@:2}" \
$(printf "%s\n" \
"Usage:" \
"\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]" \
)
)
return 1
fi
local Options=${1}
local Ownership=${2}