#!/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
# ~/.galaxyhack, and create symlinks to the data files, but the configuration
# file is copied, and write permission for the user is added to it.

cd /usr/local/share/galaxyhack || exit 1

find * -type d -exec mkdir -p ~/.galaxyhack/{} \; || exit 1

test -f ~/.galaxyhack/settings.dat || cp settings.dat ~/.galaxyhack && \
chmod u+w ~/.galaxyhack/settings.dat

find * -type f -exec ln -s /usr/local/share/galaxyhack/{} ~/.galaxyhack/{} \; 2>/dev/null || \
exit 1

cd ~/.galaxyhack || exit 1

exec /usr/local/libexec/galaxyhack "$@"
