core_functions.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # LGSM core_functions.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="180316"
  6. # Description: REDIRECT FUNCTION to new location for core_functions.sh
  7. # fn_fetch_core_dl also placed here to allow legecy servers to still download core functions
  8. if [ -z "${lgsmdir}" ]; then
  9. lgsmdir="${rootdir}/lgsm"
  10. functionsdir="${lgsmdir}/functions"
  11. libdir="${lgsmdir}/lib"
  12. fi
  13. fn_fetch_core_dl(){
  14. github_file_url_dir="lgsm/functions"
  15. github_file_url_name="${functionfile}"
  16. filedir="${functionsdir}"
  17. filename="${github_file_url_name}"
  18. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  19. # If the file is missing, then download
  20. if [ ! -f "${filedir}/${filename}" ]; then
  21. if [ ! -d "${filedir}" ]; then
  22. mkdir -p "${filedir}"
  23. fi
  24. echo -e " fetching ${filename}...\c"
  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. break
  31. fi
  32. done
  33. # If curl exists download file
  34. if [ "$(basename ${curlcmd})" == "curl" ]; then
  35. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  36. if [ $? -ne 0 ]; then
  37. echo -e "\e[0;31mFAIL\e[0m\n"
  38. echo "${curlfetch}"
  39. echo -e "${githuburl}\n"
  40. exit 1
  41. else
  42. echo -e "\e[0;32mOK\e[0m"
  43. fi
  44. else
  45. echo -e "\e[0;31mFAIL\e[0m\n"
  46. echo "Curl is not installed!"
  47. echo -e ""
  48. exit 1
  49. fi
  50. chmod +x "${filedir}/${filename}"
  51. fi
  52. source "${filedir}/${filename}"
  53. }
  54. core_functions.sh(){
  55. functionfile="${FUNCNAME}"
  56. fn_fetch_core_dl
  57. }
  58. core_functions.sh