#!/bin/sh

gamesdir=/opt/dwarf-fortress
install="$HOME/.dwarf-fortress"

do_install() {
	cp -rn "$gamesdir"/data "$install/"
	cp -rsn "$gamesdir"/* "$install/"
}

if [[ -d "$install" ]]; then
	# delete dangling symlinks
	find -L "$install/" -type l -delete
	# ignore "are the same file" errors
	do_install 2>/dev/null
else
	mkdir "$install" || exit
	do_install || exit
fi

cd "$install" || exit
exec ./libs/Dwarf_Fortress "$@"
