#!/usr/bin/env bash # Fractured / AzerothCore — native VPS rolling update (git + compile). # # Run from anywhere; resolves the repository root from this script's location. # Typical production layout: sources in ~/src/Fractured, install prefix in ~/azeroth-server # (see docs/DEPLOY_LINUX_VPS.md). # # What this does: # 1. Optionally kill running servers (tmux sessions) # 2. git pull on the current branch (optional; can skip) # 3. ./acore.sh compiler build — or compiler all for a full clean rebuild # 4. Optionally restart servers in tmux sessions # # Database migrations from data/sql/updates/ run when you next start worldserver/authserver # (Updates.* / SourceDirectory in *.conf). # # Usage: # bash scripts/vps-update-server.sh # pull + compile only # bash scripts/vps-update-server.sh --restart # pull + compile + restart servers in tmux # bash scripts/vps-update-server.sh --full --restart # clean rebuild + restart # bash scripts/vps-update-server.sh --no-pull --restart # compile current tree + restart # bash scripts/vps-update-server.sh --dry-run # bash scripts/vps-update-server.sh --run-after 'custom command here' # # Canonical Fractured source (Gitea): https://git.hisora.dev/HighSocietyRaiding/Fractured.git # If origin still points at a known legacy GitHub mirror (HighSocietyRaiding/Fractured or # Dawnforger/Fractured), the script rewrites that remote to Gitea before pulling (override with # FRACTURED_GITEA_ORIGIN_URL; disable with FRACTURED_SKIP_ORIGIN_MIGRATION=1). # # Environment: # FRACTURED_GIT_REMOTE — remote name (default: origin) # FRACTURED_GITEA_ORIGIN_URL — URL used when auto-migrating off GitHub (default: Gitea HTTPS above) # FRACTURED_SKIP_ORIGIN_MIGRATION — set to 1 to never rewrite remote URLs # FRACTURED_POST_UPDATE_CMD — shell command run after compile (used by bare --run-after) # FRACTURED_KILL_SCRIPT — with --restart: path to kill script (default: scripts/kill-azeroth-servers.sh) # FRACTURED_START_SCRIPT — with --restart: path to start script (default: scripts/start-azeroth-servers.sh) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" NO_PULL=0 FULL_BUILD=0 COMPILE_ONLY=0 DRY_RUN=0 DO_RUN_AFTER=0 DO_RESTART=0 INSTALL_PREFIX="" POST_UPDATE_CMD="${FRACTURED_POST_UPDATE_CMD:-}" GIT_REMOTE="${FRACTURED_GIT_REMOTE:-origin}" FRACTURED_GITEA_ORIGIN_URL="${FRACTURED_GITEA_ORIGIN_URL:-https://git.hisora.dev/HighSocietyRaiding/Fractured.git}" usage() { cat <<'EOF' Fractured VPS update — git pull + compiler (see header in script for full notes). Usage: bash scripts/vps-update-server.sh [options] Options: --no-pull Skip git pull (only compile current tree). --full ./acore.sh compiler all (clean + configure + compile). --compile-only ./acore.sh compiler compile (incremental). --prefix PATH Override CMAKE_INSTALL_PREFIX (updates conf/config.sh BINPATH). --dry-run Print commands without running them. --restart Kill servers before compile, restart after (see FRACTURED_KILL_SCRIPT / FRACTURED_START_SCRIPT). --run-after [CMD] Run a custom shell command after successful compile. If CMD is omitted, uses FRACTURED_POST_UPDATE_CMD. Environment: FRACTURED_GIT_REMOTE Git remote name (default: origin). FRACTURED_GITEA_ORIGIN_URL Target URL when auto-migrating from GitHub Fractured remote. FRACTURED_SKIP_ORIGIN_MIGRATION Set to 1 to skip GitHub → Gitea remote rewrite. FRACTURED_POST_UPDATE_CMD Used with bare --run-after. FRACTURED_KILL_SCRIPT Override kill script used with --restart (default: repo scripts/). FRACTURED_START_SCRIPT Override start script used with --restart (default: repo scripts/). EOF } run() { if [[ "$DRY_RUN" -eq 1 ]]; then printf '[dry-run] ' printf '%q ' "$@" printf '\n' else "$@" fi } while [[ $# -gt 0 ]]; do case "$1" in -h | --help) usage exit 0 ;; --no-pull) NO_PULL=1 shift ;; --full) FULL_BUILD=1 shift ;; --compile-only) COMPILE_ONLY=1 shift ;; --prefix) shift if [[ $# -eq 0 || "$1" == -* ]]; then echo "error: --prefix requires a path argument" >&2 exit 2 fi INSTALL_PREFIX="$1" shift ;; --dry-run) DRY_RUN=1 shift ;; --restart) DO_RESTART=1 shift ;; --run-after) DO_RUN_AFTER=1 shift if [[ $# -gt 0 && "$1" != -* ]]; then POST_UPDATE_CMD="$1" shift fi ;; *) echo "error: unknown option: $1" >&2 echo "Try: bash scripts/vps-update-server.sh --help" >&2 exit 2 ;; esac done if [[ "$FULL_BUILD" -eq 1 && "$COMPILE_ONLY" -eq 1 ]]; then echo "error: use only one of --full or --compile-only" >&2 exit 2 fi if [[ ! -d "$ROOT/.git" ]]; then echo "error: not a git clone: $ROOT" >&2 exit 1 fi if [[ ! -f "$ROOT/acore.sh" ]]; then echo "error: acore.sh not found under $ROOT" >&2 exit 1 fi if [[ ! -f "$ROOT/conf/config.sh" ]]; then echo "error: missing $ROOT/conf/config.sh — copy conf/dist/config.sh and edit (see DEPLOY_LINUX_VPS.md)." >&2 exit 1 fi cd "$ROOT" KILL_SCRIPT="${FRACTURED_KILL_SCRIPT:-$SCRIPT_DIR/kill-azeroth-servers.sh}" START_SCRIPT="${FRACTURED_START_SCRIPT:-$SCRIPT_DIR/start-azeroth-servers.sh}" if [[ "$DO_RESTART" -eq 1 ]]; then if [[ ! -f "$KILL_SCRIPT" || ! -f "$START_SCRIPT" ]]; then echo "error: --restart needs kill and start scripts (defaults under scripts/). Set FRACTURED_KILL_SCRIPT / FRACTURED_START_SCRIPT to override." >&2 exit 1 fi echo "==> stopping servers before compile" run bash "$KILL_SCRIPT" fi if [[ -n "$INSTALL_PREFIX" ]]; then echo "==> updating conf/config.sh BINPATH to: $INSTALL_PREFIX" if grep -q '^BINPATH=' conf/config.sh; then run sed -i "s|^BINPATH=.*|BINPATH=\"$INSTALL_PREFIX\"|" conf/config.sh else echo "BINPATH=\"$INSTALL_PREFIX\"" >> conf/config.sh fi export BINPATH="$INSTALL_PREFIX" fi if [[ "$DO_RUN_AFTER" -eq 1 && -z "${POST_UPDATE_CMD// }" ]]; then echo "error: --run-after needs a command or FRACTURED_POST_UPDATE_CMD set in the environment." >&2 exit 2 fi current_branch() { git symbolic-ref -q --short HEAD || git rev-parse --short HEAD } # Old VPS clones may still have origin → github.com:…/Fractured (org mirror); repoint to Gitea. ensure_fractured_origin_on_gitea() { if [[ "${FRACTURED_SKIP_ORIGIN_MIGRATION:-0}" == "1" ]]; then return 0 fi local url url="$(git remote get-url "$GIT_REMOTE" 2>/dev/null || true)" [[ -z "$url" ]] && return 0 # HTTPS: …/Org/Fractured or …/Fractured.git SSH: github.com:Org/Fractured(.git) if [[ "$url" =~ github\.com[:/](HighSocietyRaiding|Dawnforger)/Fractured(\.git)?$ ]]; then echo "==> $GIT_REMOTE still points at GitHub Fractured (${BASH_REMATCH[1]}); switching to Gitea: $FRACTURED_GITEA_ORIGIN_URL" run git remote set-url "$GIT_REMOTE" "$FRACTURED_GITEA_ORIGIN_URL" fi } if [[ "$NO_PULL" -eq 0 ]]; then ref="$(current_branch)" if [[ "$ref" == "HEAD" ]]; then echo "error: detached HEAD; checkout a branch or use --no-pull." >&2 exit 1 fi ensure_fractured_origin_on_gitea echo "==> git pull $GIT_REMOTE $ref" run git pull "$GIT_REMOTE" "$ref" else echo "==> skipping git pull (--no-pull)" fi echo "==> ensuring acore.sh and JSONPath are executable" if [[ "$DRY_RUN" -eq 1 ]]; then run chmod +x acore.sh deps/jsonpath/JSONPath.sh else chmod +x acore.sh deps/jsonpath/JSONPath.sh 2>/dev/null || true fi if [[ "$FULL_BUILD" -eq 1 ]]; then echo "==> ./acore.sh compiler all (clean, configure, compile)" run ./acore.sh compiler all elif [[ "$COMPILE_ONLY" -eq 1 ]]; then echo "==> ./acore.sh compiler compile (incremental; build dir must exist)" run ./acore.sh compiler compile else echo "==> ./acore.sh compiler build (configure + compile)" run ./acore.sh compiler build fi if [[ "$DO_RESTART" -eq 1 ]]; then echo "==> restarting servers in tmux sessions" run bash "$START_SCRIPT" fi if [[ "$DO_RUN_AFTER" -eq 1 ]]; then echo "==> post-update: $POST_UPDATE_CMD" if [[ "$DRY_RUN" -eq 1 ]]; then printf '[dry-run] eval %q\n' "$POST_UPDATE_CMD" else # shellcheck disable=SC2086 eval "$POST_UPDATE_CMD" fi fi if [[ "$DO_RESTART" -eq 0 && "$DO_RUN_AFTER" -eq 0 ]]; then echo "Done. (Re)start: bash \"$SCRIPT_DIR/start-azeroth-servers.sh\" — or set FRACTURED_START_SCRIPT for a custom path." else echo "Done." fi