diff --git a/docs/architecture.md b/docs/architecture.md index f47ddda..da4d915 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -3,8 +3,8 @@ Stand: 2026-10-31 Grundlage: `rinkplanner/rinkplanner_definition_agent_guidelines.md` Übergeordnete Reihenfolge: `docs/roadmap.md` -Letzte Session: `docs/findings-2026-10-31-arp-rig.md` -(Session davor: `docs/findings-2026-10-31-sprungkombinationen.md`) +Letzte Session: `docs/findings-2026-10-31-asset-ftp.md` +(Session davor: `docs/findings-2026-10-31-arp-rig.md`) ## 1. Leitentscheidung @@ -182,6 +182,10 @@ den Godot-Import an. Damit bleiben Checkout und Build klein, während die Arbeitsdateien versioniert und reproduzierbar bleiben. Phase 1 lädt keine 3D-Ressourcen; die Pipeline ist Vorbereitung für Phase 2. Details: `docs/assets.md`. +Für Rechner ohne Workbench spiegelt `tools/sync_assets.sh --publish` die +Dateien zusätzlich auf den bestehenden FTP-Server der Kür-Synchronisation; +`--sync` lädt sie bei Bedarf und prüft sie gegen den Manifest-Hash. Der +FTP-Spiegel ist eine Verteilungskopie, keine zweite Quelle der Wahrheit. ## 4. View- und Controller-Grenzen @@ -452,9 +456,9 @@ Aktueller Stand: PASV/EPSV/MDTM-Parsing, Sync-Stand und die Einstellungs-Verdrahtung. Der FTP-Client wurde zusätzlich gegen den echten Zielserver geprüft (Upload, Download, Übernahme, Konflikt, Aufräumen). -- **3D-Assets:** 48 Assertions für Manifest-Schema, Pfade, Platzierung, - Rig-Metadaten, Hashes und – falls synchronisiert – Größe und SHA-256 der - GLB-Datei. +- **3D-Assets:** 53 Assertions für Manifest-Schema, Pfade, FTP-Pfade, + Platzierung, Rig-Metadaten, Hashes und – falls synchronisiert – Größe und + SHA-256 der GLB-Datei. Autosave/Restore wird zusätzlich in einem isolierten `XDG_DATA_HOME` end-to-end geprüft. diff --git a/docs/assets.md b/docs/assets.md index 75009f7..5ee7c05 100644 --- a/docs/assets.md +++ b/docs/assets.md @@ -37,27 +37,88 @@ tools/sync_assets.sh `library/` legen (`..._v001.glb`, `..._v002.glb`). 3. Die bearbeitbare Quelle (`.blend`, Rig, Referenzvideo) nach `source/`. 4. Eintrag in `rinkplanner/assets/asset_manifest.json` ergänzen: - ID, Quelle, Ziel, SHA-256, Größe, Platzierung, Rig, Animationen. + ID, Quelle, Ziel, FTP-Pfad, SHA-256, Größe, Platzierung, Rig, Animationen. 5. `./tools/sync_assets.sh --sync` kopiert und importiert. -6. Vor dem Commit `./tools/sync_assets.sh --check` laufen lassen. +6. Bei geänderter Datei `./tools/sync_assets.sh --publish` für den Spiegel. +7. Vor dem Commit `./tools/sync_assets.sh --check` laufen lassen. ### Befehle ```bash -./tools/sync_assets.sh --check # Standard: nur prüfen -./tools/sync_assets.sh --sync # fehlende Dateien kopieren + Godot-Import +./tools/sync_assets.sh --check # Standard: nur lokal prüfen +./tools/sync_assets.sh --sync # kopieren/laden + Godot-Import ./tools/sync_assets.sh --sync --force # abweichendes Ziel überschreiben +./tools/sync_assets.sh --publish # Workbench-Dateien auf den FTP-Spiegel laden ``` -Umgebungsvariablen: +`--sync` arbeitet in dieser Reihenfolge: + +1. Ziel in `assets/external/` ist vorhanden und hat den Manifest-Hash → OK. +2. Workbench-Quelle ist vorhanden → kopieren. +3. Sonst vom FTP-Spiegel laden. + +Damit funktioniert ein frischer Checkout auf einem Rechner ohne +Workbench-Archiv, sofern die FTP-Zugangsdaten vorliegen. + +### FTP-Spiegel + +Der vorhandene FTP-Server der Kür-Synchronisation dient als +Verteilungskopie. Die Dateien liegen dort unterhalb des App-Verzeichnisses: + +``` +/assets/ +# z. B. rinkplanner/assets/characters/skater_figure_rigged_deform_v002.glb +``` + +`FTP_DIRECTORY` ist das Verzeichnis aus `docs/credentials.txt` (aktuell +`rinkplanner`). Der Unterordner `assets` wird beim ersten Upload automatisch +angelegt (`--ftp-create-dirs`). + +Zugangsdaten kommen aus `docs/credentials.txt` (gitignored) oder aus +`RINKPLANNER_FTP_*`-Umgebungsvariablen. Das Format ist dasselbe wie für die +App: + +``` +FTP_URL= +FTP_USER= +FTP_PASSWORD= +FTP_DIRECTORY=rinkplanner +``` + +Optional: + +| Schlüssel | Bedeutung | +| :--- | :--- | +| `FTP_ASSET_DIRECTORY` | überschreibt `/assets` | +| `FTP_VERIFY=1` | TLS-Zertifikat prüfen (Standard: 0) | + +Der Server verwendet explizites FTPS (`AUTH TLS`, Port 21). Sein Zertifikat +hat keinen passenden Hostnamen, deshalb ist die Prüfung standardmäßig aus. +Die Integrität hängt nicht am Zertifikat, sondern am SHA-256 aus dem +Manifest: Nach jedem Upload wird die Datei zurückgeladen und gehasht; nach +jedem Download wird vor dem Verschieben gehasht. + +`--publish` ist bewusst ein eigener Befehl. Ein normaler `--sync` lädt nichts +hoch und überschreibt keine Serverdatei. + +Auf einem neuen Rechner: + +```bash +cp /pfad/zu/credentials.txt docs/credentials.txt +./tools/sync_assets.sh --sync +``` + +Weitere Umgebungsvariablen: | Variable | Standard | Zweck | | :--- | :--- | :--- | | `RINKPLANNER_WORKBENCH` | `~/Documents/workbench_rinkplanner` | Archivpfad | +| `RINKPLANNER_CREDENTIALS` | `/docs/credentials.txt` | FTP-Konfiguration | | `GODOT` | `/opt/godot/Godot_v4.7.2-stable_linux.x86_64` | Import-Binary | -Das Skript prüft **Quelle und Ziel** gegen den Hash aus dem Manifest. Eine -still veränderte Workbench-Datei wird nicht kopiert, sondern gemeldet. +Das Skript prüft beim Kopieren, Laden und Veröffentlichen die jeweilige +Datei gegen den Hash aus dem Manifest. `--check` prüft nur das lokale Ziel; +eine still veränderte Workbench-Datei wird nicht kopiert, sondern gemeldet. ## Manifest @@ -69,6 +130,7 @@ still veränderte Workbench-Datei wird nicht kopiert, sondern gemeldet. "format": "glb", "source": "library/characters/skater_figure_rigged_deform_v002.glb", "target": "assets/external/characters/skater_figure_rigged_deform_v002.glb", + "remote": "characters/skater_figure_rigged_deform_v002.glb", "sha256": "1c1f0646…", "bytes": 8345424, "source_scene": "source/characters/skater/skater_rig_v002.blend", @@ -95,6 +157,7 @@ still veränderte Workbench-Datei wird nicht kopiert, sondern gemeldet. | `version` | Zähler der kuratierten Fassung | | `source` | Pfad relativ zum Workbench-Archiv | | `target` | Pfad relativ zum Godot-Projekt, immer unter `assets/external/` | +| `remote` | Pfad relativ zum FTP-Asset-Verzeichnis | | `sha256` / `bytes` | Integritätsprüfung | | `source_scene` | bearbeitbare Quelle (`.blend`) für Rig/Animation | | `placement` | Up-Achse, Blickrichtung, Pivot und Höhe für die 3D-Szene | @@ -155,6 +218,7 @@ Details und Messwerte: `docs/findings-2026-10-31-arp-rig.md`. ## Tests -`tests/run_asset_manifest_tests.gd` prüft Schema, Pfade, Hashes und – falls -synchronisiert – Größe und SHA-256 der Zieldatei. Fehlt das Asset (z. B. in -CI), wird der Dateicheck übersprungen, der Schema-Test bleibt aktiv. +`tests/run_asset_manifest_tests.gd` prüft Schema, Pfade, FTP-Pfade, Hashes +und – falls synchronisiert – Größe und SHA-256 der Zieldatei. Fehlt das +Asset (z. B. in CI), wird der Dateicheck übersprungen, der Schema-Test bleibt +aktiv. Aktuell: 53 Assertions. diff --git a/docs/findings-2026-10-31-asset-ftp.md b/docs/findings-2026-10-31-asset-ftp.md new file mode 100644 index 0000000..d8fd67d --- /dev/null +++ b/docs/findings-2026-10-31-asset-ftp.md @@ -0,0 +1,107 @@ +# Findings 2026-10-31 – FTP-Spiegel für externe Assets + +## Problem + +Ein frischer Checkout auf einem anderen Rechner hat kein +Workbench-Archiv und damit keine 3D-Modelle. `assets/external/` ist +gitignored, der Rig und die GLB fehlen. + +## Lösung + +Der vorhandene FTP-Server der Kür-Synchronisation dient zusätzlich als +Verteilungskopie für die 3D-Assets. Das Repo bleibt die Quelle der Wahrheit +für IDs und Hashes; der Workbench bleibt die Quelle für die Bearbeitung. + +``` +FTP-Server +└── rinkplanner/ # FTP_DIRECTORY aus credentials.txt + ├── ... # Kür-Dateien + └── assets/ + └── characters/ + └── skater_figure_rigged_deform_v002.glb +``` + +`FTP_ASSET_DIRECTORY` ist standardmäßig `/assets` und kann +überschrieben werden. Beim ersten Upload legt curl die Ordner an. + +## Ablauf + +### Veröffentlichen + +```bash +./tools/sync_assets.sh --publish +``` + +1. Quelle gegen den Manifest-Hash prüfen. +2. Datei per explizitem FTPS hochladen (`AUTH TLS`, Port 21). +3. Datei zurückladen, Größe und SHA-256 prüfen. +4. Erst dann „OK". + +`--publish` ist ein eigener Befehl; ein normaler `--sync` lädt nichts hoch. + +### Auf einem Rechner ohne Workbench + +```bash +cp /pfad/zu/credentials.txt docs/credentials.txt +./tools/sync_assets.sh --sync +``` + +`--sync` prüft in dieser Reihenfolge: + +1. Ziel in `assets/external/` vorhanden und Hash korrekt → OK. +2. Workbench-Quelle vorhanden → kopieren. +3. Sonst FTP-Download nach temporärer Datei, Hash prüfen, verschieben, + Godot-Import anstoßen. + +## Zugangsdaten + +`docs/credentials.txt` (gitignored) mit den bestehenden Schlüsseln: + +``` +FTP_URL= +FTP_USER= +FTP_PASSWORD= +FTP_DIRECTORY=rinkplanner +``` + +Optional `FTP_ASSET_DIRECTORY` und `FTP_VERIFY=1`. Alternativ +`RINKPLANNER_FTP_*`-Umgebungsvariablen. + +## Sicherheit und Integrität + +- Der Server nutzt explizites FTPS. Sein Zertifikat hat keinen passenden + Hostnamen; die Prüfung ist deshalb standardmäßig aus (`FTP_VERIFY=0`). +- Der Vertrauensanker ist nicht das Zertifikat, sondern der SHA-256 aus + `asset_manifest.json`. Jeder Upload wird zurückgelesen und gehasht, jeder + Download vor dem Verschieben geprüft. +- Zugangsdaten liegen ausschließlich in der gitignorierten Datei bzw. in + Umgebungsvariablen. Das Manifest enthält keine Secrets. +- Der FTP-Spiegel ist eine Verteilungskopie. Ohne Workbench kann man Assets + laden, aber keine neuen Versionen erzeugen. + +## Test + +1. `--publish` lud `skater_figure_rigged_deform_v002.glb` (8.345.424 Bytes) + nach `rinkplanner/assets/characters/` und verifizierte den Rückdownload. +2. Ziel aus `assets/external/` entfernt, `RINKPLANNER_WORKBENCH` auf ein + nicht existierendes Verzeichnis gesetzt. +3. `--sync` lud die Datei per FTP, Hash + `1c1f06461b58b02d9b8332a756fdc88f533ff2d25f65a59d21ca0209b65128cb`, + Godot-Import erfolgreich. +4. `--check` danach grün. + +## Tests und Doku + +- `tests/run_asset_manifest_tests.gd`: jetzt 53 Assertions (zusätzlich + FTP-Pfad, Relativität, Eindeutigkeit). +- Gesamtsuite: **1128 Assertions**. +- `docs/assets.md` beschreibt Spiegel, Befehle und den Rechner ohne + Workbench. + +## Offen + +- Aufräumregel für alte Versionen auf dem Server (aktuell sammeln sich + versionierte Dateien). +- Android: 1K-Texturen oder separater Asset-Pack, damit die 8,35 MB nicht + ungeprüft ins APK wandern. +- Optional: `--check --remote`, um die Serverdatei ohne Download zu prüfen. diff --git a/docs/roadmap.md b/docs/roadmap.md index 5a35706..cf40684 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -183,6 +183,7 @@ UI-Feedback der Tester ohnehin noch ausstehen. ## Phase 2 – 3D-Präsentation - [x] Externe Asset-Pipeline (Manifest, Hash-Prüfung, Sync nach `assets/external/`) +- [x] FTP-Spiegel für Rechner ohne Workbench (`--publish` / `--sync`-Fallback) - [x] Geriggter Skater (AutoRigPro, 226 Control-/30 Deform-Bones, glTF-Export) - [x] Animations-Bake und Godot-Import eines Testclips (`TestWave`) - [ ] 3D-Rink und Skater auf Basis desselben Datenmodells im Godot-Prototyp diff --git a/rinkplanner/assets/asset_manifest.json b/rinkplanner/assets/asset_manifest.json index e4c69bb..a5319a4 100644 --- a/rinkplanner/assets/asset_manifest.json +++ b/rinkplanner/assets/asset_manifest.json @@ -9,6 +9,7 @@ "format": "glb", "source": "library/characters/skater_figure_rigged_deform_v002.glb", "target": "assets/external/characters/skater_figure_rigged_deform_v002.glb", + "remote": "characters/skater_figure_rigged_deform_v002.glb", "sha256": "1c1f06461b58b02d9b8332a756fdc88f533ff2d25f65a59d21ca0209b65128cb", "bytes": 8345424, "source_scene": "source/characters/skater/skater_rig_v002.blend", diff --git a/rinkplanner/tests/run_asset_manifest_tests.gd b/rinkplanner/tests/run_asset_manifest_tests.gd index 7205ddf..a43512e 100644 --- a/rinkplanner/tests/run_asset_manifest_tests.gd +++ b/rinkplanner/tests/run_asset_manifest_tests.gd @@ -49,11 +49,12 @@ func _run() -> void: var seen_ids := {} var seen_targets := {} + var seen_remotes := {} for entry: Variant in asset_list: _check(entry is Dictionary, "asset entry is an object") if not entry is Dictionary: continue - _validate_asset(entry, seen_ids, seen_targets) + _validate_asset(entry, seen_ids, seen_targets, seen_remotes) _finish() @@ -61,7 +62,8 @@ func _run() -> void: func _validate_asset( asset: Dictionary, seen_ids: Dictionary, - seen_targets: Dictionary + seen_targets: Dictionary, + seen_remotes: Dictionary ) -> void: for key: String in [ "id", @@ -70,6 +72,7 @@ func _validate_asset( "format", "source", "target", + "remote", "sha256", "bytes", "placement", @@ -110,6 +113,19 @@ func _validate_asset( ) seen_targets[target] = true + var remote := str(asset.get("remote", "")) + _check(not remote.is_empty(), "asset '%s' has a remote path" % asset_id) + _check(_is_relative_path(remote), "asset '%s' remote path is relative" % asset_id) + _check( + not remote.contains(".."), + "asset '%s' remote path has no '..'" % asset_id + ) + _check( + not seen_remotes.has(remote), + "asset '%s' remote path is unique" % asset_id + ) + seen_remotes[remote] = true + var sha256 := str(asset.get("sha256", "")) _check(sha256.length() == 64, "asset '%s' has a SHA-256 length" % asset_id) _check(_is_hex(sha256), "asset '%s' has a hexadecimal SHA-256" % asset_id) diff --git a/tools/sync_assets.sh b/tools/sync_assets.sh index 21f91de..27b7d42 100755 --- a/tools/sync_assets.sh +++ b/tools/sync_assets.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash -# Synchronisiert externe 3D-Assets aus dem Workbench-Archiv in das Godot-Projekt. +# Synchronisiert externe 3D-Assets aus dem Workbench-Archiv oder per FTP. # -# Die Binärdateien werden nicht versioniert. Das Manifest -# rinkplanner/assets/asset_manifest.json beschreibt Quelle, Ziel, Hash und -# Metadaten. Nach dem Kopieren wird der Godot-Import angestoßen. +# Reihenfolge beim Sync: +# 1. Ziel ist vorhanden und hat den Manifest-Hash -> OK +# 2. Workbench-Quelle ist vorhanden -> kopieren +# 3. Sonst: vom FTP-Spiegel laden (für Rechner ohne Workbench) +# +# Der FTP-Spiegel ist eine Verteilungskopie, keine zweite Quelle der Wahrheit. +# Integritätsanker ist immer der SHA-256 aus asset_manifest.json. set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -11,22 +15,50 @@ PROJECT_DIR="$REPO_ROOT/rinkplanner" MANIFEST="$PROJECT_DIR/assets/asset_manifest.json" WORKBENCH="${RINKPLANNER_WORKBENCH:-$HOME/Documents/workbench_rinkplanner}" GODOT="${GODOT:-/opt/godot/Godot_v4.7.2-stable_linux.x86_64}" +CREDENTIALS_FILE="${RINKPLANNER_CREDENTIALS:-$REPO_ROOT/docs/credentials.txt}" MODE="check" FORCE=0 +ENV_FTP_HOST="${RINKPLANNER_FTP_HOST:-}" +ENV_FTP_PORT="${RINKPLANNER_FTP_PORT:-}" +ENV_FTP_USER="${RINKPLANNER_FTP_USER:-}" +ENV_FTP_PASSWORD="${RINKPLANNER_FTP_PASSWORD:-}" +ENV_FTP_ROOT="${RINKPLANNER_FTP_ROOT:-}" +ENV_FTP_ASSET_DIR="${RINKPLANNER_FTP_ASSET_DIR:-}" +ENV_FTP_VERIFY="${RINKPLANNER_FTP_VERIFY:-}" + +FILE_FTP_URL="" +FILE_FTP_USER="" +FILE_FTP_PASSWORD="" +FILE_FTP_ROOT="" +FILE_FTP_ASSET_DIR="" +FILE_FTP_VERIFY="" +FILE_FTP_PORT="" + usage() { cat <<'EOF' -Aufruf: tools/sync_assets.sh [--check|--sync] [--force] +Aufruf: tools/sync_assets.sh [--check|--sync|--publish] [--force] - --check Prüft nur, ob die Ziele vorhanden und hashes korrekt sind (Standard). - --sync Kopiert fehlende Assets und importiert sie in Godot. - --force Überschreibt vorhandene Ziele mit abweichendem Hash (nur mit --sync). + --check Prüft nur, ob die Ziele vorhanden und hashes korrekt sind (Standard). + --sync Kopiert fehlende Assets aus der Workbench oder lädt sie per FTP + und importiert sie anschließend in Godot. + --publish Lädt die Workbench-Dateien auf den FTP-Spiegel und prüft sie dort. + --force Überschreibt vorhandene Ziele mit abweichendem Hash (nur mit --sync). Umgebung: - RINKPLANNER_WORKBENCH Pfad zum Workbench-Archiv - (Standard: ~/Documents/workbench_rinkplanner) - GODOT Godot-Binary für den Import + RINKPLANNER_WORKBENCH Pfad zum Workbench-Archiv + (Standard: ~/Documents/workbench_rinkplanner) + RINKPLANNER_CREDENTIALS Pfad zur FTP-Konfiguration + (Standard: /docs/credentials.txt) + RINKPLANNER_FTP_HOST FTP-Host (überschreibt FTP_URL) + RINKPLANNER_FTP_PORT FTP-Port (Standard: 21) + RINKPLANNER_FTP_USER FTP-Benutzer + RINKPLANNER_FTP_PASSWORD FTP-Passwort + RINKPLANNER_FTP_ROOT App-Verzeichnis auf dem Server (z. B. rinkplanner) + RINKPLANNER_FTP_ASSET_DIR Asset-Verzeichnis (Standard: /assets) + RINKPLANNER_FTP_VERIFY 1 = TLS-Zertifikat prüfen, 0 = nicht prüfen + GODOT Godot-Binary für den Import EOF } @@ -34,6 +66,7 @@ while [[ $# -gt 0 ]]; do case "$1" in --check) MODE="check" ;; --sync) MODE="sync" ;; + --publish) MODE="publish" ;; --force) FORCE=1 ;; -h|--help) usage; exit 0 ;; *) echo "Unbekannte Option: $1" >&2; usage >&2; exit 2 ;; @@ -51,6 +84,114 @@ if [[ "$FORCE" -eq 1 && "$MODE" != "sync" ]]; then exit 2 fi +# --- FTP-Konfiguration lesen ------------------------------------------------- + +if [[ -f "$CREDENTIALS_FILE" ]]; then + while IFS= read -r line || [[ -n "$line" ]]; do + line="${line%$'\r'}" + [[ -z "$line" || "$line" == \#* ]] && continue + [[ "$line" != *=* ]] && continue + key="${line%%=*}" + value="${line#*=}" + value="${value#\"}"; value="${value%\"}" + value="${value#\'}"; value="${value%\'}" + case "$key" in + FTP_URL) FILE_FTP_URL="$value" ;; + FTP_USER) FILE_FTP_USER="$value" ;; + FTP_PASSWORD) FILE_FTP_PASSWORD="$value" ;; + FTP_DIRECTORY) FILE_FTP_ROOT="$value" ;; + FTP_ASSET_DIRECTORY) FILE_FTP_ASSET_DIR="$value" ;; + FTP_VERIFY) FILE_FTP_VERIFY="$value" ;; + FTP_PORT) FILE_FTP_PORT="$value" ;; + esac + done < "$CREDENTIALS_FILE" +fi + +case "$FILE_FTP_URL" in + ftp://*) FILE_FTP_URL="${FILE_FTP_URL#ftp://}" ;; + ftps://*) FILE_FTP_URL="${FILE_FTP_URL#ftps://}" ;; +esac +FILE_FTP_URL="${FILE_FTP_URL%%/*}" +if [[ "$FILE_FTP_URL" == *:* ]]; then + FILE_FTP_PORT="${FILE_FTP_URL##*:}" + FILE_FTP_URL="${FILE_FTP_URL%:*}" +fi + +FTP_HOST="${ENV_FTP_HOST:-$FILE_FTP_URL}" +FTP_PORT="${ENV_FTP_PORT:-${FILE_FTP_PORT:-21}}" +FTP_USER="${ENV_FTP_USER:-$FILE_FTP_USER}" +FTP_PASSWORD="${ENV_FTP_PASSWORD:-$FILE_FTP_PASSWORD}" +FTP_ROOT="${ENV_FTP_ROOT:-$FILE_FTP_ROOT}" +FTP_ASSET_DIR="${ENV_FTP_ASSET_DIR:-$FILE_FTP_ASSET_DIR}" +FTP_VERIFY="${ENV_FTP_VERIFY:-${FILE_FTP_VERIFY:-0}}" + +FTP_ROOT="${FTP_ROOT#/}"; FTP_ROOT="${FTP_ROOT%/}" +if [[ -z "$FTP_ASSET_DIR" ]]; then + if [[ -n "$FTP_ROOT" ]]; then + FTP_ASSET_DIR="$FTP_ROOT/assets" + else + FTP_ASSET_DIR="assets" + fi +fi +FTP_ASSET_DIR="${FTP_ASSET_DIR#/}"; FTP_ASSET_DIR="${FTP_ASSET_DIR%/}" + +REMOTE_READY=0 +CURL_BASE=() + +ensure_remote() { + if [[ "$REMOTE_READY" -eq 1 ]]; then + return + fi + if [[ -z "$FTP_HOST" || -z "$FTP_USER" || -z "$FTP_PASSWORD" ]]; then + echo "FTP-Zugang fehlt. Lege $CREDENTIALS_FILE an oder setze RINKPLANNER_FTP_*." >&2 + exit 1 + fi + + CURL_BASE=( + --ssl-reqd + --silent + --show-error + --connect-timeout 20 + --max-time 900 + --user "$FTP_USER:$FTP_PASSWORD" + ) + + case "$FTP_VERIFY" in + 1|true|TRUE|yes|YES) + ;; + *) + CURL_BASE+=(--insecure) + echo "Hinweis: TLS-Zertifikat wird nicht geprüft; Integrität sichert der SHA-256 aus dem Manifest." >&2 + ;; + esac + + REMOTE_READY=1 +} + +remote_url() { + local remote_path="$1" + remote_path="${remote_path#/}" + printf 'ftp://%s:%s/%s/%s' "$FTP_HOST" "$FTP_PORT" "$FTP_ASSET_DIR" "$remote_path" +} + +remote_download() { + local remote_path="$1" + local destination="$2" + local url + url="$(remote_url "$remote_path")" + curl "${CURL_BASE[@]}" --output "$destination" "$url" +} + +remote_upload() { + local remote_path="$1" + local source_path="$2" + local url + url="$(remote_url "$remote_path")" + curl "${CURL_BASE[@]}" --ftp-create-dirs --upload-file "$source_path" "$url" +} + +# --- Manifest lesen ---------------------------------------------------------- + mapfile -t rows < <(python3 - "$MANIFEST" <<'PY' import json import sys @@ -63,6 +204,7 @@ for asset in document.get("assets", []): asset["id"], asset["source"], asset["target"], + asset.get("remote", ""), asset["sha256"], str(asset["bytes"]), ])) @@ -74,115 +216,170 @@ if [[ ${#rows[@]} -eq 0 ]]; then exit 1 fi -problems=0 -copied=0 - -check_asset() { - local source_path="$1" - local target_path="$2" - local expected_sha="$3" - local expected_bytes="$4" - - if [[ ! -f "$source_path" ]]; then - echo " FEHLT (Quelle): $source_path" >&2 - return 1 - fi - - local actual_bytes actual_sha - actual_bytes="$(stat -c '%s' "$source_path")" - actual_sha="$(sha256sum "$source_path" | cut -d' ' -f1)" - if [[ "$actual_bytes" != "$expected_bytes" || "$actual_sha" != "$expected_sha" ]]; then - echo " HASH-FEHLER (Quelle): $source_path" >&2 - echo " erwartet: $expected_bytes Bytes / $expected_sha" >&2 - echo " gefunden: $actual_bytes Bytes / $actual_sha" >&2 - return 1 - fi - - if [[ ! -f "$target_path" ]]; then - echo " FEHLT (Ziel): $target_path" >&2 - return 1 - fi - - actual_bytes="$(stat -c '%s' "$target_path")" - actual_sha="$(sha256sum "$target_path" | cut -d' ' -f1)" - if [[ "$actual_bytes" != "$expected_bytes" || "$actual_sha" != "$expected_sha" ]]; then - echo " HASH-FEHLER (Ziel): $target_path" >&2 - echo " erwartet: $expected_bytes Bytes / $expected_sha" >&2 - echo " gefunden: $actual_bytes Bytes / $actual_sha" >&2 - return 1 - fi - - return 0 +file_size() { + stat -c '%s' "$1" } +file_sha() { + sha256sum "$1" | cut -d' ' -f1 +} + +matches_hash() { + local path="$1" + local expected_sha="$2" + local expected_bytes="$3" + [[ -f "$path" ]] || return 1 + [[ "$(file_size "$path")" == "$expected_bytes" ]] || return 1 + [[ "$(file_sha "$path")" == "$expected_sha" ]] +} + +# --- Publish ----------------------------------------------------------------- + +if [[ "$MODE" == "publish" ]]; then + ensure_remote + problems=0 + for row in "${rows[@]}"; do + IFS=$'\t' read -r asset_id relative_source relative_target remote_path expected_sha expected_bytes <<< "$row" + source_path="$WORKBENCH/$relative_source" + + echo "[$asset_id]" + if [[ -z "$remote_path" ]]; then + echo " KEIN FTP-PFAD im Manifest." >&2 + problems=$((problems + 1)) + continue + fi + if ! matches_hash "$source_path" "$expected_sha" "$expected_bytes"; then + echo " QUELLE FEHLT ODER HAT FALSCHEN HASH: $source_path" >&2 + problems=$((problems + 1)) + continue + fi + + echo " Lade hoch: $FTP_ASSET_DIR/$remote_path" + if ! remote_upload "$remote_path" "$source_path"; then + echo " UPLOAD FEHLGESCHLAGEN." >&2 + problems=$((problems + 1)) + continue + fi + + tmp="$(mktemp "${TMPDIR:-/tmp}/rinkplanner-asset.XXXXXX")" + if ! remote_download "$remote_path" "$tmp"; then + echo " KONTROLLE FEHLGESCHLAGEN (Download)." >&2 + rm -f "$tmp" + problems=$((problems + 1)) + continue + fi + if ! matches_hash "$tmp" "$expected_sha" "$expected_bytes"; then + echo " KONTROLLE FEHLGESCHLAGEN (Hash)." >&2 + rm -f "$tmp" + problems=$((problems + 1)) + continue + fi + rm -f "$tmp" + echo " OK" + done + + if [[ "$problems" -gt 0 ]]; then + echo "" >&2 + echo "$problems Asset(s) nicht veröffentlicht." >&2 + exit 1 + fi + echo "FTP-Spiegel OK." + exit 0 +fi + +# --- Check und Sync ---------------------------------------------------------- + +problems=0 +changed=0 + for row in "${rows[@]}"; do - IFS=$'\t' read -r asset_id relative_source relative_target expected_sha expected_bytes <<< "$row" + IFS=$'\t' read -r asset_id relative_source relative_target remote_path expected_sha expected_bytes <<< "$row" source_path="$WORKBENCH/$relative_source" target_path="$PROJECT_DIR/$relative_target" echo "[$asset_id]" + if matches_hash "$target_path" "$expected_sha" "$expected_bytes"; then + echo " OK" + continue + fi + if [[ "$MODE" == "check" ]]; then - if check_asset "$source_path" "$target_path" "$expected_sha" "$expected_bytes"; then - echo " OK" + if [[ ! -f "$target_path" ]]; then + echo " FEHLT (Ziel): $target_path" >&2 else - problems=$((problems + 1)) + echo " HASH-FEHLER (Ziel): $target_path" >&2 + fi + if [[ -f "$source_path" ]]; then + echo " Mit tools/sync_assets.sh --sync aus der Workbench kopieren." >&2 + else + echo " Mit tools/sync_assets.sh --sync aus dem FTP-Spiegel laden." >&2 fi - continue - fi - - if [[ ! -f "$source_path" ]]; then - echo " FEHLT (Quelle): $source_path" >&2 problems=$((problems + 1)) continue fi - source_bytes="$(stat -c '%s' "$source_path")" - source_sha="$(sha256sum "$source_path" | cut -d' ' -f1)" - if [[ "$source_bytes" != "$expected_bytes" || "$source_sha" != "$expected_sha" ]]; then - echo " HASH-FEHLER (Quelle): $source_path" >&2 - echo " Manifest und Workbench-Datei passen nicht zusammen." >&2 + if [[ -f "$target_path" && "$FORCE" -ne 1 ]]; then + echo " ABWEICHUNG: $target_path" >&2 + echo " Ziel hat einen anderen Hash. Mit --force überschreiben." >&2 problems=$((problems + 1)) continue fi - if [[ -f "$target_path" ]]; then - target_sha="$(sha256sum "$target_path" | cut -d' ' -f1)" - if [[ "$target_sha" == "$expected_sha" ]]; then - echo " OK (bereits synchronisiert)" - continue - fi - if [[ "$FORCE" -ne 1 ]]; then - echo " ABWEICHUNG: $target_path" >&2 - echo " Ziel hat einen anderen Hash. Mit --force überschreiben." >&2 + if [[ -f "$source_path" ]]; then + if ! matches_hash "$source_path" "$expected_sha" "$expected_bytes"; then + echo " HASH-FEHLER (Quelle): $source_path" >&2 + echo " Manifest und Workbench-Datei passen nicht zusammen." >&2 problems=$((problems + 1)) continue fi + mkdir -p "$(dirname "$target_path")" + cp "$source_path" "$target_path" + if ! matches_hash "$target_path" "$expected_sha" "$expected_bytes"; then + echo " KOPIERFEHLER: $target_path" >&2 + problems=$((problems + 1)) + continue + fi + echo " Kopiert (Workbench): $relative_target" + changed=$((changed + 1)) + continue fi + if [[ -z "$remote_path" ]]; then + echo " FEHLT: weder Workbench noch FTP-Pfad vorhanden." >&2 + problems=$((problems + 1)) + continue + fi + + ensure_remote + tmp="$(mktemp "${TMPDIR:-/tmp}/rinkplanner-asset.XXXXXX")" + echo " Workbench fehlt, lade aus FTP: $FTP_ASSET_DIR/$remote_path" + if ! remote_download "$remote_path" "$tmp"; then + echo " DOWNLOAD FEHLGESCHLAGEN." >&2 + rm -f "$tmp" + problems=$((problems + 1)) + continue + fi + if ! matches_hash "$tmp" "$expected_sha" "$expected_bytes"; then + echo " HASH-FEHLER (FTP): $remote_path" >&2 + rm -f "$tmp" + problems=$((problems + 1)) + continue + fi mkdir -p "$(dirname "$target_path")" - cp "$source_path" "$target_path" - target_sha="$(sha256sum "$target_path" | cut -d' ' -f1)" - if [[ "$target_sha" != "$expected_sha" ]]; then - echo " KOPIERFEHLER: $target_path" >&2 - problems=$((problems + 1)) - continue - fi - - echo " Kopiert: $relative_target" - copied=$((copied + 1)) + mv "$tmp" "$target_path" + chmod 644 "$target_path" + echo " Geladen (FTP): $relative_target" + changed=$((changed + 1)) done if [[ "$problems" -gt 0 ]]; then echo "" >&2 echo "$problems Asset(s) nicht in Ordnung." >&2 - if [[ "$MODE" == "check" ]]; then - echo "Mit tools/sync_assets.sh --sync kopieren." >&2 - fi exit 1 fi -if [[ "$MODE" == "sync" && "$copied" -gt 0 ]]; then +if [[ "$MODE" == "sync" && "$changed" -gt 0 ]]; then if [[ -x "$GODOT" ]]; then echo "Godot-Import..." "$GODOT" --headless --path "$PROJECT_DIR" --import >/dev/null