Просмотр исходного кода

Added update functionality to ts3server

first release of the update function for ts3server.
Daniel Gibbs 11 лет назад
Родитель
Сommit
7edf1e4410
2 измененных файлов с 250 добавлено и 105 удалено
  1. 189 103
      functions/fn_update_check
  2. 61 2
      functions/fn_update_dl

+ 189 - 103
functions/fn_update_check

@@ -2,20 +2,115 @@
 # LGSM fn_update_check function
 # Author: Daniel Gibbs
 # Website: http://danielgibbs.co.uk
-# Version: 210115
+# Version: 150315
 
 # Description: Checks if a server update is available.
 
 local modulename="Update"
 
+### SteamCMD Update Checker ###
+
+fn_appmanifestinfo(){
+	appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
+	appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
+}
+
+fn_appmanifestcheck(){
+fn_appmanifestinfo
+# Multiple or no matching appmanifest files may sometimes be available.
+# This is an error is corrected below if required.
+if [ "${appmanifestfilewc}" -ge "2" ]; then
+	sleep 1
+	fn_printwarn "Multiple appmanifest_${appid}.acf files found"
+	fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
+	sleep 2
+	fn_printdots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
+	sleep 1
+	for appfile in ${appmanifestfile}; do
+		rm "${appfile}"
+	done
+	appmanifestfilewc1="${appmanifestfilewc}"
+	fn_appmanifestinfo
+	if [ "${appmanifestfilewc}" -ge "2" ]; then
+		fn_printfail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
+		fn_scriptlog "Failure! Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
+		sleep 1
+		echo ""
+		echo "	Check user permissions"
+		for appfile in ${appmanifestfile}; do
+			echo "	${appfile}"
+		done
+		exit
+	else
+		sleep 1
+		fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
+		fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
+		sleep 1
+		fn_printinfonl "Forcing update to correct issue"
+		fn_scriptlog "Forcing update to correct issue"
+		sleep 1
+		fn_update_dl
+		fn_update_check
+	fi
+elif [ "${appmanifestfilewc}" -eq "0" ]; then
+	fn_printwarn "No appmanifest_${appid}.acf found"
+	fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
+	sleep 2
+	fn_printinfonl "Forcing update to correct issue"
+	fn_scriptlog "Forcing update to correct issue"
+	sleep 1
+	fn_update_dl
+	fn_update_check
+fi
+}
+
+fn_logupdaterequest(){
+# Checks for server update requests from server logs.
+echo ""
+fn_printdots "Checking server logs for update requests"
+sleep 1
+fn_printok "Checking server logs for update requests"
+fn_scriptlog "Checking server logs for update requests"
+sleep 1
+requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
+if [ "${requestrestart}" -ge "1" ]; then
+	fn_printoknl "Server requesting update"
+	sleep 1
+	echo ""
+	echo -ne "Applying update.\r"
+	sleep 1
+	echo -ne "Applying update..\r"
+	sleep 1
+	echo -ne "Applying update...\r"
+	sleep 1
+	echo -ne "\n"
+	if [ ! -z "${norestart}" ]; then
+		fn_update_dl
+	else
+		fn_stop
+		fn_update_dl
+		fn_start
+	fi
+else
+	fn_printok "No update request detected"
+	sleep 1
+fi
+echo ""
+exit
+}
+
 fn_steamcmdcheck(){
 # Checks for server update from SteamCMD
 fn_printdots "Checking for update: SteamCMD"
 fn_scriptlog "Checking for update: SteamCMD"
 sleep 1
+
+# Gets currentbuild
 currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f3)
+
+# Gets availablebuild info
 cd "${rootdir}/steamcmd"
-availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_print ${appid} +app_info_print ${appid} +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f3)
+availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_print "${appid}" +app_info_print "${appid}" +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f3)
 if [ -z "${availablebuild}" ]; then
 	fn_printfail "Checking for update: SteamCMD"
 	fn_scriptlog "Failure! Checking for update: SteamCMD"
