Daniel Gibbs пре 10 година
родитељ
комит
18df7ec459
2 измењених фајлова са 144 додато и 51 уклоњено
  1. 39 36
      JustCause2/jc2server
  2. 105 15
      functions/core_dl.sh

+ 39 - 36
JustCause2/jc2server

@@ -4,7 +4,7 @@
 # Author: Daniel Gibbs
 # Website: http://gameservermanagers.com
 if [ -f ".dev-debug" ]; then
-	exec 5>dev-debug.log
+	run 5>dev-debug.log
 	BASH_XTRACEFD="5"
 	set -x
 fi
@@ -36,7 +36,7 @@ parms=""
 # from a different repo and/or branch.
 githubuser="dgibbs64"
 githubrepo="linuxgsm"
-githubbranch="master"
+githubbranch="dlmanage"
 
 # Steam
 appid="261140"
@@ -51,6 +51,8 @@ rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
 selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
 lockselfname=".${servicename}.lock"
 filesdir="${rootdir}/serverfiles"
+lgsmdir="${rootdir}/lgsm"
+functionsdir="${lgsmdir}/functions"
 systemdir="${filesdir}"
 executabledir="${filesdir}"
 executable="./Jcmp-Server"
@@ -76,55 +78,56 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
 ##### Script #####
 # Do not edit
 
-fn_getgithubfile(){
-filename=$1
-exec=$2
-fileurl=${3:-$filename}
-filepath="${rootdir}/${filename}"
-filedir=$(dirname "${filepath}")
-# If the function file is missing, then download
-if [ ! -f "${filepath}" ]; then
+# Fetches core_dl for file downloads
+fn_fetch_core_dl(){
+github_file_url_dir="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 "${filedir}"
+		mkdir -p "${filedir}"
 	fi
-	githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
 	echo -e "    fetching ${filename}...\c"
-	if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
-		:
-	else	
+	# 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 $(echo $PATH | sed "s/\([:]\|\$\)/\/curl /g")"
+	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
+		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
 	fi
-	curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
-	if [ $? -ne 0 ]; then
-		echo -e "\e[0;31mFAIL\e[0m\n"
-		echo "${curl}"
-		echo -e "${githuburl}\n"
-		exit
-	else
-		echo -e "\e[0;32mOK\e[0m"
-	fi	
-	if [ "${exec}" ]; then
-		chmod +x "${filepath}"
-	fi
-fi
-if [ "${exec}" ]; then
-	source "${filepath}"
+	chmod +x "${filedir}/${filename}"
 fi
+source "${filedir}/${filename}"
 }
 
-fn_runfunction(){
-	fn_getgithubfile "functions/${functionfile}" 1
-}
-
-core_functions.sh(){
+core_dl.sh(){
 # Functions are defined in core_functions.sh.
 functionfile="${FUNCNAME}"
-fn_runfunction
+fn_fetch_core_dl
 }
 
+core_dl.sh
 core_functions.sh
 
 getopt=$1

+ 105 - 15
functions/core_dl.sh

@@ -12,28 +12,28 @@ lgsm_version="050216"
 
 fn_dl_md5(){
 # Runs MD5 Check if available
-if [ -n "${dl_md5}" ]; then
-	echo -ne "verifying ${dl_filename} with MD5...\c"
-	local md5check=$(md5sum "${dl_filepath}/${dl_filename}"|awk '{print $1;}')
+if [ -n "${md5}" ]; then
+	echo -ne "verifying ${filename} with MD5...\c"
+	local md5check=$(md5sum "${filedir}/${filename}"|awk '{print $1;}')
 	if [ "${md5check}" != "${dl_md5}" ]; then
 		fn_printfaileol
-		echo "${dl_filename} MD5 checksum: ${md5check}"
-		echo -e "expected MD5 checksum: ${dl_md5}"
-		while true; do
-			read -e -i "y" -p "Retry download? [Y/n]" yn
-			case $yn in
-			[Yy]* ) retry_dl=1; fn_dl;;
-			[Nn]* ) echo Exiting; exit 1;;
-			* ) echo "Please answer yes or no.";;
-		esac
-		done	
+		echo "${filename} MD5 checksum: ${md5check}"
+		echo "expected MD5 checksum: ${dl_md5}"
+		fn_scriptlog "failed to verify ${filename} with MD5"
+		fn_scriptlog "${filename} MD5 checksum: ${md5check}"
+		fn_scriptlog "expected MD5 checksum: ${dl_md5}"
+		exit 1	
 	else
 		fn_printokeol
