command_mods_remove.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. # LinuxGSM command_mods_uninstall.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: Uninstall mods along with mods_list.sh and mods_core.sh.
  7. fn_commandname(){
  8. commandname="MODS-REMOVE"
  9. commandaction="Removing mods"
  10. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  11. }
  12. fn_commandname
  13. check.sh
  14. mods_core.sh
  15. fn_mods_check_installed
  16. fn_print_header
  17. echo -e "Remove addons/mods"
  18. echo -e "================================="
  19. # Displays list of installed mods.
  20. # Generates list to display to user.
  21. fn_mods_installed_list
  22. for ((mlindex=0; mlindex < ${#installedmodslist[@]}; mlindex++)); do
  23. # Current mod is the "mlindex" value of the array we are going through.
  24. currentmod="${installedmodslist[mlindex]}"
  25. # Get mod info.
  26. fn_mod_get_info
  27. # Display mod info to the user.
  28. echo -e "${red}${modcommand}${default} - ${modprettyname} - ${moddescription}"
  29. done
  30. echo -e ""
  31. # Keep prompting as long as the user input doesn't correspond to an available mod.
  32. while [[ ! " ${installedmodslist[@]} " =~ " ${usermodselect} " ]]; do
  33. echo -en "Enter an ${cyan}addon/mod${default} to ${red}remove${default} (or exit to abort): "
  34. read -r usermodselect
  35. # Exit if user says exit or abort.
  36. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  37. core_exit.sh
  38. # Supplementary output upon invalid user input.
  39. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  40. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  41. fi
  42. done
  43. fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
  44. echo -e " * Any custom files/configuration will be removed."
  45. if ! fn_prompt_yn "Continue?" Y; then
  46. core_exit.sh
  47. fi
  48. currentmod="${usermodselect}"
  49. fn_mod_get_info
  50. fn_check_mod_files_list
  51. # Uninstall the mod.
  52. fn_script_log_info "Removing ${modsfilelistsize} files from ${modprettyname}"
  53. echo -e "removing ${modprettyname}"
  54. echo -e "* ${modsfilelistsize} files to be removed"
  55. echo -e "* location: ${modinstalldir}"
  56. fn_sleep_time
  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" "${modsdir}/${modcommand}-files.txt")
  63. # If file or directory exists, then remove it.
  64. if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
  65. rm -rf "${modinstalldir:?}/${currentfileremove:?}"
  66. ((exitcode=$?))
  67. if [ "${exitcode}" != 0 ]; then
  68. fn_script_log_fatal "Removing ${modinstalldir}/${currentfileremove}"
  69. break
  70. else
  71. fn_script_log_pass "Removing ${modinstalldir}/${currentfileremove}"
  72. fi
  73. fi
  74. tput rc; tput el
  75. echo -e "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..."
  76. ((modfileline++))
  77. done
  78. if [ "${exitcode}" != 0 ]; then
  79. fn_print_fail_eol_nl
  80. core_exit.sh
  81. else
  82. fn_print_ok_eol_nl
  83. fi
  84. # Remove file list.
  85. echo -en "removing ${modcommand}-files.txt..."
  86. fn_sleep_time
  87. rm -rf "${modsdir:?}/${modcommand}-files.txt"
  88. local exitcode=$?
  89. if [ "${exitcode}" != 0 ]; then
  90. fn_script_log_fatal "Removing ${modsdir}/${modcommand}-files.txt"
  91. fn_print_fail_eol_nl
  92. core_exit.sh
  93. else
  94. fn_script_log_pass "Removing ${modsdir}/${modcommand}-files.txt"
  95. fn_print_ok_eol_nl
  96. fi
  97. # Remove mods from installed mods list.
  98. echo -en "removing ${modcommand} from ${modsinstalledlist}..."
  99. fn_sleep_time
  100. sed -i "/^${modcommand}$/d" "${modsinstalledlistfullpath}"
  101. local exitcode=$?
  102. if [ "${exitcode}" != 0 ]; then
  103. fn_script_log_fatal "Removing ${modcommand} from ${modsinstalledlist}"
  104. fn_print_fail_eol_nl
  105. core_exit.sh
  106. else
  107. fn_script_log_pass "Removing ${modcommand} from ${modsinstalledlist}"
  108. fn_print_ok_eol_nl
  109. fi
  110. # Oxide fix
  111. # Oxide replaces server files, so a validate is required after uninstall.
  112. if [ "${engine}" == "unity3d" ]&&[[ "${modprettyname}" == *"Oxide"* ]]; then
  113. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  114. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  115. exitbypass="1"
  116. command_validate.sh
  117. fn_commandname
  118. unset exitbypass
  119. fi
  120. echo -e "${modprettyname} removed"
  121. fn_script_log "${modprettyname} removed"
  122. core_exit.sh