feat: FTP-Spiegel fuer externe 3D-Assets
- --publish laedt Workbench-Dateien per FTPS hoch und verifiziert sie durch Rueckdownload und SHA-256 - --sync laedt fehlende Assets vom Server, wenn die Workbench fehlt - Manifest um remote-Pfad ergaenzt, Manifest-Test auf 53 Assertions - Doku, Architektur (D13) und Roadmap aktualisiert
This commit is contained in:
parent
8861cbae92
commit
697274ce1b
7 changed files with 494 additions and 104 deletions
|
|
@ -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: <repo>/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: <ROOT>/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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue