58 lines
2 KiB
Bash
Executable file
58 lines
2 KiB
Bash
Executable file
#!/bin/bash
|
|
# ============================================================
|
|
# NextWks — Production Update Script
|
|
# 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'; 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..."
|
|
|
|
# Clone fresh copy
|
|
rm -rf "$REPO_DIR" 2>/dev/null
|
|
git clone --depth 1 "$REPO_URL" "$REPO_DIR" --quiet
|
|
|
|
VERSION=$(cat "$REPO_DIR/VERSION" 2>/dev/null || echo "dev")
|
|
COMMIT_SHA=$(cd "$REPO_DIR" && git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
|
|
# Build
|
|
cd "$REPO_DIR/src"
|
|
go build -ldflags="-s -w \
|
|
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.Version=${VERSION} \
|
|
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
|
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
|
|
-o /tmp/nextwks-core .
|
|
|
|
# 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 "NextWks updated to v${VERSION} (${COMMIT_SHA})"
|
|
info "Users bootstrapped from Authelia"
|
|
else
|
|
echo "Health check failed — check: sudo journalctl -u nextwks -n 20"
|
|
fi
|
|
|
|
# Cleanup
|
|
rm -rf "$REPO_DIR" /tmp/nextwks-core
|