From be948aff4f8f37274d493a32823a9b49908dde00 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 15 Apr 2017 15:50:16 +0100 Subject: [PATCH] Testing updater --- lgsm/functions/command_update_functions.sh | 30 ++++--- lgsm/functions/core_dl.sh | 13 +++ linuxgsm.sh | 94 ++++++++-------------- 3 files changed, 66 insertions(+), 71 deletions(-) diff --git a/lgsm/functions/command_update_functions.sh b/lgsm/functions/command_update_functions.sh index 34dbb8115..2cfe3ac49 100644 --- a/lgsm/functions/command_update_functions.sh +++ b/lgsm/functions/command_update_functions.sh @@ -21,22 +21,32 @@ if [ -n "${rootdir}" ]; then exitcode=$? fi fi +# Check if 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 + curlcmd=${curlcmd} + break + fi +done +echo -ne " checking _default.cfg...\c" +function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${servername}/_default.cfg")) +if [ "${function_file_diff}" != "" ]; then + fn_print_update_eol_nl + fn_script_log_info "checking ${functionfile}: UPDATE" + rm -rf "${configdirdefault}/config-lgsm/${servername}/_default.cfg" + fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5" + +else + fn_print_ok_eol_nl +fi if [ -n "${functionsdir}" ]; then if [ -d "${functionsdir}" ]; then cd "${functionsdir}" for functionfile in * do - # Check if 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 - curlcmd=${curlcmd} - break - fi - done - echo -ne " checking ${functionfile}...\c" function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlcmd} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}")) if [ "${function_file_diff}" != "" ]; then diff --git a/lgsm/functions/core_dl.sh b/lgsm/functions/core_dl.sh index d6c9b58ca..6193cfaf8 100644 --- a/lgsm/functions/core_dl.sh +++ b/lgsm/functions/core_dl.sh @@ -177,6 +177,19 @@ fn_fetch_file(){ # force: force download of file even if exists # md5: Checks fail against an md5 sum +fn_fetch_config(){ + github_file_url_dir="${1}" # github dir containing the file + github_file_url_name="${2}" # name of the github file + githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" + fileurl="${githuburl}" + filedir="${3}" + filename="${4}" + executecmd="noexecutecmd" + run="norun" + force="noforce" + md5="nomd5" + fn_boostrap_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}" +} # Fetches files from the github repo fn_fetch_file_github(){ diff --git a/linuxgsm.sh b/linuxgsm.sh index 558a4c5a0..9edad11d7 100644 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -39,16 +39,32 @@ githubuser="GameServerManagers" githubrepo="LinuxGSM" githubbranch="feature/config" +# Core Functions that are required first +core_dl.sh(){ + functionfile="${FUNCNAME}" + fn_bootstrap_fetch_file +} + +core_functions.sh(){ + functionfile="${FUNCNAME}" + fn_bootstrap_fetch_file +} + # Bootstrap +# Fetches the core functions required before passed off to core_dl.sh -# Fetches bootstrap files (configs and core functions) -fn_boostrap_fetch_file(){ - fileurl="${1}" - filedir="${2}" - filename="${3}" - executecmd="${4:-0}" - run="${5:-0}" - force="${6:-0}" +# Fetches core functions +fn_bootstrap_fetch_file(){ + github_file_url_dir="lgsm/functions" # github dir containing the file + github_file_url_name="${functionfile}" # name of the github file + githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" + fileurl="${githuburl}" + filedir="${functionsdir}" + filename="${github_file_url_name}" + executecmd="executecmd" + run="run" + force="noforce" + md5="nomd5" # If the file is missing, then download if [ ! -f "${filedir}/${filename}" ]; then if [ ! -d "${filedir}" ]; then @@ -77,9 +93,7 @@ fn_boostrap_fetch_file(){ echo -e "\e[0;32mOK\e[0m" fi else - echo -e "\e[0;31mFAIL\e[0m\n" - echo "Curl is not installed!" - echo -e "" + echo "[ FAIL ] Curl is not installed" exit 1 fi # make file executecmd if executecmd is set @@ -96,40 +110,15 @@ fn_boostrap_fetch_file(){ fi } -fn_boostrap_fetch_function(){ - github_file_url_dir="lgsm/functions" # github dir containing the file - github_file_url_name="${functionfile}" # name of the github file - githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" - fileurl="${githuburl}" - filedir="${functionsdir}" - filename="${github_file_url_name}" - executecmd="executecmd" - run="run" - force="noforce" - md5="nomd5" - fn_boostrap_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}" -} -fn_boostrap_fetch_config(){ - github_file_url_dir="${1}" # github dir containing the file - github_file_url_name="${2}" # name of the github file - githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" - fileurl="${githuburl}" - filedir="${3}" - filename="${4}" - executecmd="noexecutecmd" - run="norun" - force="noforce" - md5="nomd5" - fn_boostrap_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}" -} +# Installer menu fn_print_center() { columns="$(tput cols)" line="$@" printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}" } -# Print horizontal line + fn_print_horizontal(){ char="${1:-=}" printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "${char}" @@ -310,12 +299,15 @@ if [ "${shortname}" == "core" ]; then fi # LinuxGSM Server Mode else + core_dl.sh + core_functions.sh + # Load LinuxGSM configs # These are required to get all the default variables for the specific server. # Load the default config. If missing download it. If changed reload it. if [ ! -f "${configdirdefault}/config-lgsm/${servername}/_default.cfg" ];then mkdir -p "${configdirdefault}/config-lgsm/${servername}" - fn_boostrap_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5" + fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "noexecutecmd" "norun" "noforce" "nomd5" fi if [ ! -f "${configdirserver}/_default.cfg" ];then mkdir -p "${configdirserver}" @@ -330,39 +322,19 @@ else source "${configdirserver}/_default.cfg" # Load the common.cfg config. If missing download it if [ ! -f "${configdirserver}/common.cfg" ];then - fn_boostrap_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${executecmd}" "noexecutecmd" "norun" "noforce" "nomd5" + fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${executecmd}" "noexecutecmd" "norun" "noforce" "nomd5" source "${configdirserver}/common.cfg" else source "${configdirserver}/common.cfg" fi # Load the instance.cfg config. If missing download it if [ ! -f "${configdirserver}/${servicename}.cfg" ];then - fn_boostrap_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${servicename}.cfg" "noexecutecmd" "norun" "noforce" "nomd5" + fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${servicename}.cfg" "noexecutecmd" "norun" "noforce" "nomd5" source "${configdirserver}/${servicename}.cfg" else source "${configdirserver}/${servicename}.cfg" fi fi -######################## -######## Script ######## -###### Do not edit ##### -######################## - -core_dl.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_boostrap_fetch_function -} - -core_functions.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_boostrap_fetch_function -} - -core_dl.sh -core_functions.sh - getopt=$1 core_getopt.sh