install.sh: Node.js bei Bedarf automatisch installieren

Erkennt Paketmanager (apt/dnf/yum/apk/pacman) bzw. Homebrew und installiert
Node 20 LTS selbst, wenn node fehlt. Nutzt sudo nur wenn noetig (nicht als root).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Guido
2026-08-04 17:56:00 +02:00
parent 1a9710ec88
commit a5618596ed

View File

@@ -1,5 +1,5 @@
#!/bin/sh
# Einfaches Ein-Befehl-Setup fuer fuesse.sexy — "Where's the Feet".
# Ein-Befehl-Setup fuer fuesse.sexy — installiert bei Bedarf Node.js selbst.
# Aufruf: ./install.sh (oder: sh install.sh)
set -e
@@ -8,26 +8,86 @@ echo ""
echo "🦶 fuesse.sexy — Setup"
echo "------------------------"
# 1) Node vorhanden?
if ! command -v node >/dev/null 2>&1; then
echo "❌ Node.js ist nicht installiert."
echo " Bitte zuerst installieren: https://nodejs.org/ (LTS-Version)"
# 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
NODE_VERSION=$(node -v)
echo "✅ Node gefunden ($NODE_VERSION)"
# 2) Abhaengigkeiten installieren
# 3) Abhaengigkeiten installieren
echo ""
echo "📦 Installiere Abhaengigkeiten (npm install) ..."
npm install
# 3) Fertig
# 4) Fertig
echo ""
echo "🎉 Fertig! So startest du das Spiel:"
echo ""
echo " npm start"
echo ""
echo " Dann im Browser oeffnen: http://localhost:3000"
echo " Dann im Browser oeffnen: http://<server-ip>:3000"
echo ""