command_update_functions.sh 3.5 KB

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