#!/bin/bash
#PupClockset 2.3.1
#Functions
#Copyright GPL3, http://www.gnu.org/licenses/
#Roger Grider (radky)
#20130720 internationalized (vicmz)

export TEXTDOMAIN=pupclockset
export OUTPUT_CHARSET=UTF-8

WORKDIR="/usr/local/PupClockset"

#define current window manager
if [ -f "$HOME/Choices/windowmanager" ]; then
  CURRWM=`cat "$HOME/Choices/windowmanager"` #TazOC LHP
else
  CURRWM=`cat /etc/windowmanager`
fi
. /etc/DISTRO_SPECS
if [ "$DISTRO_NAME" = "Fatdog64" ]; then
 if [ -s "$FATDOG_STATE_DIR/windowmanager" ]; then
  CURRWM=`cat "$FATDOG_STATE_DIR/windowmanager"`
 elif [ "`pidof openbox`" ]; then
  CURRWM="openbox-session"
 elif [ "`pidof jwm`" ]; then
  CURRWM="jwm"
 elif [ "`pidof icewm`" ]; then
  CURRWM="icewm"
 elif [ "`pidof xfwm4`" ]; then
  CURRWM="xfwm4"
 fi
 echo "$CURRWM" > /etc/windowmanager
fi

case "$1" in

-clockset)
if 		[ "`pidof fbpanel`" ] && [ "`pidof lxpanel`" ]; then Xdialog --title Alert --beep --msgbox " PupClockset does not support concurrent \n active sessions of Fbpanel and Lxpanel. " 0 0

