Added root check and updated exit codes

This commit is contained in:
Asif Bacchus 2018-09-19 16:04:59 -06:00
parent 8914c7e64a
commit af70cb2e2f

View File

@ -19,7 +19,7 @@ stamp="[`date +%Y-%m-%d` `date +%H:%M:%S`]"
function scriptHelp { function scriptHelp {
echo "In the future, I will be something helpful!" echo "In the future, I will be something helpful!"
# exit with code 98 -- there is no use logging this # exit with code 98 -- there is no use logging this
exit 98 exit 1
} }
### quit -- exit the script after logging any errors, warnings, etc. and ### quit -- exit the script after logging any errors, warnings, etc. and
@ -82,6 +82,13 @@ while getopts ':l:' PARAMS; do
done done
### Verify script running as root, otherwise exit (un-logged)
if [ $(id -u) -ne 0 ]; then
echo -e "${bold}${red}This script must be run as root. Aborted.${normal}"
exit 2
fi
### Log start of script operations ### Log start of script operations
echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile" echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile"