mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 00:58:34 +00:00
155 lines
5.5 KiB
Bash
Executable File
155 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
||
# ac-compose source repository setup
|
||
set -euo pipefail
|
||
|
||
echo '🔧 Setting up AzerothCore source repository...'
|
||
|
||
# Load environment variables if .env exists
|
||
if [ -f .env ]; then
|
||
source .env
|
||
fi
|
||
|
||
# Remember project root for path normalization
|
||
PROJECT_ROOT="$(pwd)"
|
||
|
||
# Default values
|
||
MODULE_PLAYERBOTS="${MODULE_PLAYERBOTS:-0}"
|
||
PLAYERBOT_ENABLED="${PLAYERBOT_ENABLED:-0}"
|
||
STACK_SOURCE_VARIANT="${STACK_SOURCE_VARIANT:-}"
|
||
if [ -z "$STACK_SOURCE_VARIANT" ]; then
|
||
if [ "$MODULE_PLAYERBOTS" = "1" ] || [ "$PLAYERBOT_ENABLED" = "1" ]; then
|
||
STACK_SOURCE_VARIANT="playerbots"
|
||
else
|
||
STACK_SOURCE_VARIANT="core"
|
||
fi
|
||
fi
|
||
LOCAL_STORAGE_ROOT="${STORAGE_PATH_LOCAL:-./local-storage}"
|
||
DEFAULT_STANDARD_PATH="${LOCAL_STORAGE_ROOT%/}/source/azerothcore"
|
||
DEFAULT_PLAYERBOTS_PATH="${LOCAL_STORAGE_ROOT%/}/source/azerothcore-playerbots"
|
||
|
||
SOURCE_PATH_DEFAULT="$DEFAULT_STANDARD_PATH"
|
||
if [ "$STACK_SOURCE_VARIANT" = "playerbots" ]; then
|
||
SOURCE_PATH_DEFAULT="$DEFAULT_PLAYERBOTS_PATH"
|
||
fi
|
||
SOURCE_PATH="${MODULES_REBUILD_SOURCE_PATH:-$SOURCE_PATH_DEFAULT}"
|
||
|
||
show_client_data_requirement(){
|
||
local repo_path="$1"
|
||
local detector="$PROJECT_ROOT/scripts/detect-client-data-version.sh"
|
||
if [ ! -x "$detector" ]; then
|
||
return
|
||
fi
|
||
|
||
local detection
|
||
if ! detection="$("$detector" --no-header "$repo_path" 2>/dev/null | head -n1)"; then
|
||
echo "⚠️ Could not detect client data version for $repo_path"
|
||
return
|
||
fi
|
||
|
||
local detected_repo raw_version normalized_version
|
||
IFS=$'\t' read -r detected_repo raw_version normalized_version <<< "$detection"
|
||
if [ -z "$normalized_version" ] || [ "$normalized_version" = "<unknown>" ]; then
|
||
echo "⚠️ Could not detect client data version for $repo_path"
|
||
return
|
||
fi
|
||
|
||
local env_value="${CLIENT_DATA_VERSION:-}"
|
||
if [ -n "$env_value" ] && [ "$env_value" != "$normalized_version" ]; then
|
||
echo "⚠️ Source requires client data ${normalized_version} (raw ${raw_version}) but .env specifies ${env_value}. Update CLIENT_DATA_VERSION to avoid mismatched maps."
|
||
elif [ -n "$env_value" ]; then
|
||
echo "📦 Client data requirement satisfied: ${normalized_version} (raw ${raw_version})"
|
||
else
|
||
echo "ℹ️ Detected client data requirement: ${normalized_version} (raw ${raw_version}). Set CLIENT_DATA_VERSION in .env to avoid mismatches."
|
||
fi
|
||
}
|
||
|
||
STORAGE_PATH_VALUE="${STORAGE_PATH:-./storage}"
|
||
if [[ "$STORAGE_PATH_VALUE" != /* ]]; then
|
||
STORAGE_PATH_ABS="$PROJECT_ROOT/${STORAGE_PATH_VALUE#./}"
|
||
else
|
||
STORAGE_PATH_ABS="$STORAGE_PATH_VALUE"
|
||
fi
|
||
|
||
if [[ "$SOURCE_PATH_DEFAULT" != /* ]]; then
|
||
DEFAULT_SOURCE_ABS="$PROJECT_ROOT/${SOURCE_PATH_DEFAULT#./}"
|
||
else
|
||
DEFAULT_SOURCE_ABS="$SOURCE_PATH_DEFAULT"
|
||
fi
|
||
|
||
# Convert to absolute path if relative and ensure we stay local
|
||
if [[ "$SOURCE_PATH" != /* ]]; then
|
||
SOURCE_PATH="$PROJECT_ROOT/${SOURCE_PATH#./}"
|
||
fi
|
||
if [[ "$SOURCE_PATH" == "$STORAGE_PATH_ABS"* ]]; then
|
||
echo "⚠️ Source path $SOURCE_PATH is inside shared storage ($STORAGE_PATH_ABS). Using local workspace $DEFAULT_SOURCE_ABS instead."
|
||
SOURCE_PATH="$DEFAULT_SOURCE_ABS"
|
||
MODULES_REBUILD_SOURCE_PATH="$SOURCE_PATH_DEFAULT"
|
||
fi
|
||
|
||
ACORE_REPO_STANDARD="${ACORE_REPO_STANDARD:-https://github.com/azerothcore/azerothcore-wotlk.git}"
|
||
ACORE_BRANCH_STANDARD="${ACORE_BRANCH_STANDARD:-master}"
|
||
ACORE_REPO_PLAYERBOTS="${ACORE_REPO_PLAYERBOTS:-https://github.com/mod-playerbots/azerothcore-wotlk.git}"
|
||
ACORE_BRANCH_PLAYERBOTS="${ACORE_BRANCH_PLAYERBOTS:-Playerbot}"
|
||
|
||
# Repository and branch selection based on source variant
|
||
if [ "$STACK_SOURCE_VARIANT" = "playerbots" ]; then
|
||
REPO_URL="$ACORE_REPO_PLAYERBOTS"
|
||
BRANCH="$ACORE_BRANCH_PLAYERBOTS"
|
||
echo "📌 Playerbots mode: Using $REPO_URL, branch $BRANCH"
|
||
else
|
||
REPO_URL="$ACORE_REPO_STANDARD"
|
||
BRANCH="$ACORE_BRANCH_STANDARD"
|
||
echo "📌 Standard mode: Using $REPO_URL, branch $BRANCH"
|
||
fi
|
||
|
||
echo "📍 Repository: $REPO_URL"
|
||
echo "🌿 Branch: $BRANCH"
|
||
echo "📂 Source path: $SOURCE_PATH"
|
||
|
||
# Ensure destination directories exist
|
||
echo "📂 Preparing local workspace at $(dirname "$SOURCE_PATH")"
|
||
mkdir -p "$(dirname "$SOURCE_PATH")"
|
||
|
||
# Clone or update repository
|
||
if [ -d "$SOURCE_PATH/.git" ]; then
|
||
echo "📂 Existing repository found, updating..."
|
||
cd "$SOURCE_PATH"
|
||
|
||
# Check if we're on the correct repository
|
||
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
|
||
if [ "$CURRENT_REMOTE" != "$REPO_URL" ]; then
|
||
echo "🔄 Repository URL changed, re-cloning..."
|
||
cd ..
|
||
rm -rf "$(basename "$SOURCE_PATH")"
|
||
echo "⏳ Cloning $REPO_URL (branch $BRANCH) into $(basename "$SOURCE_PATH")"
|
||
git clone -b "$BRANCH" "$REPO_URL" "$(basename "$SOURCE_PATH")"
|
||
cd "$(basename "$SOURCE_PATH")"
|
||
else
|
||
echo "🔄 Fetching latest changes from origin..."
|
||
git fetch origin --progress
|
||
echo "🔀 Switching to branch $BRANCH..."
|
||
git checkout "$BRANCH"
|
||
echo "⬇️ Pulling latest commits..."
|
||
git pull --ff-only origin "$BRANCH"
|
||
echo "✅ Repository updated to latest $BRANCH"
|
||
fi
|
||
else
|
||
echo "📥 Cloning repository..."
|
||
echo "⏳ Cloning $REPO_URL (branch $BRANCH) into $SOURCE_PATH"
|
||
git clone -b "$BRANCH" "$REPO_URL" "$SOURCE_PATH"
|
||
echo "✅ Repository cloned successfully"
|
||
fi
|
||
|
||
cd "$SOURCE_PATH"
|
||
|
||
# Display current status
|
||
CURRENT_COMMIT=$(git rev-parse --short HEAD)
|
||
CURRENT_BRANCH=$(git branch --show-current)
|
||
echo "📊 Current status:"
|
||
echo " Branch: $CURRENT_BRANCH"
|
||
echo " Commit: $CURRENT_COMMIT"
|
||
echo " Last commit: $(git log -1 --pretty=format:'%s (%an, %ar)')"
|
||
show_client_data_requirement "$SOURCE_PATH"
|
||
|
||
echo '🎉 Source repository setup complete!'
|