#!/bin/sh # Ein-Befehl-Setup fuer fuesse.sexy β€” installiert bei Bedarf Node.js selbst. # Aufruf: ./install.sh (oder: sh install.sh) set -e echo "" echo "🦢 fuesse.sexy β€” Setup" echo "------------------------" # Root/sudo bestimmen (fuer Systempakete) if [ "$(id -u)" -eq 0 ]; then SUDO="" elif command -v sudo >/dev/null 2>&1; then SUDO="sudo" else SUDO="" fi NODE_MAJOR=20 # LTS install_node() { echo "" echo "πŸ“₯ Node.js nicht gefunden β€” installiere Node ${NODE_MAJOR} automatisch ..." OS="$(uname -s)" if [ "$OS" = "Linux" ]; then if command -v apt-get >/dev/null 2>&1; then export DEBIAN_FRONTEND=noninteractive $SUDO apt-get update $SUDO apt-get install -y ca-certificates curl gnupg curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | $SUDO bash - $SUDO apt-get install -y nodejs elif command -v dnf >/dev/null 2>&1; then curl -fsSL "https://rpm.nodesource.com/setup_${NODE_MAJOR}.x" | $SUDO bash - $SUDO dnf install -y nodejs elif command -v yum >/dev/null 2>&1; then curl -fsSL "https://rpm.nodesource.com/setup_${NODE_MAJOR}.x" | $SUDO bash - $SUDO yum install -y nodejs elif command -v apk >/dev/null 2>&1; then $SUDO apk add --no-cache nodejs npm elif command -v pacman >/dev/null 2>&1; then $SUDO pacman -Sy --noconfirm nodejs npm else echo "❌ Kein bekannter Paketmanager gefunden." echo " Bitte Node.js manuell installieren: https://nodejs.org/" exit 1 fi elif [ "$OS" = "Darwin" ]; then if command -v brew >/dev/null 2>&1; then brew install node else echo "❌ Homebrew nicht gefunden." echo " Bitte Node.js installieren: https://nodejs.org/ (LTS)" exit 1 fi else echo "❌ Unbekanntes System ($OS) β€” bitte Node.js manuell installieren." exit 1 fi } # 1) Node vorhanden? Sonst installieren. if command -v node >/dev/null 2>&1; then echo "βœ… Node gefunden ($(node -v))" else install_node if ! command -v node >/dev/null 2>&1; then echo "❌ Node-Installation fehlgeschlagen. Bitte manuell installieren." exit 1 fi echo "βœ… Node installiert ($(node -v))" fi # 2) npm vorhanden? if ! command -v npm >/dev/null 2>&1; then echo "❌ npm nicht gefunden (sollte mit Node kommen). Bitte npm installieren." exit 1 fi # 3) Abhaengigkeiten installieren echo "" echo "πŸ“¦ Installiere Abhaengigkeiten (npm install) ..." npm install # 4) Server detached starten (laeuft im Hintergrund weiter, auch nach Logout) PIDFILE="server.pid" LOGFILE="server.log" if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE" 2>/dev/null)" 2>/dev/null; then OLD_PID="$(cat "$PIDFILE")" echo "" echo "πŸ”„ Server lΓ€uft bereits (PID $OLD_PID) β€” wird neu gestartet ..." kill "$OLD_PID" 2>/dev/null || true sleep 1 fi echo "" echo "πŸš€ Starte Server im Hintergrund ..." nohup node server/index.js > "$LOGFILE" 2>&1 < /dev/null & NEW_PID=$! echo "$NEW_PID" > "$PIDFILE" sleep 1 if kill -0 "$NEW_PID" 2>/dev/null; then echo "" echo "πŸŽ‰ Fertig! Server lΓ€uft (PID $NEW_PID)." echo " Γ–ffnen: http://:3000" echo " Logs: tail -f server.log" echo " Stoppen: kill \$(cat server.pid)" echo "" echo " (FΓΌr Autostart beim Boot: systemd-Dienst aus DEPLOY.md einrichten.)" echo "" else echo "" echo "❌ Server konnte nicht starten. Letzte Log-Zeilen:" tail -n 20 "$LOGFILE" 2>/dev/null exit 1 fi