Files
pentest.intro/content/lib/dispatch.sh
T
quoije b9bc0eb079 Add 'save': the closing step for any change
save = snapshot --update + start, and falls back to a first-time snapshot
when no baseline exists yet. On the qemu platform it folds the working
overlays into the base images and brings the lab back up; on proxmox it
re-templates.

Documented as the rule it is: every deliberate change to the lab ends with
save, so reset always returns to the state you meant to freeze.
2026-10-24 02:13:18 -04:00

108 lines
3.3 KiB
Bash

# shellcheck shell=bash
# Shared command dispatcher. Sourced by each platform's lab.sh after the
# command implementations and before anything runs.
#
# The platform provides: LAB_DIR, CONTENT_DIR, PLATFORM, and its backend file
# at $LAB_DIR/backends/<PLATFORM>.sh.
usage() {
cat <<EOF
Norbourg lab ${LAB_SH_VERSION} — ${PLATFORM} platform
Usage: ./lab.sh [options] <command>
Options:
--strict treat check warnings as failures
-v, --verbose extra detail
-h, --help this text
--version print the version
Commands:
check preflight: host, storage, network, configuration
init create the storage layout and the runtime venv if needed
isos download the Windows media
seeds render unattend files and pack the seed ISOs
build create the VMs and run the unattended installs
provision run the role stages (--role NAME for a single VM)
web assemble the site; --sync publishes it to FS01
snapshot freeze a clean baseline
save snapshot --update then start (the closing step)
reset revert to the baseline and start
up, down start / stop the VMs
status VM table
vnc open a console on a VM
doctor end-to-end health check
kali install / start / stop the optional Kali attacker VM
answers print the instructor walkthrough
destroy remove the VMs and generated artifacts
EOF
case $PLATFORM in
proxmox) printf ' peers generate WireGuard configs for participants\n' ;;
esac
}
planned() {
warn "'$1' is not implemented on this platform"
return 3
}
# ------------------------------------------------------------------ arguments
cmd=""
while (( $# > 0 )); do
case $1 in
--strict) STRICT=1; shift ;;
-v|--verbose) VERBOSE=1; shift ;;
-h|--help|help) usage; exit 0 ;;
--version) printf '%s\n' "$LAB_SH_VERSION"; exit 0 ;;
--) shift; break ;;
-*)
# Before the command this is a typo; after it, the flag belongs to the verb.
[[ -z $cmd ]] && die "unknown option: $1 (try --help)"
break
;;
*)
# First positional is the command; everything after it belongs to the verb
# (peers wants a list of names, provision wants --role NAME).
if [[ -z $cmd ]]; then cmd=$1; shift; fi
break
;;
esac
done
if [[ -z $cmd ]]; then
usage
exit 2
fi
load_config
backend_file="$LAB_DIR/backends/${BACKEND}.sh"
[[ -r $backend_file ]] || die "no backend '${BACKEND}' for the ${PLATFORM} platform (looked for ${backend_file})"
# shellcheck disable=SC1090
source "$backend_file"
# ------------------------------------------------------------------ dispatch
case $cmd in
check) cmd_check "$@" || exit $? ;;
init) cmd_init "$@" ;;
isos) cmd_isos "$@" ;;
seeds) cmd_seeds "$@" ;;
web) cmd_web "$@" ;;
build) cmd_build "$@" ;;
up) cmd_up "$@" ;;
down) cmd_down "$@" ;;
status) cmd_status "$@" ;;
vnc) cmd_vnc "$@" ;;
provision) cmd_provision "$@" ;;
snapshot) cmd_snapshot "$@" ;;
save) cmd_save "$@" ;;
reset) cmd_reset "$@" ;;
doctor) cmd_doctor "$@" ;;
kali) cmd_kali "$@" ;;
answers) cmd_answers "$@" ;;
destroy) cmd_destroy "$@" ;;
peers) cmd_peers "$@" ;;
*) die "unknown command: ${cmd} (try --help)" ;;
esac