#!/bin/bash # Lesbare Referenzfassung des Agent-Bootstraps, den backend_generate_config() # in backend.sh zur Laufzeit envsubst-auflöst und anschließend base64-kodiert # in preseed.tpls ubiquity/success_command einsetzt (siehe backend.sh). Diese # Datei selbst wird nie direkt ausgeführt - sie existiert, damit der Code # lesbar bleibt statt nur als Base64-Blob im Preseed zu existieren. # # Inhaltlich das Bash-Pendant zu backends/fedora/kickstart.tpl %post: gleiche # curl/jq-Aufrufe, nur eingebettet über ubiquity/success_command (in-target, # chrooted) statt Kickstart %post. tuxflotte_agent_fatal() { echo "tuxflotte: Provisioning-Agent-Einrichtung fehlgeschlagen: $*" >> /var/log/tuxflotte-postinstall.log exit 1 } ANODE_URL="https://anode.tuxflotte.de" AGENT_REPO_RAW="https://git.tuxflotte.de/admin/provisioning-agent/raw/branch/main" install -d -m 0700 /etc/tuxflotte || tuxflotte_agent_fatal "Verzeichnis /etc/tuxflotte konnte nicht angelegt werden." cat > /etc/tuxflotte/runtime_blueprint.json <<'RUNTIME_BLUEPRINT_EOF' ${TUXFLOTTE_BLUEPRINTS_JSON} RUNTIME_BLUEPRINT_EOF install -d /opt/tuxflotte/agent || tuxflotte_agent_fatal "Verzeichnis /opt/tuxflotte/agent konnte nicht angelegt werden." curl --silent --show-error --fail --location \ --output /opt/tuxflotte/agent/agent.py \ "${AGENT_REPO_RAW}/agent.py" || tuxflotte_agent_fatal "agent.py konnte nicht von ${AGENT_REPO_RAW} geladen werden." curl --silent --show-error --fail --location \ --output /etc/systemd/system/tuxflotte-agent.service \ "${AGENT_REPO_RAW}/tuxflotte-agent.service" || tuxflotte_agent_fatal "tuxflotte-agent.service konnte nicht von ${AGENT_REPO_RAW} geladen werden." AGENT_BOOTSTRAP_RESPONSE="$( curl --silent --show-error --fail --location \ --header 'Content-Type: application/json' \ --data-binary "{\"device_id\": \"${TUXFLOTTE_DEVICE_ID}\"}" \ "${ANODE_URL}/api/v1/agent/bootstrap" )" || tuxflotte_agent_fatal "Bootstrap-Aufruf gegen ${ANODE_URL} ist fehlgeschlagen." jq --exit-status '.success == true' <<<"${AGENT_BOOTSTRAP_RESPONSE}" >/dev/null || tuxflotte_agent_fatal "Server hat den Bootstrap abgelehnt: ${AGENT_BOOTSTRAP_RESPONSE}" jq --null-input \ --arg device_id "${TUXFLOTTE_DEVICE_ID}" \ --argjson response "${AGENT_BOOTSTRAP_RESPONSE}" \ '{device_id: $device_id, agent_secret: $response.agent_secret}' \ > /etc/tuxflotte/agent.credentials || tuxflotte_agent_fatal "Credentials-Datei konnte nicht erzeugt werden." chmod 0600 /etc/tuxflotte/agent.credentials systemctl enable tuxflotte-agent.service || tuxflotte_agent_fatal "systemd-Dienst tuxflotte-agent konnte nicht aktiviert werden." echo "tuxflotte: Runtime Blueprint unter /etc/tuxflotte/runtime_blueprint.json hinterlegt." >> /var/log/tuxflotte-postinstall.log echo "tuxflotte: Provisioning-Agent installiert, registriert und für den ersten Boot aktiviert." >> /var/log/tuxflotte-postinstall.log