@@ -23,36 +118,13 @@ if [ -z "${availablebuild}" ]; then
 	fn_printfail "Checking for update: SteamCMD: Not returning version info"
 	fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
 	sleep 2
+	fn_logupdaterequest
 else
 	fn_printok "Checking for update: SteamCMD"
 	fn_scriptlog "Success! Checking for update: SteamCMD"
 	sleep 1
 fi
 
-if [ -z "${availablebuild}" ]; then
-	# Checks for server update from SteamDB.info if SteamCMD fails
-	echo ""
-	fn_printdots "Checking for update: SteamDB.info"
-	fn_scriptlog "Checking for update: SteamDB.info"
-	availablebuild=$(wget -qO- "http://steamdb.info/api/GetRawDepots/?appid=${appid}" | sed 's/\\n/\n/g' | grep -EA 1000 "^\s+\[branches\]" | grep -EA 5 "^\s+\[public\]" | grep -m 1 -EB 10 "^\s+\)$" | grep -E "^\s+\[buildid\]\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f4)
-	sleep 1
-	if [ -z "${availablebuild}" ]; then
-		fn_printfail "Checking for update: SteamDB.info"
-		fn_scriptlog "Failure! Checking for update: SteamDB.info"
-		sleep 1
-		fn_printfail "Checking for update: SteamDB.info: Not returning version info"
-		fn_scriptlog "Failure! Checking for update: SteamDB.info: Not returning version info"
-		sleep 2
-	else
-		fn_printok "Checking for update: SteamDB.info"
-		fn_scriptlog "Success! Checking for update: SteamDB.info"
-		sleep 1
-	fi
-fi
-if [ -z "${availablebuild}" ]; then
-	fn_logupdaterequest
-fi
-
 if [ "${currentbuild}" -ne "${availablebuild}" ]; then
 	echo -e "\n"
 	echo -e "Update available:"
@@ -94,96 +166,110 @@ else
 fi
 }
 
-fn_logupdaterequest(){
-# Checks for server update requests from server logs.
-echo ""
-fn_printdots "Checking server logs for update requests"
-sleep 1
-fn_printok "Checking server logs for update requests"
-fn_scriptlog "Checking server logs for update requests"
+### END SteamCMD Update Checker ###
+
+fn_teamspeak3_check(){
+# Checks for server update from teamspeak.com using a mirror dl.4players.de
+fn_printdots "Checking for update: teamspeak.com"
+fn_scriptlog "Checking for update: teamspeak.com"
 sleep 1
-requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
-if [ "${requestrestart}" -ge "1" ]; then
-	fn_printoknl "Server requesting update"
-	sleep 1
-	echo ""
-	echo -ne "Applying update.\r"
-	sleep 1
-	echo -ne "Applying update..\r"
-	sleep 1
-	echo -ne "Applying update...\r"
+
+# Gets currentbuild info
+# Checks currentbuild info is available, if fails a server restart will be forced to generate logs
+if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
+	fn_printfail "Checking for update: teamspeak.com"
+	fn_scriptlog "Checking for update: teamspeak.com"
 	sleep 1
-	echo -ne "\n"
-	if [ ! -z "${norestart}" ]; then
-		fn_update_dl
-	else
-		fn_stop
-		fn_update_dl
-		fn_start
+	fn_printfailnl "Checking for update: teamspeak.com: No logs with server version found"
+	fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
+	sleep 2
+	fn_printinfonl "Checking for update: teamspeak.com: Forcing server restart"
+	fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
+	sleep 2
+	./${selfname} restart
+	sleep 2
+	# If still failing will exit
+	if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
+		fn_printfailnl "Checking for update: teamspeak.com: Still No logs with server version found"
+		fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
+		exit
 	fi
-else
-	fn_printok "No update request detected"
-	sleep 1
 fi
-echo ""
-exit
-}
+currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}')
 
