 #! /bin/sh -e


if [ "$1" = "importfontspushed" ]; then

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Importing fonts..."

	sleep 5

	if [ -f  $2/*.ttf ]; then
	cp -rf $2/*.ttf /home/user/.fonts/
	FOUND="1"
	fi
	if [ -f  $2/*.TTF ]; then
	cp -rf $2/*.TTF /home/user/.fonts/
	FOUND="1"
	fi
	if [ -f $2/*.otf ]; then
	cp -rf $2/*.otf /home/user/.fonts/
	FOUND="1"
	fi
	if [ -f $2/*.OTF ]; then
	cp -rf $2/*.OTF /home/user/.fonts/
	FOUND="1"
	fi
	if [ $FOUND == 1 ];then
	run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Import complete! Restart Theme Customizer to use new fonts." uint32:0 string:'NAO OK!'
	else
	run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"No font files found from: $2" uint32:0 string:'NAO OK!'
	fi
	exit 0

elif [ "$1" = "changeimagepushed" ]; then

	if [ "$2" = "clock.png" ] && [ -f /etc/hildon/theme/backgrounds/clock.png ]; then 
	korvattava="`readlink -f /etc/hildon/theme/backgrounds/clock.png`"

	if [ ! -f /opt/theme-customizer/backups$korvattava ]; then
	mkdir -p /opt/theme-customizer/backups$korvattava
	rm -rf /opt/theme-customizer/backups$korvattava
	cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	elif [ -f /opt/theme-customizer/backups$korvattava ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$korvattava ]; then

		cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	fi

		if [ -f /opt/theme-customizer/clock.png ] && [ $korvattava ]; then
		cp -rf /opt/theme-customizer/clock.png $korvattava
		rm -rf /opt/theme-customizer/clock.png
		fi

	elif [ "$2" = "appmanager.png" ] && [ -f /etc/hildon/theme/backgrounds/applicationmanager.png ]; then 
	korvattava="`readlink -f /etc/hildon/theme/backgrounds/applicationmanager.png`"

	if [ ! -f /opt/theme-customizer/backups$korvattava ]; then
	mkdir -p /opt/theme-customizer/backups$korvattava
	rm -rf /opt/theme-customizer/backups$korvattava
	cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	elif [ -f /opt/theme-customizer/backups$korvattava ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$korvattava ]; then

		cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	fi

		if [ -f /opt/theme-customizer/appmanager.png ] && [ $korvattava ]; then
		cp -rf /opt/theme-customizer/appmanager.png $korvattava
		rm -rf /opt/theme-customizer/appmanager.png
		fi

	elif [ "$2" = "mplayer.png" ] && [ -f /etc/hildon/theme/mediaplayer/background.png ]; then 
	korvattava="`readlink -f /etc/hildon/theme/mediaplayer/background.png`"

	if [ ! -f /opt/theme-customizer/backups$korvattava ]; then
	mkdir -p /opt/theme-customizer/backups$korvattava
	rm -rf /opt/theme-customizer/backups$korvattava
	cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	elif [ -f /opt/theme-customizer/backups$korvattava ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$korvattava ]; then

		cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	fi

		if [ -f /opt/theme-customizer/mplayer.png ] && [ $korvattava ]; then
		cp -rf /opt/theme-customizer/mplayer.png $korvattava
		rm -rf /opt/theme-customizer/mplayer.png	
		fi

	elif [ "$2" = "lock.png" ] && [ -f /etc/hildon/theme/backgrounds/lockslider.png ]; then 
	korvattava="`readlink -f /etc/hildon/theme/backgrounds/lockslider.png`"

	if [ ! -f /opt/theme-customizer/backups$korvattava ]; then
	mkdir -p /opt/theme-customizer/backups$korvattava
	rm -rf /opt/theme-customizer/backups$korvattava
	cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	elif [ -f /opt/theme-customizer/backups$korvattava ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$korvattava ]; then

		cp -rf $korvattava /opt/theme-customizer/backups$korvattava

	fi

		if [ -f /opt/theme-customizer/lock.png ] && [ $korvattava ]; then
		cp -rf /opt/theme-customizer/lock.png $korvattava
		rm -rf /opt/theme-customizer/lock.png	
		fi
        fi

exit 0

elif [ "$1" = "rebootnow" ]; then

reboot

exit 0

elif [ "$1" = "restorefilespushed" ]; then

	cp -rf /opt/theme-customizer/backups/* /
	rm -rf /opt/theme-customizer/backups
	mkdir -p /opt/theme-customizer/backups/usr/bin/
	cp -rf /usr/bin/hildon-home.launch /opt/theme-customizer/backups/usr/bin/hildon-home.launch
	chmod 0777 -R /opt/theme-customizer
	cp -rf /usr/bin/hildon-home.launch666 /usr/bin/hildon-home.launch
	hildon-theme-recache-all
	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Restoring files complete!"
	exit 0

elif [ "$1" = "saveasnew" ]; then

if [ ! -d /opt/usr/share/themes/$3 ]; then
cd /etc/hildon/theme
mkdir /opt/usr/share/themes/$3
tar chf - * | tar x -C /opt/usr/share/themes/$3
echo "1" >> /opt/usr/share/themes/$3/createdbythemecustomizer

perl -pi -e "s/Name=.*/Name=$2/g" /opt/usr/share/themes/$3/index.theme
perl -pi -e "s/Icon=.*/Icon=\/usr\/share\/themes\/$3\/images\/qgn_plat_theme_thumbnail.png/g" /opt/usr/share/themes/$3/index.theme
perl -pi -e "s/GtkTheme=.*/GtkTheme=$3/g" /opt/usr/share/themes/$3/index.theme
perl -pi -e "s/IconTheme=.*/IconTheme=default/g" /opt/usr/share/themes/$3/index.theme
perl -pi -e "s/X-MatchboxTheme=.*/X-MatchboxTheme=$3/g" /opt/usr/share/themes/$3/index.theme

perl -pi -e "s/pixmap_path .*/pixmap_path \"\/usr\/share\/themes\/$3\/images\"/g" /opt/usr/share/themes/$3/gtk-2.0/gtkrc
perl -pi -e "s/gtk-theme-name .*/gtk-theme-name = \"$2\"/g" /opt/usr/share/themes/$3/gtk-2.0/gtkrc

perl -pi -e "s/Theme Name.*/Theme Name : $2/g" /opt/usr/share/themes/$3/css/colors.css

sleep 1

	if [ -f /etc/hildon/theme/images/ApplicationShortcutApplet.png ]; then 
  	ApplicationShortcutApplet="`readlink -f /etc/hildon/theme/images/ApplicationShortcutApplet.png`"
	  if [ -f /opt/theme-customizer/backups$ApplicationShortcutApplet ]; then
      cp -rf /opt/theme-customizer/backups$ApplicationShortcutApplet /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$ApplicationShortcutApplet
    fi
	fi

	if [ -f /etc/hildon/theme/images/CalendarAppletBackground.png ]; then 
  	CalendarAppletBackground="`readlink -f /etc/hildon/theme/images/CalendarAppletBackground.png`"
	  if [ -f /opt/theme-customizer/backups$CalendarAppletBackground ]; then
      cp -rf /opt/theme-customizer/backups$CalendarAppletBackground /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$CalendarAppletBackground
    fi
	fi

	if [ -f /etc/hildon/theme/images/ContactsAppletFrame.png ]; then 
  	ContactsAppletFrame="`readlink -f /etc/hildon/theme/images/ContactsAppletFrame.png`"
	  if [ -f /opt/theme-customizer/backups$ContactsAppletFrame ]; then
      cp -rf /opt/theme-customizer/backups$ContactsAppletFrame /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$ContactsAppletFrame
    fi
	fi
	
	if [ -f /etc/hildon/theme/images/MapAppletButton.png ]; then 
  	MapAppletButton="`readlink -f /etc/hildon/theme/images/MapAppletButton.png`"
	  if [ -f /opt/theme-customizer/backups$MapAppletButton ]; then
      cp -rf /opt/theme-customizer/backups$MapAppletButton /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MapAppletButton
    fi
	fi

	if [ -f /etc/hildon/theme/images/MapAppletHead.png ]; then 
  	MapAppletHead="`readlink -f /etc/hildon/theme/images/MapAppletHead.png`"
	  if [ -f /opt/theme-customizer/backups$MapAppletHead ]; then
      cp -rf /opt/theme-customizer/backups$MapAppletHead /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MapAppletHead
    fi
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletHead.png ]; then 
  	MediaPlayerAppletHead="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletHead.png`"
	  if [ -f /opt/theme-customizer/backups$MediaPlayerAppletHead ]; then
      cp -rf /opt/theme-customizer/backups$MediaPlayerAppletHead /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MediaPlayerAppletHead
    fi
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletNext.png ]; then 
  	MediaPlayerAppletNext="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletNext.png`"
	  if [ -f /opt/theme-customizer/backups$MediaPlayerAppletNext ]; then
      cp -rf /opt/theme-customizer/backups$MediaPlayerAppletNext /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MediaPlayerAppletNext
    fi
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletPrevious.png ]; then 
  	MediaPlayerAppletPrevious="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletPrevious.png`"
	  if [ -f /opt/theme-customizer/backups$MediaPlayerAppletPrevious ]; then
      cp -rf /opt/theme-customizer/backups$MediaPlayerAppletPrevious /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MediaPlayerAppletPrevious
    fi
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletStopPlay.png ]; then 
  	MediaPlayerAppletStopPlay="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletStopPlay.png`"
	  if [ -f /opt/theme-customizer/backups$MediaPlayerAppletStopPlay ]; then
      cp -rf /opt/theme-customizer/backups$MediaPlayerAppletStopPlay /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$MediaPlayerAppletStopPlay
    fi
	fi

	if [ -f /etc/hildon/theme/images/OviCenter.png ]; then 
  	OviCenter="`readlink -f /etc/hildon/theme/images/OviCenter.png`"
	  if [ -f /opt/theme-customizer/backups$OviCenter ]; then
      cp -rf /opt/theme-customizer/backups$OviCenter /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$OviCenter
    fi
	fi

	if [ -f /etc/hildon/theme/images/OviLeft.png ]; then 
  	OviLeft="`readlink -f /etc/hildon/theme/images/OviLeft.png`"
	  if [ -f /opt/theme-customizer/backups$OviLeft ]; then
      cp -rf /opt/theme-customizer/backups$OviLeft /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$OviLeft
    fi
	fi

	if [ -f /etc/hildon/theme/images/OviRight.png ]; then 
  	OviRight="`readlink -f /etc/hildon/theme/images/OviRight.png`"
	  if [ -f /opt/theme-customizer/backups$OviRight ]; then
      cp -rf /opt/theme-customizer/backups$OviRight /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$OviRight
    fi
	fi

	if [ -f /etc/hildon/theme/images/RSSAppletHead.png ]; then 
  	RSSAppletHead="`readlink -f /etc/hildon/theme/images/RSSAppletHead.png`"
	  if [ -f /opt/theme-customizer/backups$RSSAppletHead ]; then
      cp -rf /opt/theme-customizer/backups$RSSAppletHead /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$RSSAppletHead
    fi
	fi

	if [ -f /etc/hildon/theme/images/WebShortcutAppletBackground.png ]; then 
  	WebShortcutAppletBackground="`readlink -f /etc/hildon/theme/images/WebShortcutAppletBackground.png`"
	  if [ -f /opt/theme-customizer/backups$WebShortcutAppletBackground ]; then
      cp -rf /opt/theme-customizer/backups$WebShortcutAppletBackground /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$WebShortcutAppletBackground
    fi
	fi

	if [ -f /etc/hildon/theme/images/wmLeftButtonAttached.png ]; then 
  	wmLeftButtonAttached="`readlink -f /etc/hildon/theme/images/wmLeftButtonAttached.png`"
	  if [ -f /opt/theme-customizer/backups$wmLeftButtonAttached ]; then
      cp -rf /opt/theme-customizer/backups$wmLeftButtonAttached /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$wmLeftButtonAttached
    fi
	fi

	if [ -f /etc/hildon/theme/images/wmLeftButtonEnd.png ]; then 
  	wmLeftButtonEnd="`readlink -f /etc/hildon/theme/images/wmLeftButtonEnd.png`"
	  if [ -f /opt/theme-customizer/backups$wmLeftButtonEnd ]; then
      cp -rf /opt/theme-customizer/backups$wmLeftButtonEnd /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$wmLeftButtonEnd
    fi
	fi

	if [ -f /etc/hildon/theme/images/wmRightButton.png ]; then 
  	wmRightButton="`readlink -f /etc/hildon/theme/images/wmRightButton.png`"
	  if [ -f /opt/theme-customizer/backups$wmRightButton ]; then
      cp -rf /opt/theme-customizer/backups$wmRightButton /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$wmRightButton
    fi
	fi

	if [ -f /etc/hildon/theme/images/wmButtonRightHalf.png ]; then 
  	wmButtonRightHalf="`readlink -f /etc/hildon/theme/images/wmButtonRightHalf.png`"
	  if [ -f /opt/theme-customizer/backups$wmButtonRightHalf ]; then
      cp -rf /opt/theme-customizer/backups$wmButtonRightHalf /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$wmButtonRightHalf
    fi
	fi

	if [ -f /etc/hildon/theme/images/wmButtonLeftHalf.png ]; then 
  	wmButtonLeftHalf="`readlink -f /etc/hildon/theme/images/wmButtonLeftHalf.png`"
	  if [ -f /opt/theme-customizer/backups$wmButtonLeftHalf ]; then
      cp -rf /opt/theme-customizer/backups$wmButtonLeftHalf /opt/usr/share/themes/$3/images/
      /bin/touch /opt/usr/share/themes/$3/images/$wmButtonLeftHalf
    fi
	fi

