#!/bin/bash

# nacteme nastaveni
source /etc/kiosek.conf

# nastartujeme Xka
echo "Starting X server."
X $DISPLAY -nolisten tcp >/dev/null & echo $! > $XPID
export DISPLAY
sleep 2s # pockame na X

# pozadi, wm, sporic
echo "Starting kiosek environment:"
#z nejakeho me neznameho duvodu to uz nepotrebuje metacity ;), kdyz nebezi tak aspon nezaclani ten ramecek kolem ;)
#echo "* metacity"
#metacity &
echo "* loading background: `ls $BACKGROUND`"
xloadimage -onroot -fullscreen -shrink -border black -quiet $BACKGROUND
echo "* starting xscreensaver"
#xscreensaver -no-splash &

# zakazeme vetsinu tlacitek na mysi
#echo "* using xmodmap to suppress keyboard/mouse events"
#xmodmap -e "pointer = 1 8 9 4 5 6 7 2 3"
# a taky klavesy
#xmodmap -e "keycode 117 = "
i3 &
unclutter & echo $! > $UNCLPID 
#devilspie /home/kiosek/devilspie.ds & echo $! > $DEVILPID

echo "Running browser..."
# a ff budeme poustet porad dokola
while (true); do
	# smazneme ff profil, kdyz tam nahodou bude
	echo "Checking $HOME/.mozilla..."
	if [ -d "$HOME/.mozilla" ]; then
		echo "Mazu $HOME/.mozilla/*"
		rm $HOME/.mozilla/* -rf
	else
		# kdyz tam nebude, tak ten adresar vytvorime
		mkdir -pv "$HOME/.mozilla"
	fi
	rm -rf $HOME/.cache/mozilla
	# zkopirujem tam ten osekanej profil pro ff
	echo "Copying mozilla kiosek-configurations..."
	cp $HOME/config/firefox $HOME/.mozilla/ -R
	# a pustime ff
	sleep 1s
	iceweasel
done

# THAT'S ALL FOLKS!!!


