fix.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # LinuxGSM fix.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Overall module for managing fixes.
  7. # Runs modules that will fix an issue.
  8. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. # Messages that are displayed for some fixes.
  10. fn_fix_msg_start() {
  11. fn_print_dots "Applying ${fixname} fix: ${gamename}"
  12. fn_print_info "Applying ${fixname} fix: ${gamename}"
  13. fn_script_log_info "Applying ${fixname} fix: ${gamename}"
  14. }
  15. fn_fix_msg_start_nl() {
  16. fn_print_dots "Applying ${fixname} fix: ${gamename}"
  17. fn_print_info_nl "Applying ${fixname} fix: ${gamename}"
  18. fn_script_log_info "Applying ${fixname} fix: ${gamename}"
  19. }
  20. fn_fix_msg_end() {
  21. exirtcode=$?
  22. if [ "${exitcode}" -ne 0 ]; then
  23. fn_print_error_nl "Applying ${fixname} fix: ${gamename}"
  24. fn_script_log_error "Applying ${fixname} fix: ${gamename}"
  25. else
  26. fn_print_ok_nl "Applying ${fixname} fix: ${gamename}"
  27. fn_script_log_pass "Applying ${fixname} fix: ${gamename}"
  28. fi
  29. }
  30. fn_exists_fix() {
  31. local short="${1:?}"
  32. if [ "$(type -t "fix_${short}.sh")" == 'function' ]; then
  33. return 0
  34. else
  35. return 1
  36. fi
  37. }
  38. fn_apply_fix() {
  39. local phase_message="${1:?}"
  40. local short="${2:?}"
  41. if fn_exists_fix "${short}"; then
  42. "fix_${short}.sh"
  43. else
  44. fn_print_error_nl "${shortname} is marked to apply pre start fix but there is no fix registered"
  45. fi
  46. }
  47. apply_pre_start_fix=(arma3 armar ark av bt bo csgo cmw dst hw ins kf nmrih onset pvr ro rust rw samp sdtd sfc sm sof2 squad st tf2 terraria ts3 mcb mta unt vh wurm xnt zmr)
  48. apply_post_install_fix=(av kf kf2 ro ut2k4 ut ut3)
  49. # validate registered fixes for safe development
  50. for fix in "${apply_pre_start_fix[@]}" "${apply_post_install_fix[@]}"; do
  51. if ! fn_exists_fix "${fix}"; then
  52. fn_print_fail_nl "fix_${fix}.sh is registered but doesn't exist. Typo or did you miss to modify core_modules.sh?"
  53. exitcode=1
  54. core_exit.sh
  55. fi
  56. done
  57. # Fixes that are run on start.
  58. if [ "${commandname}" != "INSTALL" ] && [ -z "${fixbypass}" ]; then
  59. if [ "${appid}" ]; then
  60. fix_steamcmd.sh
  61. fi
  62. if grep -qEe "(^|\s)${shortname}(\s|$)" <<< "${apply_pre_start_fix[@]}"; then
  63. fn_apply_fix "pre start" "${shortname}"
  64. fi
  65. fi
  66. # Fixes that are run on install only.
  67. if [ "${commandname}" == "INSTALL" ]; then
  68. if grep -qEe "(^|\s)${shortname}(\s|$)" <<< "${apply_post_install_fix[@]}"; then
  69. echo -e ""
  70. echo -e "${bold}${lightyellow}Applying Post-Install Fixes${default}"
  71. fn_messages_separator
  72. postinstall=1
  73. fn_apply_fix "post install" "${shortname}"
  74. fi
  75. fi