mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 19:04:31 +00:00
153 lines
4.1 KiB
Bash
Executable File
153 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# prole.sh - Unified launcher for Prole infrastructure and installer
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "${ROOT_DIR}"
|
|
|
|
# Defaults
|
|
VERBOSE=0
|
|
DEBUG=0
|
|
LOG=0
|
|
COVERAGE=0
|
|
SILENT=0
|
|
EXTRA_ARGS=()
|
|
|
|
usage() {
|
|
echo "Usage: $0 [options] [command] [command-options]"
|
|
echo
|
|
echo "Options:"
|
|
echo " -l, --log Create a datestamped logfile in prole/logs including all stdout/stderr"
|
|
echo " -v, --verbose Pass a verbose switch to all functions called by ansible and install.py"
|
|
echo " -d, --debug Enable a debug logfile in prole/logs with high verbosity from install.py"
|
|
echo " -c, --coverage Create a coverage report for the run of install.py"
|
|
echo " -s, --silent Run unattended install (passes -S to install.py)"
|
|
echo
|
|
echo "Commands:"
|
|
echo " install Run the ncurses-based terminal installer"
|
|
echo " ansible Run ansible-playbook via ansible.sh"
|
|
echo " site Shortcut for running the site deployment"
|
|
echo " reset Shortcut for k3s factory reset"
|
|
echo
|
|
echo "Any other arguments are passed directly to ansible.sh"
|
|
}
|
|
|
|
# Parse global options
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-l|--log|--logs) LOG=1; shift ;;
|
|
-v|--verbose) VERBOSE=1; shift ;;
|
|
-d|--debug) DEBUG=1; shift ;;
|
|
-c|--coverage) COVERAGE=1; shift ;;
|
|
-s|--silent) SILENT=1; shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
install|ansible|site|reset) break ;;
|
|
*) EXTRA_ARGS+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
if [[ $# -eq 0 && ${#EXTRA_ARGS[@]} -eq 0 ]]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
CMD="${1:-ansible}"
|
|
[[ $# -gt 0 ]] && shift
|
|
|
|
# Prepare command arguments
|
|
CMD_ARGS=()
|
|
if [[ "${VERBOSE}" -eq 1 ]]; then
|
|
CMD_ARGS+=("--verbose")
|
|
fi
|
|
|
|
if [[ "${DEBUG}" -eq 1 ]]; then
|
|
if [[ "${CMD}" == "install" ]]; then
|
|
CMD_ARGS+=("--debug")
|
|
fi
|
|
fi
|
|
|
|
if [[ "${SILENT}" -eq 1 ]]; then
|
|
if [[ "${CMD}" == "install" ]]; then
|
|
if [[ ! -f "${ROOT_DIR}/conf/prole.cfg" ]]; then
|
|
echo "Error: --silent requires ${ROOT_DIR}/conf/prole.cfg" >&2
|
|
exit 1
|
|
fi
|
|
CMD_ARGS+=("-S")
|
|
fi
|
|
fi
|
|
|
|
CMD_ARGS+=("${EXTRA_ARGS[@]}" "$@")
|
|
|
|
# Helper for logging
|
|
run_with_log() {
|
|
local logfile="$1"
|
|
shift
|
|
mkdir -p "$(dirname "${logfile}")"
|
|
echo "Logging to ${logfile}"
|
|
"$@" 2>&1 | tee "${logfile}"
|
|
}
|
|
|
|
# Run command
|
|
TS="$(date +%Y%m%d-%H%M%S)"
|
|
|
|
case "${CMD}" in
|
|
install)
|
|
LOGFILE="${ROOT_DIR}/logs/install-${TS}.log"
|
|
|
|
PY_CMD=("python3")
|
|
if [[ "${COVERAGE}" -eq 1 ]]; then
|
|
PY_CMD=("coverage" "run" "--source=installer")
|
|
fi
|
|
PY_CMD+=("${ROOT_DIR}/install.py" "--no-gui")
|
|
|
|
if [[ "${LOG}" -eq 1 ]]; then
|
|
run_with_log "${LOGFILE}" "${PY_CMD[@]}" "${CMD_ARGS[@]}"
|
|
elif [[ "${COVERAGE}" -eq 1 ]]; then
|
|
"${PY_CMD[@]}" "${CMD_ARGS[@]}"
|
|
else
|
|
exec "${PY_CMD[@]}" "${CMD_ARGS[@]}"
|
|
fi
|
|
|
|
if [[ "${COVERAGE}" -eq 1 ]]; then
|
|
echo "Generating coverage report..."
|
|
coverage report -m
|
|
coverage html
|
|
echo "HTML report generated in ${ROOT_DIR}/htmlcov/index.html"
|
|
fi
|
|
;;
|
|
ansible)
|
|
LOGFILE="${ROOT_DIR}/logs/ansible-${TS}.log"
|
|
if [[ "${LOG}" -eq 1 ]]; then
|
|
run_with_log "${LOGFILE}" "${ROOT_DIR}/ansible.sh" "${CMD_ARGS[@]}"
|
|
else
|
|
exec "${ROOT_DIR}/ansible.sh" "${CMD_ARGS[@]}"
|
|
fi
|
|
;;
|
|
site)
|
|
LOGFILE="${ROOT_DIR}/logs/site-${TS}.log"
|
|
if [[ "${LOG}" -eq 1 ]]; then
|
|
run_with_log "${LOGFILE}" "${ROOT_DIR}/ansible.sh" -p infrastructure/playbooks/site.yml "${CMD_ARGS[@]}"
|
|
else
|
|
exec "${ROOT_DIR}/ansible.sh" -p infrastructure/playbooks/site.yml "${CMD_ARGS[@]}"
|
|
fi
|
|
;;
|
|
reset)
|
|
LOGFILE="${ROOT_DIR}/logs/reset-${TS}.log"
|
|
if [[ "${LOG}" -eq 1 ]]; then
|
|
run_with_log "${LOGFILE}" "${ROOT_DIR}/ansible.sh" -p infrastructure/playbooks/k3s_delete.yml "${CMD_ARGS[@]}"
|
|
else
|
|
exec "${ROOT_DIR}/ansible.sh" -p infrastructure/playbooks/k3s_delete.yml "${CMD_ARGS[@]}"
|
|
fi
|
|
;;
|
|
*)
|
|
# Default to ansible if command not matched
|
|
LOGFILE="${ROOT_DIR}/logs/${CMD}-${TS}.log"
|
|
if [[ "${LOG}" -eq 1 ]]; then
|
|
run_with_log "${LOGFILE}" "${ROOT_DIR}/ansible.sh" "${CMD}" "${CMD_ARGS[@]}"
|
|
else
|
|
exec "${ROOT_DIR}/ansible.sh" "${CMD}" "${CMD_ARGS[@]}"
|
|
fi
|
|
;;
|
|
esac
|