tuxflotte-installer/scripts/modules/25_installation_confirm.sh
Thomas Stallinger 3a7549adf1 fix: align profile selection and installation confirm with Bereitstellungsvorlage model
20_profile_selection.sh and 25_installation_confirm.sh still spoke the
old flat profile model (.profiles[], .profile.distribution,
.profile.installer.type) that the provisioning server no longer
returns - it now returns .templates[] with workspace/backend objects
(see provisioning-server's Merkmal/Blueprint/Bereitstellungsvorlage
migration). Both modules now read/write
/run/tuxflotte/assignment/template.json against the current
Bereitstellungsvorlage schema, matching 10-interactive-provisioning-flow.md.
2026-07-18 10:49:42 +02:00

114 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
readonly SCRIPT_NAME
readonly TEMPLATE_FILE="/run/tuxflotte/assignment/template.json"
readonly RUNTIME_DIR="/run/tuxflotte/installation"
readonly STATE_FILE="${RUNTIME_DIR}/state.env"
log() {
printf '[%s] %s\n' "${SCRIPT_NAME}" "$*" >&2
}
fatal() {
printf '[%s] FEHLER: %s\n' "${SCRIPT_NAME}" "$*" >&2
exit 1
}
require_root() {
if [[ "${EUID}" -ne 0 ]]; then
fatal "Das Installationsbestätigungsmodul muss als root ausgeführt werden."
fi
}
prepare_runtime() {
install -d \
--mode=0700 \
--owner=root \
--group=root \
"${RUNTIME_DIR}"
rm -f -- "${STATE_FILE}"
}
validate_template() {
[[ -r "${TEMPLATE_FILE}" ]] ||
fatal "Bereitstellungsvorlage nicht gefunden: ${TEMPLATE_FILE}"
jq --exit-status '
.schema_version == 1
and (.template | type == "object")
and (.template.id | type == "string")
and (.template.label | type == "string")
and (.template.workspace.name | type == "string")
and (.template.backend.name | type == "string")
and (.template.backend.version | type == "string")
' "${TEMPLATE_FILE}" >/dev/null ||
fatal "Bereitstellungsvorlage enthält keine gültige Auswahl."
}
show_installation_plan() {
local label
local workspace
local backend_name
local backend_version
label="$(jq -r '.template.label' "${TEMPLATE_FILE}")"
workspace="$(jq -r '.template.workspace.name' "${TEMPLATE_FILE}")"
backend_name="$(jq -r '.template.backend.name' "${TEMPLATE_FILE}")"
backend_version="$(jq -r '.template.backend.version' "${TEMPLATE_FILE}")"
printf '\n'
printf 'Geplanter Installationsvorgang\n'
printf '==============================\n\n'
printf 'Bereitstellungsvorlage: %s\n' "${label}"
printf 'Workspace: %s\n' "${workspace}"
printf 'Backend: %s %s\n' "${backend_name}" "${backend_version}"
printf '\n'
printf 'Die eigentliche Installation kann lokale Datenträger verändern.\n'
printf 'Bis zu dieser Bestätigung wurden keine destruktiven Installationsaktionen gestartet.\n'
printf '\n'
}
store_confirmation_state() {
local confirmed="$1"
umask 077
printf 'TUXFLOTTE_INSTALLATION_CONFIRMED=%s\n' \
"${confirmed}" >"${STATE_FILE}"
chmod 0600 "${STATE_FILE}"
}
confirm_installation() {
local answer
read -r -p "Installation jetzt starten? [j/N]: " answer
case "${answer}" in
j|J|ja|JA|Ja)
store_confirmation_state true
log "Installation wurde durch den Benutzer bestätigt."
;;
*)
store_confirmation_state false
log "Installation wurde durch den Benutzer abgebrochen."
log "Es wurden keine destruktiven Installationsaktionen gestartet."
;;
esac
}
main() {
require_root
prepare_runtime
validate_template
show_installation_plan
confirm_installation
}
main "$@"