og-linuxgsm/lgsm/modules/command_mods_remove.sh
Daniel Gibbs fef128fb7d
fix (alerts): Alerts on update uses the old game server version not the new one (#4854)
* feat: refactor update comparison output for consistency and clarity

- Replaced direct echo statements with fn_print functions for uniformity in output formatting across multiple update scripts.
- Ensured lockfile creation uses the correct syntax for variable expansion.
- Moved lock file to the same location to ensure monitor doesnt reboot at the wrong time
- Updated remote build information display to enhance readability and maintain consistency in logging.
- Removed unnecessary echo commands to streamline the output process.

* Refactor remote build version handling across multiple modules

- Updated variable names from 'remotebuildversion' to 'remotebuild' for consistency.
- Adjusted logic to check for remote build availability using the new variable name.
- Modified output messages to reflect the change in variable naming.
- Ensured all modules (update_mc.sh, update_mcb.sh, update_mta.sh, update_pmc.sh, update_ts3.sh, update_ut99.sh, update_vints.sh, update_xnt.sh) are aligned with the new naming convention for better readability and maintainability.

* fix(alert): resolve issue with servername not always being listed in title

* Moved `info_distro.sh`, `info_game.sh`, and `info_messages.sh` calls to the top of the `fn_alert_log` function for better clarity.
* Updated `alerticon` assignment to maintain consistency in alert information handling.

* fix(alert_discord): remove "More info" field from Discord alert JSON

* Eliminated the "More info" field to streamline the alert message.
* This change enhances the clarity of the alert by focusing on essential information.

* fix(alert): improve update alert messaging for clarity

* Updated alert messages in `fn_alert_update` and `fn_alert_update_failed` for better readability.
* Changed alert action from `update-request` to `update-restart-request` in `fn_monitor_check_update_source`.

* remove inline

* fix(alert): Correct grammar in update alert message

* Changed "an LinuxGSM update" to "a LinuxGSM update" for grammatical accuracy.

* typo

* fix(alert_discord): Add inline property to "Is my Game Server Online?" field

* Ensures proper formatting of the Discord alert message.
* Improves the display of the server status information.

* fix(pd): increase timeout for termbin.com connection

* fix(alert_discord): reorder fields in Discord alert JSON

* Changed the order of fields in the Discord alert JSON structure.
* Updated the "More info" and "Is my Game Server Online?" fields for better clarity.

* revert back to factorio.com

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Standardizes alert messages across platforms

Ensures consistency in alert messages across Discord, NTFY,
Pushover, Rocketchat, Slack, and Telegram.

Updates Discord alerts to include server hostname and time,
removes redundant formatting.

Standardizes plain-text alert formatting for NTFY.

Refactors Pushover messages to use consistent HTML formatting.

Streamlines Rocketchat and Slack messages by removing duplicate
server info and adding optional link support.

* Removes Hostname from alert messages

Removes the Hostname field from various alert messages (Discord, Gotify, IFTTT, ntfy, Pushbullet, Pushover, Rocketchat, Slack, Telegram).

The hostname was deemed redundant or unnecessary in the context of these alerts.

Relates to #4696

* Configures shellcheckrc filename

Configures the Super-Linter action to use `.shellcheckrc` as the
BASH_FILE_NAME. This ensures that shellcheck uses the correct
configuration file for bash script linting.

Fixes #4696

* Disables shellcheck errors and removes variable

Disables specific shellcheck errors to allow certain coding
patterns and removes an unused variable from the super-linter
workflow. This improves the linter's signal-to-noise ratio
and reduces unnecessary checks.

Relates to #4696

* Fixes and improves server list validation scripts

Addresses issues in the server list validation scripts:

- Fixes potential issues with parsing curl custom arguments in telegram alerts.
- Corrects the shortname array generation.
- Implements more robust checks for validating game icons.
- Ensures the consistency of server counts across different CSV files.

* Fixes glibc check and mod selection logic

Corrects glibc version comparison to properly handle version strings.

Improves mod installation and removal by validating user input
against available options, providing a more robust selection process.
This prevents errors caused by invalid mod names and enhances the
user experience.

Updates arithmetic expression syntax for better compatibility.

* Fixes cache control for dev-debug mode

Updates the handling of cache control headers in dev-debug mode.
The `nocache` variable is changed to an array to correctly pass multiple headers to `curl`.
This resolves issues with cached versions of files being used when dev-debug is enabled, ensuring that the latest versions are always fetched.

Fixes #4696

* Allows spaces in steamcmdcommand variable

Parses steamcmdcommand as an array to allow spaces in the
variable.

This prevents issues when the user wants to pass arguments
with spaces to the steamcmd executable.

* Addresses various script improvements

Addresses multiple improvements across various scripts:

- Fixes Valheim unstripped_corlib override by commenting out the lines in the config files.
- Improves process identification for source and goldsrc engines using `pgrep`.
- Enhances backup file identification using `find` with `-maxdepth 1` and `-type f`.
- Fixes glibc version comparison logic in multiple files.
- Improves UT2K4 key installation script by using printf for writing the key to the file.
- Corrects the mod info extraction logic to correctly identify mod entries.
- Improves amxmodx file installation/removal logic to prevent duplicate entries.
- Fixes server info retrieval to handle spaces in the server list.

Relates to #4696

* Fixes mono repo install exit code check

Corrects the mono repo install exit code check to use the dedicated monorepoexitcode variable, ensuring accurate error detection.

Updates the exit trap to preserve the original exit status, preventing potential loss of information when handling script termination.

* Refactors and reorders core modules

Improves module loading by reordering and refactoring the core modules.

This change addresses inconsistencies and improves the overall structure
of how core modules are handled within the system.
Some fix scripts were renamed to match the module name.

* Makes scripts executable

Changes file permissions to make shell scripts executable.
This ensures that the scripts can be run directly.

Addresses a pre-existing issue.
Related to #4696

* Adds explicit permissions to workflows

Specifies explicit permissions for GitHub Actions workflows to enhance security and control access to resources.

This ensures that each workflow only has the necessary permissions, following the principle of least privilege.

* Fixes output redirection and URL parsing

Corrects output redirection in GitHub Actions workflows by enclosing the $GITHUB_OUTPUT variable in quotes, preventing potential issues with variable expansion.

Ensures proper URL parsing in workflows by enclosing the URL within quotes, addressing potential parsing errors.

Fixes #4696

* Applies code formatting for consistency

Applies Prettier formatting to the codebase for improved
readability and consistency.

Addresses minor code style inconsistencies across several files.

* Fixes minor formatting and logic issues

Addresses various minor issues including:

- Standardizes indentation in `.editorconfig` for different file types.
- Simplifies Prettier configuration.
- Updates image links in `README.md`.
- Ensures newline character at end of `.csv` files.
- Corrects a conditional statement in `command_fastdl.sh`.
- Corrects a conditional statement in `info_messages.sh`.
- Updates server query protocols in `query_gsquery.py`.

* Configures and disables linters

Adds YAML linting configuration and disables unnecessary
linters to streamline the CI/CD process and reduce
noise from irrelevant checks.

* Improves documentation and linting

Updates documentation links to be enclosed in angle brackets, preventing markdown rendering issues.

Configures markdownlint to align with repository standards and avoid common false positives.

The updated links in the documentation ensure they are correctly interpreted by markdown parsers, improving user experience.

The markdownlint configuration fine-tunes linting rules to better match the project's existing style and conventions, reducing noise from irrelevant warnings.

* Fixes typos and improves code consistency

Addresses various typos and inconsistencies across multiple files,
enhancing code readability and maintainability.

Adds codespell and flake8 configurations for linting.

Relates to #4696

* Excludes workflow files from Prettier formatting

Prevents Prettier from formatting workflow files due to GitHub token restrictions, as the token used by the Prettier auto-commit action lacks permissions to update files within the `.github/workflows/` directory.

* chore(prettier): format code

* Updates Super-Linter configuration

Improves Super-Linter's reliability by switching to linting the entire codebase instead of relying on git history. This change also addresses potential transient fetch failures from GitHub.

Additionally, this commit expands the ignored paths in codespell and disables some linters to improve performance and reduce false positives.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: dgibbs64 <dgibbs64@users.noreply.github.com>
2026-03-12 22:37:36 +00:00

167 lines
4.8 KiB
Bash
Executable file

#!/bin/bash
# LinuxGSM command_mods_uninstall.sh module
# Author: Daniel Gibbs
# Contributors: https://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Uninstall mods along with mods_list.sh and mods_core.sh.
commandname="MODS-REMOVE"
commandaction="Removing Mods"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set
check.sh
mods_core.sh
fn_mods_check_installed
fn_print_header
echo -e "Remove addons/mods"
fn_messages_separator
# Displays list of installed mods.
# Generates list to display to user.
fn_mods_installed_list
for ((mlindex = 0; mlindex < ${#installedmodslist[@]}; mlindex++)); do
# Current mod is the "mlindex" value of the array we are going through.
currentmod="${installedmodslist[mlindex]}"
# Get mod info.
fn_mod_get_info
# Display mod info to the user.
echo -e "${red}${modcommand}${default} - ${modprettyname} - ${moddescription}"
done
echo -e ""
# Keep prompting as long as the user input doesn't correspond to an available mod.
while :; do
echo -en "Enter an ${cyan}addon/mod${default} to ${red}remove${default} (or exit to abort): "
read -r usermodselect
# Exit if user says exit or abort.
if [ "${usermodselect}" == "exit" ] || [ "${usermodselect}" == "abort" ]; then
core_exit.sh
fi
validselection=0
for installedmodcommand in "${installedmodslist[@]}"; do
if [ "${installedmodcommand}" == "${usermodselect}" ]; then
validselection=1
break
fi
done
if [ "${validselection}" -eq 1 ]; then
break
fi
# Supplementary output upon invalid user input.
fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
done
fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
echo -e " * Any custom files/configuration will be removed."
if ! fn_prompt_yn "Continue?" Y; then
exitcode=0
core_exit.sh
fi
currentmod="${usermodselect}"
fn_mod_get_info
fn_check_mod_files_list
# Uninstall the mod.
fn_script_log_info "Removing ${modsfilelistsize} files from ${modprettyname}"
echo -e "removing ${modprettyname}"
echo -e "* ${modsfilelistsize} files to be removed"
echo -e "* location: ${modinstalldir}"
fn_sleep_time_1
# Go through every file and remove it.
modfileline="1"
tput sc
while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
# Current line defines current file to remove.
currentfileremove=$(sed "${modfileline}q;d" "${modsdir}/${modcommand}-files.txt")
# If file or directory exists, then remove it.
if [ -f "${modinstalldir}/${currentfileremove}" ] || [ -d "${modinstalldir}/${currentfileremove}" ]; then
rm -rf "${modinstalldir:?}/${currentfileremove:?}"
exitcode=$?
if [ "${exitcode}" -ne 0 ]; then
fn_script_log_fail "Removing ${modinstalldir}/${currentfileremove}"
break
else
fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
fi
fi
tput rc
tput el
echo -e "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
((modfileline++))
done
# Added logic not to fail since removing game specific mods (amxmodxcs) removes files that will
# not be found when removing the base (amxmodx) mod
if [ "${modcommand}" != "amxmodx" ]; then
if [ "${exitcode}" -ne 0 ]; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_ok_eol_nl
fi
# Remove file list.
echo -en "removing ${modcommand}-files.txt..."
fn_sleep_time_1
rm -rf "${modsdir:?}/${modcommand}-files.txt"
exitcode=$?
if [ "${exitcode}" -ne 0 ]; then
fn_script_log_fail "Removing ${modsdir}/${modcommand}-files.txt"
fn_print_fail_eol_nl
core_exit.sh
else
fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
fn_print_ok_eol_nl
fi
# Remove mods from installed mods list.
echo -en "removing ${modcommand} from ${modsinstalledlist}..."
fn_sleep_time_1
sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
exitcode=$?
if [ "${exitcode}" -ne 0 ]; then
fn_script_log_fail "Removing ${modcommand} from ${modsinstalledlist}"
fn_print_fail_eol_nl
core_exit.sh
else
fn_script_log_pass "Removing ${modcommand} from ${modsinstalledlist}"
fn_print_ok_eol_nl
fi
# Oxide fix
# Oxide replaces server files, so a validate is required after uninstall.
if [ "${engine}" == "unity3d" ] && [[ "${modprettyname}" == *"Oxide"* ]]; then
fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
exitbypass=1
command_validate.sh
fn_firstcommand_reset
unset exitbypass
fi
# Remove/modify existing liblist.gam file for Metamod
if [ "${modcommand}" == "metamod" ]; then
fn_mod_remove_liblist_gam_file
fi
# Remove/modify plugins.ini file for AMX Mod X
if [ "${modcommand}" == "amxmodx" ]; then
fn_mod_remove_amxmodx_file
fi
echo -e "${modprettyname} removed"
fn_script_log "${modprettyname} removed"
core_exit.sh