#!/bin/sh
#PupControl 3.6.1
#Launch wrapper

[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@}

WORKDIR="/usr/local/PupControl"
EXIT_STATUS1=`grep -a EXIT= $WORKDIR/pupcontrol.rc 2>/dev/null | tail -n 1 | cut -d "=" -f 2 | sed 's/\"//g'`
EXIT_STATUS2=`grep -a EXIT= $WORKDIR/desktops.rc 2>/dev/null | tail -n 1 | cut -d "=" -f 2 | sed 's/\"//g'`

if [ "$EXIT_STATUS1" = "abort" -o "$EXIT_STATUS1" = "" ]; then
	grep -av '_ALL=' $WORKDIR/pupcontrol2.rc > $WORKDIR/pupcontrol.rc 2>/dev/nul
else
	grep -av '_ALL=' $WORKDIR/pupcontrol.rc > /tmp/tmpfile && mv -f /tmp/tmpfile $WORKDIR/pupcontrol.rc
	cp -f $WORKDIR/pupcontrol.rc $WORKDIR/pupcontrol2.rc 2>/dev/null &
fi

if   [ "$EXIT_STATUS2" = "abort" -o "$EXIT_STATUS2" = "" ]; then cp -f $WORKDIR/desktops2.rc $WORKDIR/desktops.rc 2>/dev/null &
else cp -f $WORKDIR/desktops.rc $WORKDIR/desktops2.rc 2>/dev/null &
fi

if [ "`pidof PC-pref`" ]; then
	sleep .8
	[ "`pidof PC-pref`" ] && Xdialog --title Alert --beep --msgbox "  Another instance of PupControl will not  \n  run when the Preferences dialog is active.  " 0 0 && exit 0
fi

$WORKDIR/PupControl-bin &

#end
