command_mods_remove.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 removal"
  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_script_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. # Returns ${modsfilelistsize}
  57. fn_check_files_list
  58. fn_script_log "Removing ${modsfilelistsize} files from ${modprettyname}"
  59. fn_print_dots "Removing ${modsfilelistsize} files from ${modprettyname}"
  60. echo " * Any mod's custom file will be deleted."
  61. echo " * Press ctrl + c to abort."
  62. sleep 4
  63. }
  64. fn_mod_remove_process(){
  65. # Check file list in order to make sure we're able to remove the mod
  66. modfileline="1"
  67. while [ $modfileline -le $modsfilelistsize ]; do
  68. # Current line defines current mod command
  69. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.list")"
  70. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  71. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  72. rm -rf "${modinstalldir}/${currentfileremove}"
  73. fi
  74. let modfileline=modfileline+1
  75. done
  76. # Remove file list
  77. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.list"
  78. rm -rf "${modsdatadir}/${modcommand}-files.list"
  79. # Remove from installed mods list
  80. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  81. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  82. fn_print_ok_nl "Removed ${modprettyname}"
  83. fn_script_log "Removed ${modprettyname}"
  84. }
  85. fn_mods_remove_init
  86. fn_mod_remove_process