command_mods_remove.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 update"
  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_scrip_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. sleep 1
  38. # Keep prompting as long as the user input doesn't correspond to an available mod
  39. while [[ ! " ${availablemodsremove[@]} " =~ " ${usermodselect} " ]]; do
  40. echo -en "Enter a \e[36mmod\e[0m to \e[31mremove\e[0m (or exit to abort): "
  41. read -r usermodselect
  42. # Exit if user says exit or abort
  43. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  44. fn_script_log "User aborted."
  45. echo "Aborted."
  46. core_exit.sh
  47. # Supplementary output upon invalid user input
  48. elif [[ ! " ${availablemodsremove[@]} " =~ " ${usermodselect} " ]]; then
  49. fn_print_error2_nl "${usermodselect} is not a valid mod."
  50. echo " * Enter a valid mod or input exit to abort."
  51. fi
  52. done
  53. # Gives a pretty name to the user and get all mod info
  54. currentmod="${usermodselect}"
  55. fn_mod_get_info_from_command
  56. fn_print_dots_nl "Removing ${modprettyname}"
  57. sleep 1
  58. fn_script_log "Removing ${modprettyname}."
  59. }
  60. fn_mod_remove_process(){
  61. # Check file list in order to make sure we're able to remove the mod
  62. # Returns ${modsfilelistsize}
  63. fn_check_files_list
  64. modfileline="1"
  65. while [ $modfileline -le $modsfilelistsize ]; do
  66. # Current line defines current mod command
  67. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  68. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -f "${modinstalldir}/${currentfileremove}" ]; then
  69. rm -rfv "${currentfileremove}"
  70. fi
  71. let modfileline=modfileline+1
  72. done
  73. # Remove file list
  74. rm -rfv "${modsdatadir}/${modcommand}-files.list"
  75. # Remove from installed mods list
  76. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  77. fn_print_ok_nl "Removed ${modprettyname}"
  78. fn_script_log "Removed ${modprettyname}"
  79. }
  80. fn_mods_remove_init
  81. fn_mod_remove_process