#!/bin/bash
#
# starts Armagetron Advanced Dedicated Server from the installation directory

GAME_CONFDIR="@GAMES_SYSCONFDIR@/armagetronad"
GAME_LIBDIR="@GAMES_LIBDIR@/armagetronad"
GAME_DATADIR="@GAMES_DATADIR@/armagetronad"

echo "Checking Configuration"
if test ! -r "${HOME}"/.armagetronad-ded ; then
	mkdir -p "${HOME}"/.armagetronad-ded

	if test -r "${HOME}"/.ArmageTronrc ; then
		echo "Migrating very old configuration"
		cp "${HOME}"/.ArmageTronrc "${HOME}"/.armagetronad-ded/user.cfg 
	fi
fi

if test ! -r "${HOME}"/.armagetronad-ded/var ; then
	files=$(ls "${HOME}"/.armagetronad-ded)
	mkdir "${HOME}"/.armagetronad-ded/var
	echo "Testing configuration"
	test "$files" != "" && mv $files "${HOME}"/.armagetronad-ded/var
fi

echo "Done"

exec \
"${GAME_LIBDIR}"/armagetronad-dedicated \
	--datadir "${GAME_DATADIR}" \
	--configdir "${GAME_CONFDIR}" \
	--userdatadir "${HOME}"/.armagetronad-ded
