4
0

command_mods_remove.sh 4.6 KB

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