diff --git a/.vim/templates/sh b/.vim/templates/sh index ff9a762..861e200 100644 --- a/.vim/templates/sh +++ b/.vim/templates/sh @@ -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 +} +