#!/bin/sh

set -e

# dh_install cannot write (overwrite?) to vfat
if [ -L /opt/maemo/usr/share/games/openxcom ]; then
	# link not broken
	if [ -r /opt/maemo/usr/share/games/openxcom ]; then
		rm -rf /opt/maemo/usr/share/games/openxcom-temp
		mv -f /opt/maemo/usr/share/games/openxcom /opt/maemo/usr/share/games/openxcom-temp
	else
		rm -f /opt/maemo/usr/share/games/openxcom
	fi

else
	# exists and not link
	# hopefully eliminates problems with different cases (MAPS vs maps)
	if [ -r /opt/maemo/usr/share/games/openxcom ]; then
		rm -rf /home/user/MyDocs/Games/OpenXcom
		cp -rfL /opt/maemo/usr/share/games/openxcom /home/user/MyDocs/Games/OpenXcom || true
		ln -s /home/user/MyDocs/Games/OpenXcom /opt/maemo/usr/share/games/openxcom-temp
	fi
fi

