# Author: Theodore Zacharia
# V0.1: 30/07/2021 - Initial Release
#
# This script provides a template to start all other scripts with
# supports arguments being passed
# Uses shell builtin function getopts
#

# *** Globals
TRACE=0
MYARG=""


# *** Functions
_usage()
{
	echo "usage: $0 [-h] [-t] [-a arg] positional_params"
	echo "where"
	cat <<- _EOF_
	  -h        Displays this help message
	  -t        Set trace on
_EOF_
}


# *** Mainline

# process input parameters
while getopts tha: AOPT
do
case $AOPT in
	t) TRACE=1 ;; # set TRACE mode
	a) MYARG=$OPTARG ;;
	h) _usage
	   exit 1 ;;
	*) # echo "-$OPTARG is an invalid option" >&2 # start getopts string with :
	   exit 2 ;;
esac
done

shift $((OPTIND-1))

if [ $TRACE -gt 0 ]
then
	echo "Starting at $(date)"
	echo "TRACE=$TRACE" >&2
	echo "MYARG=$MYARG" >&2
	echo "positional_args=$@" >&2
fi
