log() { echo "[$$] $(date): autostart: $(whoami): $0: $1" >>/tmp/mylog.txt; }
while ps ax | grep -q /rc.local$; do log "waiting for rc.local"; sleep 10; done

while true; do {
	log "s1: kill firefox"; pkill firefox
#	mkdir -p /tmp/browserhome/.mozilla
#	rm -fR /home/tasso/.mozilla
#	ln -s /tmp/browserhome/.mozilla /home/tasso/.mozilla
# 	/etc/rc.local function firefox_value_set dom.max_script_run_time 0
# 	/etc/rc.local function firefox_value_set browser.sessionstore.resume_from_crash false
	URL=; read URL </tmp/URL_FIREFOX.txt
	URL=${URL:-file:///home/tasso/default.html}
	log "s2: using url: $URL"
	[ -e /tmp/FFWAIT ] || pidof firefox >/dev/null || {
		log "s3: starting browser"
		/usr/local/bin/firefox $URL &
#		log "s4: browser started, waiting 60s"
#		sleep 60; /etc/rc.local function browser_sendkey "F11 F5"
#		log "s5: send key F11 + F5"
	}
#	/etc/rc.local function firefox_value_set dom.max_script_run_time 0
#	/etc/rc.local function firefox_value_set browser.sessionstore.resume_from_crash false
	while pidof firefox >/dev/null; do sleep 5; done
	log "s6: firefox was stopped"
	make_mustache
	rm /tmp/screenshot.jpg
#	rm /sessionstore.*
} done
