fix: skip build if standalone exists; survive SSH drops

- Screen tip added to header
- Skip npm ci + next build if .next/standalone/server.js exists
- Skip systemd service creation if unit exists (restart instead)
- Close else/fi properly for systemd block
- Re-run after SSH drop picks up where it left off
This commit is contained in:
Renato
2026-07-28 00:46:20 +02:00
parent 225bb491a6
commit 8ed9bd83ec
+20 -5
View File
@@ -3,7 +3,9 @@ set -euo pipefail
# ──────────────────────────────────────────────
# worst-scan-web — Direct installer (no Docker)
# Usage: bash <(curl -fsSL https://gitea.cbcren.online/renato97/worst-scan-web/raw/branch/main/install.sh)
# Usage:
# screen -S worst-scan # recommended — survives SSH drops
# bash <(curl -fsSL https://gitea.cbcren.online/renato97/worst-scan-web/raw/branch/main/install.sh)
# ──────────────────────────────────────────────
REPO_URL="https://gitea.cbcren.online/renato97/worst-scan-web.git"
@@ -134,30 +136,42 @@ fi
mkdir -p "$INSTALL_DIR/data"
log "Data directory ready"
# ── Build ────────────────────────────────────────
STANDALONE_DIR="$INSTALL_DIR/.next/standalone"
# ── Build (skip if already built) ──────────────────
if [ -f "$STANDALONE_DIR/server.js" ]; then
info "Build already exists — skipping"
else
info "Installing npm dependencies..."
cd "$INSTALL_DIR"
npm ci
log "Dependencies installed"
info "Building Next.js app (this may take a few minutes)..."
info "Tip: run in 'screen -S worst-scan' to survive SSH drops"
npm run build
log "Build complete"
STANDALONE_DIR="$INSTALL_DIR/.next/standalone"
# Ensure static files are copied
if [ ! -d "$STANDALONE_DIR/.next/static" ]; then
mkdir -p "$STANDALONE_DIR/.next"
cp -r "$INSTALL_DIR/.next/static" "$STANDALONE_DIR/.next/static"
fi
cp -r "$INSTALL_DIR/public" "$STANDALONE_DIR/public" 2>/dev/null || true
fi
# ── systemd service ──────────────────────────────
SERVICE_NAME="worst-scan-web"
APP_USER="$USER"
APP_HOME="$HOME"
if [ -f "/etc/systemd/system/$SERVICE_NAME.service" ]; then
info "systemd service already exists — restarting"
sudo systemctl restart "$SERVICE_NAME"
sudo systemctl enable "$SERVICE_NAME" 2>/dev/null || true
log "systemd service $SERVICE_NAME restarted"
else
info "Creating systemd service..."
sudo tee "/etc/systemd/system/$SERVICE_NAME.service" > /dev/null <<SYSTEMD
[Unit]
Description=worst-scan-web
@@ -183,7 +197,8 @@ SYSTEMD
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
log "systemd service $SERVICE_NAME started"
log "systemd service $SERVICE_NAME created and started"
fi
# ── Caddy reverse proxy ──────────────────────────
CADDYFILE="/etc/caddy/Caddyfile"