refactor: reorganize scripts under bash/python

This commit is contained in:
uprightbass360
2025-11-09 02:48:49 -05:00
parent 23456e0ab9
commit a18e315f1f
40 changed files with 265 additions and 194 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose
# azerothcore-rm
set -e
GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose
# azerothcore-rm
set -e
BACKUP_DIR_BASE="/backups"

View File

@@ -49,7 +49,7 @@ edit_config() {
# Create a minimal template if it doesn't exist
cat > "$config_file" << 'EOF'
# AzerothCore Server Configuration Overrides
# Edit this file and run './scripts/configure-server.sh apply' to update settings
# Edit this file and run './scripts/bash/configure-server.sh apply' to update settings
[worldserver.conf]
# Example settings - uncomment and modify as needed

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose
# azerothcore-rm
set -e
print_help() {

View File

@@ -1,13 +1,18 @@
#!/bin/bash
# ac-compose helper to deploy phpMyAdmin and Keira3 tooling.
# azerothcore-rm helper to deploy phpMyAdmin and Keira3 tooling.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
DEFAULT_COMPOSE_FILE="$ROOT_DIR/docker-compose.yml"
ENV_FILE="$ROOT_DIR/.env"
source "$ROOT_DIR/scripts/lib/compose_overrides.sh"
TEMPLATE_FILE="$ROOT_DIR/.env.template"
source "$ROOT_DIR/scripts/bash/project_name.sh"
# Default project name (read from .env or template)
DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_FILE" "$TEMPLATE_FILE")"
source "$ROOT_DIR/scripts/bash/compose_overrides.sh"
declare -a COMPOSE_FILE_ARGS=()
BLUE='\033[0;34m'
@@ -34,16 +39,8 @@ read_env(){
resolve_project_name(){
local raw_name sanitized
raw_name="$(read_env COMPOSE_PROJECT_NAME "azerothcore-realmmaster")"
sanitized="$(echo "$raw_name" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
sanitized="azerothcore-realmmaster"
elif [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
echo "$sanitized"
raw_name="$(read_env COMPOSE_PROJECT_NAME "$DEFAULT_PROJECT_NAME")"
project_name::sanitize "$raw_name"
}
init_compose_files(){

View File

@@ -9,10 +9,10 @@ set -euo pipefail
print_usage() {
cat <<'EOF'
Usage: scripts/detect-client-data-version.sh [--no-header] <repo-path> [...]
Usage: scripts/bash/detect-client-data-version.sh [--no-header] <repo-path> [...]
Outputs a tab-separated list of repository path, raw version token found in the
source tree, and a normalized CLIENT_DATA_VERSION (e.g., v18).
source tree, and a normalized CLIENT_DATA_VERSION (e.g., v18.0).
EOF
}

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose
# azerothcore-rm
set -e
echo '🚀 Starting AzerothCore game data setup...'

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose
# azerothcore-rm
set -e
trap 'echo " ❌ SQL helper error (line ${LINENO}): ${BASH_COMMAND}" >&2' ERR
@@ -117,8 +117,8 @@ ensure_module_metadata(){
local -a module_py_candidates=(
"${MODULE_HELPER:-}"
"${HELPER_DIR%/*}/modules.py"
"/tmp/scripts/modules.py"
"/scripts/modules.py"
"/tmp/scripts/python/modules.py"
"/scripts/python/modules.py"
)
local module_py=""

View File

@@ -10,6 +10,11 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
MODULE_HELPER="$SCRIPT_DIR/modules.py"
DEFAULT_ENV_PATH="$PROJECT_ROOT/.env"
ENV_PATH="${MODULES_ENV_PATH:-$DEFAULT_ENV_PATH}"
TEMPLATE_FILE="$PROJECT_ROOT/.env.template"
source "$PROJECT_ROOT/scripts/bash/project_name.sh"
# Default project name (read from .env or template)
DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_PATH" "$TEMPLATE_FILE")"
BLUE='\033[0;34m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
PLAYERBOTS_DB_UPDATE_LOGGED=0
@@ -75,7 +80,7 @@ resolve_manifest_path(){
setup_git_config(){
info "Configuring git identity"
git config --global user.name "${GIT_USERNAME:-ac-compose}" >/dev/null 2>&1 || true
git config --global user.name "${GIT_USERNAME:-$DEFAULT_PROJECT_NAME}" >/dev/null 2>&1 || true
git config --global user.email "${GIT_EMAIL:-noreply@azerothcore.org}" >/dev/null 2>&1 || true
}
@@ -456,8 +461,8 @@ manage_configuration_files(){
load_sql_helper(){
local helper_paths=(
"/scripts/manage-modules-sql.sh"
"/tmp/scripts/manage-modules-sql.sh"
"/scripts/bash/manage-modules-sql.sh"
"/tmp/scripts/bash/manage-modules-sql.sh"
)
if [ "${MODULES_LOCAL_RUN:-0}" = "1" ]; then
@@ -556,7 +561,7 @@ track_module_state(){
if [ -n "$host_rebuild_sentinel" ]; then
printf '%s\n' "${MODULES_COMPILE_LIST[@]}" > "$host_rebuild_sentinel" 2>/dev/null || true
fi
echo "🚨 Module changes detected; run ./scripts/rebuild-with-modules.sh to rebuild source images."
echo "🚨 Module changes detected; run ./scripts/bash/rebuild-with-modules.sh to rebuild source images."
else
rm -f "$rebuild_sentinel" 2>/dev/null || true
if [ -n "$host_rebuild_sentinel" ]; then

View File

@@ -8,6 +8,11 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$PROJECT_ROOT/.env"
TEMPLATE_FILE="$PROJECT_ROOT/.env.template"
source "$PROJECT_ROOT/scripts/bash/project_name.sh"
# Default project name (read from .env or template)
DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_FILE" "$TEMPLATE_FILE")"
read_env_value(){
local key="$1" default="$2" value=""
@@ -25,17 +30,8 @@ read_env_value(){
resolve_project_name(){
local raw_name
raw_name="$(read_env_value COMPOSE_PROJECT_NAME "azerothcore-realmmaster")"
local sanitized
sanitized="$(echo "$raw_name" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
sanitized="azerothcore-realmmaster"
elif [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
echo "$sanitized"
raw_name="$(read_env_value COMPOSE_PROJECT_NAME "$DEFAULT_PROJECT_NAME")"
project_name::sanitize "$raw_name"
}
resolve_project_image(){
@@ -79,7 +75,7 @@ Options:
--user USER SSH username on remote host (required)
--port PORT SSH port (default: 22)
--identity PATH SSH private key (passed to scp/ssh)
--project-dir DIR Remote project directory (default: ~/AzerothCore-RealmMaster)
--project-dir DIR Remote project directory (default: ~/<project-name>)
--tarball PATH Output path for the image tar (default: ./local-storage/images/acore-modules-images.tar)
--storage PATH Remote storage directory (default: <project-dir>/storage)
--skip-storage Do not sync the storage directory
@@ -129,7 +125,7 @@ expand_remote_path(){
esac
}
PROJECT_DIR="${PROJECT_DIR:-/home/${USER}/AzerothCore-RealmMaster}"
PROJECT_DIR="${PROJECT_DIR:-/home/${USER}/$(resolve_project_name)}"
PROJECT_DIR="$(expand_remote_path "$PROJECT_DIR")"
REMOTE_STORAGE="${REMOTE_STORAGE:-${PROJECT_DIR}/storage}"
REMOTE_STORAGE="$(expand_remote_path "$REMOTE_STORAGE")"

View File

@@ -0,0 +1,49 @@
#!/bin/bash
project_name::extract(){
local file="$1"
if [ -n "$file" ] && [ -f "$file" ]; then
local line value
line="$(grep -E '^COMPOSE_PROJECT_NAME=' "$file" 2>/dev/null | tail -n1)"
if [ -n "$line" ]; then
value="${line#*=}"
value="${value%$'\r'}"
value="$(printf '%s\n' "$value" | awk -F'#' '{print $1}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
value="${value%\"}"; value="${value#\"}"
value="${value%\'}"; value="${value#\'}"
printf '%s\n' "$value"
fi
fi
}
project_name::resolve(){
local env_file="$1" template_file="$2" value=""
value="$(project_name::extract "$env_file")"
if [ -z "$value" ] && [ -n "$template_file" ]; then
value="$(project_name::extract "$template_file")"
fi
if [ -z "$value" ] && [ -n "${COMPOSE_PROJECT_NAME:-}" ]; then
value="${COMPOSE_PROJECT_NAME}"
fi
if [ -z "$value" ]; then
echo "Error: COMPOSE_PROJECT_NAME not defined in $env_file, $template_file, or environment." >&2
exit 1
fi
printf '%s\n' "$value"
}
project_name::sanitize(){
local raw="$1"
local sanitized
sanitized="$(echo "$raw" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
echo "Error: COMPOSE_PROJECT_NAME '$raw' is invalid after sanitization." >&2
exit 1
fi
if [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
printf '%s\n' "$sanitized"
}

View File

@@ -1,12 +1,17 @@
#!/bin/bash
# ac-compose helper to rebuild AzerothCore from source with enabled modules.
# azerothcore-rm helper to rebuild AzerothCore from source with enabled modules.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$PROJECT_DIR/.env"
TEMPLATE_FILE="$PROJECT_DIR/.env.template"
source "$PROJECT_DIR/scripts/bash/project_name.sh"
# Default project name (read from .env or template)
DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_FILE" "$TEMPLATE_FILE")"
BLUE='\033[0;34m'
GREEN='\033[0;32m'
@@ -98,17 +103,8 @@ ensure_project_image_tag(){
resolve_project_name(){
local raw_name
raw_name="$(read_env COMPOSE_PROJECT_NAME "azerothcore-realmmaster")"
local sanitized
sanitized="$(echo "$raw_name" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
sanitized="azerothcore-realmmaster"
elif [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
echo "$sanitized"
raw_name="$(read_env COMPOSE_PROJECT_NAME "$DEFAULT_PROJECT_NAME")"
project_name::sanitize "$raw_name"
}
resolve_project_image(){
@@ -158,7 +154,7 @@ ASSUME_YES=0
SOURCE_OVERRIDE=""
SKIP_STOP=0
MODULE_HELPER="$PROJECT_DIR/scripts/modules.py"
MODULE_HELPER="$PROJECT_DIR/scripts/python/modules.py"
MODULE_STATE_DIR=""
declare -a MODULES_COMPILE_LIST=()

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# ac-compose source repository setup
# azerothcore-rm source repository setup
set -euo pipefail
echo '🔧 Setting up AzerothCore source repository...'
@@ -35,7 +35,7 @@ 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"
local detector="$PROJECT_ROOT/scripts/bash/detect-client-data-version.sh"
if [ ! -x "$detector" ]; then
return
fi

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# ac-compose helper to automatically stage modules and trigger source builds when needed.
# azerothcore-rm helper to automatically stage modules and trigger source builds when needed.
set -e
@@ -64,8 +64,13 @@ sync_local_staging(){
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$PROJECT_DIR/.env"
TEMPLATE_FILE="$PROJECT_DIR/.env.template"
source "$PROJECT_DIR/scripts/bash/project_name.sh"
# Default project name (read from .env or template)
DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_FILE" "$TEMPLATE_FILE")"
DEFAULT_COMPOSE_FILE="$PROJECT_DIR/docker-compose.yml"
source "$PROJECT_DIR/scripts/lib/compose_overrides.sh"
source "$PROJECT_DIR/scripts/bash/compose_overrides.sh"
usage(){
cat <<EOF
@@ -101,17 +106,8 @@ read_env(){
resolve_project_name(){
local raw_name
raw_name="$(read_env COMPOSE_PROJECT_NAME "azerothcore-realmmaster")"
local sanitized
sanitized="$(echo "$raw_name" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
sanitized="azerothcore-realmmaster"
elif [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
echo "$sanitized"
raw_name="$(read_env COMPOSE_PROJECT_NAME "$DEFAULT_PROJECT_NAME")"
project_name::sanitize "$raw_name"
}
if [ -z "${COMPOSE_FILE:-}" ]; then

View File

@@ -1,5 +1,5 @@
#!/bin/bash
# Project: ac-compose
# Project: azerothcore-rm
set -e
# Simple profile-aware deploy + health check for profiles-verify/docker-compose.yml
@@ -13,7 +13,9 @@ err(){ echo -e "${RED}❌ $*${NC}"; }
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
COMPOSE_FILE="$PROJECT_DIR/docker-compose.yml"
ENV_FILE=""
source "$PROJECT_DIR/scripts/lib/compose_overrides.sh"
TEMPLATE_FILE="$PROJECT_DIR/.env.template"
source "$PROJECT_DIR/scripts/bash/project_name.sh"
source "$PROJECT_DIR/scripts/bash/compose_overrides.sh"
PROFILES=(db services-standard client-data modules tools)
SKIP_DEPLOY=false
QUICK=false
@@ -46,20 +48,17 @@ resolve_project_name(){
else
env_path="$(dirname "$COMPOSE_FILE")/.env"
fi
local raw_name=""
if [ -f "$env_path" ]; then
raw_name="$(grep -E '^COMPOSE_PROJECT_NAME=' "$env_path" | tail -n1 | cut -d'=' -f2-)"
fi
if [ -z "$raw_name" ]; then
raw_name="azerothcore-realmmaster"
fi
local raw_name
raw_name="$(project_name::resolve "$env_path" "$TEMPLATE_FILE")"
local sanitized
sanitized="$(echo "$raw_name" | tr '[:upper:]' '[:lower:]')"
sanitized="${sanitized// /-}"
sanitized="$(echo "$sanitized" | tr -cd 'a-z0-9_-')"
if [[ -z "$sanitized" ]]; then
sanitized="azerothcore-realmmaster"
elif [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
echo "Error: COMPOSE_PROJECT_NAME is invalid" >&2
exit 1
fi
if [[ ! "$sanitized" =~ ^[a-z0-9] ]]; then
sanitized="ac${sanitized}"
fi
echo "$sanitized"
@@ -120,21 +119,21 @@ handle_auto_rebuild(){
local auto_rebuild
auto_rebuild="$(read_env_value AUTO_REBUILD_ON_DEPLOY "0")"
if [ "$auto_rebuild" != "1" ]; then
warn "Run ./scripts/rebuild-with-modules.sh after preparing your source tree."
warn "Run ./scripts/bash/rebuild-with-modules.sh after preparing your source tree."
return 0
fi
local rebuild_source
rebuild_source="$(read_env_value MODULES_REBUILD_SOURCE_PATH "")"
info "AUTO_REBUILD_ON_DEPLOY=1; invoking ./scripts/rebuild-with-modules.sh."
local cmd=(./scripts/rebuild-with-modules.sh --yes)
info "AUTO_REBUILD_ON_DEPLOY=1; invoking ./scripts/bash/rebuild-with-modules.sh."
local cmd=(./scripts/bash/rebuild-with-modules.sh --yes)
if [ -n "$rebuild_source" ]; then
cmd+=(--source "$rebuild_source")
fi
if "${cmd[@]}"; then
info "Module rebuild completed."
else
warn "Automatic rebuild failed; run ./scripts/rebuild-with-modules.sh manually."
warn "Automatic rebuild failed; run ./scripts/bash/rebuild-with-modules.sh manually."
fi
}

View File

@@ -260,7 +260,7 @@ def write_outputs(state: ModuleCollectionState, output_dir: Path) -> None:
output_dir.mkdir(parents=True, exist_ok=True)
env_lines: List[str] = [
"# Autogenerated by scripts/modules.py",
"# Autogenerated by scripts/python/modules.py",
f"# Generated at {state.generated_at.isoformat()}",
f'export MODULES_MANIFEST="{state.manifest_path}"',
f'export MODULES_ENV_PATH="{state.env_path}"',