/usr/bin/hildon-theme-cacher /opt/usr/share/themes/$3

/usr/bin/personalisation /opt/usr/share/themes/$3

else

echo "Theme found already!"

fi

exit 0

elif [ "$1" = "deletethemepushed" ]; then

rm -rf /opt/usr/share/themes/$2

exit 0

elif [ "$1" = "exporttheme" ]; then

ACTUALTHEMEDIR="`readlink -f /etc/hildon/theme`"

# cd $ACTUALTHEMEDIR

tar chf ${2}.tgz $ACTUALTHEMEDIR

exit 0

elif [ "$1" = "importtheme" ]; then

tar xvf $2 -C /

exit 0
	
fi


	THEMEDIR='/etc/hildon/theme'

	ACTUALTHEMEDIR="`readlink -f /etc/hildon/theme`"
	GTKR="`readlink -f /etc/hildon/theme/gtk-2.0/gtkrc`"
	CSS="`readlink -f /etc/hildon/theme/css/colors.css`"
	MATCHBOX="`readlink -f /etc/hildon/theme/matchbox/theme.xml`"
	MATCHBOX2="`readlink -f /etc/hildon/theme/matchbox2/theme.xml`"
	COLORS="`readlink -f /etc/hildon/theme/colors.config`"

	ACTUALIMAGES="`readlink -f /etc/hildon/theme/images`"
	chmod 0777 -R $ACTUALIMAGES
	chmod 0777 -R $ACTUALTHEMEDIR
	chmod 0777 -R /opt/theme-customizer/backups

