command_mods_remove.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. # LGSM command_mods_uninstall.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Uninstall mods along with mods_list.sh and mods_core.sh.
  7. local commandname="MODS"
  8. local commandaction="addons/mods"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. mods_core.sh
  12. fn_mods_check_installed
  13. fn_print_header
  14. echo "Remove addons/mods"
  15. echo "================================="
  16. ## Displays list of installed mods
  17. # Generates list to display to user
  18. fn_mods_installed_list
  19. for ((mlindex=0; mlindex < ${#installedmodslist[@]}; mlindex++)); do
  20. # Current mod is the "mlindex" value of the array we are going through
  21. currentmod="${installedmodslist[mlindex]}"
  22. # Get mod info
  23. fn_mod_get_info
  24. # Display mod info to the user
  25. echo -e "${red}${modcommand}${default} - ${modprettyname} - ${moddescription}"
  26. done
  27. echo ""
  28. # Keep prompting as long as the user input doesn't correspond to an available mod
  29. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  30. echo -en "Enter an ${cyan}addon/mod${default} to ${green}install${default} (or exit to abort): "
  31. read -r usermodselect
  32. # Exit if user says exit or abort
  33. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  34. core_exit.sh
  35. # Supplementary output upon invalid user input
  36. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  37. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  38. fi
  39. done
  40. fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
  41. echo " * Any custom files/configuration will be removed."
  42. while true; do
  43. read -e -i "y" -p "Continue? [Y/n]" yn
  44. case $yn in
  45. [Yy]* ) break;;
  46. [Nn]* ) echo Exiting; exit;;
  47. * ) echo "Please answer yes or no.";;
  48. esac
  49. done
  50. currentmod="${usermodselect}"
  51. fn_mod_get_info
  52. fn_check_mod_files_list
  53. # Uninstall the mod
  54. fn_script_log_info "Removing ${modsfilelistsize} files from ${modprettyname}"
  55. echo -e "removing ${modprettyname}"
  56. echo -e "* ${modsfilelistsize} files to be removed"
  57. echo -e "* location: ${modinstalldir}"
  58. sleep 1
  59. # Go through every file and remove it
  60. modfileline="1"
  61. tput sc
  62. while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
  63. # Current line defines current file to remove
  64. currentfileremove="$(sed "${modfileline}q;d" "${modsdir}/${modcommand}-files.txt")"
  65. # If file or directory exists, then remove it
  66. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  67. rm -rf "${modinstalldir}/${currentfileremove}"
  68. ((exitcode=$?))
  69. if [ ${exitcode} -ne 0 ]; then
  70. fn_script_log_fatal "Removing ${modinstalldir}/${currentfileremove}"
  71. break
  72. else
  73. fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
  74. fi
  75. fi
  76. tput rc; tput el
  77. printf "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  78. ((modfileline++))
  79. done
  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. sleep 0.5
  87. # Remove file list
  88. echo -en "removing ${modcommand}-files.txt..."
  89. sleep 0.5
  90. rm -rf "${modsdir}/${modcommand}-files.txt"
  91. local exitcode=$?
  92. if [ ${exitcode} -ne 0 ]; then
  93. fn_script_log_fatal "Removing ${modsdir}/${modcommand}-files.txt"
  94. fn_print_fail_eol_nl
  95. core_exit.sh
  96. else
  97. fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
  98. fn_print_ok_eol_nl
  99. fi
  100. # Remove mods from installed mods list
  101. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  102. sleep 0.5
  103. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  104. local exitcode=$?
  105. if [ ${exitcode} -ne 0 ]; then
  106. fn_script_loga_fatal "Removing ${modcommand} from ${modsinstalledlist}"
  107. fn_print_fail_eol_nl
  108. core_exit.sh
  109. else
  110. fn_script_loga_pass "Removing ${modcommand} from ${modsinstalledlist}"
  111. fn_print_ok_eol_nl
  112. fi
  113. # Oxide fix
  114. # Oxide replaces server files, so a validate is required after uninstall
  115. if [ "${engine}" == "unity3d" ]&&[[ "${modprettyname}" == *"Oxide"* ]]; then
  116. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  117. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  118. exitbypass="1"
  119. command_validate.sh
  120. unset exitbypass
  121. fi
  122. echo "${modprettyname} removed"
  123. fn_script_log "${modprettyname} removed"
  124. core_exit.sh