#!/bin/sh

if test ! $pmdir; then
	cd "$(pwd)"; pmdir="$(pwd)"
	ln -fs "$(pwd)/pmodules" /home
	pmagic_load_sqfm -l pmodules/*.sqfm
	custom=$(echo /run/sqfm.088-custom*)
	rsync -av $custom/root /
fi

if test ! -e /home/apps; then
	if test -d "$pmdir/apps"; then 
		apps=/home/apps
		ln -fs "$pmdir/apps" $apps
		cp -fs $apps/desktop/* /root/Desktop
		cp -fs $apps/applications/* /usr/share/applications
	fi
fi

if test ! -e /home/winapps; then
	if test -e /root/.wine; then
		winapps=/home/winapps
		ln -fs "$pmdir/winapps" $winapps
		cp -fs $winapps/desktop/* /root/Desktop
		cp -fs $winapps/applications/* /usr/share/applications
	fi
fi

if test "$(pwd)" = "$pmdir"; then
	sleep 3
	killall Xorg
fi
