command_update_functions.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # LGSM command_update_functions.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="210516"
  6. # Description: Deletes the functions dir to allow re-downloading of functions from GitHub.
  7. function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. check.sh
  9. fn_print_dots "Updating functions"
  10. fn_script_log_info "Updating functions"
  11. sleep 1
  12. echo -ne "\n"
  13. # Removed legecy functions dir
  14. if [ -n "${rootdir}" ]; then
  15. if [ -d "${rootdir}/functions/" ]; then
  16. rm -rfv "${rootdir}/functions/"
  17. exitcode=$?
  18. fi
  19. fi
  20. if [ -n "${functionsdir}" ]; then
  21. if [ -d "${functionsdir}" ]; then
  22. cd "${functionsdir}"
  23. for functionfile in *
  24. do
  25. # Check curl exists and use available path
  26. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  27. for curlcmd in ${curlpaths}
  28. do
  29. if [ -x "${curlcmd}" ]; then
  30. curlcmd=${curlcmd}
  31. break
  32. fi
  33. done
  34. echo -ne " checking ${functionfile}...\c"
  35. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  36. if [ "${function_file_diff}" != "" ]; then
  37. ${curlcmd} -s --fail -o "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"
  38. local exitcode=$?
  39. if [ "${exitcode}" != "0" ]; then
  40. fn_print_fail_eol_nl
  41. rm -rf "${functionsdir}/${functionfile}"
  42. exitcode=2
  43. else
  44. echo -ne "\e[0;33mUPDATE\e[0m"
  45. rm -rf "${functionsdir}/${functionfile}"
  46. fn_update_function
  47. fi
  48. else
  49. fn_print_ok_eol_nl
  50. fi
  51. done
  52. fi
  53. fi
  54. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  55. fn_print_fail "Updating functions"
  56. fn_script_log_fatal "Failure! Updating functions"
  57. else
  58. fn_print_ok "Updating functions"
  59. fn_script_log_pass "Success! Updating functions"
  60. exitcode=0
  61. fi
  62. echo -ne "\n"
  63. core_exit.sh