command_update_functions.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 functions"
  10. sleep 1
  11. check.sh
  12. fn_script_log_info "Updating functions"
  13. echo -ne "\n"
  14. # Removed legacy functions dir
  15. if [ -n "${rootdir}" ]; then
  16. if [ -d "${rootdir}/functions/" ]; then
  17. rm -rfv "${rootdir}/functions/"
  18. exitcode=$?
  19. fi
  20. fi
  21. # Check curl exists and use available path
  22. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  23. for curlpath in ${curlpaths}
  24. do
  25. if [ -x "${curlpath}" ]; then
  26. break
  27. fi
  28. done
  29. echo -ne " checking _default.cfg...\c"
  30. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${servername}/_default.cfg"))
  31. if [ "${function_file_diff}" != "" ]; then
  32. fn_print_update_eol_nl
  33. fn_script_log_info "checking ${functionfile}: UPDATE"
  34. rm -rf "${configdirdefault}/config-lgsm/${servername}/_default.cfg"
  35. fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5"
  36. else
  37. fn_print_ok_eol_nl
  38. fi
  39. if [ -n "${functionsdir}" ]; then
  40. if [ -d "${functionsdir}" ]; then
  41. cd "${functionsdir}"
  42. for functionfile in *
  43. do
  44. echo -ne " checking ${functionfile}...\c"
  45. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  46. if [ "${function_file_diff}" != "" ]; then
  47. fn_print_update_eol_nl
  48. fn_script_log_info "checking ${functionfile}: UPDATE"
  49. rm -rf "${functionsdir}/${functionfile}"
  50. fn_update_function
  51. else
  52. fn_print_ok_eol_nl
  53. fi
  54. done
  55. fi
  56. fi
  57. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  58. fn_print_fail "Updating functions"
  59. fn_script_log_fatal "Updating functions"
  60. else
  61. fn_print_ok "Updating functions"
  62. fn_script_log_pass "Updating functions"
  63. fi
  64. echo -ne "\n"
  65. core_exit.sh