summaryrefslogtreecommitdiff
path: root/apps/installer/includes/modules-manager
diff options
context:
space:
mode:
Diffstat (limited to 'apps/installer/includes/modules-manager')
-rw-r--r--apps/installer/includes/modules-manager/README.md6
-rw-r--r--apps/installer/includes/modules-manager/modules.sh151
2 files changed, 97 insertions, 60 deletions
diff --git a/apps/installer/includes/modules-manager/README.md b/apps/installer/includes/modules-manager/README.md
index 93496a91a6..d6a160b6c7 100644
--- a/apps/installer/includes/modules-manager/README.md
+++ b/apps/installer/includes/modules-manager/README.md
@@ -63,7 +63,7 @@ repo[:dirname][@branch[:commit]]
./acore.sh module install https://github.com/azerothcore/mod-transmog.git@main
# Install multiple modules
-./acore.sh module install mod-transmog mod-eluna:custom-eluna
+./acore.sh module install mod-transmog mod-ale:custom-eluna
# Install all modules from list
./acore.sh module install --all
@@ -92,7 +92,7 @@ repo[:dirname][@branch[:commit]]
./acore.sh module remove https://github.com/azerothcore/mod-transmog.git
# Remove multiple modules
-./acore.sh module remove mod-transmog mod-eluna
+./acore.sh module remove mod-transmog mod-ale
```
### Searching Modules
@@ -232,7 +232,7 @@ repo_reference branch commit
# Examples:
azerothcore/mod-transmog master abc123def456
https://github.com/custom/mod-custom.git develop def456abc789
-mod-eluna:custom-eluna-dir main 789abc123def
+mod-ale:custom-eluna-dir main 789abc123def
```
The list maintains:
diff --git a/apps/installer/includes/modules-manager/modules.sh b/apps/installer/includes/modules-manager/modules.sh
index 787d07677c..89c7ea50ac 100644
--- a/apps/installer/includes/modules-manager/modules.sh
+++ b/apps/installer/includes/modules-manager/modules.sh
@@ -59,7 +59,6 @@ else
C_GREEN=''
C_YELLOW=''
C_BLUE=''
- C_MAGENTA=''
C_CYAN=''
fi
@@ -127,10 +126,13 @@ function inst_module_help() {
echo " ./acore.sh module # Interactive menu"
echo " ./acore.sh module search [terms...]"
echo " ./acore.sh module install [--all | modules...]"
- echo " ./acore.sh module update [--all | modules...]"
+ echo " ./acore.sh module update [--discard-changes] [--all | modules...]"
echo " ./acore.sh module remove [modules...]"
echo " ./acore.sh module list # List installed modules"
echo ""
+ echo "Options:"
+ echo " --discard-changes Reset module repositories to a clean state before updating"
+ echo ""
echo "Module Specification Syntax:"
echo " name # Simple name (e.g., mod-transmog)"
echo " owner/name # GitHub repository"
@@ -171,42 +173,8 @@ function inst_module_list() {
# Usage: ./acore.sh module <search|install|update|remove> [args...]
# ./acore.sh module # Interactive menu
function inst_module() {
- # If no arguments provided, start interactive menu
- if [[ $# -eq 0 ]]; then
- menu_run_with_items "MODULE MANAGER" handle_module_command -- "${module_menu_items[@]}" --
- return $?
- fi
-
- # Normalize arguments into an array
- local tokens=()
- read -r -a tokens <<< "$*"
- local cmd="${tokens[0]}"
- local args=("${tokens[@]:1}")
-
- case "$cmd" in
- ""|"help"|"-h"|"--help")
- inst_module_help
- ;;
- "search"|"s")
- inst_module_search "${args[@]}"
- ;;
- "install"|"i")
- inst_module_install "${args[@]}"
- ;;
- "update"|"u")
- inst_module_update "${args[@]}"
- ;;
- "remove"|"r")
- inst_module_remove "${args[@]}"
- ;;
- "list"|"l")
- inst_module_list "${args[@]}"
- ;;
- *)
- print_error "Unknown module command: $cmd. Use 'help' to see available commands."
- return 1
- ;;
- esac
+ menu_run_with_items "MODULE MANAGER" handle_module_command -- "${module_menu_items[@]}" -- "$@"
+ return $?
}
# =============================================================================
@@ -602,6 +570,37 @@ function inst_mod_is_installed() {
return 1
}
+# Discard local changes from a module repository to guarantee a clean update.
+function inst_module_reset_repo() {
+ local repo_ref="$1"
+ local dirname="$2"
+ local repo_path="$J_PATH_MODULES/$dirname"
+
+ if [ ! -d "$repo_path" ]; then
+ print_error "[$repo_ref] Cannot discard changes; path not found ($repo_path)."
+ return 1
+ fi
+
+ if [ ! -d "$repo_path/.git" ]; then
+ print_error "[$repo_ref] Cannot discard changes; $repo_path is not a git repository."
+ return 1
+ fi
+
+ print_warn "[$repo_ref] Discarding local changes (--discard-changes)."
+
+ if ! git -C "$repo_path" reset --hard >/dev/null 2>&1; then
+ print_error "[$repo_ref] Failed to reset repository at $repo_path."
+ return 1
+ fi
+
+ if ! git -C "$repo_path" clean -fd >/dev/null 2>&1; then
+ print_error "[$repo_ref] Failed to remove untracked files from $repo_path."
+ return 1
+ fi
+
+ return 0
+}
+
# =============================================================================
# Conflict Detection and Validation
# =============================================================================
@@ -649,7 +648,7 @@ function inst_getVersionBranch() {
res="none"
# since we've the pair version,branch alternated in not associative and one-dimensional
# array, we've to simulate the association with length/2 trick
- for idx in `seq 0 $((${#vers[*]}/2-1))`; do
+ for idx in $(seq 0 $((${#vers[*]}/2-1))); do
semverParseInto "${vers[idx*2]}" MODULE_MAJOR MODULE_MINOR MODULE_PATCH MODULE_SPECIAL
if [[ $MODULE_MAJOR -eq $ACV_MAJOR && $MODULE_MINOR -le $ACV_MINOR ]]; then
res="${vers[idx*2+1]}"
@@ -901,31 +900,48 @@ function inst_module_install {
# Update one or more modules
function inst_module_update {
- # Handle help request
- if [[ "$1" == "--help" || "$1" == "-h" ]]; then
- inst_module_help
- return 0
- fi
-
- # Support multiple modules and the --all flag; prompt if none specified.
- local args=("$@")
+ local modules=()
local use_all=false
- if [ ${#args[@]} -gt 0 ] && { [ "${args[0]}" = "--all" ] || [ "${args[0]}" = "-a" ]; }; then
- use_all=true
+ local discard_changes=false
+ local had_errors=0
+
+ while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --help|-h)
+ inst_module_help
+ return 0
+ ;;
+ --all|-a)
+ use_all=true
+ ;;
+ --discard-changes|--reset|-r)
+ discard_changes=true
+ ;;
+ --)
+ shift || true
+ while [[ $# -gt 0 ]]; do
+ modules+=("$1")
+ shift || true
+ done
+ break
+ ;;
+ *)
+ modules+=("$1")
+ ;;
+ esac
shift || true
- fi
-
- local _tmp=$PWD
+ done
if $use_all; then
- local line repo_ref branch commit newCommit owner modname url dirname
+ local repo_ref branch commit owner modname url dirname newCommit
+ local parsed_output
while read -r repo_ref branch commit; do
[ -z "$repo_ref" ] && continue
- # Skip excluded modules during update --all
if inst_mod_is_excluded "$repo_ref"; then
print_warn "[$repo_ref] Excluded by MODULES_EXCLUDE_LIST (skipping)."
continue
fi
+
parsed_output=$(inst_parse_module_spec "$repo_ref")
IFS=' ' read -r _ owner modname _ _ url dirname <<< "$parsed_output"
@@ -935,16 +951,23 @@ function inst_module_update {
continue
fi
+ if $discard_changes; then
+ if ! inst_module_reset_repo "$repo_ref" "$dirname"; then
+ had_errors=1
+ continue
+ fi
+ fi
+
if Joiner:upd_repo "$url" "$dirname" "$branch" ""; then
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
inst_mod_list_upsert "$repo_ref" "$branch" "$newCommit"
print_success "[$repo_ref] Updated to latest commit on '$branch'."
else
print_error "[$repo_ref] Cannot update"
+ had_errors=1
fi
done < <(inst_mod_list_read)
else
- local modules=("$@")
if [ ${#modules[@]} -eq 0 ]; then
echo "Type the name(s) of the module(s) to update"
read -p "Insert name(s): " _line
@@ -952,6 +975,7 @@ function inst_module_update {
fi
local spec repo_ref override_branch override_commit owner modname url dirname v b branch def newCommit
+ local parsed_output
for spec in "${modules[@]}"; do
[ -z "$spec" ] && continue
parsed_output=$(inst_parse_module_spec "$spec")
@@ -959,11 +983,10 @@ function inst_module_update {
dirname="${dirname:-$modname}"
if [ -d "$J_PATH_MODULES/$dirname/" ]; then
- # determine preferred branch if not provided
+ b=""
if [ -n "$override_branch" ] && [ "$override_branch" != "-" ]; then
b="$override_branch"
else
- # try reading acore-module.json for this repo
if [[ "$url" =~ github.com ]]; then
read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/${owner}/${modname}/master/acore-module.json")
else
@@ -981,21 +1004,35 @@ function inst_module_update {
fi
fi
+ if $discard_changes; then
+ if ! inst_module_reset_repo "$repo_ref" "$dirname"; then
+ had_errors=1
+ continue
+ fi
+ fi
+
if Joiner:upd_repo "$url" "$dirname" "$b" ""; then
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
inst_mod_list_upsert "$repo_ref" "$b" "$newCommit"
print_success "[$repo_ref] Done, please re-run compiling and db assembly"
else
print_error "[$repo_ref] Cannot update"
+ had_errors=1
fi
else
print_error "[$repo_ref] Cannot update! Path doesn't exist ($J_PATH_MODULES/$dirname/)"
+ had_errors=1
fi
done
fi
echo ""
echo ""
+
+ if [ "$had_errors" -ne 0 ]; then
+ return 1
+ fi
+ return 0
}
# Remove one or more modules