command_update_functions.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 if 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 curlcmd in ${curlpaths}
  24. do
  25. if [ -x "${curlcmd}" ]; then
  26. curlcmd=${curlcmd}
  27. break
  28. fi
  29. done
  30. echo -ne " checking _default.cfg...\c"
  31. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${servername}/_default.cfg"))
  32. if [ "${function_file_diff}" != "" ]; then
  33. fn_print_update_eol_nl
  34. fn_script_log_info "checking ${functionfile}: UPDATE"
  35. rm -rf "${configdirdefault}/config-lgsm/${servername}/_default.cfg"
  36. fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5"
  37. else
  38. fn_print_ok_eol_nl
  39. fi
  40. if [ -n "${functionsdir}" ]; then
  41. if [ -d "${functionsdir}" ]; then
  42. cd "${functionsdir}"
  43. for functionfile in *
  44. do
  45. echo -ne " checking ${functionfile}...\c"
  46. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  47. if [ "${function_file_diff}" != "" ]; then
  48. fn_print_update_eol_nl
  49. fn_script_log_info "checking ${functionfile}: UPDATE"
  50. rm -rf "${functionsdir}/${functionfile}"
  51. fn_update_function
  52. else
  53. fn_print_ok_eol_nl
  54. fi
  55. done
  56. fi
  57. fi
  58. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  59. fn_print_fail "Updating functions"
  60. fn_script_log_fatal "Updating functions"
  61. else
  62. fn_print_ok "Updating functions"
  63. fn_script_log_pass "Updating functions"
  64. fi
  65. echo -ne "\n"
  66. core_exit.sh