command_mods_remove.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 :; do
  31. echo -en "Enter an ${cyan}addon/mod${default} to ${red}remove${default} (or exit to abort): "
  32. if ! read -r usermodselect && [ -z "${usermodselect}" ]; then
  33. echo -e ""
  34. fn_print_error_nl "Unable to read an addon/mod: no input available"
  35. fn_script_log_error "Unable to read an addon/mod: no input available"
  36. exitcode=2
  37. core_exit.sh
  38. fi
  39. # Exit if user says exit or abort.
  40. if [ "${usermodselect}" == "exit" ] || [ "${usermodselect}" == "abort" ]; then
  41. core_exit.sh
  42. fi
  43. validselection=0
  44. for installedmodcommand in "${installedmodslist[@]}"; do
  45. if [ "${installedmodcommand}" == "${usermodselect}" ]; then
  46. validselection=1
  47. break
  48. fi
  49. done
  50. if [ "${validselection}" -eq 1 ]; then
  51. break
  52. fi
  53. # Supplementary output upon invalid user input.
  54. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  55. done
  56. fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
  57. echo -e " * Any custom files/configuration will be removed."
  58. if ! fn_prompt_yn "Continue?" Y; then
  59. exitcode=0
  60. core_exit.sh
  61. fi
  62. currentmod="${usermodselect}"
  63. fn_mod_get_info
  64. fn_check_mod_files_list
  65. # Uninstall the mod.
  66. fn_script_log_info "Removing ${modsfilelistsize} files from ${modprettyname}"
  67. echo -e "removing ${modprettyname}"
  68. echo -e "* ${modsfilelistsize} files to be removed"
  69. echo -e "* location: ${modinstalldir}"
  70. fn_sleep_time_1
  71. # Go through every file and remove it.
  72. modfileline="1"
  73. tput sc
  74. while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
  75. # Current line defines current file to remove.
  76. currentfileremove=$(sed "${modfileline}q;d" "${modsdir}/${modcommand}-files.txt")
  77. # If file or directory exists, then remove it.
  78. if [ -f "${modinstalldir}/${currentfileremove}" ] || [ -d "${modinstalldir}/${currentfileremove}" ]; then
  79. rm -rf "${modinstalldir:?}/${currentfileremove:?}"
  80. exitcode=$?
  81. if [ "${exitcode}" -ne 0 ]; then
  82. fn_script_log_fail "Removing ${modinstalldir}/${currentfileremove}"
  83. break
  84. else
  85. fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
  86. fi
  87. fi
  88. tput rc
  89. tput el
  90. echo -e "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  91. ((modfileline++))
  92. done
  93. # Added logic not to fail since removing game specific mods (amxmodxcs) removes files that will
  94. # not be found when removing the base (amxmodx) mod
  95. if [ "${modcommand}" != "amxmodx" ]; then
  96. if [ "${exitcode}" -ne 0 ]; then
  97. fn_print_fail_eol_nl
  98. core_exit.sh
  99. else
  100. fn_print_ok_eol_nl
  101. fi
  102. else
  103. fn_print_ok_eol_nl
  104. fi
  105. # Remove file list.
  106. echo -en "removing ${modcommand}-files.txt..."
  107. fn_sleep_time_1
  108. rm -rf "${modsdir:?}/${modcommand}-files.txt"
  109. exitcode=$?
  110. if [ "${exitcode}" -ne 0 ]; then
  111. fn_script_log_fail "Removing ${modsdir}/${modcommand}-files.txt"
  112. fn_print_fail_eol_nl
  113. core_exit.sh
  114. else
  115. fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
  116. fn_print_ok_eol_nl
  117. fi
  118. # Remove mods from installed mods list.
  119. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  120. fn_sleep_time_1
  121. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  122. exitcode=$?
  123. if [ "${exitcode}" -ne 0 ]; then
  124. fn_script_log_fail "Removing ${modcommand} from ${modsinstalledlist}"
  125. fn_print_fail_eol_nl
  126. core_exit.sh
  127. else
  128. fn_script_log_pass "Removing ${modcommand} from ${modsinstalledlist}"
  129. fn_print_ok_eol_nl
  130. fi
  131. # Oxide fix
  132. # Oxide replaces server files, so a validate is required after uninstall.
  133. if [ "${engine}" == "unity3d" ] && [[ "${modprettyname}" == *"Oxide"* ]]; then
  134. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  135. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  136. exitbypass=1
  137. command_validate.sh
  138. fn_firstcommand_reset
  139. unset exitbypass
  140. fi
  141. # Remove the Metamod:Source search path for CS2.
  142. if [ "${modcommand}" == "metamodsource2" ]; then
  143. fn_mod_remove_gameinfo_gi_file
  144. fi
  145. # Remove/modify existing liblist.gam file for Metamod
  146. if [ "${modcommand}" == "metamod" ]; then
  147. fn_mod_remove_liblist_gam_file
  148. fi
  149. # Remove/modify plugins.ini file for AMX Mod X
  150. if [ "${modcommand}" == "amxmodx" ]; then
  151. fn_mod_remove_amxmodx_file
  152. fi
  153. echo -e "${modprettyname} removed"
  154. fn_script_log "${modprettyname} removed"
  155. core_exit.sh