command_mods_remove.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. # Displays installed addons to the user
  20. fn_installed_mods_medium_list
  21. echo ""
  22. # Keep prompting as long as the user input doesn't correspond to an available mod
  23. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  24. echo -en "Enter a ${cyan}mod${default} to ${red}remove${default} (or exit to abort): "
  25. read -r usermodselect
  26. # Exit if user says exit or abort
  27. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  28. core_exit.sh
  29. # Supplementary output upon invalid user input
  30. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  31. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  32. fi
  33. done
  34. fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
  35. echo " * Any custom files/configuration will be removed."
  36. while true; do
  37. read -e -i "y" -p "Continue? [Y/n]" yn
  38. case $yn in
  39. [Yy]* ) break;;
  40. [Nn]* ) echo Exiting; exit;;
  41. * ) echo "Please answer yes or no.";;
  42. esac
  43. done
  44. # Gives a pretty name to the user and get all mod info
  45. currentmod="${usermodselect}"
  46. fn_mod_get_info_from_command
  47. # Check file list in order to make sure we're able to remove the mod (returns ${modsfilelistsize})
  48. fn_check_files_list
  49. }
  50. # Uninstall the mod
  51. fn_mod_remove_process(){
  52. fn_script_log "Removing ${modsfilelistsize} files from ${modprettyname}"
  53. echo -e "removing ${modprettyname}"
  54. echo -e "* ${modsfilelistsize} files to be removed"
  55. echo -e "* location: ${modinstalldir}"
  56. sleep 1
  57. # Go through every file and remove it
  58. modfileline="1"
  59. tput sc
  60. while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
  61. # Current line defines current file to remove
  62. currentfileremove="$(sed "${modfileline}q;d" "${modsdatadir}/${modcommand}-files.txt")"
  63. # If file or directory exists, then remove it
  64. fn_script_log "Removing: ${modinstalldir}/${currentfileremove}"
  65. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  66. rm -rf "${modinstalldir}/${currentfileremove}"
  67. local exitcode=$?
  68. fi
  69. tput rc; tput el
  70. printf "removing ${modprettyname} ${totalfileswc} / ${modsfilelistsize} : ${currentfileremove}..."
  71. ((totalfileswc++))
  72. let modfileline=modfileline+1
  73. done
  74. tput rc; tput ed;
  75. echo -ne "removing ${modprettyname} ${totalfileswc} / ${modsfilelistsize}..."
  76. if [ ${exitcode} -ne 0 ]; then
  77. fn_print_fail_eol_nl
  78. core_exit.sh
  79. else
  80. fn_print_ok_eol_nl
  81. fi
  82. sleep 0.5
  83. # Remove file list
  84. echo -en "removing ${modcommand}-files.txt..."
  85. sleep 0.5
  86. fn_script_log "Removing: ${modsdatadir}/${modcommand}-files.txt"
  87. rm -rf "${modsdatadir}/${modcommand}-files.txt"
  88. local exitcode=$?
  89. if [ ${exitcode} -ne 0 ]; then
  90. fn_print_fail_eol_nl
  91. core_exit.sh
  92. else
  93. fn_print_ok_eol_nl
  94. fi
  95. # Remove from installed mods list
  96. echo -en "removing ${modcommand} from ${modslockfile}..."
  97. sleep 0.5
  98. fn_script_log "Removing: ${modcommand} from ${modslockfilefullpath}"
  99. sed -i "/^${modcommand}$/d" "${modslockfilefullpath}"
  100. # Post install tasks to solve potential issues
  101. local exitcode=$?
  102. if [ ${exitcode} -ne 0 ]; then
  103. fn_print_fail_eol_nl
  104. core_exit.sh
  105. else
  106. fn_print_ok_eol_nl
  107. fi
  108. fn_postuninstall_tasks
  109. echo "${modprettyname} removed"
  110. fn_script_log "${modprettyname} removed"
  111. }
  112. fn_mods_remove_init
  113. fn_mod_remove_process
  114. core_exit.sh