#!/usr/bin/env bash # TrainPulse – Installation in einem Debian-LXC (Proxmox). Im Container als root: # bash deploy/install.sh # Erneut ausführen = Update des Programmcodes (Daten, Karte und Einstellungen bleiben). set -euo pipefail APP=/opt/trainpulse DATA=/var/lib/trainpulse SRC=$(cd "$(dirname "$0")/.." && pwd) BBOX=5.8,45.7,10.6,47.9 # Schweiz mit etwas Rand [ "$(id -u)" = 0 ] || { echo "Bitte als root ausführen" >&2; exit 1; } command -v apt-get >/dev/null || { echo "Nur für Debian/Ubuntu (apt) gedacht" >&2; exit 1; } command -v systemctl >/dev/null || { echo "systemd fehlt – im Proxmox-LXC mit Debian-Template ist es dabei" >&2; exit 1; } mem=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo) [ "$mem" -ge 3500 ] || echo "WARNUNG: nur ${mem} MB RAM – für die Fahrplan-Aufbereitung werden ~4 GB empfohlen" >&2 echo "==> Pakete (Python, Compiler und Bibliotheken für pfaedle, Werkzeuge)" export DEBIAN_FRONTEND=noninteractive apt-get update -qq apt-get install -y -qq python3 python3-venv python3-pip git cmake g++ make \ libzip-dev zlib1g-dev libbz2-dev curl ca-certificates tar >/dev/null echo "==> Programm nach $APP" id trainpulse &>/dev/null || useradd --system --home-dir "$DATA" --shell /usr/sbin/nologin trainpulse mkdir -p "$APP" "$DATA/tiles" rm -rf "$APP/trainpulse" "$APP/web" cp -r "$SRC/trainpulse" "$SRC/web" "$SRC/requirements.txt" "$APP/" [ -d "$APP/.venv" ] || python3 -m venv "$APP/.venv" "$APP/.venv/bin/pip" install -q --upgrade -r "$APP/requirements.txt" if ! command -v pfaedle >/dev/null; then echo "==> pfaedle bauen (Streckenverläufe aus OpenStreetMap, dauert ein paar Minuten)" tmp=$(mktemp -d) git clone -q --depth 1 --recurse-submodules --shallow-submodules https://github.com/ad-freiburg/pfaedle "$tmp/src" cmake -S "$tmp/src" -B "$tmp/build" -DCMAKE_BUILD_TYPE=Release >/dev/null make -C "$tmp/build" -j"$(nproc)" >/dev/null make -C "$tmp/build" install >/dev/null rm -rf "$tmp" fi if ! command -v pmtiles >/dev/null; then echo "==> pmtiles-Werkzeug" url=$(curl -fsSL https://api.github.com/repos/protomaps/go-pmtiles/releases/latest | python3 -c \ 'import json,sys; print(next(a["browser_download_url"] for a in json.load(sys.stdin)["assets"] if a["name"].endswith("Linux_x86_64.tar.gz")))') curl -fsSL "$url" | tar xz -C /usr/local/bin pmtiles fi if [ ! -s "$DATA/tiles/region.pmtiles" ]; then echo "==> Kartenkacheln (OpenStreetMap via Protomaps) für $BBOX" for i in 1 2 3 4 5 6 7; do d=$(date -d "-$i day" +%Y%m%d) if pmtiles extract "https://build.protomaps.com/$d.pmtiles" "$DATA/tiles/region.tmp.pmtiles" --bbox=$BBOX --maxzoom=15; then mv "$DATA/tiles/region.tmp.pmtiles" "$DATA/tiles/region.pmtiles" break fi done [ -s "$DATA/tiles/region.pmtiles" ] || { echo "Kartenkacheln konnten nicht geladen werden" >&2; exit 1; } fi if [ ! -f /etc/trainpulse.env ]; then cat > /etc/trainpulse.env < Dienste" cp "$SRC"/deploy/trainpulse.service "$SRC"/deploy/trainpulse-update.service "$SRC"/deploy/trainpulse-update.timer /etc/systemd/system/ systemctl daemon-reload systemctl enable --now trainpulse-update.timer systemctl enable trainpulse.service systemctl restart trainpulse.service systemctl start --no-block trainpulse-update.service ip=$(hostname -I | awk '{print $1}') cat <