if [ "$1" = "createbackups" ]; then


	cp -rf /opt/theme-customizer/css-template /opt/theme-customizer/css-template-modded
	cp -rf /opt/theme-customizer/gtk-template /opt/theme-customizer/gtk-template-modded

	if [ -f /etc/hildon/theme/images/ApplicationShortcutApplet.png ]; then 
	ApplicationShortcutApplet="`readlink -f /etc/hildon/theme/images/ApplicationShortcutApplet.png`"
	chmod 0777 $ApplicationShortcutApplet
	fi

	if [ -f /etc/hildon/theme/images/CalendarAppletBackground.png ]; then 
	CalendarAppletBackground="`readlink -f /etc/hildon/theme/images/CalendarAppletBackground.png`"
	chmod 0777 $CalendarAppletBackground
	fi

	if [ -f /etc/hildon/theme/images/ContactsAppletFrame.png ]; then 
	ContactsAppletFrame="`readlink -f /etc/hildon/theme/images/ContactsAppletFrame.png`"
	chmod 0777 $ContactsAppletFrame
	fi

	if [ -f /etc/hildon/theme/images/MapAppletButton.png ]; then 
	MapAppletButton="`readlink -f /etc/hildon/theme/images/MapAppletButton.png`"
	chmod 0777 $MapAppletButton
	fi

	if [ -f /etc/hildon/theme/images/MapAppletHead.png ]; then
	MapAppletHead="`readlink -f /etc/hildon/theme/images/MapAppletHead.png`"
	chmod 0777 $MapAppletHead
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletHead.png ]; then
	MediaPlayerAppletHead="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletHead.png`"
	chmod 0777 $MediaPlayerAppletHead
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletNext.png ]; then
	MediaPlayerAppletNext="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletNext.png`"
	chmod 0777 $MediaPlayerAppletNext
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletPrevious.png ]; then
	MediaPlayerAppletPrevious="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletPrevious.png`"
	chmod 0777 $MediaPlayerAppletPrevious
	fi

	if [ -f /etc/hildon/theme/images/MediaPlayerAppletStopPlay.png ]; then
	MediaPlayerAppletStopPlay="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletStopPlay.png`"
	chmod 0777 $MediaPlayerAppletStopPlay
	fi

	if [ -f /etc/hildon/theme/images/OviCenter.png ]; then
	OviCenter="`readlink -f /etc/hildon/theme/images/OviCenter.png`"
	chmod 0777 $OviCenter
	fi

	if [ -f /etc/hildon/theme/images/OviLeft.png ]; then
	OviLeft="`readlink -f /etc/hildon/theme/images/OviLeft.png`"
	chmod 0777 $OviLeft
	fi

	if [ -f /etc/hildon/theme/images/OviRight.png ]; then
	OviRight="`readlink -f /etc/hildon/theme/images/OviRight.png`"
	chmod 0777 $OviRight
	fi

	if [ -f /etc/hildon/theme/images/RSSAppletHead.png ]; then
	RSSAppletHead="`readlink -f /etc/hildon/theme/images/RSSAppletHead.png`"
	chmod 0777 $RSSAppletHead
	fi

	if [ -f /etc/hildon/theme/images/WebShortcutAppletBackground.png ]; then
	WebShortcutAppletBackground="`readlink -f /etc/hildon/theme/images/WebShortcutAppletBackground.png`"
	chmod 0777 $WebShortcutAppletBackground
	fi

	if [ -f /etc/hildon/theme/images/wmLeftButtonAttached.png ]; then 
	wmLeftButtonAttached="`readlink -f /etc/hildon/theme/images/wmLeftButtonAttached.png`"
	chmod 0777 $wmLeftButtonAttached
	fi

	if [ -f /etc/hildon/theme/images/wmLeftButtonEnd.png ]; then 
	wmLeftButtonEnd="`readlink -f /etc/hildon/theme/images/wmLeftButtonEnd.png`"
	chmod 0777 $wmLeftButtonEnd
	fi

	if [ -f /etc/hildon/theme/images/wmRightButton.png ]; then 
	wmRightButton="`readlink -f /etc/hildon/theme/images/wmRightButton.png`"
	chmod 0777 $wmRightButton
	fi

	if [ -f /etc/hildon/theme/images/wmButtonRightHalf.png ]; then 
	wmButtonRightHalf="`readlink -f /etc/hildon/theme/images/wmButtonRightHalf.png`"
	chmod 0777 $wmButtonRightHalf
	fi

	if [ -f /etc/hildon/theme/images/wmButtonLeftHalf.png ]; then 
	wmButtonLeftHalf="`readlink -f /etc/hildon/theme/images/wmButtonLeftHalf.png`"
	chmod 0777 $wmButtonLeftHalf
	fi

	if [ ! -f /opt/theme-customizer/backups$GTKR ]; then
	mkdir -p /opt/theme-customizer/backups$GTKR
	rm -rf /opt/theme-customizer/backups$GTKR
	fi

	if [ ! -f /opt/theme-customizer/backups$ApplicationShortcutApplet ] && [ $ApplicationShortcutApplet ]; then
	mkdir -p /opt/theme-customizer/backups$ApplicationShortcutApplet
	rm -rf /opt/theme-customizer/backups$ApplicationShortcutApplet
	cp -rf $ApplicationShortcutApplet /opt/theme-customizer/backups$ApplicationShortcutApplet

	elif [ $ApplicationShortcutApplet ] && [ -f /opt/theme-customizer/backups$ApplicationShortcutApplet ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$ApplicationShortcutApplet ]; then

		cp -rf $ApplicationShortcutApplet /opt/theme-customizer/backups$ApplicationShortcutApplet

	fi

	if [ ! -f /opt/theme-customizer/backups$CalendarAppletBackground ] && [ $CalendarAppletBackground ]; then
	mkdir -p /opt/theme-customizer/backups$CalendarAppletBackground
	rm -rf /opt/theme-customizer/backups$CalendarAppletBackground
	cp -rf $CalendarAppletBackground /opt/theme-customizer/backups$CalendarAppletBackground

	elif [ $CalendarAppletBackground ] && [ -f /opt/theme-customizer/backups$CalendarAppletBackground ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$CalendarAppletBackground ]; then

		cp -rf $CalendarAppletBackground /opt/theme-customizer/backups$CalendarAppletBackground

	fi

	if [ ! -f /opt/theme-customizer/backups$ContactsAppletFrame ] && [ $ContactsAppletFrame ]; then
	mkdir -p /opt/theme-customizer/backups$ContactsAppletFrame
	rm -rf /opt/theme-customizer/backups$ContactsAppletFrame
	cp -rf $ContactsAppletFrame /opt/theme-customizer/backups$ContactsAppletFrame

	elif [ $ContactsAppletFrame ] && [ -f /opt/theme-customizer/backups$ContactsAppletFrame ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$ContactsAppletFrame ]; then

		cp -rf $ContactsAppletFrame /opt/theme-customizer/backups$ContactsAppletFrame

	fi

	if [ ! -f /opt/theme-customizer/backups$MapAppletButton ] && [ $MapAppletButton ]; then
	mkdir -p /opt/theme-customizer/backups$MapAppletButton
	rm -rf /opt/theme-customizer/backups$MapAppletButton
	cp -rf $MapAppletButton /opt/theme-customizer/backups$MapAppletButton

	elif [ $MapAppletButton ] && [ -f /opt/theme-customizer/backups$MapAppletButton ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MapAppletButton ]; then

		cp -rf $MapAppletButton /opt/theme-customizer/backups$MapAppletButton

	fi

	if [ ! -f /opt/theme-customizer/backups$MapAppletHead ] && [ $MapAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$MapAppletHead
	rm -rf /opt/theme-customizer/backups$MapAppletHead
	cp -rf $MapAppletHead /opt/theme-customizer/backups$MapAppletHead

	elif [ $MapAppletHead ] && [ -f /opt/theme-customizer/backups$MapAppletHead ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MapAppletHead ]; then

		cp -rf $MapAppletHead /opt/theme-customizer/backups$MapAppletHead

	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletHead ] && [ $MediaPlayerAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletHead
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletHead
	cp -rf $MediaPlayerAppletHead /opt/theme-customizer/backups$MediaPlayerAppletHead

	elif [ $MediaPlayerAppletHead ] && [ -f /opt/theme-customizer/backups$MediaPlayerAppletHead ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MediaPlayerAppletHead ]; then

		cp -rf $MediaPlayerAppletHead /opt/theme-customizer/backups$MediaPlayerAppletHead

	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletNext ] && [ $MediaPlayerAppletNext ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletNext
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletNext
	cp -rf $MediaPlayerAppletNext /opt/theme-customizer/backups$MediaPlayerAppletNext

	elif [ $MediaPlayerAppletNext ] && [ -f /opt/theme-customizer/backups$MediaPlayerAppletNext ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MediaPlayerAppletNext ]; then

		cp -rf $MediaPlayerAppletNext /opt/theme-customizer/backups$MediaPlayerAppletNext

	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletPrevious ] && [ $MediaPlayerAppletPrevious ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletPrevious
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletPrevious
	cp -rf $MediaPlayerAppletPrevious /opt/theme-customizer/backups$MediaPlayerAppletPrevious

	elif [ $MediaPlayerAppletPrevious ] && [ -f /opt/theme-customizer/backups$MediaPlayerAppletPrevious ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MediaPlayerAppletPrevious ]; then

		cp -rf $MediaPlayerAppletPrevious /opt/theme-customizer/backups$MediaPlayerAppletPrevious

	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletStopPlay ] && [ $MediaPlayerAppletStopPlay ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletStopPlay
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletStopPlay
	cp -rf $MediaPlayerAppletStopPlay /opt/theme-customizer/backups$MediaPlayerAppletStopPlay

	elif [ $MediaPlayerAppletStopPlay ] && [ -f /opt/theme-customizer/backups$MediaPlayerAppletStopPlay ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$MediaPlayerAppletStopPlay ]; then

		cp -rf $MediaPlayerAppletStopPlay /opt/theme-customizer/backups$MediaPlayerAppletStopPlay

	fi

	if [ ! -f /opt/theme-customizer/backups$OviCenter ] && [ $OviCenter ]; then
	mkdir -p /opt/theme-customizer/backups$OviCenter
	rm -rf /opt/theme-customizer/backups$OviCenter
	cp -rf $OviCenter /opt/theme-customizer/backups$OviCenter

	elif [ $OviCenter ] && [ -f /opt/theme-customizer/backups$OviCenter ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$OviCenter ]; then

		cp -rf $OviCenter /opt/theme-customizer/backups$OviCenter

	fi

	if [ ! -f /opt/theme-customizer/backups$OviLeft ] && [ $OviLeft ]; then
	mkdir -p /opt/theme-customizer/backups$OviLeft
	rm -rf /opt/theme-customizer/backups$OviLeft
	cp -rf $OviLeft /opt/theme-customizer/backups$OviLeft

	elif [ $OviLeft ] && [ -f /opt/theme-customizer/backups$OviLeft ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$OviLeft ]; then

		cp -rf $OviLeft /opt/theme-customizer/backups$OviLeft

	fi

	if [ ! -f /opt/theme-customizer/backups$OviRight ] && [ $OviRight ]; then
	mkdir -p /opt/theme-customizer/backups$OviRight
	rm -rf /opt/theme-customizer/backups$OviRight
	cp -rf $OviRight /opt/theme-customizer/backups$OviRight

	elif [ $OviRight ] && [ -f /opt/theme-customizer/backups$OviRight ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$OviRight ]; then

		cp -rf $OviRight /opt/theme-customizer/backups$OviRight

	fi

	if [ ! -f /opt/theme-customizer/backups$RSSAppletHead ] && [ $RSSAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$RSSAppletHead
	rm -rf /opt/theme-customizer/backups$RSSAppletHead
	cp -rf $RSSAppletHead /opt/theme-customizer/backups$RSSAppletHead

	elif [ $RSSAppletHead ] && [ -f /opt/theme-customizer/backups$RSSAppletHead ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$RSSAppletHead ]; then

		cp -rf $RSSAppletHead /opt/theme-customizer/backups$RSSAppletHead

	fi

	if [ ! -f /opt/theme-customizer/backups$WebShortcutAppletBackground ] && [ $WebShortcutAppletBackground ]; then
	mkdir -p /opt/theme-customizer/backups$WebShortcutAppletBackground
	rm -rf /opt/theme-customizer/backups$WebShortcutAppletBackground
	cp -rf $WebShortcutAppletBackground /opt/theme-customizer/backups$WebShortcutAppletBackground

	elif [ $WebShortcutAppletBackground ] && [ -f /opt/theme-customizer/backups$WebShortcutAppletBackground ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$WebShortcutAppletBackground ]; then

		cp -rf $WebShortcutAppletBackground /opt/theme-customizer/backups$WebShortcutAppletBackground

	fi

	if [ ! -f /opt/theme-customizer/backups$wmLeftButtonAttached ] && [ $wmLeftButtonAttached ]; then
	mkdir -p /opt/theme-customizer/backups$wmLeftButtonAttached
	rm -rf /opt/theme-customizer/backups$wmLeftButtonAttached
	cp -rf $wmLeftButtonAttached /opt/theme-customizer/backups$wmLeftButtonAttached

	elif [ $wmLeftButtonAttached ] && [ -f /opt/theme-customizer/backups$wmLeftButtonAttached ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$wmLeftButtonAttached ]; then

		cp -rf $wmLeftButtonAttached /opt/theme-customizer/backups$wmLeftButtonAttached

	fi

	if [ ! -f /opt/theme-customizer/backups$wmLeftButtonEnd ] && [ $wmLeftButtonEnd ]; then
	mkdir -p /opt/theme-customizer/backups$wmLeftButtonEnd
	rm -rf /opt/theme-customizer/backups$wmLeftButtonEnd
	cp -rf $wmLeftButtonEnd /opt/theme-customizer/backups$wmLeftButtonEnd

	elif [ $wmLeftButtonEnd ] && [ -f /opt/theme-customizer/backups$wmLeftButtonEnd ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$wmLeftButtonEnd ]; then

		cp -rf $wmLeftButtonEnd /opt/theme-customizer/backups$wmLeftButtonEnd

	fi

	if [ ! -f /opt/theme-customizer/backups$wmRightButton ] && [ $wmRightButton ]; then
	mkdir -p /opt/theme-customizer/backups$wmRightButton
	rm -rf /opt/theme-customizer/backups$wmRightButton
	cp -rf $wmRightButton /opt/theme-customizer/backups$wmRightButton

	elif [ $wmRightButton ] && [ -f /opt/theme-customizer/backups$wmRightButton ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$wmRightButton ]; then

		cp -rf $wmRightButton /opt/theme-customizer/backups$wmRightButton

	fi

	if [ ! -f /opt/theme-customizer/backups$wmButtonLeftHalf ] && [ $wmButtonLeftHalf ]; then
	mkdir -p /opt/theme-customizer/backups$wmButtonLeftHalf
	rm -rf /opt/theme-customizer/backups$wmButtonLeftHalf
	cp -rf $wmButtonLeftHalf /opt/theme-customizer/backups$wmButtonLeftHalf

	elif [ $wmButtonLeftHalf ] && [ -f /opt/theme-customizer/backups$wmButtonLeftHalf ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$wmButtonLeftHalf ]; then

		cp -rf $wmButtonLeftHalf /opt/theme-customizer/backups$wmButtonLeftHalf

	fi

	if [ ! -f /opt/theme-customizer/backups$wmButtonRightHalf ] && [ $wmButtonRightHalf ]; then
	mkdir -p /opt/theme-customizer/backups$wmButtonRightHalf
	rm -rf /opt/theme-customizer/backups$wmButtonRightHalf
	cp -rf $wmButtonRightHalf /opt/theme-customizer/backups$wmButtonRightHalf

	elif [ $wmButtonRightHalf ] && [ -f /opt/theme-customizer/backups$wmButtonRightHalf ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$wmButtonRightHalf ]; then

		cp -rf $wmButtonRightHalf /opt/theme-customizer/backups$wmButtonRightHalf

	fi

	if [ ! -f /opt/theme-customizer/backups$CSS ]; then
	mkdir -p /opt/theme-customizer/backups$CSS
	rm -rf /opt/theme-customizer/backups$CSS
	fi

	if [ ! -f /opt/theme-customizer/backups$MATCHBOX ]; then
	mkdir -p /opt/theme-customizer/backups$MATCHBOX
	rm -rf /opt/theme-customizer/backups$MATCHBOX
	fi

	if [ ! -f /opt/theme-customizer/backups$MATCHBOX2 ]; then
	mkdir -p /opt/theme-customizer/backups$MATCHBOX2
	rm -rf /opt/theme-customizer/backups$MATCHBOX2
	fi

	if [ ! -f /opt/theme-customizer/backups$COLORS ]; then
	mkdir -p /opt/theme-customizer/backups$COLORS
	rm -rf /opt/theme-customizer/backups$COLORS
	fi
	
	if [ ! -f /opt/theme-customizer/backups$CSS ]; then
	cp -rf $CSS /opt/theme-customizer/backups$CSS

	elif [ -f /opt/theme-customizer/backups$CSS ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$CSS ]; then

		cp -rf $CSS /opt/theme-customizer/backups$CSS

	fi

	if [ ! -f /opt/theme-customizer/backups$COLORS ]; then
	cp -rf $COLORS /opt/theme-customizer/backups$COLORS

	elif [ -f /opt/theme-customizer/backups$COLORS ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$COLORS ]; then

		cp -rf $COLORS /opt/theme-customizer/backups$COLORS

	fi
	
	if [ ! -f /opt/theme-customizer/backups$GTKR ]; then
	cp -rf $GTKR /opt/theme-customizer/backups$GTKR

	elif [ -f /opt/theme-customizer/backups$GTKR ] && [ /etc/hildon/theme/index.theme -nt /opt/theme-customizer/backups$GTKR ]; then

		cp -rf $GTKR /opt/theme-customizer/backups$GTKR

	fi
	
	if [ -f /opt/theme-customizer/backups$MATCHBOX ]; then
	cp -rf /opt/theme-customizer/matchbox/theme.xml $MATCHBOX
	else
	cp -rf $MATCHBOX /opt/theme-customizer/backups$MATCHBOX
	cp -rf /opt/theme-customizer/matchbox/theme.xml $MATCHBOX
	fi
	
	if [ -f /opt/theme-customizer/backups$MATCHBOX2 ]; then
	cp -rf /opt/theme-customizer/matchbox2/theme.xml $MATCHBOX2
	else
	cp -rf $MATCHBOX2 /opt/theme-customizer/backups$MATCHBOX2
	cp -rf /opt/theme-customizer/matchbox2/theme.xml $MATCHBOX2
	fi
	
	exit 0
	
elif [ "$1" = "setfontfamily" ]; then

	FONT="$2"
	
	perl -pi -e 's/.*font_name =.*//g' $GTKR
	perl -pi -e 's/.*font: .*//g' $CSS

	perl -pi -e "s/Droid Sans/$FONT/g" /opt/theme-customizer/gtk-template-modded $MATCHBOX $MATCHBOX2 /opt/theme-customizer/css-template-modded

        exit 0

elif [ "$1" = "setfontsize" ]; then

	if [ "$2" = "-1" ] || [ "$2" = "-2" ] || [ "$2" = "-3" ] || [ "$2" = "-4" ] || [ "$2" = "-5" ] || [ "$2" = "+1" ] || [ "$2" = "+2" ] || [ "$2" = "+3" ] || [ "$2" = "+4" ] || [ "$2" = "+5" ]; then
	MUUTTUJA="$2"
	else
	MUUTTUJA="+0"
	fi

	# sleep 2

	let KORVAA1=13$MUUTTUJA
	perl -pi -e "s/FONTTI1"/${KORVAA1}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA2=15$MUUTTUJA
	perl -pi -e "s/FONTTI2"/${KORVAA2}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA3=18$MUUTTUJA
	perl -pi -e "s/FONTTI3"/${KORVAA3}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA4=20$MUUTTUJA
	perl -pi -e "s/FONTTI4"/${KORVAA4}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA5=24$MUUTTUJA
	perl -pi -e "s/FONTTI5"/${KORVAA5}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA6=26$MUUTTUJA
	perl -pi -e "s/FONTTI6"/${KORVAA6}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA7=36$MUUTTUJA
	perl -pi -e "s/FONTTI7"/${KORVAA7}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA8=52$MUUTTUJA
	perl -pi -e "s/FONTTI8"/${KORVAA8}"/g" /opt/theme-customizer/gtk-template-modded


	perl -pi -e "s/FONTTI1/${KORVAA1}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI2/${KORVAA2}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI3/${KORVAA3}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI4/${KORVAA4}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI5/${KORVAA5}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI6/${KORVAA6}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI7/${KORVAA7}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/FONTTI8/${KORVAA8}px/g" /opt/theme-customizer/css-template-modded


	
	
	exit 0
	
elif [ "$1" = "setfontcolors" ]; then

	COLOR1NEW="$2"
	COLOR2NEW="$3"
	COLOR3NEW="$4"
	COLOR4NEW="$5"
	COLOR5NEW="$6"
	COLOR6NEW="$7"
	COLOR7NEW="$8"
	COLOR8NEW="$9"

	perl -pi -e "s/.*color\[\"DefaultTextColor\"\].*/color\[\"DefaultTextColor\"\] = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"SecondaryTextColor\"\].*/color\[\"SecondaryTextColor\"\] = \"$COLOR2NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ActiveTextColor\"\].*/color\[\"ActiveTextColor\"\] = \"$COLOR3NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"DisabledTextColor\"\].*/color\[\"DisabledTextColor\"\] = \"$COLOR4NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"PaintedTextColor\"\].*/color\[\"PaintedTextColor\"\] = \"$COLOR5NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"SelectionColor\"\].*/color\[\"SelectionColor\"\] = \"$COLOR6NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ReversedSelectionColor\"\].*/color\[\"ReversedSelectionColor\"\] = \"$COLOR6NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"TitleTextColor\"\].*/color\[\"TitleTextColor\"\]        = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextColor\"\].*/color\[\"ButtonTextColor\"\]        = \"$COLOR7NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextPressedColor\"\].*/color\[\"ButtonTextPressedColor\"\]        = \"$COLOR8NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextDisabledColor\"\].*/color\[\"ButtonTextDisabledColor\"\]        = \"$COLOR4NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"AccentColor1\"\].*/color\[\"AccentColor1\"\] = \"$COLOR3NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"AccentColor2\"\].*/color\[\"AccentColor2\"\] = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"AccentColor3\"\].*/color\[\"AccentColor3\"\] = \"$COLOR3NEW\"/g" $GTKR

	perl -pi -e "s/DefaultTextColor.*/DefaultTextColor=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/SecondaryTextColor.*/SecondaryTextColor=$COLOR2NEW/g" $COLORS
	perl -pi -e "s/ActiveTextColor.*/ActiveTextColor=$COLOR3NEW/g" $COLORS
	perl -pi -e "s/DisabledTextColor.*/DisabledTextColor=$COLOR4NEW/g" $COLORS
	perl -pi -e "s/PaintedTextColor.*/PaintedTextColor=$COLOR5NEW/g" $COLORS

	perl -pi -e "s/SelectionColor.*/SelectionColor=$COLOR6NEW/g" $COLORS
	perl -pi -e "s/SelectionColor.*/SelectionColor=$COLOR6NEW/g" $COLORS

	perl -pi -e "s/TitleTextColor.*/TitleTextColor=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/ButtonTextColor.*/ButtonTextColor=$COLOR7NEW/g" $COLORS
	perl -pi -e "s/ButtonTextPressedColor.*/ButtonTextPressedColor=$COLOR8NEW/g" $COLORS
	perl -pi -e "s/ButtonTextDisabledColor.*/ButtonTextDisabledColor=$COLOR4NEW/g" $COLORS

	perl -pi -e "s/AccentColor1.*/AccentColor1=$COLOR3NEW/g" $COLORS
	perl -pi -e "s/AccentColor2.*/AccentColor2=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/AccentColor3.*/AccentColor3=$COLOR3NEW/g" $COLORS

	perl -pi -e "s/#COLOR1/$COLOR1NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR2/$COLOR2NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR3/$COLOR3NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR4/$COLOR4NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR5/$COLOR5NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR6/$COLOR6NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR7/$COLOR7NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR8/$COLOR8NEW/g" /opt/theme-customizer/css-template-modded
	
	exit 0

elif [ "$1" = "seticontheme" ]; then

	perl -pi -e "s/.*gtk-icon-theme-name.*/gtk-icon-theme-name = \"$2\"/g" $GTKR
	# sleep 2

	sed -i "/MODDING STARTS/,/MODDING ENDS/d" $CSS
	sed -i "/MODDING STARTS/,/MODDING ENDS/d" $GTKR

	cat /opt/theme-customizer/css-template-modded >> $CSS
	cat /opt/theme-customizer/gtk-template-modded >> $GTKR

	rm /opt/theme-customizer/css-template-modded
	rm /opt/theme-customizer/gtk-template-modded

	hildon-theme-cacher $ACTUALTHEMEDIR
	
	# sleep 2
	
	exit 0
	
elif [ "$1" = "setsnaptogrid" ]; then

	if [ -f $THEMEDIR/transitions.ini ]; then

		# sleep 2
		perl -pi -e "s/snap_grid_size.*/snap_grid_size=$2/g" $THEMEDIR/transitions.ini
	
	elif [ -f /usr/share/hildon-desktop/transitions.ini ]; then

		# sleep 2
		perl -pi -e "s/snap_grid_size.*/snap_grid_size=$2/g" /usr/share/hildon-desktop/transitions.ini
	fi 
	
	exit 0

elif [ "$1" = "seticonsizes" ]; then

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-size -t int $2

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-bookmarks-size -t int $3

	if [ "$4" = "Don't show icon backgrounds" ]; then

		run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-back -t int 0

	else

		run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-back -t int 1

	fi
	
	exit 0
	
fi

exit 0 
