#!/bin/bash
xset s off
xset -dpms

export HOME=/tmp

DISPLAY_URL='http://localhost:8069/point_of_sale/display'
URL=${DISPLAY_URL}

maciotbox=$(/sbin/ifconfig eth0 |grep -Eo ..\(\:..\){5})

if [ -e /home/pi/odoo-remote-server.conf ]
	then
	URL_SERVER=$(grep "" /home/pi/odoo-remote-server.conf)/iot/box/${maciotbox}/screen_url
	var=0
	while [ ${var} -lt 30 ]; do
		var=$((var+1))
		sleep 1
		status_code=$(wget ${URL_SERVER} --server-response 2>&1|grep 'HTTP/'|awk '{print $2}')
		if [ ${status_code} -eq 200 ]
		then
			URL=$(wget ${URL_SERVER} -q -O -)
			break
		fi
	done
fi
# wait until odoo is ready, otherwise you will have to plug a
# keyboard into the posbox just to refresh firefox
until wget -q "${DISPLAY_URL}" -O /dev/null ; do sleep 1 ; done
/usr/bin/firefox "${URL}" &