command_mods_remove.sh 3.5 KB

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