#!/bin/sh

# The executable needs to be run from its data directory, and needs to store
# configuration in it. We therefore mirror the data directory hierarchy in
# ~/.glest, and create symlinks to the data files.

if [ -d ~/.glest ]
then
        echo "Using existing ~/.glest directory."
else
        echo "Creating ~/.glest directory."
        cd /usr/local/share/glest || exit 1
        find * -type d -exec mkdir -p ~/.glest/{} \;
        find * -type f -exec ln -s /usr/local/share/glest/{} ~/.glest/{} \; 2>/dev/null
	mkdir -p ~/.glest/screens
	mkdir -p ~/.glest/shaders/standard
	touch ~/.glest/glest.log
	rm ~/.glest/glest.ini ~/.glest/glest ~/.glest/servers.ini
	cp -f /usr/local/share/glest/glest.ini ~/.glest/
	cp -f /usr/local/share/glest/servers.ini ~/.glest/
	chmod 640 ~/.glest/glest.ini ~/.glest/servers.ini
fi

cd ~/.glest || exit 1
exec /usr/local/share/glest/glest "$@"
