Skip to content

Instantly share code, notes, and snippets.

@santosh-gouda
Forked from idleuncle/main_template.sh
Created October 27, 2025 07:49
Show Gist options
  • Save santosh-gouda/3c8ee141443ed30955d3fe37d2c6b7db to your computer and use it in GitHub Desktop.
Save santosh-gouda/3c8ee141443ed30955d3fe37d2c6b7db to your computer and use it in GitHub Desktop.
[Bash main script] #bash
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
# --- Helper scripts begin ---
#/ Usage: saltstackcmd <command> [options...]
#/
#/ Commands:
#/
#/ start Start the salt master.
#/ stop Stop the salt master.
#/
#/ Options:
#/ -h, --help Show this help message and exit.
#/ -v, --verbose Turn on command verbosity.
#/
Usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
#__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
#__base="$(basename "${__file}" .sh)"
#__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
readonly LOG_FILE="/tmp/$(basename "$0").log"
readonly DATE_FORMAT="+%Y-%m-%d %H:%M:%S.%3N"
info() { ( echo $(date "${DATE_FORMAT}") [INFO] $* | tee -a "$LOG_FILE" >&2 ; ) }
warning() { ( echo $(date "${DATE_FORMAT}") [WARNING] $* | tee -a "$LOG_FILE" >&2 ; ) }
error() { ( echo $(date "${DATE_FORMAT}") [ERROR] $* | tee -a "$LOG_FILE" >&2 ; ) }
fatal() { echo $(date "${DATE_FORMAT}") [FATAL] $* | tee -a "$LOG_FILE" >&2 ; kill 0 ; }
cleanup() {
local result=$?
if (( result > 0 )); then
error "Exiting with code ${result}."
else
info "Exiting with code ${result}."
fi
}
trap cleanup EXIT
trap "kill 0" SIGINT
if [ $# -lt 1 ]; then
Usage
exit
fi
function cmd_start(){
echo 'cmd_start()'
}
function main() {
local cmd=$1
shift
if [ "$cmd" == "start" ]; then
cmd_start "$@"
else
Usage
fi
return
}
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment