#!/bin/sh
#
ambra_on="gpio disable 3"
ambra_off="gpio enable 3"
bianco_on="gpio disable 2"
bianco_off="gpio enable 2"

date > /tmp/upline.log

# Check connessione internet
ping -c 5 google.com >> /tmp/upline.log 
if [ $? == 0 ]; then
	# accende luce ambra
	echo "ambra on"
	echo "ok" > /tmp/statointernet.log
	$bianco_off
	$ambra_on
else
	# controllo connessione default gateway
	ping -c 5 `findgw -1` >> /tmp/upline.log 
	if [ $? == 0 ]; then       
        	# accende luce bianca
		echo "bianco on"
		echo "internet down" > /tmp/statointernet.log
		$ambra_off
		$bianco_on
	else           
        	# spenge tutto
		echo "tutto off"
		echo "gateway down" > /tmp/statointernet.log
		$bianco_off
		$ambra_off
	fi
fi                

