#!/bin/bash
# LGSM fn_check_steamcmd function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
# Version: 210115

# Description: Downloads SteamCMD on install and checks if missing before running functions that require SteamCMD


if [ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament 2004" ]; then
	: # These servers do not require SteamCMD. Check is skipped.
elif [ "${modulename}" == "Starting" ]||[ "${modulename}" == "Update" ]; then
	# Checks if SteamCMD exists when starting or updating a server.
	# Re-installs if missing.
	if [ ! -f ${rootdir}/steamcmd/steamcmd.sh ]; then
		fn_details_config
		fn_printwarn "SteamCMD is missing"
		fn_scriptlog "SteamCMD is missing"
		sleep 1
		echo -en "\n"
		mkdir -pv "${rootdir}/steamcmd"
		cd "${rootdir}/steamcmd"
		echo -e "downloading steamcmd_linux.tar.gz...\c"
		wget -N /dev/null http://media.steampowered.com/client/steamcmd_linux.tar.gz 2>&1 | grep -F HTTP | cut -c45-| uniq
		tar --verbose -zxf steamcmd_linux.tar.gz
		rm -v steamcmd_linux.tar.gz
		chmod +x steamcmd.sh
		fn_scriptlog "Re-installed SteamCMD"
		fn_printdots "${servername}"
		sleep 1
	fi
	cd "${rootdir}"
fi
