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:
+36
-21
@@ -3,7 +3,9 @@ set -euo pipefail
|
|||||||
|
|
||||||
# ──────────────────────────────────────────────
|
# ──────────────────────────────────────────────
|
||||||
# worst-scan-web — Direct installer (no Docker)
|
# 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"
|
REPO_URL="https://gitea.cbcren.online/renato97/worst-scan-web.git"
|
||||||
@@ -134,31 +136,43 @@ fi
|
|||||||
mkdir -p "$INSTALL_DIR/data"
|
mkdir -p "$INSTALL_DIR/data"
|
||||||
log "Data directory ready"
|
log "Data directory ready"
|
||||||
|
|
||||||
# ── Build ────────────────────────────────────────
|
|
||||||
info "Installing npm dependencies..."
|
|
||||||
cd "$INSTALL_DIR"
|
|
||||||
npm ci
|
|
||||||
log "Dependencies installed"
|
|
||||||
|
|
||||||
info "Building Next.js app (this may take a few minutes)..."
|
|
||||||
npm run build
|
|
||||||
log "Build complete"
|
|
||||||
|
|
||||||
STANDALONE_DIR="$INSTALL_DIR/.next/standalone"
|
STANDALONE_DIR="$INSTALL_DIR/.next/standalone"
|
||||||
|
|
||||||
# Ensure static files are copied
|
# ── Build (skip if already built) ──────────────────
|
||||||
if [ ! -d "$STANDALONE_DIR/.next/static" ]; then
|
if [ -f "$STANDALONE_DIR/server.js" ]; then
|
||||||
mkdir -p "$STANDALONE_DIR/.next"
|
info "Build already exists — skipping"
|
||||||
cp -r "$INSTALL_DIR/.next/static" "$STANDALONE_DIR/.next/static"
|
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"
|
||||||
|
|
||||||
|
# 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
|
fi
|
||||||
cp -r "$INSTALL_DIR/public" "$STANDALONE_DIR/public" 2>/dev/null || true
|
|
||||||
|
|
||||||
# ── systemd service ──────────────────────────────
|
# ── systemd service ──────────────────────────────
|
||||||
SERVICE_NAME="worst-scan-web"
|
SERVICE_NAME="worst-scan-web"
|
||||||
APP_USER="$USER"
|
APP_USER="$USER"
|
||||||
APP_HOME="$HOME"
|
APP_HOME="$HOME"
|
||||||
|
|
||||||
sudo tee "/etc/systemd/system/$SERVICE_NAME.service" > /dev/null <<SYSTEMD
|
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]
|
[Unit]
|
||||||
Description=worst-scan-web
|
Description=worst-scan-web
|
||||||
After=network.target
|
After=network.target
|
||||||
@@ -180,10 +194,11 @@ RestartSec=5
|
|||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
SYSTEMD
|
SYSTEMD
|
||||||
|
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
sudo systemctl enable "$SERVICE_NAME"
|
sudo systemctl enable "$SERVICE_NAME"
|
||||||
sudo systemctl restart "$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 ──────────────────────────
|
# ── Caddy reverse proxy ──────────────────────────
|
||||||
CADDYFILE="/etc/caddy/Caddyfile"
|
CADDYFILE="/etc/caddy/Caddyfile"
|
||||||
|
|||||||
Reference in New Issue
Block a user