command_mods_remove.sh 4.8 KB

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