command_mods_remove.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_remove_init(){
  13. fn_print_header
  14. echo "Remove addons/mods"
  15. echo "================================="
  16. # A simple function to exit if no mods were installed
  17. # Also returns ${installedmodscount} if mods were found
  18. fn_mods_exit_if_not_installed
  19. echo ""
  20. # Displays installed addons to the user
  21. fn_installed_mods_medium_list
  22. echo ""
  23. # Keep prompting as long as the user input doesn't correspond to an available mod
  24. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  25. echo -en "Enter a ${cyan}mod${default} to ${red}remove${default} (or exit to abort): "
  26. read -r usermodselect
  27. # Exit if user says exit or abort
  28. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  29. core_exit.sh
  30. # Supplementary output upon invalid user input
  31. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  32. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  33. fi
  34. done
  35. fn_print_warning_nl "You are about to remove ${usermodselect}."
  36. echo " * Any custom files/configuration will be removed."
  37. while true; do
  38. read -e -i "y" -p "Continue? [Y/n]" yn
  39. case $yn in
  40. [Yy]* ) break;;
  41. [Nn]* ) echo Exiting; exit;;
  42. * ) echo "Please answer yes or no.";;
  43. esac
  44. done
  45. # Gives a pretty name to the user and get all mod info
  46. currentmod="${usermodselect}"
  47. fn_mod_get_info_from_command
  48. # Check file list in order to make sure we're able to remove the mod (returns ${modsfilelistsize})
  49. fn_check_files_list
  50. fn_script_log "Removing ${modsfilelistsize} files from ${modprettyname}"
  51. fn_print_dots "Removing ${modsfilelistsize} files from ${modprettyname}"
  52. }
  53. # Uninstall the mod
  54. fn_mod_remove_process(){
  55. # Go through every file and remove it
  56. modfileline="1"
  57. while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
  58. # Current line defines current file to remove
  59. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  60. # If file or directory exists, then remove it
  61. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  62. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  63. rm -rf "${modinstalldir}/${currentfileremove}"
  64. fi
  65. let modfileline=modfileline+1
  66. done
  67. # Remove file list
  68. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.list"
  69. rm -rf "${modsdatadir}/${modcommand}-files.list"
  70. # Remove from installed mods list
  71. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  72. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  73. # Post install tasks to solve potential issues
  74. fn_postuninstall_tasks
  75. fn_print_ok_nl "Removed ${modprettyname}"
  76. fn_script_log "Removed ${modprettyname}"
  77. }
  78. fn_mods_remove_init
  79. fn_mod_remove_process
  80. core_exit.sh