4
0

command_mods_remove.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/bash
  2. # LinuxGSM command_mods_uninstall.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Uninstall mods along with mods_list.sh and mods_core.sh.
  7. commandname="MODS-REMOVE"
  8. commandaction="Removing Mods"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. check.sh
  12. mods_core.sh
  13. fn_mods_check_installed
  14. fn_print_header
  15. echo -e "Remove addons/mods"
  16. fn_messages_separator
  17. # Displays list of installed mods.
  18. # Generates list to display to user.
  19. fn_mods_installed_list
  20. for ((mlindex = 0; mlindex < ${#installedmodslist[@]}; mlindex++)); do
  21. # Current mod is the "mlindex" value of the array we are going through.
  22. currentmod="${installedmodslist[mlindex]}"
  23. # Get mod info.
  24. fn_mod_get_info
  25. # Display mod info to the user.
  26. echo -e "${red}${modcommand}${default} - ${modprettyname} - ${moddescription}"
  27. done
  28. echo -e ""
  29. # Keep prompting as long as the user input doesn't correspond to an available mod.
  30. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  31. echo -en "Enter an ${cyan}addon/mod${default} to ${red}remove${default} (or exit to abort): "
  32. read -r usermodselect
  33. # Exit if user says exit or abort.
  34. if [ "${usermodselect}" == "exit" ] || [ "${usermodselect}" == "abort" ]; then
  35. core_exit.sh
  36. # Supplementary output upon invalid user input.
  37. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  38. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  39. fi
  40. done
  41. fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
  42. echo -e " * Any custom files/configuration will be removed."
  43. if ! fn_prompt_yn "Continue?" Y; then
  44. exitcode=0
  45. core_exit.sh
  46. fi
  47. currentmod="${usermodselect}"
  48. fn_mod_get_info
  49. fn_check_mod_files_list
  50. # Uninstall the mod.
  51. fn_script_log_info "Removing ${modsfilelistsize} files from ${modprettyname}"
  52. echo -e "removing ${modprettyname}"
  53. echo -e "* ${modsfilelistsize} files to be removed"
  54. echo -e "* location: ${modinstalldir}"
  55. fn_sleep_time_1
  56. # Go through every file and remove it.
  57. modfileline="1"
  58. tput sc
  59. while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
  60. # Current line defines current file to remove.
  61. currentfileremove=$(sed "${modfileline}q;d" "${modsdir}/${modcommand}-files.txt")
  62. # If file or directory exists, then remove it.
  63. if [ -f "${modinstalldir}/${currentfileremove}" ] || [ -d "${modinstalldir}/${currentfileremove}" ]; then
  64. rm -rf "${modinstalldir:?}/${currentfileremove:?}"
  65. exitcode=$?
  66. if [ "${exitcode}" -ne 0 ]; then
  67. fn_script_log_fail "Removing ${modinstalldir}/${currentfileremove}"
  68. break
  69. else
  70. fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
  71. fi
  72. fi
  73. tput rc
  74. tput el
  75. echo -e "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  76. ((modfileline++))
  77. done
  78. # Added logic not to fail since removing game specific mods (amxmodxcs) removes files that will
  79. # not be found when removing the base (amxmodx) mod
  80. if [ "${modcommand}" != "amxmodx" ]; then
  81. if [ "${exitcode}" -ne 0 ]; then
  82. fn_print_fail_eol_nl
  83. core_exit.sh
  84. else
  85. fn_print_ok_eol_nl
  86. fi
  87. else
  88. fn_print_ok_eol_nl
  89. fi
  90. # Remove file list.
  91. echo -en "removing ${modcommand}-files.txt..."
  92. fn_sleep_time_1
  93. rm -rf "${modsdir:?}/${modcommand}-files.txt"
  94. exitcode=$?
  95. if [ "${exitcode}" -ne 0 ]; then
  96. fn_script_log_fail "Removing ${modsdir}/${modcommand}-files.txt"
  97. fn_print_fail_eol_nl
  98. core_exit.sh
  99. else
  100. fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
  101. fn_print_ok_eol_nl
  102. fi
  103. # Remove mods from installed mods list.
  104. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  105. fn_sleep_time_1
  106. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  107. exitcode=$?
  108. if [ "${exitcode}" -ne 0 ]; then
  109. fn_script_log_fail "Removing ${modcommand} from ${modsinstalledlist}"
  110. fn_print_fail_eol_nl
  111. core_exit.sh
  112. else
  113. fn_script_log_pass "Removing ${modcommand} from ${modsinstalledlist}"
  114. fn_print_ok_eol_nl
  115. fi
  116. # Oxide fix
  117. # Oxide replaces server files, so a validate is required after uninstall.
  118. if [ "${engine}" == "unity3d" ] && [[ "${modprettyname}" == *"Oxide"* ]]; then
  119. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  120. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  121. exitbypass=1
  122. command_validate.sh
  123. fn_firstcommand_reset
  124. unset exitbypass
  125. fi
  126. # Remove/modify existing liblist.gam file for Metamod
  127. if [ "${modcommand}" == "metamod" ]; then
  128. fn_mod_remove_liblist_gam_file
  129. fi
  130. # Remove/modify plugins.ini file for AMX Mod X
  131. if [ "${modcommand}" == "amxmodx" ]; then
  132. fn_mod_remove_amxmodx_file
  133. fi
  134. echo -e "${modprettyname} removed"
  135. fn_script_log "${modprettyname} removed"
  136. core_exit.sh