fix.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 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. 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 kf nmrih onset pvr ro rust rw samp sdtd sfc sof2 squad st tf2 terraria ts3 mcb mta unt vh wurm zmr)
  47. apply_post_install_fix=(av kf kf2 ro 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_modules.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. fn_messages_separator
  71. postinstall=1
  72. fn_apply_fix "post install" "${shortname}"
  73. fi
  74. fi