+# Gets the teamspeak server architecture
+ts3arch=$(ls $(find ${filesdir}/ -name 'ts3server_*_*' 2> /dev/null | grep -v 'ts3server_minimal_runscript.sh' | sort | tail -1) | egrep -o '(amd64|x86)' | tail -1)
 
-fn_appmanifestinfo(){
-	appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
-	appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
-}
+# Gets availablebuild info
+wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '<a href=\".*\/\">.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > .ts3_version_numbers.tmp
+# Finds directory with most recent server version.
+while read ts3_version_number; do
+	wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux-${ts3arch}-${ts3_version_number}.tar.gz"
+	if [[ $? == 0 ]]; then
+		availablebuild="${ts3_version_number}"
+		# Break while-loop, if the latest release could be found
+		break
+	fi
+done < .ts3_version_numbers.tmp
+rm .ts3_version_numbers.tmp
 
-fn_appmanifestcheck(){
-fn_appmanifestinfo
-# Multiple or no matching appmanifest files may sometimes be available.
-# This is an error is corrected below if required.
-if [ "${appmanifestfilewc}" -ge "2" ]; then
+# Checks availablebuild info is available
+if [ -z "${availablebuild}" ]; then
+	fn_printfail "Checking for update: teamspeak.com"
+	fn_scriptlog "Checking for update: teamspeak.com"
 	sleep 1
-	fn_printwarn "Multiple appmanifest_${appid}.acf files found"
-	fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
+	fn_printfail "Checking for update: teamspeak.com: Not returning version info"
+	fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
 	sleep 2
-	fn_printdots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
+	exit
+else
+	fn_printok "Checking for update: teamspeak.com"
+	fn_scriptlog "Success! Checking for update: teamspeak.com"
 	sleep 1
-	for appfile in ${appmanifestfile}; do
-		rm "${appfile}"
-	done
-	appmanifestfilewc1="${appmanifestfilewc}"
-	fn_appmanifestinfo
-	if [ "${appmanifestfilewc}" -ge "2" ]; then
-		fn_printfail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
-		fn_scriptlog "Failure! Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
-		sleep 1
-		echo ""
-		echo "	Check user permissions"
-		for appfile in ${appmanifestfile}; do
-			echo "	${appfile}"
-		done
-		exit
-	else
-		sleep 1
-		fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
-		fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
-		sleep 1
-		fn_printinfonl "Forcing update to correct issue"
-		fn_scriptlog "Forcing update to correct issue"
-		sleep 1
-		fn_update_dl
-		fn_update_check
-	fi
-elif [ "${appmanifestfilewc}" -eq "0" ]; then
-	fn_printwarn "No appmanifest_${appid}.acf found"
-	fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
-	sleep 2
-	fn_printinfonl "Forcing update to correct issue"
-	fn_scriptlog "Forcing update to correct issue"
+fi
+
+# Removes dots so if can compare version numbers
+currentbuilddigit=$(echo "${currentbuild}"|tr -cd "[:digit:]")
+availablebuilddigit=$(echo "${availablebuild}"|tr -cd "[:digit:]")
+if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
+	echo -e "\n"
+	echo -e "Update available:"
+	sleep 1
+	echo -e "	Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
+	echo -e "	Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
+	echo -e ""
+	sleep 1
+	echo ""
+	echo -en "Applying update.\r"
 	sleep 1
+	echo -en "Applying update..\r"
+	sleep 1
+	echo -en "Applying update...\r"
+	sleep 1
+	echo -en "\n"
+	fn_scriptlog "Update available"
+	fn_scriptlog "Current build: ${currentbuild}"
+	fn_scriptlog "Available build: ${availablebuild}"
+	fn_scriptlog "${currentbuild} > ${availablebuild}"
+	fn_stop
 	fn_update_dl
-	fn_update_check
+	fn_start
+else
+	echo -e "\n"
+	echo -e "No update available:"
+	echo -e "	Current version: \e[0;32m${currentbuild}\e[0;39m"
+	echo -e "	Available version: \e[0;32m${availablebuild}\e[0;39m"
+	echo -e ""
+	fn_printoknl "No update available"
+	fn_scriptlog "Current build: ${currentbuild}"
+	fn_scriptlog "Available build: ${availablebuild}"
 fi
 }
 
 fn_printdots "Checking for update"
