command_update_functions.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # LGSM 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 LGSM"
  7. local commandaction="Update LGSM"
  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. if [ -n "${functionsdir}" ]; then
  22. if [ -d "${functionsdir}" ]; then
  23. cd "${functionsdir}"
  24. for functionfile in *
  25. do
  26. # Check if curl exists and use available path
  27. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  28. for curlcmd in ${curlpaths}
  29. do
  30. if [ -x "${curlcmd}" ]; then
  31. curlcmd=${curlcmd}
  32. break
  33. fi
  34. done
  35. echo -ne " checking ${functionfile}...\c"
  36. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  37. if [ "${function_file_diff}" != "" ]; then
  38. fn_print_update_eol_nl
  39. fn_script_log_info "checking ${functionfile}: UPDATE"
  40. rm -rf "${functionsdir}/${functionfile}"
  41. fn_update_function
  42. else
  43. fn_print_ok_eol_nl
  44. fi
  45. done
  46. fi
  47. fi
  48. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  49. fn_print_fail "Updating functions"
  50. fn_script_log_fatal "Updating functions"
  51. else
  52. fn_print_ok "Updating functions"
  53. fn_script_log_pass "Updating functions"
  54. fi
  55. echo -ne "\n"
  56. core_exit.sh