refactoring and adding automations

This commit is contained in:
Deckard
2025-10-17 01:40:50 -04:00
parent 4bf22d1829
commit 859a214e12
65 changed files with 4622 additions and 956 deletions

View File

@@ -1,128 +1,195 @@
#!/bin/bash
# AzerothCore Module Rebuild Script
# Automates the process of rebuilding AzerothCore with enabled modules
# ac-compose helper to rebuild AzerothCore from source with enabled modules.
set -e
echo "🔧 AzerothCore Module Rebuild Script"
echo "==================================="
echo ""
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$PROJECT_DIR/.env"
# Check if source repository exists
SOURCE_COMPOSE="/tmp/acore-dev-test/docker-compose.yml"
usage(){
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip interactive confirmation prompts
--source PATH Override MODULES_REBUILD_SOURCE_PATH from .env
--skip-stop Do not run 'docker compose down' in the source tree before rebuilding
-h, --help Show this help
EOF
}
read_env(){
local key="$1" default="$2" env_path="$ENV_FILE" value
if [ -f "$env_path" ]; then
value="$(grep -E "^${key}=" "$env_path" | tail -n1 | cut -d'=' -f2- | tr -d '\r')"
fi
if [ -z "$value" ]; then
value="$default"
fi
echo "$value"
}
confirm(){
local prompt="$1" default="$2" reply
if [ "$ASSUME_YES" = "1" ]; then
return 0
fi
while true; do
if [ "$default" = "y" ]; then
read -r -p "$prompt [Y/n]: " reply
reply="${reply:-y}"
else
read -r -p "$prompt [y/N]: " reply
reply="${reply:-n}"
fi
case "$reply" in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}
ASSUME_YES=0
SOURCE_OVERRIDE=""
SKIP_STOP=0
while [[ $# -gt 0 ]]; do
case "$1" in
--yes|-y) ASSUME_YES=1; shift;;
--source) SOURCE_OVERRIDE="$2"; shift 2;;
--skip-stop) SKIP_STOP=1; shift;;
-h|--help) usage; exit 0;;
*) echo "Unknown option: $1" >&2; usage; exit 1;;
esac
done
if ! command -v docker >/dev/null 2>&1; then
echo "❌ Docker CLI not found in PATH."
exit 1
fi
STORAGE_PATH="$(read_env STORAGE_PATH "./storage")"
if [[ "$STORAGE_PATH" != /* ]]; then
STORAGE_PATH="$PROJECT_DIR/$STORAGE_PATH"
fi
MODULES_DIR="$STORAGE_PATH/modules"
SENTINEL_FILE="$MODULES_DIR/.requires_rebuild"
REBUILD_SOURCE_PATH="$SOURCE_OVERRIDE"
if [ -z "$REBUILD_SOURCE_PATH" ]; then
REBUILD_SOURCE_PATH="$(read_env MODULES_REBUILD_SOURCE_PATH "")"
fi
if [ -z "$REBUILD_SOURCE_PATH" ]; then
cat <<EOF
❌ MODULES_REBUILD_SOURCE_PATH is not configured.
Set MODULES_REBUILD_SOURCE_PATH in .env to the AzerothCore source repository
that contains the Docker Compose file used for source builds, then rerun:
scripts/rebuild-with-modules.sh --yes
EOF
exit 1
fi
if [[ "$REBUILD_SOURCE_PATH" != /* ]]; then
REBUILD_SOURCE_PATH="$(realpath "$REBUILD_SOURCE_PATH" 2>/dev/null || echo "$REBUILD_SOURCE_PATH")"
fi
SOURCE_COMPOSE="$REBUILD_SOURCE_PATH/docker-compose.yml"
if [ ! -f "$SOURCE_COMPOSE" ]; then
echo "Error: Source-based Docker Compose file not found at $SOURCE_COMPOSE"
echo "Please ensure AzerothCore source repository is available for compilation."
exit 1
echo "Source docker-compose.yml not found at $SOURCE_COMPOSE"
exit 1
fi
# Check current module configuration
echo "📋 Checking current module configuration..."
declare -A MODULE_REPO_MAP=(
[MODULE_AOE_LOOT]=mod-aoe-loot
[MODULE_LEARN_SPELLS]=mod-learn-spells
[MODULE_FIREWORKS]=mod-fireworks-on-level
[MODULE_INDIVIDUAL_PROGRESSION]=mod-individual-progression
[MODULE_AHBOT]=mod-ahbot
[MODULE_AUTOBALANCE]=mod-autobalance
[MODULE_TRANSMOG]=mod-transmog
[MODULE_NPC_BUFFER]=mod-npc-buffer
[MODULE_DYNAMIC_XP]=mod-dynamic-xp
[MODULE_SOLO_LFG]=mod-solo-lfg
[MODULE_1V1_ARENA]=mod-1v1-arena
[MODULE_PHASED_DUELS]=mod-phased-duels
[MODULE_BREAKING_NEWS]=mod-breaking-news-override
[MODULE_BOSS_ANNOUNCER]=mod-boss-announcer
[MODULE_ACCOUNT_ACHIEVEMENTS]=mod-account-achievements
[MODULE_AUTO_REVIVE]=mod-auto-revive
[MODULE_GAIN_HONOR_GUARD]=mod-gain-honor-guard
[MODULE_ELUNA]=mod-eluna
[MODULE_TIME_IS_TIME]=mod-TimeIsTime
[MODULE_POCKET_PORTAL]=mod-pocket-portal
[MODULE_RANDOM_ENCHANTS]=mod-random-enchants
[MODULE_SOLOCRAFT]=mod-solocraft
[MODULE_PVP_TITLES]=mod-pvp-titles
[MODULE_NPC_BEASTMASTER]=mod-npc-beastmaster
[MODULE_NPC_ENCHANTER]=mod-npc-enchanter
[MODULE_INSTANCE_RESET]=mod-instance-reset
[MODULE_LEVEL_GRANT]=mod-quest-count-level
)
MODULES_ENABLED=0
ENABLED_MODULES=""
compile_modules=()
for key in "${!MODULE_REPO_MAP[@]}"; do
if [ "$(read_env "$key" "0")" = "1" ]; then
compile_modules+=("${MODULE_REPO_MAP[$key]}")
fi
done
# Read environment file to check enabled modules
if [ -f "docker-compose-azerothcore-services.env" ]; then
while IFS= read -r line; do
if echo "$line" | grep -q "^MODULE_.*=1$"; then
MODULE_NAME=$(echo "$line" | cut -d'=' -f1)
MODULES_ENABLED=$((MODULES_ENABLED + 1))
ENABLED_MODULES="$ENABLED_MODULES $MODULE_NAME"
fi
done < docker-compose-azerothcore-services.env
if [ ${#compile_modules[@]} -eq 0 ]; then
echo "✅ No C++ modules enabled that require a source rebuild."
rm -f "$SENTINEL_FILE" 2>/dev/null || true
exit 0
fi
echo "🔧 Modules requiring compilation:"
for mod in "${compile_modules[@]}"; do
echo "$mod"
done
if [ ! -d "$MODULES_DIR" ]; then
echo "⚠️ Modules directory not found at $MODULES_DIR"
fi
if ! confirm "Proceed with source rebuild in $REBUILD_SOURCE_PATH? (15-45 minutes)" n; then
echo "❌ Rebuild cancelled"
exit 1
fi
pushd "$REBUILD_SOURCE_PATH" >/dev/null
if [ "$SKIP_STOP" != "1" ]; then
echo "🛑 Stopping existing source services (if any)..."
docker compose down || true
fi
if [ -d "$MODULES_DIR" ]; then
echo "🔄 Syncing enabled modules into source tree..."
mkdir -p modules
if command -v rsync >/dev/null 2>&1; then
rsync -a --delete "$MODULES_DIR"/ modules/
else
rm -rf modules/*
cp -R "$MODULES_DIR"/. modules/
fi
else
echo "⚠️ Warning: Environment file not found, checking default configuration..."
echo "⚠️ No modules directory found at $MODULES_DIR; continuing without sync."
fi
echo "🔍 Found $MODULES_ENABLED enabled modules"
if [ $MODULES_ENABLED -eq 0 ]; then
echo "✅ No modules enabled - rebuild not required"
echo "You can use pre-built containers for better performance."
exit 0
fi
echo "📦 Enabled modules:$ENABLED_MODULES"
echo ""
# Confirm rebuild
read -p "🤔 Proceed with rebuild? This will take 15-45 minutes. (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "❌ Rebuild cancelled"
exit 0
fi
echo ""
echo "🛑 Stopping current services..."
docker compose -f docker-compose-azerothcore-services.yml down || echo "⚠️ Services may not be running"
echo ""
echo "🔧 Starting source-based compilation..."
echo "⏱️ This will take 15-45 minutes depending on your system..."
echo ""
# Build with source
cd /tmp/acore-dev-test
echo "📁 Switched to source directory: $(pwd)"
# Copy modules to source build
echo "📋 Copying modules to source build..."
if [ -d "/home/upb/src/acore-compose2/storage/azerothcore/modules" ]; then
# Ensure modules directory exists in source
mkdir -p modules
# Copy enabled modules only
echo "🔄 Syncing enabled modules..."
for module_dir in /home/upb/src/acore-compose2/storage/azerothcore/modules/*/; do
if [ -d "$module_dir" ]; then
module_name=$(basename "$module_dir")
echo " Copying $module_name..."
cp -r "$module_dir" modules/
fi
done
else
echo "⚠️ Warning: No modules directory found"
fi
# Start build process
echo ""
echo "🚀 Building AzerothCore with modules..."
docker compose build --no-cache
if [ $? -eq 0 ]; then
echo ""
echo "✅ Build completed successfully!"
echo ""
echo "🟢 Starting source services..."
docker compose up -d
# Start services
echo "🟢 Starting services with compiled modules..."
docker compose up -d
popd >/dev/null
if [ $? -eq 0 ]; then
echo ""
echo "🎉 SUCCESS! AzerothCore is now running with compiled modules."
echo ""
echo "📊 Service status:"
docker compose ps
echo ""
echo "📝 To monitor logs:"
echo " docker compose logs -f"
echo ""
echo "🌐 Server should be available on configured ports once fully started."
else
echo "❌ Failed to start services"
exit 1
fi
else
echo "❌ Build failed"
echo ""
echo "🔍 Check build logs for errors:"
echo " docker compose logs"
exit 1
fi
rm -f "$SENTINEL_FILE" 2>/dev/null || true
echo ""
echo "✅ Rebuild process complete!"
echo "🎉 SUCCESS! AzerothCore source build completed with modules."