mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(ServiceManager): enhance path handling and add canonicalization function
This commit is contained in:
@@ -13,10 +13,57 @@ SCRIPT_DIR="$CURRENT_PATH"
|
|||||||
|
|
||||||
ROOT_DIR="$(cd "$CURRENT_PATH/../../.." && pwd)"
|
ROOT_DIR="$(cd "$CURRENT_PATH/../../.." && pwd)"
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
readonly YELLOW='\033[1;33m'
|
||||||
|
readonly GREEN='\033[0;32m'
|
||||||
|
readonly RED='\033[0;31m'
|
||||||
|
readonly BLUE='\033[0;34m'
|
||||||
|
readonly NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
canonicalize_path() {
|
||||||
|
local input="$1"
|
||||||
|
|
||||||
|
if [ -z "$input" ]; then
|
||||||
|
echo ""
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v realpath >/dev/null 2>&1; then
|
||||||
|
local resolved
|
||||||
|
resolved="$(realpath -m "$input" 2>/dev/null)" && { echo "$resolved"; return; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v python3 >/dev/null 2>&1; then
|
||||||
|
local py_resolved
|
||||||
|
py_resolved="$(python3 -c 'import os,sys; print(os.path.abspath(os.path.normpath(sys.argv[1])))' "$input" 2>/dev/null)" && {
|
||||||
|
echo "$py_resolved"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$input" ]; then
|
||||||
|
(cd "$input" 2>/dev/null && pwd) && return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local dir base
|
||||||
|
dir=$(dirname "$input")
|
||||||
|
base=$(basename "$input")
|
||||||
|
if [ -d "$dir" ]; then
|
||||||
|
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd)" "$base") && return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$input"
|
||||||
|
}
|
||||||
|
|
||||||
# Configuration directory (can be overridden with AC_SERVICE_CONFIG_DIR)
|
# Configuration directory (can be overridden with AC_SERVICE_CONFIG_DIR)
|
||||||
CONFIG_DIR="${AC_SERVICE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/azerothcore/services}"
|
CONFIG_DIR_RAW="${AC_SERVICE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/azerothcore/services}"
|
||||||
|
|
||||||
|
# Create config directory if it doesn't exist
|
||||||
|
mkdir -p "$CONFIG_DIR_RAW"
|
||||||
|
|
||||||
|
CONFIG_DIR="$(canonicalize_path "$CONFIG_DIR_RAW")"
|
||||||
|
export AC_SERVICE_CONFIG_DIR="$CONFIG_DIR"
|
||||||
REGISTRY_FILE="$CONFIG_DIR/service_registry.json"
|
REGISTRY_FILE="$CONFIG_DIR/service_registry.json"
|
||||||
export AC_SERVICE_CONFIG_DIR="${AC_SERVICE_CONFIG_DIR:-$CONFIG_DIR}"
|
|
||||||
|
|
||||||
# Default values for variables that might be loaded from config files
|
# Default values for variables that might be loaded from config files
|
||||||
# This prevents "unbound variable" errors when sourcing configuration files
|
# This prevents "unbound variable" errors when sourcing configuration files
|
||||||
@@ -30,14 +77,8 @@ RESTART_POLICY="${RESTART_POLICY:-}"
|
|||||||
GDB_ENABLED="${GDB_ENABLED:-}"
|
GDB_ENABLED="${GDB_ENABLED:-}"
|
||||||
SERVER_CONFIG="${SERVER_CONFIG:-}"
|
SERVER_CONFIG="${SERVER_CONFIG:-}"
|
||||||
|
|
||||||
# Colors for output
|
|
||||||
readonly YELLOW='\033[1;33m'
|
|
||||||
readonly GREEN='\033[0;32m'
|
|
||||||
readonly RED='\033[0;31m'
|
|
||||||
readonly BLUE='\033[0;34m'
|
|
||||||
readonly NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
# Create config directory if it doesn't exist
|
# Create config directory if it doesn't exist
|
||||||
|
# (already ensured above), but keep for robustness
|
||||||
mkdir -p "$CONFIG_DIR"
|
mkdir -p "$CONFIG_DIR"
|
||||||
|
|
||||||
# Initialize registry if it doesn't exist
|
# Initialize registry if it doesn't exist
|
||||||
@@ -1534,10 +1575,10 @@ function create_service() {
|
|||||||
|
|
||||||
# Determine server binary based on service type
|
# Determine server binary based on service type
|
||||||
local server_bin="${service_type}server"
|
local server_bin="${service_type}server"
|
||||||
local server_binary_path=$(realpath "$bin_path/$server_bin")
|
local server_binary_path="$(canonicalize_path "$bin_path/$server_bin")"
|
||||||
local real_config_path=""
|
local real_config_path=""
|
||||||
if [ -n "$server_config" ]; then
|
if [ -n "$server_config" ]; then
|
||||||
real_config_path=$(realpath "$server_config")
|
real_config_path="$(canonicalize_path "$server_config")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if binary exists
|
# Check if binary exists
|
||||||
|
|||||||
Reference in New Issue
Block a user