#!/usr/bin/env bash # Installiert Nexus auf srv04. Läuft AUF srv04 und braucht root (sudo). # # Was es tut (und nichts anderes): # 1. legt /srv/apps/nexus/{releases/,data} an (Besitzer svc-scotty) # 2. kopiert das Binary nach releases//nexus und schaltet den # Symlink /srv/apps/nexus/current darauf um (die alte Version bleibt) # 3. legt /srv/apps/nexus/config.toml an, NUR wenn es sie noch nicht gibt # 4. schreibt /etc/systemd/system/nexus.service und lädt systemd neu # Es startet und aktiviert den Dienst NICHT, außer mit --start bzw. --enable. # Es ändert keine bestehende Engine-Installation und keine Modelle. # # Aufruf: sudo VERSION=0.1.0-dev bash install.sh [--start] [--enable] # sudo bash install.sh --rollback (vorherige Version, Dienst neu starten) set -euo pipefail USER_NAME="svc-scotty" BASE="/srv/apps/nexus" UNIT="/etc/systemd/system/nexus.service" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LISTEN="${LISTEN:-127.0.0.1:8080}" [ "$(id -u)" -eq 0 ] || { echo "Bitte mit sudo ausführen." >&2; exit 1; } id "$USER_NAME" >/dev/null 2>&1 || { echo "Benutzer $USER_NAME fehlt." >&2; exit 1; } as_user() { sudo -u "$USER_NAME" "$@"; } if [ "${1:-}" = "--rollback" ]; then [ -d "$BASE/releases" ] || { echo "Keine Releases unter $BASE/releases." >&2; exit 1; } current="$(basename "$(readlink -f "$BASE/current")")" previous="$(ls -1t "$BASE/releases" | grep -vx "$current" | head -n 1 || true)" [ -n "$previous" ] || { echo "Es gibt keine ältere Version für den Rückfall." >&2; exit 1; } ln -sfn "$BASE/releases/$previous" "$BASE/current.new" mv -T "$BASE/current.new" "$BASE/current" echo "Rückfall: current zeigt jetzt auf $previous (vorher $current)." if systemctl is-active --quiet nexus; then systemctl restart nexus && echo "Dienst neu gestartet."; fi exit 0 fi VERSION="${VERSION:?VERSION fehlt (zum Beispiel VERSION=0.1.0-dev)}" [ -x "$HERE/nexus" ] || { echo "$HERE/nexus fehlt oder ist nicht ausführbar." >&2; exit 1; } "$HERE/nexus" version | grep -q "$VERSION" || { echo "Das Binary meldet nicht die Version $VERSION." >&2; exit 1; } install -d -o "$USER_NAME" -g "$USER_NAME" -m 0755 "$BASE" "$BASE/releases" "$BASE/releases/$VERSION" install -d -o "$USER_NAME" -g "$USER_NAME" -m 0750 "$BASE/data" install -o "$USER_NAME" -g "$USER_NAME" -m 0755 "$HERE/nexus" "$BASE/releases/$VERSION/nexus" ln -sfn "$BASE/releases/$VERSION" "$BASE/current.new" mv -T "$BASE/current.new" "$BASE/current" echo "Version $VERSION installiert, current zeigt darauf." if [ -e "$BASE/config.toml" ]; then echo "config.toml existiert und bleibt unverändert." else cat >"$BASE/config.toml" <"$UNIT" <