51 lines
1.5 KiB
Bash
Executable file
51 lines
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
# ============================================================
|
|
# NextWks — Production Update Script
|
|
# Pulls latest code, rebuilds, restarts services
|
|
# Run: cd /opt/nextwks && sudo bash update.sh
|
|
# ============================================================
|
|
set -euo pipefail
|
|
|
|
GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'
|
|
info() { echo -e "${BLUE}$1${NC}"; }
|
|
ok() { echo -e "${GREEN}$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"
|
|
|
|
info "Updating NextWks..."
|
|
|
|
# Clone fresh copy
|
|
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
|
|
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 .
|
|
|
|
# Replace
|
|
systemctl stop nextwks
|
|
cp /tmp/nextwks-core "$BIN_DIR/core"
|
|
chmod 755 "$BIN_DIR/core"
|
|
chown nextwks:nextwks "$BIN_DIR/core"
|
|
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}"
|
|
else
|
|
echo "Health check failed — check journalctl -u nextwks"
|
|
fi
|
|
|
|
# Cleanup
|
|
rm -rf "$REPO_DIR" /tmp/nextwks-core
|