diff --git a/scripts/modules/20_profile_selection.sh b/scripts/modules/20_profile_selection.sh index 94e0d9a..546e153 100755 --- a/scripts/modules/20_profile_selection.sh +++ b/scripts/modules/20_profile_selection.sh @@ -6,7 +6,7 @@ readonly SCRIPT_NAME readonly SERVER_RESPONSE_FILE="/run/tuxflotte/server/response.json" readonly RUNTIME_DIR="/run/tuxflotte/assignment" -readonly PROFILE_FILE="${RUNTIME_DIR}/profile.json" +readonly TEMPLATE_FILE="${RUNTIME_DIR}/template.json" log() { printf '[%s] %s\n' "${SCRIPT_NAME}" "$*" @@ -25,7 +25,7 @@ require_root() { prepare_runtime() { install -d -m 0700 "${RUNTIME_DIR}" - rm -f -- "${PROFILE_FILE}" + rm -f -- "${TEMPLATE_FILE}" } validate_server_response() { @@ -37,47 +37,53 @@ validate_server_response() { jq --exit-status ' .success == true - and (.profiles | type == "array") - and (.profiles | length > 0) + and (.templates | type == "array") + and (.templates | length > 0) ' "${SERVER_RESPONSE_FILE}" >/dev/null || - fatal "Serverantwort enthält keine auswählbaren Profile." + fatal "Serverantwort enthält keine auswählbaren Bereitstellungsvorlagen." } -show_profiles() { +show_templates() { local index=1 - local profile + local template - log "Verfügbare Provisioning-Profile:" + log "Verfügbare Bereitstellungsvorlagen:" - while IFS= read -r profile; do + while IFS= read -r template; do printf '\n' - printf ' %d) %s\n' \ + printf ' %d) %s' \ "${index}" \ - "$(jq -r '.label' <<<"${profile}")" + "$(jq -r '.label' <<<"${template}")" - printf ' Distribution: %s %s\n' \ - "$(jq -r '.distribution' <<<"${profile}")" \ - "$(jq -r '.version' <<<"${profile}")" + if [[ "$(jq -r '.is_default' <<<"${template}")" == "true" ]]; then + printf ' (Standard)' + fi - printf ' %s\n' \ - "$(jq -r '.description // ""' <<<"${profile}")" + 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 '.profiles[]' "${SERVER_RESPONSE_FILE}") + done < <(jq -c '.templates[]' "${SERVER_RESPONSE_FILE}") } -select_profile() { - local profile_count +select_template() { + local template_count local selection - profile_count="$(jq '.profiles | length' "${SERVER_RESPONSE_FILE}")" + template_count="$(jq '.templates | length' "${SERVER_RESPONSE_FILE}")" while true; do printf '\n' - read -r -p "Profil auswählen [1-${profile_count}]: " selection + read -r -p "Bereitstellungsvorlage auswählen [1-${template_count}]: " selection if [[ "${selection}" =~ ^[0-9]+$ ]] && - ((selection >= 1 && selection <= profile_count)); then + ((selection >= 1 && selection <= template_count)); then break fi @@ -88,30 +94,32 @@ select_profile() { --argjson index "$((selection - 1))" \ '{ schema_version: 1, - profile: .profiles[$index] + template: .templates[$index] }' \ - "${SERVER_RESPONSE_FILE}" >"${PROFILE_FILE}" + "${SERVER_RESPONSE_FILE}" >"${TEMPLATE_FILE}" - chmod 0600 "${PROFILE_FILE}" + chmod 0600 "${TEMPLATE_FILE}" jq --exit-status ' .schema_version == 1 - and (.profile | type == "object") - and (.profile.id | type == "string") - and (.profile.id | length > 0) - ' "${PROFILE_FILE}" >/dev/null || - fatal "Ausgewähltes Profil konnte nicht gültig gespeichert werden." + 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 "Profil $(jq -r '.profile.id' "${PROFILE_FILE}") wurde ausgewählt." - log "Profilauswahl wurde unter ${PROFILE_FILE} gespeichert." + 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_profiles - select_profile + show_templates + select_template } main "$@" diff --git a/scripts/modules/25_installation_confirm.sh b/scripts/modules/25_installation_confirm.sh index 952dd75..22e8a18 100755 --- a/scripts/modules/25_installation_confirm.sh +++ b/scripts/modules/25_installation_confirm.sh @@ -4,7 +4,7 @@ set -Eeuo pipefail SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")" readonly SCRIPT_NAME -readonly PROFILE_FILE="/run/tuxflotte/assignment/profile.json" +readonly TEMPLATE_FILE="/run/tuxflotte/assignment/template.json" readonly RUNTIME_DIR="/run/tuxflotte/installation" readonly STATE_FILE="${RUNTIME_DIR}/state.env" @@ -34,38 +34,39 @@ prepare_runtime() { rm -f -- "${STATE_FILE}" } -validate_profile() { - [[ -r "${PROFILE_FILE}" ]] || - fatal "Profilauswahl nicht gefunden: ${PROFILE_FILE}" +validate_template() { + [[ -r "${TEMPLATE_FILE}" ]] || + fatal "Bereitstellungsvorlage nicht gefunden: ${TEMPLATE_FILE}" jq --exit-status ' .schema_version == 1 - and (.profile | type == "object") - and (.profile.id | type == "string") - and (.profile.label | type == "string") - and (.profile.distribution | type == "string") - and (.profile.version | type == "string") - ' "${PROFILE_FILE}" >/dev/null || - fatal "Profilauswahl enthält kein gültiges Profil." + 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 distribution - local version - local installer_type + local workspace + local backend_name + local backend_version - label="$(jq -r '.profile.label' "${PROFILE_FILE}")" - distribution="$(jq -r '.profile.distribution' "${PROFILE_FILE}")" - version="$(jq -r '.profile.version' "${PROFILE_FILE}")" - installer_type="$(jq -r '.profile.installer.type // "unbekannt"' "${PROFILE_FILE}")" + 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 'Profil: %s\n' "${label}" - printf 'Distribution: %s %s\n' "${distribution}" "${version}" - printf 'Installer: %s\n' "${installer_type}" + 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' @@ -104,7 +105,7 @@ confirm_installation() { main() { require_root prepare_runtime - validate_profile + validate_template show_installation_plan confirm_installation }