elif 	[ "$CURRWM" = "openbox" -o "$CURRWM" = "openbox-session" ] && [ "`pidof fbpanel`" ]; then #FbPanel
		FBPANEL="$HOME/.config/fbpanel/default"
		if [ "`grep dclock $FBPANEL`" ]; then sed -i 's/dclock/tclock/' $FBPANEL & fi
		if [ "`grep dclock /usr/sbin/pfbpanel`" ]; then sed -i 's/dclock/tclock/' /usr/sbin/pfbpanel & fi
		if [ "`grep PupClockset /usr/sbin/pfbpanel`" = "" ]; then sed '/if/s/^.*grep CLOCK12.*$/  if [ -f \/usr\/local\/PupClockset\/PupClockset ]; then\n  echo "`cat \/usr\/local\/PupClockset\/fbpanelClockFmt`" >> $DEFAULT\n  elif [ "`cat $CONFIG | grep CLOCK12 | cut -f 2 -d '='`" = true ]; then/' /usr/sbin/pfbpanel > /tmp/tmpfile ; chmod 755 /tmp/tmpfile ; mv -f /tmp/tmpfile /usr/sbin/pfbpanel & fi
		if [ "`grep 'Action = PupClockset' /usr/sbin/pfbpanel`" = "" ]; then sed '/Action =/s/^.*grep CLOCKPROG.*$/  if [ -f \/usr\/local\/PupClockset\/PupClockset ]; then\n  echo "Action = PupClockset \&" >> $DEFAULT\n  else\n  echo Action = `cat $CONFIG | grep CLOCKPROG | cut -f 2 -d '='` \& >> $DEFAULT\n  fi/' /usr/sbin/pfbpanel > /tmp/tmpfile ; chmod 755 /tmp/tmpfile ; mv -f /tmp/tmpfile /usr/sbin/pfbpanel & fi
		if [ "`which minixcal`" ]; then
		 MINIXCAL=`cat $WORKDIR/fbp_xcal 2>/dev/null`
		 if [ "$MINIXCAL" = "true" ]; then
		  [ ! "`grep 'Action = minixcal' $FBPANEL`" ] && sed -i 's/Action \= PupClockset \&/Action \= minixcal \&/' $FBPANEL
		 else	 
		  [ ! "`grep 'Action = PupClockset' $FBPANEL`" ] && sed -i 's/Action \= minixcal \&/Action \= PupClockset \&/' $FBPANEL
		 fi
		fi
		FBPFONTNAME=`grep -a FBPFONTNAME= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBPFONTSIZE=`grep -a FBPFONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBPFONTWEIGHT=`grep -a FBPFONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBPFONTSTYLE=`grep -a FBPFONTSTYLE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBPFONTCOLOR=`grep -a FBPFONTCOLOR= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBPFONTSTRING=`grep -a FBPFONT_STRING= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$FBPFONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		[ "$CLOCKVAR1" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%l:%M %p<\/span>/' $FBPANEL
		[ "$CLOCKVAR2" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%l:%M:%S %p<\/span>/' $FBPANEL
		[ "$CLOCKVAR3" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%a %l:%M %p<\/span>/' $FBPANEL
		[ "$CLOCKVAR4" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%a %d %b %l:%M %p<\/span>/' $FBPANEL
		[ "$CLOCKVAR5" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%H:%M<\/span>/' $FBPANEL
		[ "$CLOCKVAR6" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%H:%M:%S<\/span>/' $FBPANEL
		[ "$CLOCKVAR7" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%a %H:%M<\/span>/' $FBPANEL
		[ "$CLOCKVAR8" = "true" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">%a %d %b %H:%M<\/span>/' $FBPANEL
		[ "$FBPFONTSTRING" != "" ] && sed -i 's/^.*ClockFmt.*$/ClockFmt = <span font-family="'$FBPFONTNAME'" size="'$FBPFONTSIZE'" weight="'$FBPFONTWEIGHT'" style="'$FBPFONTSTYLE'" color="'$FBPFONTCOLOR'">'"$FBPFONTSTRING"'<\/span>/' $FBPANEL
		killall -USR1 fbpanel
		grep ClockFmt $FBPANEL > $WORKDIR/fbpanelClockFmt
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/fbp.rc
		cat $FBPFONTCOLOR > /tmp/fbpclockcolor.tmp 2>/dev/null
		$WORKDIR/PupClockset

elif 	[ "$CURRWM" = "startfluxbox" -o "$CURRWM" = "fluxbox" -o "$CURRWM" = "fluxbox-session" ]; then #FluxBox
		FLUXBOX="$HOME/.fluxbox/init"
		FLUXBOX2="$HOME/.fluxbox/overlay"
		if [ ! -d $HOME/.fluxbox/ ]; then mkdir -p $HOME/.fluxbox/ & fi
		if [ ! -s $FLUXBOX ]; then cp -f /usr/share/fluxbox/init $FLUXBOX & fi
		if [ ! -s $FLUXBOX2 ]; then cp -f /usr/share/fluxbox/overlay $FLUXBOX2 & fi
		if [ "`grep 'session.screen0.strftimeFormat:' $FLUXBOX`" = "" ]; then echo "session.screen0.strftimeFormat:" >> $FLUXBOX & fi
		if [ "`grep '~/.fluxbox/overlay' $FLUXBOX`" = "" ]; then echo 'session.styleOverlay: ~/.fluxbox/overlay' >> $FLUXBOX & fi
		if [ "`grep 'toolbar.clock.font:' $FLUXBOX2`" = "" ]; then echo "toolbar.clock.font:" >> $FLUXBOX2 & fi
		FBXFONTNAME=`grep -a FBXFONTNAME= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBXFONTSIZE=`grep -a FBXFONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBXFONTWEIGHT=`grep -a FBXFONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBXFONTSTYLE=`grep -a FBXFONTSTYLE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		FBXFONTSTRING=`grep -a FBXFONT_STRING= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$FBXFONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		[ "$CLOCKVAR9" = "true" ]  && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%l:%M %p/' $FLUXBOX
		[ "$CLOCKVAR10" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%l:%M:%S %p/' $FLUXBOX
		[ "$CLOCKVAR11" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%a %l:%M %p/' $FLUXBOX
		[ "$CLOCKVAR12" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%a %d %b %l:%M %p/' $FLUXBOX
		[ "$CLOCKVAR13" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%H:%M/' $FLUXBOX
		[ "$CLOCKVAR14" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%H:%M:%S/' $FLUXBOX
		[ "$CLOCKVAR15" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%a %H:%M/' $FLUXBOX
		[ "$CLOCKVAR16" = "true" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	%a %d %b %H:%M/' $FLUXBOX
		[ "$FBXFONTSTRING" != "" ] && sed -i 's/^.*strftimeFormat.*$/session.screen0.strftimeFormat:	'"$FBXFONTSTRING"'/' $FLUXBOX
		sed -i 's/^.*toolbar.clock.font.*$/toolbar.clock.font:'"$FBXFONTNAME-$FBXFONTSIZE:$FBXFONTWEIGHT:$FBXFONTSTYLE"'/' $FLUXBOX2
		kill -1 $(xprop -root _BLACKBOX_PID | awk '{print $3}')
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/fbx.rc
		$WORKDIR/PupClockset

elif 	[ "$CURRWM" = "icewm" -o "$CURRWM" = "starticewm" -o "$CURRWM" = "icewm-session" ]; then #IceWM
		ICEWM="$HOME/.icewm/preferences"
		ICEWM2="$HOME/.icewm/prefoverride"
		ICEWMCLOCKLEDS=`grep -a TaskBarClockLeds $ICEWM2 | cut -d "=" -f2 | cut -d " " -f1`
		if [ ! -d $HOME/.icewm/ ]; then mkdir -p $HOME/.icewm/ & fi
		if [ "`grep 'TimeFormat=' $ICEWM`" = "" ]; then cp -f /usr/share/icewm/preferences $HOME/.icewm/ & fi
		if [ "`grep 'TaskBarClockLeds' $ICEWM2`" = "" ]; then cp -f /usr/share/icewm/prefoverride $HOME/.icewm/ & fi
		if [ "`grep 'TaskBarClockLeds' $ICEWM2`" = "" ]; then echo -e "\n TaskBarClockLeds=0 # 0/1/" >> $ICEWM2 & fi
		if [ "$ICEWMCLOCKLEDS" != "0" ]; then sed -i 's/^.*TaskBarClockLeds.*$/ TaskBarClockLeds=0 # 0\/1/' $ICEWM2 & fi
		if [ "`grep -a 'ClockFontNameXft' $ICEWM2`" = "" ]; then echo -e "\n ClockFontNameXft" >> $ICEWM2 & fi
		ICECLOCK_CMD="PupClockset"
		if [ "`which minixcal`" ]; then
		 MINIXCAL=`cat $WORKDIR/ice_xcal 2>/dev/null`
		 if [ "$MINIXCAL" = "true" ]; then
		  ICECLOCK_CMD="minixcal"
		 fi
		fi
		sed -i 's/^.*ClockCommand=.*$/ClockCommand="'$ICECLOCK_CMD'"/' $ICEWM &
		sed -i -e 's/ClockCommand/Clock#Command/' -e 's/TimeFormat/Time#Format/' $ICEWM2
		ICEWMFONTNAME=`grep -a ICEWMFONTNAME= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		ICEWMFONTSIZE=`grep -a ICEWMFONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		ICEWMFONTWEIGHT=`grep -a ICEWMFONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		ICEWMFONTSTYLE=`grep -a ICEWMFONTSTYLE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		ICEWMFONTSTRING=`grep -a ICEWMFONT_STRING= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$ICEWMFONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		[ "$CLOCKVAR17" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%l:%M %p"/' $ICEWM
		[ "$CLOCKVAR18" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%l:%M:%S %p"/' $ICEWM
		[ "$CLOCKVAR19" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%a %l:%M %p"/' $ICEWM
		[ "$CLOCKVAR20" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%a %d %b %l:%M %p"/' $ICEWM
		[ "$CLOCKVAR21" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%H:%M"/' $ICEWM
		[ "$CLOCKVAR22" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%H:%M:%S"/' $ICEWM
		[ "$CLOCKVAR23" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%a %H:%M"/' $ICEWM
		[ "$CLOCKVAR24" = "true" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="%a %d %b %H:%M"/' $ICEWM
		[ "$ICEWMFONTSTRING" != "" ] && sed -i 's/^.*TimeFormat=.*$/TimeFormat="'"$ICEWMFONTSTRING"'"/' $ICEWM
		sed -i 's/^.*ClockFontNameXft.*$/ ClockFontNameXft='"$ICEWMFONTNAME-$ICEWMFONTSIZE:weight=$ICEWMFONTWEIGHT:slant=$ICEWMFONTSTYLE"'/' $ICEWM2
		killall -HUP icewm
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/icewm.rc
		$WORKDIR/PupClockset

elif 	[ "$CURRWM" = "jwm" -o "$CURRWM" = "jwm-session" -o "$CURRWM" = "startjwm" ]; then #JWM
		if [ -f $HOME/.jwm/jwmrc-tray1 ]; then
		 JWM="$HOME/.jwm/jwmrc-tray1"
		else
		 JWM="$HOME/.jwmrc-tray"
		fi
		JWMFONT="$HOME/.jwm/jwmrc-theme"
		if [ "`grep '<ClockStyle>' $JWMFONT`" = "" ]; then echo -e "`cat $JWMFONT | sed 's/<\/JWM>/	<ClockStyle>\\n	<\/ClockStyle>/'`\n\n</JWM>" > /tmp/tmpfile && mv -f /tmp/tmpfile $JWMFONT & fi
		JWMFONTNAME=`grep -a JWMFONTNAME= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		JWMFONTSIZE=`grep -a JWMFONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		JWMFONTWEIGHT=`grep -a JWMFONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		JWMFONTSTYLE=`grep -a JWMFONTSTYLE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		JWMFONTCOLOR=`grep -a JWMFONTCOLOR= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		JWMFONTSTRING=`grep -a JWMFONT_STRING= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$JWMFONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		JWMCLOCK_CMD="PupClockset"
		if [ "`which minixcal`" ]; then
		 MINIXCAL=`cat $WORKDIR/jwm_xcal 2>/dev/null`
		 if [ "$MINIXCAL" = "true" ]; then
		  JWMCLOCK_CMD="minixcal"
		 fi
		fi
		sed -i -e 's/^.*<ClockStyle>.*$/	<ClockStyle>/' -e 's/^.*<\/ClockStyle>.*$/	<\/ClockStyle>/' $JWMFONT ## assure consistent ClockStyle tags in jwmrc-theme
		[ "$CLOCKVAR25" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%l:%M %p">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR26" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%l:%M:%S %p">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR27" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%a %l:%M %p">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR28" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%a %d %b %l:%M %p">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR29" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%H:%M">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR30" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%H:%M:%S">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR31" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%a %H:%M">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$CLOCKVAR32" = "true" ] && sed -i 's/^.*Clock.*$/		<Clock format="%a %d %b %H:%M">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		[ "$JWMFONTSTRING" != "" ] && sed -i 's/^.*Clock.*$/		<Clock format="'"$JWMFONTSTRING"'">'"$JWMCLOCK_CMD"'<\/Clock>/' $JWM
		awk '/<ClockStyle>/{p=1;print;print "		<Font>'"$JWMFONTNAME-$JWMFONTSIZE:$JWMFONTWEIGHT:$JWMFONTSTYLE"'<\/Font>\n		<Foreground>'"$JWMFONTCOLOR"'<\/Foreground>"}/	<\/ClockStyle>/{p=0}!p' $JWMFONT 2>/dev/null > /tmp/tmpfile && mv -f /tmp/tmpfile $JWMFONT
		jwm -restart
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/jwm.rc
		cat $JWMFONTCOLOR > /tmp/jwmclockcolor.tmp 2>/dev/null
		$WORKDIR/PupClockset

elif 	[ "`pidof lxpanel`" -o "`pidof lxpanel.bin`" ]; then #LXPanel
		if [ "$DISTRO_NAME" = "Lighthouse64" ]; then
		   if [ "$CURRWM" = "openbox-lxde" -o "$CURRWM" = "startlxde" ]; then
		    LXPANEL="$HOME/.config/lxpanel/LXDE/panels/panel"
		   else
		    LXPANEL="$HOME/.config/lxpanel/default/panels/panel"
		   fi
		elif [ -f "$HOME/.config/lxpanelx/default/panels/panel.panel" ]; then #LXPanelx
		 LXPANEL="$HOME/.config/lxpanelx/default/panels/panel.panel"
		elif [ "$CURRWM" = "openbox-lxde" -o "$CURRWM" = "startlxde" ]; then
		 LXPANEL="$HOME/.config/lxpanel/LXDE/panels/panel"
		else
		 LXPANEL=`find $HOME/.config/lxpanel/ -name 'panel'`
		fi
		LXPCLOCK_CMD="PupClockset"
		if [ "`which minixcal`" ]; then
		   MINIXCAL=`cat $WORKDIR/lxp_xcal 2>/dev/null`
		   if [ "$MINIXCAL" = "true" ]; then
		    LXPCLOCK_CMD="minixcal"
		   fi
		fi
		sed -i 's/^.*Action                   =.*$/        Action=/' $LXPANEL #LXPanelx
		sed -i 's/^.*Action=.*$/        Action='"$LXPCLOCK_CMD"'/' $LXPANEL
		if [ "`grep 'set-time-for-puppy' $LXPANEL`" != "" ]; then sed -i 's/set-time-for-puppy/PupClockset/' $LXPANEL & fi
		if [ "`grep 'Action=' $LXPANEL`" = "" ]; then sed -i '/TooltipFmt/a\        Action='"$LXPCLOCK_CMD"'' $LXPANEL & fi
		if [ ! "` grep lxpanelx $LXPANEL`" ]; then
		   if [ ! "`grep 'usefontcolor=' $LXPANEL`" ]; then sed -i '/setdocktype/a\    usefontcolor=1' $LXPANEL & fi
		   if [ ! "`grep ' fontcolor=' $LXPANEL`" ]; then sed -i '/usefontcolor/a\    fontcolor=#ffffff' $LXPANEL & fi
		   if [ ! "`grep 'usefontsize=' $LXPANEL`" ]; then sed -i '/ fontcolor=/a\    usefontsize=1' $LXPANEL & fi
		   if [ ! "`grep ' fontsize=' $LXPANEL`" ]; then sed -i '/usefontsize/a\    fontsize=12' $LXPANEL & fi
		fi
		LXPFONTSIZE=`grep -a LXPFONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		LXPFONTWEIGHT=`grep -a LXPFONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		if [ "$LXPFONTWEIGHT" = "bold" ]; then
		 LXPFONTWEIGHT="1"
		else
		 LXPFONTWEIGHT="0"
		fi
		LXPFONTCOLOR=`grep -a LXPFONTCOLOR= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "`grep UseFontSize $LXPANEL`" ] && sed -i -e 's/^.*UseFontSize.*$/    UseFontSize=1/' -e 's/^.* FontSize.*$/    FontSize='"$LXPFONTSIZE"'/' -e 's/^.*UseFontColor.*$/    UseFontColor=1/' -e 's/^.* FontColor.*$/    FontColor='"$LXPFONTCOLOR"'/' -e 's/^.*BoldFont.*$/        BoldFont='"$LXPFONTWEIGHT"'/' $LXPANEL #LXPanelx
		[ "`grep usefontsize $LXPANEL`" ] && sed -i -e 's/^.*usefontsize.*$/    usefontsize=1/' -e 's/^.* fontsize.*$/    fontsize='"$LXPFONTSIZE"'/' -e 's/^.*usefontcolor.*$/    usefontcolor=1/' -e 's/^.* fontcolor.*$/    fontcolor='"$LXPFONTCOLOR"'/' -e 's/^.*BoldFont.*$/        BoldFont='"$LXPFONTWEIGHT"'/' $LXPANEL #LXPanel
		LXPFONTSTRING=`grep -a LXPFONT_STRING $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$LXPFONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		[ "$CLOCKVAR33" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%l:%M %p/' $LXPANEL
		[ "$CLOCKVAR34" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%l:%M:%S %p/' $LXPANEL
		[ "$CLOCKVAR35" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%a %l:%M %p/' $LXPANEL
		[ "$CLOCKVAR36" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%a %d %b %l:%M %p/' $LXPANEL
		[ "$CLOCKVAR37" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%H:%M/' $LXPANEL
		[ "$CLOCKVAR38" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%H:%M:%S/' $LXPANEL
		[ "$CLOCKVAR39" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%a %H:%M/' $LXPANEL
		[ "$CLOCKVAR40" = "true" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt=%a %d %b %H:%M/' $LXPANEL
		[ "$LXPFONTSTRING" != "" ] && sed -i 's/^.*ClockFmt.*$/        ClockFmt='"$LXPFONTSTRING"'/' $LXPANEL
		if [ "$DISTRO_NAME" = "Lighthouse64" ]; then ## sync panel clocks of dual LXDE-LXPanel options in Lighthouse64
		 grep ClockFmt $LXPANEL > $WORKDIR/lxpanelClockFmt
		 LXPANEL_CLOCKFMT=`cat $WORKDIR/lxpanelClockFmt`
		 sed -i -e 's/^.*usefontsize.*$/    usefontsize=1/' -e 's/^.* fontsize.*$/    fontsize='"$LXPFONTSIZE"'/' -e 's/^.*usefontcolor.*$/    usefontcolor=1/' -e 's/^.* fontcolor.*$/    fontcolor='"$LXPFONTCOLOR"'/' -e 's/^.*BoldFont.*$/        BoldFont='"$LXPFONTWEIGHT"'/' -e 's/^.*ClockFmt.*$/'"$LXPANEL_CLOCKFMT"'/' $HOME/.config/lxpanel/LXDE/panels/panel
		 sed -i -e 's/^.*usefontsize.*$/    usefontsize=1/' -e 's/^.* fontsize.*$/    fontsize='"$LXPFONTSIZE"'/' -e 's/^.*usefontcolor.*$/    usefontcolor=1/' -e 's/^.* fontcolor.*$/    fontcolor='"$LXPFONTCOLOR"'/' -e 's/^.*BoldFont.*$/        BoldFont='"$LXPFONTWEIGHT"'/' -e 's/^.*ClockFmt.*$/'"$LXPANEL_CLOCKFMT"'/' $HOME/.config/lxpanel/default/panels/panel
		fi
		if [ "`which lxpanel_menu_refresh`" ]; then
		 lxpanel_menu_refresh &
		elif [ "`which lxpanelctl`" ]; then
		 lxpanelctl restart &
		else
		 killall -9 lxpanel
		 if [ "`echo "$CURRWM" | grep lxde`" ]; then
		  lxpanel --profile LXDE &
		 else
		  lxpanel &
		 fi
		fi
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/lxp.rc
		cat $LXPFONTCOLOR > /tmp/lxpclockcolor.tmp 2>/dev/null
		$WORKDIR/PupClockset

elif 	[ "`pidof xfce4-panel`" ]; then #Xfce4
		XFCE4FONTNAME=`grep -a XFCE4FONTNAME= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		XFCE4FONTSIZE=`grep -a XFCE4FONTSIZE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		XFCE4FONTWEIGHT=`grep -a XFCE4FONTWEIGHT= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		XFCE4FONTSTYLE=`grep -a XFCE4FONTSTYLE= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		XFCE4FONTCOLOR=`grep -a XFCE4FONTCOLOR= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		XFCE4FONTSTRING=`grep -a XFCE4FONT_STRING= $WORKDIR/clock-variables.rc | cut -d "=" -f 2  | sed 's/\"//g'`
		[ "$XFCE4FONTSTRING" != "" ] && CLOCKVAR*="false" 2>/dev/null
		[ "$CLOCKVAR41" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%l:%M %p</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR42" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%l:%M:%S %p</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR43" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%a %l:%M %p</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR44" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%a %d %b %l:%M %p</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR45" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%H:%M</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR46" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%H:%M:%S</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR47" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%a %H:%M</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$CLOCKVAR48" = "true" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">%a %d %b %H:%M</span>" > /$WORKDIR/xfce4ClockFmt
		[ "$XFCE4FONTSTRING" != "" ] && echo "<span font="'"'$XFCE4FONTNAME $XFCE4FONTSIZE'"' weight='"'$XFCE4FONTWEIGHT'"' style='"'$XFCE4FONTSTYLE'"' color='"'$XFCE4FONTCOLOR'"'">"$XFCE4FONTSTRING" </span>" > /$WORKDIR/xfce4ClockFmt
		XFCE4CLOCKFMT=`cat /$WORKDIR/xfce4ClockFmt`
		XFCE4PANEL="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml"
		XFCE4PLUGIN=`grep 'clock' $XFCE4PANEL | awk '{print $2}' | cut -d "=" -f2 | sed -e 's/\"//g'`
		xfconf-query -c xfce4-panel -p /plugins/$XFCE4PLUGIN/mode -n -t uint -s 2 #assure the clock is in digital mode
		xfconf-query -c xfce4-panel -p /plugins/$XFCE4PLUGIN/digital-format -n -t string -s "$XFCE4CLOCKFMT" #set the digital clock format
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/xfce4.rc
		cat $XFCE4FONTCOLOR > /tmp/xfce4clockcolor.tmp 2>/dev/null
		$WORKDIR/PupClockset

else 	Xdialog --title Alert --beep --msgbox " $(gettext 'PupClockset does not support this \n clock and/or desktop environment.') " 0 0

fi
;;

-current_fontcolor)
		[ "`pidof fbpanel`" ] && [ ! -s /tmp/fbpclockcolor.tmp ] && grep -a FBPFONTCOLOR= $WORKDIR/fbp.rc | cut -d "=" -f 2  | sed 's/\"//g' > /tmp/fbpclockcolor.tmp
		[ "`pidof jwm`" ] && [ ! -s /tmp/jwmclockcolor.tmp ] && grep -a JWMFONTCOLOR= $WORKDIR/jwm.rc | cut -d "=" -f 2  | sed 's/\"//g' > /tmp/jwmclockcolor.tmp
		[ "`pidof lxpanel`" -o "`pidof lxpanel.bin`" ] && [ ! -s /tmp/lxpclockcolor.tmp ] && grep -a LXPFONTCOLOR= $WORKDIR/lxp.rc | cut -d "=" -f 2  | sed 's/\"//g' > /tmp/lxpclockcolor.tmp
		[ "`pidof xfce4-panel`" ] && [ ! -s /tmp/xfce4clockcolor.tmp ] && grep -a XFCE4FONTCOLOR= $WORKDIR/xfce4.rc | cut -d "=" -f 2  | sed 's/\"//g' > /tmp/xfce4clockcolor.tmp
		;;

-current_fontname)
		echo "`fc-list : family | sort | uniq`" | awk '{print "<item>"$1" "$2" "$3" "$4"</item>"}' | sed -e 's/ //g;s/\\//g' > /tmp/clockfontlist_1.tmp
		[ "`pidof fbpanel`" ] && grep -a FBPFONTNAME= $WORKDIR/fbp.rc | cut -d "=" -f 2 | sed 's/\"//g' | awk '{print "<item>"$1"</item>"}' > /tmp/clockfontlist_2.tmp
		[ "`pidof fluxbox`" ] && grep -a FBXFONTNAME= $WORKDIR/fbx.rc | cut -d "=" -f 2 | sed 's/\"//g' | awk '{print "<item>"$1"</item>"}' > /tmp/clockfontlist_2.tmp
		[ "`pidof icewm`" -o "`pidof icewm-session`" ] && grep -a ICEWMFONTNAME= $WORKDIR/icewm.rc | cut -d "=" -f 2 | sed 's/\"//g' | awk '{print "<item>"$1"</item>"}' > /tmp/clockfontlist_2.tmp
		[ "`pidof jwm`" ] && grep -a JWMFONTNAME= $WORKDIR/jwm.rc | cut -d "=" -f 2 | sed 's/\"//g' | awk '{print "<item>"$1"</item>"}' > /tmp/clockfontlist_2.tmp
		[ "`pidof xfce4-panel`" ] && grep -a XFCE4FONTNAME= $WORKDIR/xfce4.rc | cut -d "=" -f 2 | sed 's/\"//g' | awk '{print "<item>"$1"</item>"}' > /tmp/clockfontlist_2.tmp
		awk 'BEGIN{print ""}1' /tmp/clockfontlist_1.tmp > /tmp/clockfontlist_3.tmp
		sed '1r /tmp/clockfontlist_2.tmp' < /tmp/clockfontlist_3.tmp | sed '1d' > /tmp/tmpfile ; mv -f /tmp/tmpfile /tmp/PCS-fontlist.txt
		rm -f /tmp/clockfontlist_*.tmp
		;;

-sync_clock)
		if [ -f /usr/local/psync/psync ]; then /usr/local/psync/psync & else Xdialog --title Alert --beep --msgbox " $(gettext 'Psync is not available.') " 0 0 &  fi ;;

-restore_rc)
		sleep .3
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/fbp.rc | grep -v 'ALL=' > $WORKDIR/clock-variables.rc
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/fbx.rc | grep -v 'ALL=' >> $WORKDIR/clock-variables.rc
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/icewm.rc | grep -v 'ALL=' >> $WORKDIR/clock-variables.rc
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/jwm.rc | grep -v 'ALL=' >> $WORKDIR/clock-variables.rc
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/lxp.rc | grep -v 'ALL=' >> $WORKDIR/clock-variables.rc
		grep -Ea 'FONT|CLOCKVAR' $WORKDIR/xfce4.rc | grep -v 'ALL=' >> $WORKDIR/clock-variables.rc
		echo 'EXIT="quit_now"' >> $WORKDIR/clock-variables.rc
		cp -f $WORKDIR/clock-variables.rc $WORKDIR/clock-variables2.rc
		;;

esac
