Added root function to shell script template

This commit is contained in:
chawley@hq.overdrive.com (chawley-vm)
2021-02-05 16:38:28 -05:00
parent c63d385ff9
commit b6f9e0db8b

View File

@@ -16,7 +16,15 @@
set -o nounset # Treat unset variables as an error
# Check for empty argument
# set variables
declare -r TRUE=0
declare -r FALSE=1
##################################################################
# Purpose: Check for empty argument
# Arguments: at least one
# Return: Either error message or exit with an error code 1
##################################################################
if [ -z "${1:-}" ]; then
arg="undefined"
echo "Required Argument Missing"
@@ -25,9 +33,11 @@ else
arg=$1
fi
# Log Echo: send output to screen and specified file
##################################################################
# Purpose: Send output to screen and specified file
# Requires: define to `logfile` variable to send out put to logfile
# Usage: logecho "Log Message"
# define logfile and path to enable logging to file
##################################################################
logfile=
logecho() {
echo "${1}"
@@ -35,3 +45,15 @@ logecho() {
echo "${1}" >> "${logfile}"
fi
}
##################################################################
# Purpose: Return true if script is executed by the root user
# Arguments: none
# Return: True or False
# Usage: is_root && echo "root" || echo "not root"
##################################################################
function is_root()
{
[ $(id -u) -eq 0 ] && return $TRUE || return $FALSE
}