feat: import Landwelle v1.5.62 source

This commit is contained in:
root committed 2026-09-24 11:27:18 +02:00
1 parent e521a98535
commit ac1e072f4e
496 files changed
+74796 -34

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}"
BACKUP_DIR="${LANDWELLE_BACKUP_DIR:-/var/backups/landwelle}"
RETENTION_DAYS="${LANDWELLE_BACKUP_RETENTION_DAYS:-14}"
[[ $EUID -eq 0 ]] || { echo "Bitte mit sudo starten." >&2; exit 1; }
[[ -r "$ENV_FILE" ]] || { echo "Environment-Datei nicht lesbar: $ENV_FILE" >&2; exit 1; }
set -a; source "$ENV_FILE"; set +a
[[ -n "${DATABASE_URL:-}" ]] || { echo "DATABASE_URL fehlt." >&2; exit 1; }
command -v pg_dump >/dev/null || { echo "pg_dump fehlt (postgresql-client installieren)." >&2; exit 1; }
install -d -o root -g landwelle -m 750 "$BACKUP_DIR"
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
TARGET="$BACKUP_DIR/landwelle-$STAMP.dump"
pg_dump --dbname="$DATABASE_URL" --format=custom --compress=9 --file="$TARGET.tmp"
mv "$TARGET.tmp" "$TARGET"
sha256sum "$TARGET" > "$TARGET.sha256"
chmod 640 "$TARGET" "$TARGET.sha256"
find "$BACKUP_DIR" -type f -name 'landwelle-*.dump*' -mtime "+$RETENTION_DAYS" -delete
printf 'Backup erstellt: %s\n' "$TARGET"
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
mkdir -p dist
# Das Firebase-Quellupdate kann auf älteren Installationen ohne vollständige
# go.sum liegen. Tidy ergänzt reproduzierbar die benötigten Modulprüfsummen.
go mod tidy
go mod download
go mod verify
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
go build -trimpath -ldflags="-s -w" \
-o dist/landwelle-migrate-linux-arm64 ./cmd/migrate
echo "Erstellt: dist/landwelle-migrate-linux-arm64"
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
mkdir -p "$ROOT_DIR/dist"
cd "$ROOT_DIR"
# Startkritische ServeMux-Routen vor dem Build statisch prüfen.
# contentPages() registriert seine Slugs später dynamisch als "/"+slug. Deshalb
# reicht ein grep nach wörtlichen HandleFunc-Aufrufen nicht aus: Ein Slug darf
# nicht gleichzeitig explizit in main.go registriert sein.
EXPLICIT_PUBLIC_ROUTES="$(grep -oE 'mux\.HandleFunc\("/[^"]+"' main.go | sed -E 's/.*HandleFunc\("([^"]+)"/\1/' | sort -u)"
CONTENT_PAGE_SLUGS="$(sed -n '/^func contentPages()/,/^}/p' content.go | sed -nE 's/^[[:space:]]*"([^"]+)"[[:space:]]*:.*/\1/p')"
while IFS= read -r slug; do
[[ -z "$slug" ]] && continue
if grep -Fxq "/$slug" <<<"$EXPLICIT_PUBLIC_ROUTES"; then
printf 'Build abgebrochen: Route /%s wird sowohl explizit als auch dynamisch über contentPages() registriert.\n' "$slug" >&2
exit 1
fi
done <<<"$CONTENT_PAGE_SLUGS"
# Alte Build-Artefakte vor einem neuen Build entfernen. So kann ein fehlgeschlagener
# Build niemals versehentlich ein altes Portal-Binary für das Update stehen lassen.
rm -f "$ROOT_DIR/dist/landwelle-portal-linux-arm64" "$ROOT_DIR/dist/landwelle-adminpass-linux-arm64"
# Das Firebase-Quellupdate kann auf älteren Installationen ohne vollständige
# go.sum liegen. Tidy ergänzt reproduzierbar die benötigten Modulprüfsummen.
go mod tidy
go mod download
go mod verify
COMMIT="$(git rev-parse --short=12 HEAD 2>/dev/null || printf unknown)"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
LDFLAGS="-s -w -X main.buildCommit=$COMMIT -X main.buildTime=$BUILD_TIME"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="$LDFLAGS" -o dist/landwelle-portal-linux-arm64 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="-s -w" -o dist/landwelle-adminpass-linux-arm64 ./cmd/adminpass
SOURCE_VERSION="$(sed -nE 's/^[[:space:]]*applicationVersion[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' main.go | head -n1)"
BUILT_VERSION="$("$ROOT_DIR/dist/landwelle-portal-linux-arm64" --version 2>/dev/null || true)"
if [[ -z "$SOURCE_VERSION" || "$BUILT_VERSION" != "Landwelle v$SOURCE_VERSION" ]]; then
printf 'Build abgebrochen: Binary-Version passt nicht zum Quellstand (Quelle: %s, Binary: %s).\n' "${SOURCE_VERSION:-unbekannt}" "${BUILT_VERSION:-unbekannt}" >&2
rm -f "$ROOT_DIR/dist/landwelle-portal-linux-arm64"
exit 1
fi
printf '%s\n' "ARM64-Portal erstellt: $ROOT_DIR/dist/landwelle-portal-linux-arm64" "Version: $BUILT_VERSION" "Commit: $COMMIT" "Build-Zeit: $BUILD_TIME"
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ASSETS="$ROOT/web/assets"
mkdir -p "$ASSETS"
cp "$1" "$ASSETS/Landwelle-Player-Windows-amd64.exe"
cp "$2" "$ASSETS/Landwelle-Player-Linux-amd64.AppImage"
cp "$3" "$ASSETS/Landwelle-Player-macOS-amd64.zip"
echo "Desktop-Releases wurden in web/assets übernommen."
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then echo "Bitte mit sudo ausführen." >&2; exit 1; fi
SOURCE=${1:-}
if [[ -z "$SOURCE" || ! -f "$SOURCE" ]]; then echo "Aufruf: sudo $0 /pfad/firebase-service-account.json" >&2; exit 1; fi
python3 - "$SOURCE" <<'PY'
import json,sys
with open(sys.argv[1],encoding='utf-8') as f: d=json.load(f)
for key in ('type','project_id','private_key','client_email','token_uri'):
if not d.get(key): raise SystemExit(f'Pflichtfeld fehlt: {key}')
if d['type']!='service_account': raise SystemExit('Keine Firebase Service-Account-Datei')
print('Firebase-Projekt:',d['project_id'])
PY
install -d -o root -g landwelle -m 0750 /etc/landwelle
install -o root -g landwelle -m 0640 "$SOURCE" /etc/landwelle/firebase-service-account.json
ENV=/etc/landwelle/landwelle.env
touch "$ENV"; chown root:landwelle "$ENV"; chmod 0640 "$ENV"
if grep -q '^FIREBASE_SERVICE_ACCOUNT_FILE=' "$ENV"; then
sed -i 's|^FIREBASE_SERVICE_ACCOUNT_FILE=.*|FIREBASE_SERVICE_ACCOUNT_FILE=/etc/landwelle/firebase-service-account.json|' "$ENV"
else
echo 'FIREBASE_SERVICE_ACCOUNT_FILE=/etc/landwelle/firebase-service-account.json' >> "$ENV"
fi
echo "Firebase Service Account sicher installiert."
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_DIR"
MIGRATOR="${MIGRATOR:-$PROJECT_DIR/dist/landwelle-migrate-linux-arm64}"
ENV_FILE="${ENV_FILE:-/etc/landwelle/landwelle.env}"
if [[ ! -x "$MIGRATOR" ]]; then
echo "Migrator nicht gefunden oder nicht ausführbar: $MIGRATOR" >&2
exit 1
fi
exec "$MIGRATOR" \
--env-file "$ENV_FILE" \
--dir "$PROJECT_DIR/migrations" \
--archive-dir "$PROJECT_DIR/migrations/applied" \
"$@"
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}"
BACKUP="${1:-}"
[[ $EUID -eq 0 ]] || { echo "Bitte mit sudo starten." >&2; exit 1; }
[[ -n "$BACKUP" && -f "$BACKUP" ]] || { echo "Aufruf: sudo $0 /pfad/backup.dump" >&2; exit 1; }
set -a; source "$ENV_FILE"; set +a
[[ -n "${DATABASE_URL:-}" ]] || { echo "DATABASE_URL fehlt." >&2; exit 1; }
command -v pg_restore >/dev/null || { echo "pg_restore fehlt." >&2; exit 1; }
systemctl stop landwelle-radio
pg_restore --dbname="$DATABASE_URL" --clean --if-exists --no-owner --no-privileges "$BACKUP"
systemctl start landwelle-radio
curl -fsS http://127.0.0.1:2200/ready >/dev/null
printf 'Wiederherstellung erfolgreich: %s\n' "$BACKUP"
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}"
NAME="${1:-}"; FEED_URL="${2:-}"; MODE="${3:-review}"
[[ -n "$NAME" && -n "$FEED_URL" ]] || { echo "Aufruf: $0 'Quellenname' 'https://.../feed.xml' [review|automatic]" >&2; exit 1; }
[[ "$MODE" == "review" || "$MODE" == "automatic" ]] || { echo "Modus muss review oder automatic sein." >&2; exit 1; }
set -a; source "$ENV_FILE"; set +a
psql "$DATABASE_URL" --set ON_ERROR_STOP=1 --set name="$NAME" --set url="$FEED_URL" --set mode="$MODE" --no-psqlrc <<SQL
SET search_path TO landwelle,public;
INSERT INTO feed_sources(name,feed_url,source_type,enabled,publication_mode,rights_status,allow_title,allow_summary,allow_image)
VALUES (:'name',:'url','auto',true,:'mode','review_required',true,false,false)
ON CONFLICT(feed_url) DO UPDATE SET name=EXCLUDED.name,enabled=true,publication_mode=EXCLUDED.publication_mode,updated_at=now();
SQL
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="/etc/landwelle/landwelle.env"
HASHER="/opt/landwelle/landwelle-adminpass"
ADMIN_USER="${LANDWELLE_ADMIN_USER:-admin}"
if [[ $EUID -ne 0 ]]; then
echo "Bitte mit sudo starten: sudo ./scripts/setup-admin-on-pi.sh" >&2
exit 1
fi
if [[ ! -x "$HASHER" ]]; then
echo "Passwortwerkzeug fehlt: $HASHER. Installiere zuerst v11 mit update-portal-on-pi.sh." >&2
exit 1
fi
read -rsp "Neues Admin-Passwort (mindestens 12 Zeichen): " PASSWORD
echo
read -rsp "Admin-Passwort wiederholen: " PASSWORD_REPEAT
echo
if [[ "$PASSWORD" != "$PASSWORD_REPEAT" ]]; then
echo "Die Passwörter stimmen nicht überein." >&2
exit 1
fi
HASH=$(LANDWELLE_NEW_ADMIN_PASSWORD="$PASSWORD" "$HASHER")
unset PASSWORD PASSWORD_REPEAT
install -d -o root -g root -m 750 /etc/landwelle
touch "$ENV_FILE"
TMP=$(mktemp)
grep -vE '^(LANDWELLE_ADMIN_USER|LANDWELLE_ADMIN_PASSWORD|LANDWELLE_ADMIN_PASSWORD_HASH)=' "$ENV_FILE" > "$TMP" || true
{
cat "$TMP"
echo
echo "# Landwelle Adminbereich"
echo "LANDWELLE_ADMIN_USER=$ADMIN_USER"
echo "LANDWELLE_ADMIN_PASSWORD_HASH=$HASH"
echo "LANDWELLE_ADMIN_SESSION_TTL=12h"
} > "$ENV_FILE"
rm -f "$TMP"
chown root:root "$ENV_FILE"
chmod 600 "$ENV_FILE"
systemctl restart landwelle-radio
for _ in {1..20}; do
if curl -fsS http://127.0.0.1:2200/health >/dev/null 2>&1; then
echo "Adminzugang ist eingerichtet: /admin"
exit 0
fi
sleep 1
done
echo "Dienst wurde nicht rechtzeitig bereit. Logs:" >&2
journalctl -u landwelle-radio -n 80 --no-pager >&2
exit 1
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}"
SERVICE="${LANDWELLE_SERVICE:-landwelle-radio}"
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
echo "Bitte als root bzw. mit sudo ausführen." >&2
exit 1
fi
install -d -m 0750 "$(dirname "$ENV_FILE")"
touch "$ENV_FILE"
if command -v openssl >/dev/null 2>&1; then
TOKEN="$(openssl rand -hex 32)"
else
TOKEN="$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')"
fi
TMP="$(mktemp)"
trap 'rm -f "$TMP"' EXIT
grep -v '^LANDWELLE_CRON_TOKEN=' "$ENV_FILE" > "$TMP" || true
printf '\n# Zentraler KeyHelp-Cron für KI & Automatisierung\nLANDWELLE_CRON_TOKEN=%s\n' "$TOKEN" >> "$TMP"
cat "$TMP" > "$ENV_FILE"
if getent group landwelle >/dev/null 2>&1; then
chown root:landwelle "$ENV_FILE"
else
chown root:root "$ENV_FILE"
fi
chmod 0640 "$ENV_FILE"
if systemctl list-unit-files "${SERVICE}.service" >/dev/null 2>&1; then
systemctl restart "$SERVICE"
fi
echo "LANDWELLE_CRON_TOKEN wurde neu erzeugt und gespeichert."
echo "Öffne jetzt /admin/ai/auto-tasks. Dort wird der fertige KeyHelp-Befehl angezeigt."
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "Bitte mit sudo starten: sudo ./scripts/update-migrations-on-pi.sh" >&2
exit 1
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TARGET="${LANDWELLE_DIR:-/opt/landwelle}"
SERVICE="${LANDWELLE_SERVICE:-landwelle-radio}"
APP_USER="${LANDWELLE_USER:-landwelle}"
APP_GROUP="${LANDWELLE_GROUP:-landwelle}"
ENV_FILE="${LANDWELLE_ENV_FILE:-/etc/landwelle/landwelle.env}"
if ! id "$APP_USER" >/dev/null 2>&1; then
echo "Systembenutzer $APP_USER existiert nicht." >&2
exit 1
fi
if [[ ! -f "$ENV_FILE" ]]; then
echo "Konfiguration fehlt: $ENV_FILE" >&2
exit 1
fi
if ! command -v psql >/dev/null 2>&1; then
echo "PostgreSQL-Client wird einmalig installiert ..."
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-client
fi
install -d -o root -g root -m 755 "$TARGET/dist" "$TARGET/scripts"
install -d -o "$APP_USER" -g "$APP_GROUP" -m 750 \
"$TARGET/migrations" "$TARGET/migrations/applied"
install -o root -g root -m 755 \
"$ROOT/dist/landwelle-migrate-linux-arm64" \
"$TARGET/dist/landwelle-migrate-linux-arm64"
install -o root -g root -m 755 \
"$ROOT/scripts/migrate.sh" \
"$TARGET/scripts/migrate.sh"
# Bereinigt die beiden kurzzeitig falsch nummerierten Landwelle-Zuhause-Dateien.
# 0039 und 0040 sind im produktiven Stand bereits durch andere Fachmigrationen belegt.
# Die konsolidierte Zuhause-Navigation verwendet deshalb die bereits eingeführte Nummer 9000.
rm -f \
"$ROOT/migrations/0039_landwelle_zuhause_navigation.sql" \
"$ROOT/migrations/0040_landwelle_zuhause_navigation.sql" \
"$TARGET/migrations/0039_landwelle_zuhause_navigation.sql" \
"$TARGET/migrations/0040_landwelle_zuhause_navigation.sql"
shopt -s nullglob
migration_files=("$ROOT"/migrations/*.sql)
if (( ${#migration_files[@]} > 0 )); then
for migration in "${migration_files[@]}"; do
install -o "$APP_USER" -g "$APP_GROUP" -m 640 \
"$migration" "$TARGET/migrations/$(basename "$migration")"
done
fi
# Der Dienstbenutzer braucht Leserechte auf die Environment-Datei und
# Ausführungsrecht auf allen übergeordneten Verzeichnissen, um sie öffnen zu können.
ENV_DIR="$(dirname "$ENV_FILE")"
install -d -o root -g "$APP_GROUP" -m 750 "$ENV_DIR"
chown root:"$APP_GROUP" "$ENV_FILE"
chmod 640 "$ENV_FILE"
if ! runuser -u "$APP_USER" -- test -r "$ENV_FILE"; then
echo "Environment-Datei ist für $APP_USER nicht lesbar: $ENV_FILE" >&2
echo "Berechtigungen:" >&2
namei -l "$ENV_FILE" >&2 || true
exit 1
fi
if ! grep -q '^DATABASE_URL=' "$ENV_FILE"; then
echo "DATABASE_URL fehlt in $ENV_FILE" >&2
exit 1
fi
echo "Starte PostgreSQL-Migrationen ..."
runuser -u "$APP_USER" -- \
"$TARGET/scripts/migrate.sh" \
--env-file "$ENV_FILE" \
--dir "$TARGET/migrations" \
--archive-dir "$TARGET/migrations/applied"
if systemctl list-unit-files "$SERVICE.service" >/dev/null 2>&1; then
systemctl restart "$SERVICE"
systemctl --no-pager --full status "$SERVICE" || true
fi
echo
echo "Fertig. Erfolgreiche SQL-Dateien liegen unter:"
echo " $TARGET/migrations/applied"
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SOURCE_BINARY="$PROJECT_DIR/dist/landwelle-portal-linux-arm64"
SOURCE_ADMINPASS="$PROJECT_DIR/dist/landwelle-adminpass-linux-arm64"
TARGET_DIR="/opt/landwelle"
TARGET_BINARY="$TARGET_DIR/landwelle-portal"
SOURCE_SERVICE="$PROJECT_DIR/deploy/landwelle-radio.service"
TARGET_SERVICE="/etc/systemd/system/landwelle-radio.service"
SERVICE="landwelle-radio"
if [[ $EUID -ne 0 ]]; then
echo "Bitte mit sudo starten: sudo ./scripts/update-portal-on-pi.sh" >&2
exit 1
fi
if [[ ! -f "$SOURCE_BINARY" ]]; then
echo "ARM64-Binary fehlt: $SOURCE_BINARY" >&2
exit 1
fi
EXPECTED_VERSION="$($SOURCE_BINARY --version 2>/dev/null || true)"
if [[ -z "$EXPECTED_VERSION" ]]; then
echo "Version der ARM64-Binary konnte nicht ermittelt werden: $SOURCE_BINARY" >&2
exit 1
fi
SOURCE_VERSION="$(sed -nE 's/^[[:space:]]*applicationVersion[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' "$PROJECT_DIR/main.go" | head -n1)"
if [[ -z "$SOURCE_VERSION" ]]; then
echo "Quellversion konnte nicht aus $PROJECT_DIR/main.go ermittelt werden." >&2
exit 1
fi
if [[ "$EXPECTED_VERSION" != "Landwelle v$SOURCE_VERSION" ]]; then
echo "Update abgebrochen: dist-Binary ist veraltet oder stammt aus einem anderen Quellstand." >&2
echo "Quellstand: Landwelle v$SOURCE_VERSION" >&2
echo "dist-Binary: $EXPECTED_VERSION" >&2
echo "Bitte zuerst ausführen: ./scripts/build-pi.sh" >&2
exit 1
fi
if [[ ! -f "$SOURCE_ADMINPASS" ]]; then
echo "Admin-Passwortwerkzeug fehlt: $SOURCE_ADMINPASS" >&2
exit 1
fi
install -d -o root -g root -m 755 "$TARGET_DIR"
install -d -o landwelle -g landwelle -m 750 /var/lib/landwelle
if [[ -f "$SOURCE_SERVICE" ]]; then
install -o root -g root -m 644 "$SOURCE_SERVICE" "$TARGET_SERVICE"
systemctl daemon-reload
fi
BACKUP_BINARY=""
if [[ -f "$TARGET_BINARY" ]]; then
BACKUP_BINARY="$TARGET_BINARY.backup-$(date +%Y%m%d-%H%M%S)"
cp -a "$TARGET_BINARY" "$BACKUP_BINARY"
fi
systemctl stop "$SERVICE"
install -o root -g root -m 755 "$SOURCE_BINARY" "$TARGET_BINARY.new"
mv -f "$TARGET_BINARY.new" "$TARGET_BINARY"
install -o root -g root -m 755 "$SOURCE_ADMINPASS" "$TARGET_DIR/landwelle-adminpass"
systemctl start "$SERVICE"
for _ in {1..20}; do
if curl -fsS http://127.0.0.1:2200/ready >/dev/null 2>&1; then
ACTIVE_VERSION="$(curl -fsS http://127.0.0.1:2200/version 2>/dev/null | tr -d '\r\n' || true)"
if [[ "$ACTIVE_VERSION" != "$EXPECTED_VERSION" ]]; then
echo "Versionsprüfung fehlgeschlagen: erwartet $EXPECTED_VERSION, aktiv ${ACTIVE_VERSION:-unbekannt}" >&2
journalctl -u "$SERVICE" -n 80 --no-pager >&2
exit 1
fi
echo "$ACTIVE_VERSION ist aktiv: http://127.0.0.1:2200"
if ! grep -qE '^LANDWELLE_ADMIN_PASSWORD(_HASH)?=' /etc/landwelle/landwelle.env 2>/dev/null; then
echo "Adminzugang noch einrichten: sudo ./scripts/setup-admin-on-pi.sh"
fi
exit 0
fi
sleep 1
done
echo "Readiness-Check fehlgeschlagen. Starte automatisches Rollback." >&2
journalctl -u "$SERVICE" -n 80 --no-pager >&2
if [[ -n "$BACKUP_BINARY" && -f "$BACKUP_BINARY" ]]; then
systemctl stop "$SERVICE" || true
install -o root -g root -m 755 "$BACKUP_BINARY" "$TARGET_BINARY"
systemctl start "$SERVICE"
sleep 2
if curl -fsS http://127.0.0.1:2200/ready >/dev/null 2>&1; then
echo "Rollback erfolgreich: $BACKUP_BINARY" >&2
else
echo "Rollback konnte den Dienst nicht wiederherstellen." >&2
fi
fi
exit 1
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -Eeuo pipefail
LOCAL_BASE="${LANDWELLE_LOCAL_API_BASE:-http://127.0.0.1:2200}"
PUBLIC_BASE="${LANDWELLE_PUBLIC_API_BASE:-https://api.landwelle.de}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
check_endpoint() {
local label="$1"
local url="$2"
local expected_content_type="$3"
local headers="$TMP_DIR/${label}.headers"
local body="$TMP_DIR/${label}.body"
local status
status="$(curl -sS --connect-timeout 5 --max-time 20 -D "$headers" -o "$body" -w '%{http_code}' "$url" || true)"
printf '%-28s %s HTTP %s\n' "$label" "$url" "$status"
if [[ "$status" != "200" ]]; then
echo " FEHLER: Erwartet wurde HTTP 200."
if [[ -s "$body" ]]; then
echo " Antwort: $(tr '\n' ' ' < "$body" | head -c 240)"
echo
fi
return 1
fi
if ! grep -qi "content-type:.*${expected_content_type}" "$headers"; then
echo " FEHLER: Unerwarteter Content-Type."
sed -n '1,20p' "$headers" | sed 's/^/ /'
return 1
fi
echo " OK"
}
local_ok=0
public_ok=0
if check_endpoint "lokales Bootstrap" "$LOCAL_BASE/v1/app/bootstrap" "application/json"; then
local_ok=1
fi
if check_endpoint "öffentlicher Bootstrap" "$PUBLIC_BASE/v1/app/bootstrap" "application/json"; then
public_ok=1
fi
check_endpoint "öffentliche API-Wurzel" "$PUBLIC_BASE/v1" "application/json" || true
check_endpoint "öffentlicher Healthcheck" "$PUBLIC_BASE/health" "application/json" || true
if [[ "$local_ok" -eq 1 && "$public_ok" -eq 0 ]]; then
cat <<'MSG'
DIAGNOSE:
Die Go-API läuft lokal, aber die API-Subdomain reicht /v1 nicht weiter.
In KeyHelp bei api.landwelle.de das vollständige Fragment
„deploy/keyhelp-api-subdomain-https.conf“ in „Anweisungen für HTTPS“ eintragen,
speichern und die Webserver-Konfiguration neu laden lassen.
MSG
exit 2
fi
if [[ "$local_ok" -ne 1 ]]; then
cat <<'MSG'
DIAGNOSE:
Die API antwortet bereits lokal nicht korrekt. Portalstatus prüfen:
systemctl status landwelle-radio --no-pager
curl -i http://127.0.0.1:2200/v1/app/bootstrap
MSG
exit 3
fi
if [[ "$public_ok" -ne 1 ]]; then
exit 4
fi
echo
echo "Landwelle API-Subdomain ist korrekt erreichbar."
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -Eeuo pipefail
LOCAL_BASE="${LANDWELLE_LOCAL_API_BASE:-http://127.0.0.1:2200}"
PUBLIC_BASE="${LANDWELLE_PUBLIC_API_BASE:-https://api.landwelle.de}"
MUTATING="${LANDWELLE_VERIFY_MUTATING:-0}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
json_status() {
local method="$1" url="$2" body="${3:-}" headers="$TMP_DIR/h" output="$TMP_DIR/b" status
if [[ -n "$body" ]]; then
status="$(curl -sS --connect-timeout 5 --max-time 30 -X "$method" -H 'Content-Type: application/json' -D "$headers" -o "$output" -w '%{http_code}' --data "$body" "$url" || true)"
else
status="$(curl -sS --connect-timeout 5 --max-time 30 -X "$method" -D "$headers" -o "$output" -w '%{http_code}' "$url" || true)"
fi
printf '%s' "$status"
}
assert_json_status() {
local label="$1" expected="$2" method="$3" url="$4" body="${5:-}" status
status="$(json_status "$method" "$url" "$body")"
printf '%-34s HTTP %s\n' "$label" "$status"
if [[ "$status" != "$expected" ]]; then
echo " FEHLER: erwartet HTTP $expected"
cat "$TMP_DIR/b" 2>/dev/null || true
echo
return 1
fi
if ! grep -qi 'content-type:.*application/json' "$TMP_DIR/h"; then
echo " FEHLER: Antwort ist nicht application/json"
return 1
fi
}
assert_json_status "lokal /v1/wishes GET" 405 GET "$LOCAL_BASE/v1/wishes"
assert_json_status "öffentlich /v1/wishes GET" 405 GET "$PUBLIC_BASE/v1/wishes"
if [[ "$MUTATING" != "1" ]]; then
cat <<'MSG'
Nur nicht-mutierende Routentests wurden ausgeführt.
Für die im Auftrag verlangten POST-Tests einmal bewusst ausführen:
LANDWELLE_VERIFY_MUTATING=1 ./scripts/verify-app-api-production.sh
Dabei werden zwei Test-Musikwünsche angelegt und anschließend eine temporäre App-Installation registriert und wieder gelöscht.
MSG
exit 0
fi
wish='{"name":"App Test","place":"Visselhövede","artist":"Testinterpret","song":"Testtitel","message":"API-Verifikation aus dem Landwelle-Portal","publish_consent":true}'
assert_json_status "lokaler Wunschbox-POST" 201 POST "$LOCAL_BASE/v1/wishes" "$wish"
assert_json_status "öffentlicher Wunschbox-POST" 201 POST "$PUBLIC_BASE/v1/wishes" "$wish"
installation='{"platform":"android","device_class":"unknown","distribution_channel":"development","app_version":"1.3.2","app_build":"8","os_version":"Android Test","locale":"de-DE","timezone":"Europe/Berlin"}'
status="$(json_status POST "$PUBLIC_BASE/v1/installations" "$installation")"
printf '%-34s HTTP %s\n' "Installation registrieren" "$status"
[[ "$status" == "201" ]] || { cat "$TMP_DIR/b"; exit 1; }
python3 - "$TMP_DIR/b" "$TMP_DIR/installation.env" <<'PY'
import json,sys
p=json.load(open(sys.argv[1]))['data']
with open(sys.argv[2],'w') as f:
f.write('INSTALLATION_ID='+p['installation_id']+'\n')
f.write('INSTALLATION_TOKEN='+p['installation_token']+'\n')
PY
# shellcheck disable=SC1090
source "$TMP_DIR/installation.env"
AUTH="Authorization: Installation $INSTALLATION_TOKEN"
status="$(curl -sS --connect-timeout 5 --max-time 30 -H "$AUTH" -D "$TMP_DIR/h" -o "$TMP_DIR/b" -w '%{http_code}' "$PUBLIC_BASE/v1/installations/$INSTALLATION_ID/topics" || true)"
printf '%-34s HTTP %s\n' "Push-Themen laden" "$status"
[[ "$status" == "200" ]] || { cat "$TMP_DIR/b"; exit 1; }
for topic in breaking-news niedersachsen program; do
grep -q "\"slug\":\"$topic\"" "$TMP_DIR/b" || { echo "Thema $topic fehlt"; exit 1; }
done
status="$(curl -sS --connect-timeout 5 --max-time 30 -X DELETE -H "$AUTH" -o /dev/null -w '%{http_code}' "$PUBLIC_BASE/v1/installations/$INSTALLATION_ID" || true)"
printf '%-34s HTTP %s\n' "Testinstallation löschen" "$status"
[[ "$status" == "204" ]] || exit 1
echo
echo "Landwelle Wunschbox-/Installations-API ist lokal und öffentlich erreichbar."
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
ENABLE=false
if [[ ${1:-} == "--enable" ]]; then
ENABLE=true
elif [[ $# -gt 0 ]]; then
echo "Aufruf: $0 [--enable]" >&2
exit 2
fi
CREDENTIAL_FILE="${FIREBASE_SERVICE_ACCOUNT_FILE:-/etc/landwelle/firebase-service-account.json}"
if [[ "$CREDENTIAL_FILE" != /* ]]; then
echo "FIREBASE_SERVICE_ACCOUNT_FILE muss absolut sein." >&2
exit 1
fi
if [[ ! -r "$CREDENTIAL_FILE" ]]; then
echo "Firebase-Service-Account-Datei ist nicht lesbar." >&2
exit 1
fi
if ! command -v gcloud >/dev/null 2>&1; then
echo "gcloud fehlt. Prüfe die Firebase Cloud Messaging API in der Firebase-/Google-Cloud-Konsole." >&2
exit 1
fi
PROJECT_ID="$(python3 - "$CREDENTIAL_FILE" <<'PY'
import json, sys
with open(sys.argv[1], encoding='utf-8') as handle:
payload = json.load(handle)
project = str(payload.get('project_id', '')).strip()
if not project:
raise SystemExit('project_id fehlt')
print(project)
PY
)"
if $ENABLE; then
gcloud services enable fcm.googleapis.com --project "$PROJECT_ID"
fi
ENABLED="$(gcloud services list --enabled --project "$PROJECT_ID" --filter='config.name=fcm.googleapis.com' --format='value(config.name)')"
if [[ "$ENABLED" != "fcm.googleapis.com" ]]; then
echo "Firebase Cloud Messaging API ist für Projekt $PROJECT_ID nicht als aktiviert erkennbar." >&2
echo "Aktivieren: $0 --enable" >&2
exit 1
fi
echo "Firebase Cloud Messaging API ist aktiviert: project=$PROJECT_ID service=fcm.googleapis.com"
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
forbidden=(
"firebase_push_stub.go"
)
for rel in "${forbidden[@]}"; do
if [[ -e "$ROOT_DIR/$rel" ]]; then
printf 'FEHLER: Test-/Stub-Datei darf nicht im Produktivquellstand liegen: %s\n' "$rel" >&2
printf 'Bitte einen sauberen COMPLETE-Quellstand verwenden.\n' >&2
exit 1
fi
done
printf 'Release-Quellstand geprüft: keine verbotenen Firebase-Test-Stubs gefunden.\n'