fix(update): wipe DB on update, bootstrap from Authelia, don't touch Authelia service

This commit is contained in:
Claus Lohmar 2026-06-14 17:39:56 +00:00
parent 583e1a5eea
commit cb4eb38289

View file

@ -1,19 +1,22 @@
#!/bin/bash
# ============================================================
# NextWks — Production Update Script
# Pulls latest code, rebuilds, restarts services
# Pulls latest code, rebuilds, restarts NextWks only.
# Users & auth are managed by Authelia (untouched).
# Run: cd /opt/nextwks && sudo bash update.sh
# ============================================================
set -euo pipefail
GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'
GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${BLUE}$1${NC}"; }
ok() { echo -e "${GREEN}$1${NC}"; }
warn() { echo -e "${YELLOW}$1${NC}"; }
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
REPO_DIR="/tmp/nextwks-update"
INSTALL_DIR="/opt/nextwks"
BIN_DIR="${INSTALL_DIR}/bin"
DATA_DIR="${INSTALL_DIR}/data"
info "Updating NextWks..."
@ -21,7 +24,6 @@ info "Updating NextWks..."
rm -rf "$REPO_DIR" 2>/dev/null
git clone --depth 1 "$REPO_URL" "$REPO_DIR" --quiet
# Read new version
VERSION=$(cat "$REPO_DIR/VERSION" 2>/dev/null || echo "dev")
# Build
@ -32,19 +34,23 @@ go build -ldflags="-s -w \
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
-o /tmp/nextwks-core .
# Replace
# Stop, wipe data, replace, restart
systemctl stop nextwks
warn "Wiping NextWks database (users restored from Authelia on boot)"
find "$DATA_DIR" -name "*.db*" -delete 2>/dev/null || true
cp /tmp/nextwks-core "$BIN_DIR/core"
chmod 755 "$BIN_DIR/core"
chown nextwks:nextwks "$BIN_DIR/core"
chown -R nextwks:nextwks "$DATA_DIR" 2>/dev/null || true
systemctl start nextwks
sleep 2
# Verify
if curl -s --max-time 3 http://localhost:8080/api/health | grep -q ok; then
ok "Updated to v${VERSION}"
ok "NextWks updated to v${VERSION}"
info "Users bootstrapped from Authelia"
else
echo "Health check failed — check journalctl -u nextwks"
echo "Health check failed — check: sudo journalctl -u nextwks -n 20"
fi
# Cleanup