#!/bin/bash

# what are we trying to install?
game_nm="DST"
game_id=343050

cluster_name="Zom.bi"
dontstarve_dir="$HOME/.klei/DoNotStarveTogether"

# install game to this directory
installdir=/home/steam/games/$game_nm

# if path does not exist, create it
mkdir -p $installdir

if [[ -w $installdir ]] # can we write into the directory?
then
	# Install or update the game in /home/steam/games/[game name]
	/opt/steamcmd/steamcmd.sh \
		+login anonymous \
		+force_install_dir $installdir \
		+app_update $game_id validate \
		+quit
else
	# install dir maybe mounted read-only, simply
	# skip installing/updating and inform the user.
	echo "Skipped game installation."
fi

# run the next commands from the installdir
cd $installdir/bin

run_shared=(./dontstarve_dedicated_server_nullrenderer)
run_shared+=(-console)
run_shared+=(-cluster "$cluster_name")
run_shared+=(-monitor_parent_process $$)

"${run_shared[@]}" -shard Caves  | sed 's/^/Caves:  /' &
"${run_shared[@]}" -shard Master | sed 's/^/Master: /'