Improvements
This commit is contained in:
parent
726463c3ab
commit
589b6fa2f4
9 changed files with 55 additions and 56 deletions
|
@ -1,28 +1,15 @@
|
|||
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 '%s %s\n' $(ANSI_Yellow 'WARNING:') "$(echo "$@")" )
|
||||
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
|
||||
}
|
||||
|
||||
# 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() {
|
||||
printf "(>&2 \
|
||||
printf '%%s %%b' '$(ANSI_Red 'ERROR:')' '$(printf "%b " "${@:2}")') \
|
||||
&& echo '' && return ${1} 2>/dev/null || exit ${1}"
|
||||
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
|
||||
}
|
||||
|
||||
require_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
eval $(error 1 "This script should only be run using sudo or as the root user")
|
||||
error "This script should only be run using sudo or as the root user"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -35,14 +22,9 @@ recommend_root() {
|
|||
|
||||
function setacl() {
|
||||
if [[ $# -lt 4 ]]; then
|
||||
eval $(error 1 \
|
||||
"setacl missing arguments, called with '$1' ${@:2}" \
|
||||
$(printf "%s\n" \
|
||||
"Usage:" \
|
||||
"\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]" \
|
||||
)
|
||||
)
|
||||
return 1
|
||||
error "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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue