Skip to content
Snippets Groups Projects
geolocator.sh 1.6 KiB
Newer Older
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
AUTO_LOCATION=`uci get gluon-node-info.@location[0].auto_location`
if [ $AUTO_LOCATION -eq 0 ]; then
	exit 0
fi

PID_PART="/var/run/geolocator.pid"
TIME_STAMP="/tmp/geolocator_timestamp"

if [ -f $PID_PART ]; then
	echo "The geolocator is still running"
	exit 0
else
	touch $PID_PART
fi

Clean_pid() {
	if [ -f $PID_PART ]; then
		rm $PID_PART
	fi
	exit 0
}

# Get localization interval
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
INTERVAL=`uci get gluon-node-info.@location[0].refresh_interval`

# get position
Get_geolocation_info() {
	LWTRACE=`lwtrace -t 2> /dev/null`
	echo $LWTRACE | grep "Scan completed : Your location:" >> /dev/null
	if [ $? -eq "0" ]; then
		for x in $LWTRACE
		do
			if [ $x == '(lat)' ]; then
			fi
			if [ $x == '(lon)' ]; then
			fi
			if [ $x == '%' ]; then
		done
		return 0
	else
		echo "lwtrace doesn't gif a location";
		return 1
	fi
}

#check if interval over or not exist
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
if [ ! -f $TIME_STAMP ] || [ $(( `date +%s` - `cat $TIME_STAMP` )) -gt $(( $INTERVAL * 60 )) ]; then
	Get_geolocation_info
	if [ $? -eq 1 ]; then
		Clean_pid
	fi
	#ceck if static location true or not
	STATIC_LOCATION=`uci get gluon-node-info.@location[0].static_location`
	if [ $STATIC_LOCATION -eq 0 ]; then
		SHARE_LOCATION=`uci get gluon-node-info.@location[0].share_location`
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
		if [ $SHARE_LOCATION -eq 0 ]; then
			$(uci set gluon-node-info.@location[0].share_location=1)
		fi
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
		$(uci set gluon-node-info.@location[0].latitude=$LAT)
		$(uci set gluon-node-info.@location[0].longitude=$LON)
		`uci commit gluon-node-info`
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
	date +%s > $TIME_STAMP