core_functions.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # LGSM core_functions.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="210516"
  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. if [ -z "${githubuser}" ]; then
  15. githubuser="GameServerManagers"
  16. fi
  17. if [ -z "${githubrepo}" ]; then
  18. githubrepo="LinuxGSM"
  19. fi
  20. if [ -z "${githubbranch}" ]; then
  21. githubbranch="master"
  22. fi
  23. github_file_url_dir="lgsm/functions"
  24. github_file_url_name="${functionfile}"
  25. filedir="${functionsdir}"
  26. filename="${github_file_url_name}"
  27. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  28. # If the file is missing, then download
  29. if [ ! -f "${filedir}/${filename}" ]; then
  30. if [ ! -d "${filedir}" ]; then
  31. mkdir -p "${filedir}"
  32. fi
  33. echo -e " fetching ${filename}...\c"
  34. # Check curl exists and use available path
  35. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  36. for curlcmd in ${curlpaths}
  37. do
  38. if [ -x "${curlcmd}" ]; then
  39. break
  40. fi
  41. done
  42. # If curl exists download file
  43. if [ "$(basename ${curlcmd})" == "curl" ]; then
  44. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  45. if [ $? -ne 0 ]; then
  46. echo -e "${red}FAIL${default}\n"
  47. echo "${curlfetch}"
  48. echo -e "${githuburl}\n"
  49. exit 1
  50. else
  51. echo -e "${green}OK${default}"
  52. fi
  53. else
  54. echo -e "${red}FAIL${default}\n"
  55. echo "Curl is not installed!"
  56. echo -e ""
  57. exit 1
  58. fi
  59. chmod +x "${filedir}/${filename}"
  60. fi
  61. source "${filedir}/${filename}"
  62. }
  63. core_functions.sh(){
  64. functionfile="${FUNCNAME}"
  65. fn_fetch_core_dl
  66. }
  67. core_functions.sh