4
0

command_mods_remove.sh 4.1 KB

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