mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(bash): several chores to bash scripts: (#23250)
This commit is contained in:
2
.github/workflows/dashboard-ci.yml
vendored
2
.github/workflows/dashboard-ci.yml
vendored
@@ -92,6 +92,8 @@ jobs:
|
|||||||
./acore.sh module update --all
|
./acore.sh module update --all
|
||||||
|
|
||||||
- name: Run complete installation (deps, compile, database, client-data)
|
- name: Run complete installation (deps, compile, database, client-data)
|
||||||
|
env:
|
||||||
|
AC_ENABLE_ROOT_CMAKE_INSTALL: 1
|
||||||
run: |
|
run: |
|
||||||
# This runs: install-deps, compile, database setup, client-data download
|
# This runs: install-deps, compile, database setup, client-data download
|
||||||
./acore.sh init
|
./acore.sh init
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ function comp_compile() {
|
|||||||
echo "Setting permissions on binary files"
|
echo "Setting permissions on binary files"
|
||||||
find "$AC_BINPATH_FULL" -mindepth 1 -maxdepth 1 -type f -exec $SUDO chown root:root -- {} +
|
find "$AC_BINPATH_FULL" -mindepth 1 -maxdepth 1 -type f -exec $SUDO chown root:root -- {} +
|
||||||
find "$AC_BINPATH_FULL" -mindepth 1 -maxdepth 1 -type f -exec $SUDO chmod u+s -- {} +
|
find "$AC_BINPATH_FULL" -mindepth 1 -maxdepth 1 -type f -exec $SUDO chmod u+s -- {} +
|
||||||
|
$SUDO setcap cap_sys_nice=eip "$AC_BINPATH_FULL/worldserver"
|
||||||
|
$SUDO setcap cap_sys_nice=eip "$AC_BINPATH_FULL/authserver"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -f "$confDir/worldserver.conf.dist" ]] && \
|
[[ -f "$confDir/worldserver.conf.dist" ]] && \
|
||||||
|
|||||||
@@ -127,10 +127,13 @@ function inst_module_help() {
|
|||||||
echo " ./acore.sh module # Interactive menu"
|
echo " ./acore.sh module # Interactive menu"
|
||||||
echo " ./acore.sh module search [terms...]"
|
echo " ./acore.sh module search [terms...]"
|
||||||
echo " ./acore.sh module install [--all | modules...]"
|
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 remove [modules...]"
|
||||||
echo " ./acore.sh module list # List installed modules"
|
echo " ./acore.sh module list # List installed modules"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " --discard-changes Reset module repositories to a clean state before updating"
|
||||||
|
echo ""
|
||||||
echo "Module Specification Syntax:"
|
echo "Module Specification Syntax:"
|
||||||
echo " name # Simple name (e.g., mod-transmog)"
|
echo " name # Simple name (e.g., mod-transmog)"
|
||||||
echo " owner/name # GitHub repository"
|
echo " owner/name # GitHub repository"
|
||||||
@@ -602,6 +605,37 @@ function inst_mod_is_installed() {
|
|||||||
return 1
|
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
|
# Conflict Detection and Validation
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -901,31 +935,48 @@ function inst_module_install {
|
|||||||
|
|
||||||
# Update one or more modules
|
# Update one or more modules
|
||||||
function inst_module_update {
|
function inst_module_update {
|
||||||
# Handle help request
|
local modules=()
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
local use_all=false
|
||||||
|
local discard_changes=false
|
||||||
|
local had_errors=0
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--help|-h)
|
||||||
inst_module_help
|
inst_module_help
|
||||||
return 0
|
return 0
|
||||||
fi
|
;;
|
||||||
|
--all|-a)
|
||||||
# Support multiple modules and the --all flag; prompt if none specified.
|
|
||||||
local args=("$@")
|
|
||||||
local use_all=false
|
|
||||||
if [ ${#args[@]} -gt 0 ] && { [ "${args[0]}" = "--all" ] || [ "${args[0]}" = "-a" ]; }; then
|
|
||||||
use_all=true
|
use_all=true
|
||||||
|
;;
|
||||||
|
--discard-changes|--reset|-r)
|
||||||
|
discard_changes=true
|
||||||
|
;;
|
||||||
|
--)
|
||||||
shift || true
|
shift || true
|
||||||
fi
|
while [[ $# -gt 0 ]]; do
|
||||||
|
modules+=("$1")
|
||||||
local _tmp=$PWD
|
shift || true
|
||||||
|
done
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
modules+=("$1")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift || true
|
||||||
|
done
|
||||||
|
|
||||||
if $use_all; then
|
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
|
while read -r repo_ref branch commit; do
|
||||||
[ -z "$repo_ref" ] && continue
|
[ -z "$repo_ref" ] && continue
|
||||||
# Skip excluded modules during update --all
|
|
||||||
if inst_mod_is_excluded "$repo_ref"; then
|
if inst_mod_is_excluded "$repo_ref"; then
|
||||||
print_warn "[$repo_ref] Excluded by MODULES_EXCLUDE_LIST (skipping)."
|
print_warn "[$repo_ref] Excluded by MODULES_EXCLUDE_LIST (skipping)."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
parsed_output=$(inst_parse_module_spec "$repo_ref")
|
parsed_output=$(inst_parse_module_spec "$repo_ref")
|
||||||
IFS=' ' read -r _ owner modname _ _ url dirname <<< "$parsed_output"
|
IFS=' ' read -r _ owner modname _ _ url dirname <<< "$parsed_output"
|
||||||
|
|
||||||
@@ -935,16 +986,23 @@ function inst_module_update {
|
|||||||
continue
|
continue
|
||||||
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" "$branch" ""; then
|
if Joiner:upd_repo "$url" "$dirname" "$branch" ""; then
|
||||||
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
|
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
|
||||||
inst_mod_list_upsert "$repo_ref" "$branch" "$newCommit"
|
inst_mod_list_upsert "$repo_ref" "$branch" "$newCommit"
|
||||||
print_success "[$repo_ref] Updated to latest commit on '$branch'."
|
print_success "[$repo_ref] Updated to latest commit on '$branch'."
|
||||||
else
|
else
|
||||||
print_error "[$repo_ref] Cannot update"
|
print_error "[$repo_ref] Cannot update"
|
||||||
|
had_errors=1
|
||||||
fi
|
fi
|
||||||
done < <(inst_mod_list_read)
|
done < <(inst_mod_list_read)
|
||||||
else
|
else
|
||||||
local modules=("$@")
|
|
||||||
if [ ${#modules[@]} -eq 0 ]; then
|
if [ ${#modules[@]} -eq 0 ]; then
|
||||||
echo "Type the name(s) of the module(s) to update"
|
echo "Type the name(s) of the module(s) to update"
|
||||||
read -p "Insert name(s): " _line
|
read -p "Insert name(s): " _line
|
||||||
@@ -952,6 +1010,7 @@ function inst_module_update {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local spec repo_ref override_branch override_commit owner modname url dirname v b branch def newCommit
|
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
|
for spec in "${modules[@]}"; do
|
||||||
[ -z "$spec" ] && continue
|
[ -z "$spec" ] && continue
|
||||||
parsed_output=$(inst_parse_module_spec "$spec")
|
parsed_output=$(inst_parse_module_spec "$spec")
|
||||||
@@ -959,11 +1018,10 @@ function inst_module_update {
|
|||||||
|
|
||||||
dirname="${dirname:-$modname}"
|
dirname="${dirname:-$modname}"
|
||||||
if [ -d "$J_PATH_MODULES/$dirname/" ]; then
|
if [ -d "$J_PATH_MODULES/$dirname/" ]; then
|
||||||
# determine preferred branch if not provided
|
b=""
|
||||||
if [ -n "$override_branch" ] && [ "$override_branch" != "-" ]; then
|
if [ -n "$override_branch" ] && [ "$override_branch" != "-" ]; then
|
||||||
b="$override_branch"
|
b="$override_branch"
|
||||||
else
|
else
|
||||||
# try reading acore-module.json for this repo
|
|
||||||
if [[ "$url" =~ github.com ]]; then
|
if [[ "$url" =~ github.com ]]; then
|
||||||
read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/${owner}/${modname}/master/acore-module.json")
|
read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/${owner}/${modname}/master/acore-module.json")
|
||||||
else
|
else
|
||||||
@@ -981,21 +1039,35 @@ function inst_module_update {
|
|||||||
fi
|
fi
|
||||||
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
|
if Joiner:upd_repo "$url" "$dirname" "$b" ""; then
|
||||||
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
|
newCommit=$(git -C "$J_PATH_MODULES/$dirname" rev-parse HEAD 2>/dev/null || echo "")
|
||||||
inst_mod_list_upsert "$repo_ref" "$b" "$newCommit"
|
inst_mod_list_upsert "$repo_ref" "$b" "$newCommit"
|
||||||
print_success "[$repo_ref] Done, please re-run compiling and db assembly"
|
print_success "[$repo_ref] Done, please re-run compiling and db assembly"
|
||||||
else
|
else
|
||||||
print_error "[$repo_ref] Cannot update"
|
print_error "[$repo_ref] Cannot update"
|
||||||
|
had_errors=1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
print_error "[$repo_ref] Cannot update! Path doesn't exist ($J_PATH_MODULES/$dirname/)"
|
print_error "[$repo_ref] Cannot update! Path doesn't exist ($J_PATH_MODULES/$dirname/)"
|
||||||
|
had_errors=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
if [ "$had_errors" -ne 0 ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove one or more modules
|
# Remove one or more modules
|
||||||
|
|||||||
@@ -277,6 +277,9 @@ function restore_missing_services() {
|
|||||||
local service_exists=false
|
local service_exists=false
|
||||||
|
|
||||||
if [ "$provider" = "pm2" ]; then
|
if [ "$provider" = "pm2" ]; then
|
||||||
|
echo "Check if PM2 is installed..."
|
||||||
|
check_pm2 || { echo -e "${RED}PM2 is not installed. Cannot check service status.${NC}"; exit 1; }
|
||||||
|
|
||||||
if pm2 describe "$name" >/dev/null 2>&1; then
|
if pm2 describe "$name" >/dev/null 2>&1; then
|
||||||
service_exists=true
|
service_exists=true
|
||||||
fi
|
fi
|
||||||
|
|||||||
3
conf/dist/config.sh
vendored
3
conf/dist/config.sh
vendored
@@ -112,7 +112,8 @@ export CCACHE_DIR=${CCACHE_DIR:-"$AC_PATH_VAR/ccache"}
|
|||||||
# Enable running the cmake install as root
|
# Enable running the cmake install as root
|
||||||
# Installing as root allows to set the SUID bit on
|
# Installing as root allows to set the SUID bit on
|
||||||
# the worldserver binary. This is required if you want
|
# the worldserver binary. This is required if you want
|
||||||
# to bind the worldserver to reserved ports
|
# to bind the worldserver to reserved ports and allow
|
||||||
|
# it to set higher process priority.
|
||||||
# Default: 0 (false)
|
# Default: 0 (false)
|
||||||
#
|
#
|
||||||
export AC_ENABLE_ROOT_CMAKE_INSTALL=${AC_ENABLE_ROOT_CMAKE_INSTALL:-0}
|
export AC_ENABLE_ROOT_CMAKE_INSTALL=${AC_ENABLE_ROOT_CMAKE_INSTALL:-0}
|
||||||
|
|||||||
17
deps/acore/joiner/joiner.sh
vendored
17
deps/acore/joiner/joiner.sh
vendored
@@ -116,7 +116,21 @@ function Joiner:add_repo() (
|
|||||||
if [ -e "$path/.git/" ]; then
|
if [ -e "$path/.git/" ]; then
|
||||||
# if exists , update
|
# if exists , update
|
||||||
echo "Updating $name on branch $branch..."
|
echo "Updating $name on branch $branch..."
|
||||||
git --git-dir="$path/.git/" --work-tree="$path" rev-parse && git --git-dir="$path/.git/" --work-tree="$path" pull origin "$branch" | grep 'Already up-to-date.' && changed="no" || true
|
if ! git --git-dir="$path/.git/" --work-tree="$path" rev-parse >/dev/null 2>&1; then
|
||||||
|
echo "Unable to read repository at $path/.git/"
|
||||||
|
return $FALSE
|
||||||
|
fi
|
||||||
|
|
||||||
|
local pull_output
|
||||||
|
if ! pull_output=$(git --git-dir="$path/.git/" --work-tree="$path" pull origin "$branch" 2>&1); then
|
||||||
|
printf "%s\n" "$pull_output"
|
||||||
|
return $FALSE
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\n" "$pull_output"
|
||||||
|
if echo "$pull_output" | grep -qE 'Already up[- ]to-date.'; then
|
||||||
|
changed="no"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# otherwise clone
|
# otherwise clone
|
||||||
echo "Cloning $name on branch $branch..."
|
echo "Cloning $name on branch $branch..."
|
||||||
@@ -440,4 +454,3 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|||||||
else
|
else
|
||||||
Joiner:_checkOptions $@
|
Joiner:_checkOptions $@
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user