command_update_linuxgsm.sh 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # LinuxGSM command_update_linuxgsm.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Deletes the functions dir to allow re-downloading of functions from GitHub.
  6. local commandname="UPDATE LinuxGSM"
  7. local commandaction="Update LinuxGSM"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_print_dots "Updating LinuxGSM"
  10. sleep 1
  11. check.sh
  12. fn_script_log_info "Updating LinuxGSM"
  13. echo -ne "\n"
  14. # Check and update _default.cfg
  15. echo -ne " checking config _default.cfg...\c"
  16. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${servername}/_default.cfg" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${servername}/_default.cfg"))
  17. if [ "${config_file_diff}" != "" ]; then
  18. fn_print_update_eol_nl
  19. fn_script_log_info "checking config _default.cfg: UPDATE"
  20. rm -f "${configdirdefault}/config-lgsm/${servername}/_default.cfg"
  21. fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5"
  22. else
  23. fn_print_ok_eol_nl
  24. fn_script_log_info "checking config _default.cfg: OK"
  25. fi
  26. echo -ne " checking linuxgsm.sh...\c"
  27. tmp_script_diff=$(diff "${functionsdir}/linuxgsm.sh" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  28. if [ "${tmp_script_diff}" != "" ]; then
  29. fn_print_update_eol_nl
  30. fn_script_log_info "checking linuxgsm.sh: UPDATE"
  31. rm -f "${functionsdir}/linuxgsm.sh"
  32. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  33. # Compare selfname against linuxgsm.sh in the tmp dir. Ignoring server specific vars.
  34. else
  35. fn_script_log_info "checking linuxgsm.sh: OK"
  36. fn_print_ok_eol_nl
  37. fi
  38. echo -ne " checking ${selfname}...\c"
  39. script_diff=$(diff <(sed '/shortname/d;/servername/d;/gamename/d' "${functionsdir}/linuxgsm.sh") <(sed '/shortname/d;/servername/d;/gamename/d' "${rootdir}/${selfname}"))
  40. if [ "${script_diff}" != "" ]; then
  41. fn_print_update_eol_nl
  42. echo -ne " backup ${selfname}...\c"
  43. cp "${rootdir}/${selfname}" "${tmpdir}/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  44. if [ $? -ne 0 ]; then
  45. fn_print_fail_eol_nl
  46. core_exit.sh
  47. else
  48. fn_print_ok_eol_nl
  49. echo -e " Backup: ${tmpdir}/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  50. fi
  51. echo -ne " fetching ${selfname}...\c"
  52. cp "${functionsdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  53. sed -i "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${rootdir}/${selfname}"
  54. sed -i "s/servername=\"core\"/servername=\"${servername}\"/g" "${rootdir}/${selfname}"
  55. sed -i "s/gamename=\"core\"/gamename=\"${gamename}\"/g" "${rootdir}/${selfname}"
  56. if [ $? -ne 0 ]; then
  57. fn_print_fail_eol_nl
  58. core_exit.sh
  59. else
  60. fn_print_ok_eol_nl
  61. fi
  62. else
  63. fn_print_ok_eol_nl
  64. fi
  65. # Check and update functions
  66. if [ -n "${functionsdir}" ]; then
  67. if [ -d "${functionsdir}" ]; then
  68. cd "${functionsdir}"
  69. for functionfile in *
  70. do
  71. echo -ne " checking function ${functionfile}...\c"
  72. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  73. if [ "${function_file_diff}" != "" ]; then
  74. fn_print_update_eol_nl
  75. fn_script_log_info "checking function ${functionfile}: UPDATE"
  76. rm -rf "${functionsdir}/${functionfile}"
  77. fn_update_function
  78. else
  79. fn_print_ok_eol_nl
  80. fi
  81. done
  82. fi
  83. fi
  84. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  85. fn_print_fail "Updating functions"
  86. fn_script_log_fatal "Updating functions"
  87. else
  88. fn_print_ok "Updating functions"
  89. fn_script_log_pass "Updating functions"
  90. fi
  91. echo -ne "\n"
  92. core_exit.sh