dotfiles.2022/_home/dot_sz.shrc.d/01_util.functions

41 lines
956 B
Plaintext
Raw Normal View History

2022-09-29 22:29:13 +00:00
warn() {
2022-10-06 02:29:21 +00:00
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
2022-09-29 22:29:13 +00:00
}
2022-07-15 00:00:09 +00:00
error() {
2022-10-06 02:29:21 +00:00
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
2022-07-15 00:00:09 +00:00
}
require_root() {
if [[ $EUID -ne 0 ]]; then
2022-10-06 02:29:21 +00:00
error "This script should only be run using sudo or as the root user"
exit 1
2022-07-15 00:00:09 +00:00
fi
}
2022-09-29 22:29:13 +00:00
recommend_root() {
if [[ $EUID -ne 0 ]]; then
warn "This script works better using sudo or as the root user"
return 3
fi
}
2022-07-15 00:00:09 +00:00
function setacl() {
if [[ $# -lt 4 ]]; then
2022-10-06 02:29:21 +00:00
error "setacl missing arguments, called with '$1' ${@:2}"
printf "%s\n" "Usage:" "\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]"
return 1
2022-07-15 00:00:09 +00:00
fi
local Options=${1}
local Ownership=${2}
local Permissions=${3}
[[ -n "${SZ_DEBUG}" ]] \
&& echo "chown $Options $Ownership \"${@:4}\""
chown $Options $Ownership "${@:4}"
[[ -n "${SZ_DEBUG}" ]] \
&& echo "chmod $Options $Permissions \"${@:4}\""
chmod $Options $Permissions "${@:4}"
}