From cfc86788434ec824eeccb519bf130e93ffc94d51 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Wed, 15 Oct 2025 02:10:14 +0200 Subject: [PATCH] feat(bash): several chores to bash scripts: (#23250) --- .github/workflows/dashboard-ci.yml | 2 + apps/compiler/includes/functions.sh | 2 + .../includes/modules-manager/modules.sh | 110 +++++++++++++++--- apps/startup-scripts/src/service-manager.sh | 3 + conf/dist/config.sh | 3 +- deps/acore/joiner/joiner.sh | 17 ++- 6 files changed, 115 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dashboard-ci.yml b/.github/workflows/dashboard-ci.yml index 1bbad51c3..93e4e6791 100644 --- a/.github/workflows/dashboard-ci.yml +++ b/.github/workflows/dashboard-ci.yml @@ -92,6 +92,8 @@ jobs: ./acore.sh module update --all - name: Run complete installation (deps, compile, database, client-data) + env: + AC_ENABLE_ROOT_CMAKE_INSTALL: 1 run: | # This runs: install-deps, compile, database setup, client-data download ./acore.sh init diff --git a/apps/compiler/includes/functions.sh b/apps/compiler/includes/functions.sh index c608cff24..a6caef9f3 100644 --- a/apps/compiler/includes/functions.sh +++ b/apps/compiler/includes/functions.sh @@ -156,6 +156,8 @@ function comp_compile() { 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 chmod u+s -- {} + + $SUDO setcap cap_sys_nice=eip "$AC_BINPATH_FULL/worldserver" + $SUDO setcap cap_sys_nice=eip "$AC_BINPATH_FULL/authserver" fi [[ -f "$confDir/worldserver.conf.dist" ]] && \ diff --git a/apps/installer/includes/modules-manager/modules.sh b/apps/installer/includes/modules-manager/modules.sh index 787d07677..be050cff1 100644 --- a/apps/installer/includes/modules-manager/modules.sh +++ b/apps/installer/includes/modules-manager/modules.sh @@ -127,10 +127,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" @@ -602,6 +605,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 # ============================================================================= @@ -901,31 +935,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 - shift || true - fi + local discard_changes=false + local had_errors=0 - local _tmp=$PWD + 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 + 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 +986,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 +1010,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 +1018,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 +1039,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 diff --git a/apps/startup-scripts/src/service-manager.sh b/apps/startup-scripts/src/service-manager.sh index ac9278c89..5e0a31d34 100755 --- a/apps/startup-scripts/src/service-manager.sh +++ b/apps/startup-scripts/src/service-manager.sh @@ -277,6 +277,9 @@ function restore_missing_services() { local service_exists=false 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 service_exists=true fi diff --git a/conf/dist/config.sh b/conf/dist/config.sh index e33d19f21..f8e78a8b8 100644 --- a/conf/dist/config.sh +++ b/conf/dist/config.sh @@ -112,7 +112,8 @@ export CCACHE_DIR=${CCACHE_DIR:-"$AC_PATH_VAR/ccache"} # Enable running the cmake install as root # Installing as root allows to set the SUID bit on # 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) # export AC_ENABLE_ROOT_CMAKE_INSTALL=${AC_ENABLE_ROOT_CMAKE_INSTALL:-0} diff --git a/deps/acore/joiner/joiner.sh b/deps/acore/joiner/joiner.sh index 1b1300716..a67badaa2 100755 --- a/deps/acore/joiner/joiner.sh +++ b/deps/acore/joiner/joiner.sh @@ -116,7 +116,21 @@ function Joiner:add_repo() ( if [ -e "$path/.git/" ]; then # if exists , update 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 # otherwise clone echo "Cloning $name on branch $branch..." @@ -440,4 +454,3 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then else Joiner:_checkOptions $@ fi -