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

207
scripts/download-client-data.sh Normal file → Executable file
View File

@@ -1,32 +1,40 @@
#!/bin/bash
# ac-compose
set -e
echo '🚀 Starting AzerothCore game data setup...'
# Get the latest release info from wowgaming/client-data
echo '📡 Fetching latest client data release info...'
RELEASE_INFO=$(wget -qO- https://api.github.com/repos/wowgaming/client-data/releases/latest 2>/dev/null)
REQUESTED_TAG="${CLIENT_DATA_VERSION:-}"
if [ -n "$REQUESTED_TAG" ]; then
echo "📌 Using requested client data version: $REQUESTED_TAG"
LATEST_TAG="$REQUESTED_TAG"
LATEST_URL="https://github.com/wowgaming/client-data/releases/download/${REQUESTED_TAG}/data.zip"
else
echo '📡 Fetching latest client data release info...'
RELEASE_INFO=$(wget -qO- https://api.github.com/repos/wowgaming/client-data/releases/latest 2>/dev/null)
if [ -n "$RELEASE_INFO" ]; then
LATEST_URL=$(echo "$RELEASE_INFO" | grep '"browser_download_url":' | grep '\.zip' | cut -d'"' -f4 | head -1)
LATEST_TAG=$(echo "$RELEASE_INFO" | grep '"tag_name":' | cut -d'"' -f4)
LATEST_SIZE=$(echo "$RELEASE_INFO" | grep '"size":' | head -1 | grep -o '[0-9]*')
fi
if [ -n "$RELEASE_INFO" ]; then
LATEST_URL=$(echo "$RELEASE_INFO" | grep '"browser_download_url":' | grep '\.zip' | cut -d'"' -f4 | head -1)
LATEST_TAG=$(echo "$RELEASE_INFO" | grep '"tag_name":' | cut -d'"' -f4)
LATEST_SIZE=$(echo "$RELEASE_INFO" | grep '"size":' | head -1 | grep -o '[0-9]*')
fi
if [ -z "$LATEST_URL" ]; then
echo '❌ Could not fetch latest release URL'
echo '📥 Using fallback: direct download from v16 release'
LATEST_URL='https://github.com/wowgaming/client-data/releases/download/v16/data.zip'
LATEST_TAG='v16'
LATEST_SIZE='0'
echo '❌ Could not fetch client-data release information. Aborting.'
exit 1
fi
fi
echo "📍 Latest release: $LATEST_TAG"
echo "📥 Download URL: $LATEST_URL"
# Cache file paths
CACHE_FILE="/cache/client-data-$LATEST_TAG.zip"
VERSION_FILE="/cache/client-data-version.txt"
CACHE_DIR="/cache"
mkdir -p "$CACHE_DIR"
CACHE_FILE="${CACHE_DIR}/client-data-${LATEST_TAG}.zip"
TMP_FILE="${CACHE_FILE}.tmp"
VERSION_FILE="${CACHE_DIR}/client-data-version.txt"
# Check if we have a cached version
if [ -f "$CACHE_FILE" ] && [ -f "$VERSION_FILE" ]; then
@@ -36,7 +44,22 @@ if [ -f "$CACHE_FILE" ] && [ -f "$VERSION_FILE" ]; then
echo "📊 Cached file size: $(ls -lh "$CACHE_FILE" | awk '{print $5}')"
# Verify cache file integrity
if unzip -t "$CACHE_FILE" > /dev/null 2>&1; then
echo "🔍 Verifying cached file integrity..."
CACHE_INTEGRITY_OK=false
if command -v 7z >/dev/null 2>&1; then
if 7z t "$CACHE_FILE" >/dev/null 2>&1; then
CACHE_INTEGRITY_OK=true
fi
fi
if [ "$CACHE_INTEGRITY_OK" = "false" ]; then
if unzip -t "$CACHE_FILE" > /dev/null 2>&1; then
CACHE_INTEGRITY_OK=true
fi
fi
if [ "$CACHE_INTEGRITY_OK" = "true" ]; then
echo "✅ Cache file integrity verified"
echo "⚡ Using cached download - skipping download phase"
cp "$CACHE_FILE" data.zip
@@ -47,140 +70,90 @@ if [ -f "$CACHE_FILE" ] && [ -f "$VERSION_FILE" ]; then
else
echo "📦 Cache version ($CACHED_VERSION) differs from latest ($LATEST_TAG)"
echo "🗑️ Removing old cache"
rm -f /cache/client-data-*.zip "$VERSION_FILE"
rm -f "${CACHE_DIR}"/client-data-*.zip "$VERSION_FILE"
fi
fi
# Download if we don't have a valid cached file
if [ ! -f "data.zip" ]; then
echo "📥 Downloading client data (~15GB, may take 10-30 minutes)..."
echo "📥 Downloading client data (~15GB)..."
echo "📍 Source: $LATEST_URL"
# Download with clean progress indication
echo "📥 Starting download..."
wget --progress=dot:giga -O "$CACHE_FILE.tmp" "$LATEST_URL" 2>&1 | sed 's/^/📊 /' || {
echo '❌ wget failed, trying curl...'
curl -L --progress-bar -o "$CACHE_FILE.tmp" "$LATEST_URL" || {
echo '❌ All download methods failed'
rm -f "$CACHE_FILE.tmp"
exit 1
if command -v aria2c >/dev/null 2>&1; then
aria2c --max-connection-per-server=8 --split=8 --min-split-size=10M \
--summary-interval=5 --download-result=hide \
--console-log-level=warn --show-console-readout=false \
--dir "$CACHE_DIR" -o "$(basename "$TMP_FILE")" "$LATEST_URL" || {
echo '⚠️ aria2c failed, falling back to wget...'
wget --progress=dot:giga -O "$TMP_FILE" "$LATEST_URL" 2>&1 | sed 's/^/📊 /' || {
echo '❌ wget failed, trying curl...'
curl -L --progress-bar -o "$TMP_FILE" "$LATEST_URL" || {
echo '❌ All download methods failed'
rm -f "$TMP_FILE"
exit 1
}
}
}
}
else
echo "📥 Using wget (aria2c not available)..."
wget --progress=dot:giga -O "$TMP_FILE" "$LATEST_URL" 2>&1 | sed 's/^/📊 /' || {
echo '❌ wget failed, trying curl...'
curl -L --progress-bar -o "$TMP_FILE" "$LATEST_URL" || {
echo '❌ All download methods failed'
rm -f "$TMP_FILE"
exit 1
}
}
fi
# Verify download integrity
if unzip -t "$CACHE_FILE.tmp" > /dev/null 2>&1; then
mv "$CACHE_FILE.tmp" "$CACHE_FILE"
echo "🔍 Verifying download integrity..."
INTEGRITY_OK=false
if command -v 7z >/dev/null 2>&1; then
if 7z t "$TMP_FILE" >/dev/null 2>&1; then
INTEGRITY_OK=true
fi
fi
if [ "$INTEGRITY_OK" = "false" ]; then
if unzip -t "$TMP_FILE" > /dev/null 2>&1; then
INTEGRITY_OK=true
fi
fi
if [ "$INTEGRITY_OK" = "true" ]; then
mv "$TMP_FILE" "$CACHE_FILE"
echo "$LATEST_TAG" > "$VERSION_FILE"
echo '✅ Download completed and verified'
echo "📊 File size: $(ls -lh "$CACHE_FILE" | awk '{print $5}')"
cp "$CACHE_FILE" data.zip
else
echo '❌ Downloaded file is corrupted'
rm -f "$CACHE_FILE.tmp"
rm -f "$TMP_FILE"
exit 1
fi
fi
echo '📂 Extracting client data (this may take 10-15 minutes)...'
echo '⏳ Please wait while extracting...'
# Clear existing data if extraction failed previously
echo '📂 Extracting client data (this may take some minutes)...'
rm -rf /azerothcore/data/maps /azerothcore/data/vmaps /azerothcore/data/mmaps /azerothcore/data/dbc
# Extract with detailed progress tracking
echo '🔄 Starting extraction with progress monitoring...'
# Start extraction in background with overwrite
unzip -o -q data.zip -d /azerothcore/data/ &
UNZIP_PID=$!
LAST_CHECK_TIME=0
# Monitor progress with directory size checks
while kill -0 "$UNZIP_PID" 2>/dev/null; do
CURRENT_TIME=$(date +%s)
if [ $((CURRENT_TIME - LAST_CHECK_TIME)) -ge 30 ]; then
LAST_CHECK_TIME=$CURRENT_TIME
# Check what's been extracted so far
PROGRESS_MSG="📊 Progress at $(date '+%H:%M:%S'):"
if [ -d "/azerothcore/data/dbc" ] && [ -n "$(ls -A /azerothcore/data/dbc 2>/dev/null)" ]; then
DBC_SIZE=$(du -sh /azerothcore/data/dbc 2>/dev/null | cut -f1)
PROGRESS_MSG="$PROGRESS_MSG DBC($DBC_SIZE)"
fi
if [ -d "/azerothcore/data/maps" ] && [ -n "$(ls -A /azerothcore/data/maps 2>/dev/null)" ]; then
MAPS_SIZE=$(du -sh /azerothcore/data/maps 2>/dev/null | cut -f1)
PROGRESS_MSG="$PROGRESS_MSG Maps($MAPS_SIZE)"
fi
if [ -d "/azerothcore/data/vmaps" ] && [ -n "$(ls -A /azerothcore/data/vmaps 2>/dev/null)" ]; then
VMAPS_SIZE=$(du -sh /azerothcore/data/vmaps 2>/dev/null | cut -f1)
PROGRESS_MSG="$PROGRESS_MSG VMaps($VMAPS_SIZE)"
fi
if [ -d "/azerothcore/data/mmaps" ] && [ -n "$(ls -A /azerothcore/data/mmaps 2>/dev/null)" ]; then
MMAPS_SIZE=$(du -sh /azerothcore/data/mmaps 2>/dev/null | cut -f1)
PROGRESS_MSG="$PROGRESS_MSG MMaps($MMAPS_SIZE)"
fi
echo "$PROGRESS_MSG"
fi
sleep 5
done
wait "$UNZIP_PID"
UNZIP_EXIT_CODE=$?
if [ $UNZIP_EXIT_CODE -ne 0 ]; then
echo '❌ Extraction failed'
rm -f data.zip
exit 1
if command -v 7z >/dev/null 2>&1; then
7z x -aoa -o/azerothcore/data/ data.zip >/dev/null 2>&1
else
unzip -o -q data.zip -d /azerothcore/data/
fi
# Handle nested Data directory issue - move contents if extracted to Data subdirectory
if [ -d "/azerothcore/data/Data" ] && [ -n "$(ls -A /azerothcore/data/Data 2>/dev/null)" ]; then
echo '🔧 Fixing data directory structure (moving from Data/ subdirectory)...'
# Move all contents from Data subdirectory to the root data directory
for item in /azerothcore/data/Data/*; do
if [ -e "$item" ]; then
mv "$item" /azerothcore/data/ 2>/dev/null || {
echo "⚠️ Could not move $(basename "$item"), using copy instead..."
cp -r "$item" /azerothcore/data/
rm -rf "$item"
}
fi
done
# Remove empty Data directory
rmdir /azerothcore/data/Data 2>/dev/null || true
echo '✅ Data directory structure fixed'
fi
# Clean up temporary extraction file (keep cached version)
rm -f data.zip
echo '✅ Client data extraction complete!'
echo '📁 Verifying extracted directories:'
# Verify required directories exist and have content
ALL_GOOD=true
for dir in maps vmaps mmaps dbc; do
if [ -d "/azerothcore/data/$dir" ] && [ -n "$(ls -A /azerothcore/data/$dir 2>/dev/null)" ]; then
DIR_SIZE=$(du -sh /azerothcore/data/$dir 2>/dev/null | cut -f1)
echo "$dir directory: OK ($DIR_SIZE)"
else
echo "$dir directory: MISSING or EMPTY"
ALL_GOOD=false
exit 1
fi
done
if [ "$ALL_GOOD" = "true" ]; then
echo '🎉 Game data setup complete! AzerothCore worldserver can now start.'
echo "💾 Cached version $LATEST_TAG for future use"
else
echo '❌ Some directories are missing or empty'
exit 1
fi
echo '🎉 Game data setup complete! AzerothCore worldserver can now start.'