command_update_functions.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # LinuxGSM command_update_functions.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. fi
  25. echo -ne " checking linuxgsm.sh...\c"
  26. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  27. if [ "${tmp_script_diff}" != "" ]; then
  28. fn_print_update_eol_nl
  29. fn_script_log_info "checking ${selfname}: UPDATE"
  30. rm -f "${tmpdir}/linuxgsm.sh"
  31. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  32. # Compare selfname against linuxgsm.sh in the tmp dir. Ignoring server specific vars.
  33. else
  34. fn_print_ok_eol_nl
  35. fi
  36. script_diff=$(diff <(sed '/shortname/d;/servername/d;/gamename/d' "${tmpdir}/linuxgsm.sh") <(sed '/shortname/d;/servername/d;/gamename/d' "${rootdir}/${selfname}"))
  37. if [ "${script_diff}" != "" ]; then
  38. echo -ne " backup linuxgsm.sh...\c"
  39. cp "${rootdir}/${selfname}" "${tmpdir}/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  40. if [ $? -ne 0 ]; then
  41. fn_print_fail_eol_nl
  42. core_exit.sh
  43. else
  44. fn_print_ok_eol_nl
  45. echo -en "${tmpdir}/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  46. fi
  47. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  48. sed -i "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${rootdir}/${selfname}"
  49. sed -i "s/servername=\"core\"/servername=\"${servername}\"/g" "${rootdir}/${selfname}"
  50. sed -i "s/gamename=\"core\"/gamename=\"${gamename}\"/g" "${rootdir}/${selfname}"
  51. else
  52. fn_print_ok_eol_nl
  53. fi
  54. # Check and update functions
  55. if [ -n "${functionsdir}" ]; then
  56. if [ -d "${functionsdir}" ]; then
  57. cd "${functionsdir}"
  58. for functionfile in *
  59. do
  60. echo -ne " checking function ${functionfile}...\c"
  61. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  62. if [ "${function_file_diff}" != "" ]; then
  63. fn_print_update_eol_nl
  64. fn_script_log_info "checking function ${functionfile}: UPDATE"
  65. rm -rf "${functionsdir}/${functionfile}"
  66. fn_update_function
  67. else
  68. fn_print_ok_eol_nl
  69. fi
  70. done
  71. fi
  72. fi
  73. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  74. fn_print_fail "Updating functions"
  75. fn_script_log_fatal "Updating functions"
  76. else
  77. fn_print_ok "Updating functions"
  78. fn_script_log_pass "Updating functions"
  79. fi
  80. echo -ne "\n"
  81. core_exit.sh