Files
Wegwichtel/scripts/upload-presentation-route.sh
T
Florian Zumpe 497b7b8050
Sonarqube Scanner / Prepare environment (push) Successful in 11s
Sonarqube Scanner / Build and test (push) Successful in 29s
Sonarqube Scanner / SonarQube analysis (push) Successful in 1m25s
Sonarqube Scanner / Deploy to Server (push) Successful in 7s
directory cleanup for tests
2026-10-04 08:12:08 +02:00

80 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${1:-https://wegwichtel.de/api}"
GPX_FILE="${2:-}"
JSON_FILE="${3:-}"
if [[ ! -f "$GPX_FILE" || ! -f "$JSON_FILE" ]]; then
echo "Aufruf: $0 <API-Adresse> <GPX-Datei> <JSON-Datei>" >&2
echo "Gib vorhandene Dateien an. Die Beispielstrecken werden nicht mehr mitgeliefert." >&2
exit 2
fi
for command in curl python3; do
command -v "$command" >/dev/null 2>&1 || {
echo "Fehler: $command wird benötigt." >&2
exit 1
}
done
read_json() {
python3 - "$JSON_FILE" "$1" <<'PY'
import json
import sys
with open(sys.argv[1], encoding='utf-8') as handle:
data = json.load(handle)
value = data
for part in sys.argv[2].split('.'):
value = value[int(part)] if part.isdigit() else value[part]
print(value)
PY
}
NAME="$(read_json name)"
DESCRIPTION="$(read_json description)"
echo "Lege Beispielstrecke über $BASE_URL an …"
ROUTE_RESPONSE="$(curl --fail --silent --show-error \
-X POST "$BASE_URL/routes" \
-F "name=$NAME" \
-F "description=$DESCRIPTION" \
-F "gpx=@$GPX_FILE;type=application/gpx+xml")"
ROUTE_ID="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])' <<<"$ROUTE_RESPONSE")"
rollback() {
echo "Upload fehlgeschlagen. Entferne die unvollständige Beispielstrecke $ROUTE_ID …" >&2
curl --fail --silent --show-error -X DELETE "$BASE_URL/routes/$ROUTE_ID" >/dev/null || true
}
trap rollback ERR
POI_COUNT="$(python3 -c 'import json,sys; print(len(json.load(open(sys.argv[1], encoding="utf-8"))["pois"]))' "$JSON_FILE")"
for ((index=0; index<POI_COUNT; index+=1)); do
TITLE="$(read_json "pois.$index.title")"
POI_DESCRIPTION="$(read_json "pois.$index.description")"
LAT="$(read_json "pois.$index.lat")"
LON="$(read_json "pois.$index.lon")"
RADIUS="$(read_json "pois.$index.triggerRadiusM")"
SEQUENCE="$(read_json "pois.$index.sequence")"
curl --fail --silent --show-error \
-X POST "$BASE_URL/routes/$ROUTE_ID/pois" \
-F "title=$TITLE" \
-F "description=$POI_DESCRIPTION" \
-F "lat=$LAT" \
-F "lon=$LON" \
-F "triggerRadiusM=$RADIUS" \
-F "sequence=$SEQUENCE" >/dev/null
echo " Streckenpunkt $((index + 1))/$POI_COUNT: $TITLE"
done
trap - ERR
cat <<EOF
Beispielstrecke erfolgreich angelegt.
Server-ID: $ROUTE_ID
API: $BASE_URL/routes/$ROUTE_ID
Hinweis: POST /routes setzt activated_at nicht. Die Strecke bleibt daher zunächst unveröffentlicht und ist für die serverseitige Prüfung vorgesehen.
EOF