+		fn_scriptlog "verifyed ${filename} with MD5"
+		fn_scriptlog "${filename} MD5 checksum: ${md5check}"
+		fn_scriptlog "expected MD5 checksum: ${dl_md5}"		
 	fi
 fi	
 }
 
-fn_dl(){
+
+fn_dl_file(){
 # defines variables from other script file
 dl_filename=$1
 dl_filepath=$2
@@ -65,7 +65,97 @@ else
 	done
 fi	
 
-
 fn_dl_md5
 }
 
+
+
+# Downloads file using curl and run it if required
+fn_dl_file(){
+fileurl="${1}"
+filedir="${2}"
+filename="${3}"
+run=${4:-0}
+force=${5:-0}
+md5=${6}
+# If the file is missing or forced, then download
+if [ ! -f "${filedir}" ] || [ "${force}" == "1" ] || [ "${force}" == "yes" ]; then
+	if [ ! -d "${filedir}" ]; then
+		mkdir -p "${filedir}"
+	fi
+	
+	# 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 $(echo $PATH | sed "s/\([:]\|\$\)/\/curl /g")"
+	for curlcmd in ${curlpaths}
+	do
+		if [ -x "${curlcmd}" ]; then
+			curlcmd=${curlcmd}
+			break
+		fi
+	done
+	# If curl exists download file
+	if [ "$(basename ${curlcmd})" == "curl" ]; then
+		# if larger file shows progress bar
+		if [ "${filename}" == *".tar"* ]; then
+			curlfetch=$(${curlcmd} --progress-bar -s --fail -o "${filedir}/${filename}" "${fileurl}" 2>&1)
+		else	
+			curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${fileurl}" 2>&1)
+		fi
+		if [ $? -ne 0 ]; then
+			fn_printfaileol
+			echo "${curlfetch}"
+			echo -e "${fileurl}\n"
+			fn_scriptlog "failed to download ${filedir}/${filename}"
+			fn_scriptlog "${curlfetch}"
+			fn_scriptlog -e "${fileurl}\n"
+			sleep 1
+			echo "Removing failed ${filename}..."
+			rm -f "${filedir}/${filename}"
+			if [ $? -ne 0 ]; then
+				fn_printfaileol
+			else
+				fn_printokeol
+			fi 
+			exit 1
+		else
+			fn_printokeol
+			fn_scriptlog "downloaded ${filedir}/${filename}"
+		fi		
+	else
+		echo -e "fn_printfaileol"
+		echo "Curl is not installed!"
+		echo -e ""
+		exit 1
+	fi
+	fn_dl_md5
+
+	# make file executable if run is set
+	if [ "${run}" == "run" ]; then
+		chmod +x "${filedir}/${filename}"
+	fi
+fi
+# run file if run is set
+if [ "${run}" == "run" ]; then
+	source "${filedir}/${filename}"
+fi
+}
+
+
+# fn_fetch_file_github
+# Parameters:
+# github_file_url_dir: The directory the file is located in teh GitHub repo
+# github_file_url_name: name of file
+# filepath: location file to be saved
+# run: Optional, set to 1 to make file executable
+# force: force download of file even if exists
+fn_fetch_file_github(){
+github_file_url_dir=${1}
+github_file_url_name=${2}
+filepath=${3}
+filename="${github_file_url_name}"
+run=${4:-0}
+force=${5:-0}
+githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
+echo -e "    fetching ${filename}...\c"
+fn_fetch_file "${githuburl}" "${filepath}" "${filename}" "${run}" "${force}"
+}