#!/bin/bash
# Version 1

. /usr/local/bin/7dtd-common.sh
checkRootLoadConf

for I in $SDTD_BASE/instances/*; do
	ins=`basename $I`
	run=$(isRunning $ins)
	if [ $run -eq 1 ]; then
		echo "At least one instance is still running."
		echo "Before updating the engine please stop all instances!"
		exit 1
	fi
done

if [ ! -e $STEAMCMD_ROOT ]; then
	mkdir $STEAMCMD_ROOT
	cd /tmp
	wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz
	tar -xvzf steamcmd_linux.tar.gz -C $STEAMCMD_ROOT
	cd $STEAMCMD_ROOT
	./steamcmd.sh +quit
fi

cd $STEAMCMD_ROOT

./steamcmd.sh +@sSteamCmdForcePlatformType windows +login $STEAM_USER $STEAM_PASS +force_install_dir $SDTD_ROOT "+app_update 251570" validate +quit
chown $SDTD_USER.$SDTD_GROUP -R $SDTD_ROOT

cp $SDTD_ROOT/Install/32bit/7DaysToDie.exe $SDTD_ROOT/
cp $SDTD_ROOT/Install/32bit/mono.dll $SDTD_ROOT/7DaysToDie_Data/Mono/
cp $SDTD_ROOT/Install/32bit/SteamworksManaged.dll $SDTD_ROOT/7DaysToDie_Data/Managed/
cp $SDTD_BASE/msvcr100.dll $SDTD_ROOT/
