fix.sh 2.5 KB

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