#!/usr/bin/env bash # One-time server setup for Robot Clash. Run ON the Hetzner box as root: # bash setup.sh # uses roboclash.michael-media.de # bash setup.sh my.domain.tld # custom domain # Installs Node + Caddy (auto-TLS), creates the systemd service, firewall and a daily DB backup. # Then push the code (deploy/push.ps1 from Windows) and: systemctl start robotclash set -euo pipefail DOMAIN="${1:-roboclash.michael-media.de}" APP=/opt/robotclash echo ">> Robot Clash setup for $DOMAIN" # --- Node LTS ------------------------------------------------------------------------------------- if ! command -v node >/dev/null 2>&1; then curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt-get install -y nodejs fi apt-get install -y build-essential python3 git ufw sqlite3 curl # --- Caddy (reverse proxy + automatic HTTPS) ------------------------------------------------------ if ! command -v caddy >/dev/null 2>&1; then apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null apt-get update apt-get install -y caddy fi mkdir -p "$APP/game" "$APP/server" "$APP/backups" # --- .env (random JWT secret, kept across deploys) ------------------------------------------------ if [ ! -f "$APP/server/.env" ]; then cat > "$APP/server/.env" <> wrote $APP/server/.env (random JWT_SECRET)" fi # --- systemd service ------------------------------------------------------------------------------ cat > /etc/systemd/system/robotclash.service < /etc/caddy/Caddyfile </dev/null || systemctl restart caddy # --- firewall ------------------------------------------------------------------------------------- ufw allow 22 >/dev/null; ufw allow 80 >/dev/null; ufw allow 443 >/dev/null ufw --force enable >/dev/null # --- daily SQLite backup (keep 14) ---------------------------------------------------------------- cat > /etc/cron.daily/robotclash-backup </dev/null || cp $APP/server/data.sqlite "\$D/data-\$(date +%F).sqlite" 2>/dev/null || true ls -1t "\$D"/data-*.sqlite 2>/dev/null | tail -n +15 | xargs -r rm EOF chmod +x /etc/cron.daily/robotclash-backup echo ">> Setup done." echo ">> DNS: point $DOMAIN A-record to this server's IP." echo ">> Next: push the code (deploy/push.ps1 from Windows), then: systemctl start robotclash"