check.sh: clean up

This commit is contained in:
Dimitry Ishenko
2022-12-22 10:38:43 -05:00
parent ed47249e37
commit f073089820

View File

@@ -6,29 +6,27 @@
# @description Check if the command exists in the system.
#
# @example
# check::command_exists "tput"
# check::command_exists "tput" && echo "yes" || echo "no"
#
# @arg $1 string Command name to be searched.
#
# @exitcode 0 If the command exists.
# @exitcode 1 If the command does not exist.
# @exitcode 0 If the command exists.
# @exitcode 1 If the command does not exist.
# @exitcode 2 Function missing arguments.
check::command_exists() {
[[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2
(( $# == 0 )) && { printf "%s: Missing arguments\n" "${FUNCNAME[0]}"; return 2; }
hash "${1}" 2> /dev/null
}
# @description Check if the script is executed with sudo privilege.
# @description Check if the script is running with root privileges.
#
# @example
# check::is_sudo
# check::is_sudo && echo "yes" || echo "no"
#
# @noargs
#
# @exitcode 0 If the script is executed with root privilege.
# @exitcode 1 If the script is not executed with root privilege
# @exitcode 0 If the script is executed with root privilege.
# @exitcode 1 If the script is not executed with root privilege
check::is_sudo() {
if [[ $(id -u) -ne 0 ]]; then
return 1
fi
(( $(id -u) == 0 )) && return 0 || return 1
}