command_mods_remove.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # LinuxGSM command_mods_uninstall.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://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. functionselfname="$(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. echo -e "================================="
  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
  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}" != 0 ]; then
  66. fn_script_log_fatal "Removing ${modinstalldir}/${currentfileremove}"
  67. break
  68. else
  69. fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
  70. fi
  71. fi
  72. tput rc; tput el
  73. echo -e "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  74. ((modfileline++))
  75. done
  76. # Added logic not to fail since removing game specific mods (amxmodxcs) removes files that will
  77. # not be found when removing the base (amxmodx) mod
  78. if [ "${modcommand}" != "amxmodx" ]; then
  79. if [ "${exitcode}" != 0 ]; then
  80. fn_print_fail_eol_nl
  81. core_exit.sh
  82. else
  83. fn_print_ok_eol_nl
  84. fi
  85. else
  86. fn_print_ok_eol_nl
  87. fi
  88. # Remove file list.
  89. echo -en "removing ${modcommand}-files.txt..."
  90. fn_sleep_time
  91. rm -rf "${modsdir:?}/${modcommand}-files.txt"
  92. exitcode=$?
  93. if [ "${exitcode}" != 0 ]; then
  94. fn_script_log_fatal "Removing ${modsdir}/${modcommand}-files.txt"
  95. fn_print_fail_eol_nl
  96. core_exit.sh
  97. else
  98. fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
  99. fn_print_ok_eol_nl
  100. fi
  101. # Remove mods from installed mods list.
  102. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  103. fn_sleep_time
  104. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  105. exitcode=$?
  106. if [ "${exitcode}" != 0 ]; then
  107. fn_script_log_fatal "Removing ${modcommand} from ${modsinstalledlist}"
  108. fn_print_fail_eol_nl
  109. core_exit.sh
  110. else
  111. fn_script_log_pass "Removing ${modcommand} from ${modsinstalledlist}"
  112. fn_print_ok_eol_nl
  113. fi
  114. # Oxide fix
  115. # Oxide replaces server files, so a validate is required after uninstall.
  116. if [ "${engine}" == "unity3d" ]&&[[ "${modprettyname}" == *"Oxide"* ]]; then
  117. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  118. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  119. exitbypass="1"
  120. command_validate.sh
  121. fn_firstcommand_reset
  122. unset exitbypass
  123. fi
  124. # Remove/modify existing liblist.gam file for Metamod
  125. if [ "${modcommand}" == "metamod" ]; then
  126. fn_mod_remove_liblist_gam_file
  127. fi
  128. # Remove/modify plugins.ini file for AMX Mod X
  129. if [ "${modcommand}" == "amxmodx" ]; then
  130. fn_mod_remove_amxmodx_file
  131. fi
  132. echo -e "${modprettyname} removed"
  133. fn_script_log "${modprettyname} removed"
  134. core_exit.sh