mirror of
https://github.com/armbian/bash-util.git
synced 2026-01-06 10:37:49 -08:00
check.sh: clean up
This commit is contained in:
20
src/check.sh
20
src/check.sh
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user