command_mods_remove.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.
  7. local commandname="MODS"
  8. local commandaction="Mod Remove"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. mods_core.sh
  12. mods_list.sh
  13. fn_mods_remove_init(){
  14. fn_script_log "Entering mods & addons removal"
  15. echo "================================="
  16. echo "${gamename} mods & addons removal"
  17. echo ""
  18. # Installed mod dir is "${modslockfilefullpath}"
  19. # How many mods are installed
  20. installedmodscount="$(cat "${modslockfilefullpath}" | wc -l)"
  21. # If no mods to be updated
  22. if [ ! -f "${modslockfilefullpath}" ]||[ $installedmodscount -eq 0 ]; then
  23. fn_print_information_nl "No mods or addons to remove"
  24. echo " * Did you install any mod using LGSM?"
  25. fn_script_log_info "No mods or addons to remove."
  26. core_exit.sh
  27. fi
  28. # Build installed mods list and display to the user.
  29. installedmodsline=1
  30. availablemodsremove=()
  31. while [ $installedmodsline -le $installedmodscount ]; do
  32. availablemodsremove+=( "$(sed "${installedmodsline}q;d" "${modslockfilefullpath}" )" )
  33. echo -e " * \e[36m$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")\e[0m"
  34. let installedmodsline=installedmodsline+1
  35. done
  36. echo ""
  37. # Keep prompting as long as the user input doesn't correspond to an available mod
  38. while [[ ! " ${availablemodsremove[@]} " =~ " ${usermodselect} " ]]; do
  39. echo -en "Enter a \e[36mmod\e[0m to \e[31mremove\e[0m (or exit to abort): "
  40. read -r usermodselect
  41. # Exit if user says exit or abort
  42. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  43. fn_script_log "User aborted."
  44. echo "Aborted."
  45. core_exit.sh
  46. # Supplementary output upon invalid user input
  47. elif [[ ! " ${availablemodsremove[@]} " =~ " ${usermodselect} " ]]; then
  48. fn_print_error2_nl "${usermodselect} is not a valid mod."
  49. echo " * Enter a valid mod or input exit to abort."
  50. fi
  51. done
  52. # Gives a pretty name to the user and get all mod info
  53. currentmod="${usermodselect}"
  54. fn_mod_get_info_from_command
  55. # Returns ${modsfilelistsize}
  56. fn_check_files_list
  57. fn_script_log "Removing ${modsfilelistsize} files from ${modprettyname}"
  58. fn_print_dots "Removing ${modsfilelistsize} files from ${modprettyname}"
  59. echo " * Any mod's custom file will be deleted."
  60. echo " * Press ctrl + c to abort."
  61. sleep 4
  62. }
  63. fn_mod_remove_process(){
  64. # Check file list in order to make sure we're able to remove the mod
  65. modfileline="1"
  66. while [ $modfileline -le $modsfilelistsize ]; do
  67. # Current line defines current mod command
  68. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  69. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  70. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  71. rm -rf "${modinstalldir}/${currentfileremove}"
  72. fi
  73. let modfileline=modfileline+1
  74. done
  75. # Remove file list
  76. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.list"
  77. rm -rf "${modsdatadir}/${modcommand}-files.list"
  78. # Remove from installed mods list
  79. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  80. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  81. fn_print_ok_nl "Removed ${modprettyname}"
  82. fn_script_log "Removed ${modprettyname}"
  83. }
  84. fn_mods_remove_init
  85. fn_mod_remove_process