FSCash/update.sh
fds2610-bot cf7371fb40 Deploy-Skript update.sh mit DB-Migrationssystem hinzugefügt
Kopiert den git-Stand nach /var/www/html (config.php bleibt unangetastet),
prüft PHP-Syntax vorab und wendet ausstehende Migrationen aus migrations/
über eine schema_migrations-Tracking-Tabelle an. Tests werden ausgeführt,
sobald welche existieren.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-23 15:18:03 +02:00

72 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Deployt den aktuellen git-Stand dieses Projektverzeichnisses in den Webroot
# und wendet danach ausstehende Datenbank-Migrationen an.
#
# Aufruf (im Projektverzeichnis):
# ./update.sh
#
# Optional per Umgebungsvariable überschreibbar:
# WEBROOT=/anderer/pfad ./update.sh
# CONFIG_FILE=/anderer/pfad/config.php ./update.sh
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEBROOT="${WEBROOT:-/var/www/html}"
CONFIG_FILE="${CONFIG_FILE:-$WEBROOT/config.php}"
log() { echo "==> $*"; }
fail() { echo "FEHLER: $*" >&2; exit 1; }
cd "$PROJECT_DIR"
command -v php >/dev/null 2>&1 || fail "php ist nicht installiert bzw. nicht im PATH."
[ -d "$WEBROOT" ] || fail "Webroot $WEBROOT existiert nicht."
[ -w "$WEBROOT" ] || fail "Keine Schreibrechte auf $WEBROOT."
# --- 1. Sicherstellen, dass das Projektverzeichnis sauber ist ---
if ! git diff --quiet || ! git diff --cached --quiet; then
fail "Lokale Änderungen im Projektverzeichnis vorhanden - bitte erst committen oder stashen."
fi
# --- 2. Neuesten Stand holen ---
log "git pull..."
git pull --ff-only
# --- 3. PHP-Syntaxcheck als Sicherheitsnetz vor dem Kopieren ---
log "Prüfe PHP-Syntax..."
while IFS= read -r -d '' file; do
php -l "$file" >/dev/null || fail "Syntaxfehler in $file - es wird nichts kopiert."
done < <(find html -name '*.php' -print0)
# --- 4. Dateien kopieren, config.php bleibt unangetastet ---
log "Kopiere Dateien nach $WEBROOT..."
config_backup=""
if [ -f "$CONFIG_FILE" ]; then
config_backup="$(mktemp)"
cp "$CONFIG_FILE" "$config_backup"
fi
cp -r html/. "$WEBROOT/"
if [ -n "$config_backup" ]; then
cp "$config_backup" "$CONFIG_FILE"
rm -f "$config_backup"
fi
# --- 5. Datenbank-Migrationen ---
if [ -d migrations ] && [ -f migrations/run_migrations.php ]; then
log "Wende Datenbank-Migrationen an..."
php migrations/run_migrations.php "$CONFIG_FILE"
fi
# --- 6. Tests ---
if [ -f tests/run.sh ]; then
log "Führe Tests aus..."
bash tests/run.sh
else
log "Noch keine Tests vorhanden - werden später ergänzt."
fi
log "Update abgeschlossen."