command_mods_remove.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "${cyan}${modcommand}${default} - \e[1m${modprettyname}${default} - ${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 "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. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  67. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  68. rm -rf "${modinstalldir}/${currentfileremove}"
  69. ((exitcode=$?))
  70. fi
  71. tput rc; tput el
  72. printf "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  73. ((modfileline++))
  74. done
  75. if [ ${exitcode} -ne 0 ]; then
  76. fn_print_fail_eol_nl
  77. core_exit.sh
  78. else
  79. fn_print_ok_eol_nl
  80. fi
  81. sleep 0.5
  82. # Remove file list
  83. echo -en "removing ${modcommand}-files.txt..."
  84. sleep 0.5
  85. fn_script_log "Removing: ${modsdir}/${modcommand}-files.txt"
  86. rm -rf "${modsdir}/${modcommand}-files.txt"
  87. local exitcode=$?
  88. if [ ${exitcode} -ne 0 ]; then
  89. fn_print_fail_eol_nl
  90. core_exit.sh
  91. else
  92. fn_print_ok_eol_nl
  93. fi
  94. # Remove mods from installed mods list
  95. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  96. sleep 0.5
  97. fn_script_log "Removing: ${modcommand} from ${modsinstalledlist}"
  98. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  99. local exitcode=$?
  100. if [ ${exitcode} -ne 0 ]; then
  101. fn_print_fail_eol_nl
  102. core_exit.sh
  103. else
  104. fn_print_ok_eol_nl
  105. fi
  106. # Oxide fix
  107. # Oxide replaces server files, so a validate is required after uninstall
  108. if [ "${engine}" == "unity3d" ]&&[[ "${modprettyname}" == *"Oxide"* ]]; then
  109. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  110. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  111. exitbypass="1"
  112. command_validate.sh
  113. unset exitbypass
  114. fi
  115. echo "${modprettyname} removed"
  116. fn_script_log "${modprettyname} removed"
  117. core_exit.sh