-fn_appmanifestcheck
-fn_steamcmdcheck
+if [ "${gamename}" == "Teamspeak 3" ]; then
+	fn_teamspeak3_check
+else
+	fn_appmanifestcheck
+	fn_steamcmdcheck
+fi

+ 61 - 2
functions/fn_update_dl

@@ -2,11 +2,13 @@
 # LGSM fn_update_dl function
 # Author: Daniel Gibbs
 # Website: http://danielgibbs.co.uk
-# Version: 210115
+# Version: 150315
 
 # Description: Runs a server update.
 
 local modulename="Update"
+
+fn_steamcmd_dl(){
 fn_check_root
 fn_check_systemdir
 fn_details_config
@@ -18,4 +20,61 @@ fn_scriptlog "Updating ${servername}"
 sleep 1
 cd "${rootdir}"
 cd "steamcmd"
-./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" +quit|tee -a "${scriptlog}"
+./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" +quit|tee -a "${scriptlog}"
+}
+
+fn_teamspeak3_dl(){
+fn_check_root
+fn_check_systemdir
+fn_details_config
+fn_printdots "Updating ${servername}"
+sleep 1
+fn_printoknl "Updating ${servername}"
+fn_scriptlog "Updating ${servername}"
+sleep 1
+cd ${rootdir}
+echo -e "downloading teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz...\c"
+fn_scriptlog "Downloading teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz"
+wget -N --no-check-certificate /dev/null http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux-${ts3arch}-${ts3_version_number}.tar.gz 2>&1 | grep -F HTTP | cut -c45-| uniq
+sleep 1
+echo -e "extracting teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz...\c"
+fn_scriptlog "Extracting teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz"
+tar -xf "teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz" 2> "${scriptlogdir}/.${servicename}-tar-error.tmp"
+local status=$?
+if [ ${status} -eq 0 ]; then
+	echo "OK"
+else
+	echo "FAIL - Exit status ${status}"
+	fn_scriptlog "Failed to extract - Exit status ${status}"
+	sleep 1
+	cat "${scriptlogdir}/.${servicename}-tar-error.tmp"
+	cat "${scriptlogdir}/.${servicename}-tar-error.tmp" >> "${scriptlog}"
+	rm "${scriptlogdir}/.${servicename}-tar-error.tmp"
+	fn_scriptlog "Failure! Unable to update"
+	exit
+fi
+echo -e "copying to ${filesdir}...\c"
+fn_scriptlog "Copying to ${filesdir}"
+cp -R ${rootdir}/teamspeak3-server_linux-${ts3arch}/* "${filesdir}" 2> "${scriptlogdir}/.${servicename}-cp-error.tmp"
+local status=$?
+if [ ${status} -eq 0 ]; then
+	echo "OK"
+else
+	echo "FAIL - Exit status ${status}"
+	fn_scriptlog "Failed to copy - Exit status ${status}"
+	sleep 1
+	cat "${scriptlogdir}/.${servicename}-cp-error.tmp"
+	cat "${scriptlogdir}/.${servicename}-cp-error.tmp" >> "${scriptlog}"
+	rm "${scriptlogdir}/.${servicename}-cp-error.tmp"
+	fn_scriptlog "Failure! Unable to update"
+	exit
+fi
+rm -f teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz
+rm -rf ${rootdir}/teamspeak3-server_linux-${ts3arch}
+}
+
+if [ "${gamename}" == "Teamspeak 3" ]; then
+	fn_teamspeak3_dl
+else
+	fn_steamcmd_dl
+fi