From 93c9f83b2a3363f7ddd1c5ef5c4d558cf09db557 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 18 Mar 2016 18:56:36 +0000 Subject: [PATCH] Improving backwards compatibility --- functions/core_functions.sh | 73 +++++++++++++++++++++++++------------ functions/core_getopt.sh | 15 ++++++++ functions/fn_getopt | 31 ++-------------- 3 files changed, 69 insertions(+), 50 deletions(-) create mode 100644 functions/core_getopt.sh diff --git a/functions/core_functions.sh b/functions/core_functions.sh index 45bc375df..81500398a 100644 --- a/functions/core_functions.sh +++ b/functions/core_functions.sh @@ -2,35 +2,62 @@ # LGSM core_functions.sh function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -lgsm_version="271215" +lgsm_version="180316" -# Description: Redirect to new core_functions.sh +# Description: Redirect to new location for core_functions.sh -core_functions.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_runfunction -} +# fn_fetch_core_dl also placed here to allow legecy servers to still download core functions +if [ -z "${lgsmdir}" ]; then + lgsmdir="${rootdir}/lgsm" + functionsdir="${lgsmdir}/functions" + libdir="${lgsmdir}/lib" +fi -core_dl.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_runfunction +fn_fetch_core_dl(){ +github_file_url_dir="lgsm/functions" +github_file_url_name="${functionfile}" +filedir="${functionsdir}" +filename="${github_file_url_name}" +githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" +# If the file is missing, then download +if [ ! -f "${filedir}/${filename}" ]; then + if [ ! -d "${filedir}" ]; then + mkdir -p "${filedir}" + fi + echo -e " fetching ${filename}...\c" + # Check curl exists and use available path + curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)" + for curlcmd in ${curlpaths} + do + if [ -x "${curlcmd}" ]; then + break + fi + done + # If curl exists download file + if [ "$(basename ${curlcmd})" == "curl" ]; then + curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1) + if [ $? -ne 0 ]; then + echo -e "\e[0;31mFAIL\e[0m\n" + echo "${curlfetch}" + echo -e "${githuburl}\n" + exit 1 + else + echo -e "\e[0;32mOK\e[0m" + fi + else + echo -e "\e[0;31mFAIL\e[0m\n" + echo "Curl is not installed!" + echo -e "" + exit 1 + fi + chmod +x "${filedir}/${filename}" +fi +source "${filedir}/${filename}" } -core_getopt.sh(){ -functionfile="${FUNCNAME}" -fn_runfunction -} - -core_messages.sh(){ -functionfile="${FUNCNAME}" -fn_runfunction -} - -command_update_functions.sh(){ +core_functions.sh(){ functionfile="${FUNCNAME}" -fn_runfunction +fn_fetch_core_dl } core_functions.sh \ No newline at end of file diff --git a/functions/core_getopt.sh b/functions/core_getopt.sh new file mode 100644 index 000000000..aa487b0a2 --- /dev/null +++ b/functions/core_getopt.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# LGSM core_getopt function +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +lgsm_version="180316" + +# Description: Redirect to new location for core_getopt.sh + +core_getopt.sh(){ +# Functions are defined in core_functions.sh. +functionfile="${FUNCNAME}" +fn_fetch_core_dl +} + +core_getopt.sh \ No newline at end of file diff --git a/functions/fn_getopt b/functions/fn_getopt index 67e7dc4a2..73d3b530d 100644 --- a/functions/fn_getopt +++ b/functions/fn_getopt @@ -1,37 +1,14 @@ #!/bin/bash -# LGSM core_functions.sh function +# LGSM fn_getopt function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -lgsm_version="271215" +lgsm_version="180316" -# Description: Redirect to new core_functions.sh - -core_functions.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_runfunction -} - -core_dl.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_runfunction -} +# Description: Redirect to new core_getopt.sh core_getopt.sh(){ functionfile="${FUNCNAME}" -fn_runfunction -} - -core_messages.sh(){ -functionfile="${FUNCNAME}" -fn_runfunction -} - -command_update_functions.sh(){ -functionfile="${FUNCNAME}" -fn_runfunction +fn_fetch_core_dl } -core_functions.sh core_getopt.sh \ No newline at end of file