command_mods_remove.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Displays installed addons to the user
  28. fn_installed_mods_list
  29. echo ""
  30. # Keep prompting as long as the user input doesn't correspond to an available mod
  31. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  32. echo -en "Enter a \e[36mmod\e[0m to \e[31mremove\e[0m (or exit to abort): "
  33. read -r usermodselect
  34. # Exit if user says exit or abort
  35. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  36. fn_script_log "User aborted."
  37. echo "Aborted."
  38. core_exit.sh
  39. # Supplementary output upon invalid user input
  40. elif [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; then
  41. fn_print_error2_nl "${usermodselect} is not a valid mod."
  42. echo " * Enter a valid mod or input exit to abort."
  43. fi
  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. echo ""
  53. echo " * Any mod's custom file will be deleted."
  54. echo " * Press ctrl + c to abort."
  55. sleep 4
  56. }
  57. # Uninstall the mod
  58. fn_mod_remove_process(){
  59. # Go through every file and remove it
  60. modfileline="1"
  61. while [ $modfileline -le $modsfilelistsize ]; do
  62. # Current line defines current file to remove
  63. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  64. # If file or directory exists, then remove it
  65. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  66. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  67. rm -rf "${modinstalldir}/${currentfileremove}"
  68. fi
  69. let modfileline=modfileline+1
  70. done
  71. # Remove file list
  72. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.list"
  73. rm -rf "${modsdatadir}/${modcommand}-files.list"
  74. # Remove from installed mods list
  75. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  76. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  77. # Post install tasks to solve potential issues
  78. fn_postuninstall_tasks
  79. fn_print_ok_nl "Removed ${modprettyname}"
  80. fn_script_log "Removed ${modprettyname}"
  81. }
  82. fn_mods_remove_init
  83. fn_mod_remove_process
  84. core_exit.sh