command_mods_remove.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. # 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 \e[36mmod\e[0m to \e[31mremove\e[0m (or exit to abort): "
  26. read -r usermodselect
  27. # Exit if user says exit or abort
  28. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  29. fn_script_log "User aborted."
  30. echo "Aborted."
  31. core_exit.sh
  32. # Supplementary output upon invalid user input
  33. elif [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; then
  34. fn_print_error2_nl "${usermodselect} is not a valid mod."
  35. echo " * Enter a valid mod or input exit to abort."
  36. fi
  37. done
  38. # Gives a pretty name to the user and get all mod info
  39. currentmod="${usermodselect}"
  40. fn_mod_get_info_from_command
  41. # Check file list in order to make sure we're able to remove the mod (returns ${modsfilelistsize})
  42. fn_check_files_list
  43. fn_script_log "Removing ${modsfilelistsize} files from ${modprettyname}"
  44. fn_print_dots "Removing ${modsfilelistsize} files from ${modprettyname}"
  45. echo ""
  46. echo " * Any mod's custom file will be deleted."
  47. echo " * Press ctrl + c to abort."
  48. sleep 4
  49. }
  50. # Uninstall the mod
  51. fn_mod_remove_process(){
  52. # Go through every file and remove it
  53. modfileline="1"
  54. while [ $modfileline -le $modsfilelistsize ]; do
  55. # Current line defines current file to remove
  56. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  57. # If file or directory exists, then remove it
  58. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  59. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  60. rm -rf "${modinstalldir}/${currentfileremove}"
  61. fi
  62. let modfileline=modfileline+1
  63. done
  64. # Remove file list
  65. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.list"
  66. rm -rf "${modsdatadir}/${modcommand}-files.list"
  67. # Remove from installed mods list
  68. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  69. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  70. # Post install tasks to solve potential issues
  71. fn_postuninstall_tasks
  72. fn_print_ok_nl "Removed ${modprettyname}"
  73. fn_script_log "Removed ${modprettyname}"
  74. }
  75. fn_mods_remove_init
  76. fn_mod_remove_process
  77. core_exit.sh