big update

This commit is contained in:
2026-11-18 15:18:38 +01:00
parent e0496fa089
commit 64c5b65543
39 changed files with 1938 additions and 367 deletions

87
server/deploy/setup.sh Normal file
View File

@@ -0,0 +1,87 @@
#!/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" <<EOF
PORT=8080
JWT_SECRET=$(head -c 32 /dev/urandom | base64 | tr -d '\n')
ADMIN_UID=
DB_FILE=$APP/server/data.sqlite
ANTICHEAT=0
EOF
echo ">> wrote $APP/server/.env (random JWT_SECRET)"
fi
# --- systemd service ------------------------------------------------------------------------------
cat > /etc/systemd/system/robotclash.service <<EOF
[Unit]
Description=Robot Clash server
After=network.target
[Service]
WorkingDirectory=$APP/server
EnvironmentFile=$APP/server/.env
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable robotclash
# --- Caddy site -----------------------------------------------------------------------------------
cat > /etc/caddy/Caddyfile <<EOF
$DOMAIN {
encode gzip
reverse_proxy localhost:8080
}
EOF
systemctl reload caddy 2>/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 <<EOF
#!/usr/bin/env bash
D=$APP/backups
sqlite3 $APP/server/data.sqlite ".backup '\$D/data-\$(date +%F).sqlite'" 2>/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"