#!/bin/sh
#PupClockset 2.3.1
#Launch wrapper
#20130720 internationalized (vicmz)

export TEXTDOMAIN=pupclockset
export OUTPUT_CHARSET=UTF-8

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

WORKDIR="/usr/local/PupClockset"
EXIT_STATUS1=`grep EXIT= $WORKDIR/clock-variables.rc | tail -n 1 | cut -d "=" -f 2 | sed 's/\"//g'`
EXIT_STATUS2=`grep EXIT= $WORKDIR/tint2clock-variables.rc | tail -n 1 | cut -d "=" -f 2 | sed 's/\"//g'`
RESTORE1=`grep -a FBPFONTCOLOR= $WORKDIR/fbp.rc | cut -d "=" -f 2  | sed 's/\"//g'`
RESTORE2=`grep -a JWMFONTCOLOR= $WORKDIR/jwm.rc | cut -d "=" -f 2  | sed 's/\"//g'`
RESTORE3=`grep -a LXPFONTCOLOR= $WORKDIR/lxp.rc | cut -d "=" -f 2  | sed 's/\"//g'`
RESTORE4=`grep -a XFCE4FONTCOLOR= $WORKDIR/xfce4.rc | cut -d "=" -f 2  | sed 's/\"//g'`
RESTORE5=`grep -a TINT2_FONTCOLOR= $WORKDIR/tint2bak.rc | cut -d "=" -f 2  | sed 's/\"//g'`

if [ ! "`pidof tint2`" ]; then
	[ "`pidof PupClockset-bin`" ] && Xdialog --title Alert --beep --msgbox " $(gettext 'PupClockset is already active.') " 0 0 && exit 0
	if [ "$EXIT_STATUS1" = "abort" -o "$EXIT_STATUS1" = "" ]; then
	 [ "`pidof fbpanel`" ] && echo "$RESTORE1" > /tmp/fbpclockcolor.tmp
	 [ "`pidof jwm`" ] && echo "$RESTORE2" > /tmp/jwmclockcolor.tmp
	 [ "`pidof lxpanel`" -o "`pidof lxpanel.bin`" ] && echo "$RESTORE3" > /tmp/lxpclockcolor.tmp
	 [ "`pidof xfce4-panel`" ] && echo "$RESTORE4" > /tmp/xfce4clockcolor.tmp
	 . $WORKDIR/func -restore_rc
	 $WORKDIR/PupClockset-bin
	else
	 cp -f $WORKDIR/clock-variables.rc $WORKDIR/clock-variables2.rc
	 $WORKDIR/PupClockset-bin
	fi
fi

if [ "`pidof tint2`" ]; then
	[ "`pidof Tint2Clockset`" ] && Xdialog --title Alert --beep --msgbox " $(gettext 'PupClockset is already active.') " 0 0 && exit 0
	if [ "$EXIT_STATUS2" = "abort" -o "$EXIT_STATUS2" = "" ]; then
	 echo "$RESTORE5" > /tmp/tint2clockcolor.tmp
	 cp -f $WORKDIR/tint2bak.rc $WORKDIR/tint2clock-variables.rc
	 cp -f $WORKDIR/tint2bak.rc $WORKDIR/tint2clock-variables2.rc
	 $WORKDIR/Tint2Clockset
	else
	 cp -f $WORKDIR/tint2clock-variables.rc $WORKDIR/tint2clock-variables2.rc
	 $WORKDIR/Tint2Clockset
	fi
fi

#end
