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.
126 lines
3.3 KiB
Bash
Executable File
126 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
|
|
readonly SCRIPT_NAME
|
|
|
|
readonly SERVER_RESPONSE_FILE="/run/tuxflotte/server/response.json"
|
|
readonly RUNTIME_DIR="/run/tuxflotte/assignment"
|
|
readonly TEMPLATE_FILE="${RUNTIME_DIR}/template.json"
|
|
|
|
log() {
|
|
printf '[%s] %s\n' "${SCRIPT_NAME}" "$*"
|
|
}
|
|
|
|
fatal() {
|
|
printf '[%s] FEHLER: %s\n' "${SCRIPT_NAME}" "$*" >&2
|
|
exit 1
|
|
}
|
|
|
|
require_root() {
|
|
if [[ "${EUID}" -ne 0 ]]; then
|
|
fatal "Das Profilauswahlmodul muss als root ausgeführt werden."
|
|
fi
|
|
}
|
|
|
|
prepare_runtime() {
|
|
install -d -m 0700 "${RUNTIME_DIR}"
|
|
rm -f -- "${TEMPLATE_FILE}"
|
|
}
|
|
|
|
validate_server_response() {
|
|
[[ -r "${SERVER_RESPONSE_FILE}" ]] ||
|
|
fatal "Serverantwort nicht gefunden: ${SERVER_RESPONSE_FILE}"
|
|
|
|
jq --exit-status . "${SERVER_RESPONSE_FILE}" >/dev/null ||
|
|
fatal "Serverantwort enthält kein gültiges JSON."
|
|
|
|
jq --exit-status '
|
|
.success == true
|
|
and (.templates | type == "array")
|
|
and (.templates | length > 0)
|
|
' "${SERVER_RESPONSE_FILE}" >/dev/null ||
|
|
fatal "Serverantwort enthält keine auswählbaren Bereitstellungsvorlagen."
|
|
}
|
|
|
|
show_templates() {
|
|
local index=1
|
|
local template
|
|
|
|
log "Verfügbare Bereitstellungsvorlagen:"
|
|
|
|
while IFS= read -r template; do
|
|
printf '\n'
|
|
printf ' %d) %s' \
|
|
"${index}" \
|
|
"$(jq -r '.label' <<<"${template}")"
|
|
|
|
if [[ "$(jq -r '.is_default' <<<"${template}")" == "true" ]]; then
|
|
printf ' (Standard)'
|
|
fi
|
|
|
|
printf '\n'
|
|
|
|
printf ' Workspace: %s\n' \
|
|
"$(jq -r '.workspace.name' <<<"${template}")"
|
|
|
|
printf ' Backend: %s %s\n' \
|
|
"$(jq -r '.backend.name' <<<"${template}")" \
|
|
"$(jq -r '.backend.version' <<<"${template}")"
|
|
|
|
((index += 1))
|
|
done < <(jq -c '.templates[]' "${SERVER_RESPONSE_FILE}")
|
|
}
|
|
|
|
select_template() {
|
|
local template_count
|
|
local selection
|
|
|
|
template_count="$(jq '.templates | length' "${SERVER_RESPONSE_FILE}")"
|
|
|
|
while true; do
|
|
printf '\n'
|
|
read -r -p "Bereitstellungsvorlage auswählen [1-${template_count}]: " selection
|
|
|
|
if [[ "${selection}" =~ ^[0-9]+$ ]] &&
|
|
((selection >= 1 && selection <= template_count)); then
|
|
break
|
|
fi
|
|
|
|
log "Ungültige Auswahl."
|
|
done
|
|
|
|
jq \
|
|
--argjson index "$((selection - 1))" \
|
|
'{
|
|
schema_version: 1,
|
|
template: .templates[$index]
|
|
}' \
|
|
"${SERVER_RESPONSE_FILE}" >"${TEMPLATE_FILE}"
|
|
|
|
chmod 0600 "${TEMPLATE_FILE}"
|
|
|
|
jq --exit-status '
|
|
.schema_version == 1
|
|
and (.template | type == "object")
|
|
and (.template.id | type == "string")
|
|
and (.template.id | length > 0)
|
|
and (.template.workspace | type == "object")
|
|
and (.template.backend | type == "object")
|
|
' "${TEMPLATE_FILE}" >/dev/null ||
|
|
fatal "Ausgewählte Bereitstellungsvorlage konnte nicht gültig gespeichert werden."
|
|
|
|
log "Bereitstellungsvorlage $(jq -r '.template.id' "${TEMPLATE_FILE}") wurde ausgewählt."
|
|
log "Auswahl wurde unter ${TEMPLATE_FILE} gespeichert."
|
|
}
|
|
|
|
main() {
|
|
require_root
|
|
prepare_runtime
|
|
validate_server_response
|
|
show_templates
|
|
select_template
|
|
}
|
|
|
|
main "$@"
|