113 lines
2.9 KiB
Bash
Executable File
113 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
|
|
readonly SCRIPT_NAME
|
|
|
|
readonly PROFILE_FILE="/run/tuxflotte/assignment/profile.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_profile() {
|
|
[[ -r "${PROFILE_FILE}" ]] ||
|
|
fatal "Profilauswahl nicht gefunden: ${PROFILE_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."
|
|
}
|
|
|
|
show_installation_plan() {
|
|
local label
|
|
local distribution
|
|
local version
|
|
local installer_type
|
|
|
|
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}")"
|
|
|
|
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 '\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_profile
|
|
show_installation_plan
|
|
confirm_installation
|
|
}
|
|
|
|
main "$@"
|