Skip to content

Instantly share code, notes, and snippets.

@TylerDurham
Created December 10, 2025 03:36
Show Gist options
  • Select an option

  • Save TylerDurham/331bab3509c7736a8e5ce1b69e9485d3 to your computer and use it in GitHub Desktop.

Select an option

Save TylerDurham/331bab3509c7736a8e5ce1b69e9485d3 to your computer and use it in GitHub Desktop.
bash install script boilerplate/template.
#!/usr/bin/env bash
# We need to source locally as we are not installed yet...
source ./core/.local/share/tylerd/lib/bash/styles.sh
source ./core/.local/share/tylerd/lib/bash/validation.sh
VERBOSE=
ACTION=install
POSITIONAL_ARGUMENTS=()
show_help() {
cat << EOF
USAGE: $(basename "$0") [OPTIONS] [pkg1] [pkg2] ...
A script to install or remove one or more packages.
OPTIONS:
-h, --help Display this help message and exit
-r, --remove Remove/uninstall instead of installing (default: install)
-v, --verbose Enable verbose output for debugging
EXAMPLES:
$(basename "$0") Install with default settings
$(basename "$0") --verbose Install with verbose output
$(basename "$0") --remove Remove/uninstall components
$(basename "$0") -r -v Remove with verbose output
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
show_help
exit 1
;;
-i | install)
ACTION=install
shift
;;
-r | --remove)
ACTION=remove
shift
;;
-v | --verbose)
VERBOSE=1
shift
;;
-* | --*)
error "Invalid option: '$1'!"
show_help
exit 1
shift
;;
*)
POSITIONAL_ARGUMENTS+=("$1")
shift
;;
esac
done
# Restore positional parameters
set -- "${POSITIONAL_ARGUMENTS[@]}"
do_install() {
echo "INSTALL"
}
do_remove() {
echo "REMOVE"
}
completed() {
if [ -n "$VERBOSE" ]; then
debug "VERBOSE: "$VERBOSE""
debug "ACTION: $ACTION"
debug "POSITIONAL_ARGUMENTS: ${#POSITIONAL_ARGUMENTS[@]}:"
for i in "${POSITIONAL_ARGUMENTS[@]}"; do
echo " - $i"
done
fi
}
main() {
case "$ACTION" in
install)
do_install
;;
remove)
do_remove
;;
esac
completed
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment