4
0
Daniel Gibbs 10 жил өмнө
parent
commit
cecee81c30
1 өөрчлөгдсөн 63 нэмэгдсэн , 20 устгасан
  1. 63 20
      functions/core_dl.sh

+ 63 - 20
functions/core_dl.sh

@@ -6,24 +6,67 @@ lgsm_version="050216"
 
 # Description: Deals with all downloads for LGSM.
 
-fn_curl_dl(){
-curl_filename=$1
-curl_filepath=$2
-curl_url=$3
-echo "curl_filename $curl_filename"
-echo "curl_url ${curl_url}"
-echo "curl_filepath ${curl_filepath}"
-
-echo -ne "Downloading ${mm_file_latest}...\c"
-
-curl_dl=$(curl --fail -o "${curl_filepath}" "${curl_url}" )
-exitcode=$?
-if [ $? -ne 0 ]; then
-	fn_printfaileol
-	echo "${curl_dl}"
-	echo -e "${url}\n"
-	exit ${exitcode}
+# Downloads can be defined in code like so
+# fn_dl "dl_filename" "dl_filepath" "dl_url" "dl_md5"
+# fn_dl "file.tar.bz2" "/home/gameserver" "http://example.com/file.tar/bz2" "10cd7353aa9d758a075c600a6dd193fd"
+
+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 [ "${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	
+	else
+		fn_printokeol
+	fi
+fi	
+}
+
+fn_dl(){
+# defines variables from other script file
+dl_filename=$1
+dl_filepath=$2
+dl_url=$3
+dl_md5=$4
+
+if [ ! -f "${dl_filepath}/${dl_filename}" ]||[ -n "${retry_dl}" ]; then
+	echo -ne "downloading ${dl_filename}...\c"
+
+	local dl=$(curl --fail -o "${dl_filepath}" "${dl_url}")
+	local exitcode=$?
+	if [ ${exitcode} -ne 0 ]; then
+		fn_printfaileol
+		echo "${curl_dl}"
+		echo -e "${url}\n"
+		exit ${exitcode}
+	else
+		fn_printokeol
+	fi
+else	
+	echo -ne "${dl_filename} already exists...\c"
+	fn_dl_md5
+	while true; do
+		read -e -i "n" -p "Download again? [y/N]" yn
+		case $yn in
+		[Yy]* ) fn_dl; retry_dl=1;;
+		[Nn]* ) break;;
+		* ) echo "Please answer yes or no.";;
+	esac
+	done	
 else
-	fn_printokeol
-fi
-}
+
+
+fn_dl_md5
+}
+