command_mods_remove.sh 4.0 KB

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