Added an automatism which will retrive Router-Coordinates from the old Netmon system

Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
Reviewed-by: Christian Dresel <fff@chrisi01.de>
Reviewed-by: Tim Niemeyer <tim@tn-x.org>
This commit is contained in:
Jan Kraus 2016-07-16 19:29:55 +02:00 committed by Jan Kraus
parent 0950e58c58
commit d6f2f18e49
3 changed files with 67 additions and 3 deletions

View File

@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-sysupgrade
PKG_VERSION:=0.0.2
PKG_RELEASE:=2
PKG_VERSION:=0.0.3
PKG_RELEASE:=3
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-sysupgrade
@ -13,7 +13,7 @@ define Package/fff-sysupgrade
CATEGORY:=Freifunk
TITLE:=Freifunk-Franken sysupgrade
URL:=http://www.freifunk-franken.de
DEPENDS:=+fff-boardname
DEPENDS:=+fff-boardname +micrond
endef
define Package/fff-sysupgrade/description

View File

@ -0,0 +1 @@
*/5 * * * * /usr/sbin/copy_netmon_coordinates.sh

View File

@ -0,0 +1,63 @@
#!/bin/sh
delete_myself()
{
echo "This Script will be deleted now!"
rm -f /usr/lib/micron.d/fff-sysupgrade
rm -f "$0"
exit 0
}
#Get Mac Address of br-mesh if already up
if ! mac=$( cat /sys/class/net/br-mesh/address ); then
echo "Interface br-mesh is not available!"
exit 1
fi
#Check if Coordinates are already set
if uci get system.@system[0].latitude && uci get system.@system[0].longitude; then
echo "Coordinates are already set."
delete_myself
fi
#Get Router from Netmon Database
xml_data=$( wget -q -O - "http://fe80::ff:feee:1%br-mesh/api/rest/api.php?rquest=router&mac=${mac//:}" 2>&1)
if [ -z "$xml_data" ]; then
echo "xml_data is not set"
exit 1
elif echo "$xml_data"|grep "HTTP/1.1 404 Not Found" ;then
echo "This Router is not present in the Netmon Database."
delete_myself
fi
#Reduce XML_DATA to Router only
xml_data=$( echo $xml_data |grep -o '<router>.*<\/router>' |sed -e 's/<user>.*<\/user>//g' |sed -e 's/<chipset>.*<\/chipset>//g' |sed -e 's/<chipset>.*<\/chipset>//g' )
#Get needed Variables
hostname=$( echo $xml_data |grep -o '<hostname>.*<\/hostname>'|sed -e 's/<\/\?hostname>//g' )
description=$( echo $xml_data |grep -o '<description>.*<\/description>'|sed -e 's/<\/\?description>//g' )
latitude=$( echo $xml_data |grep -o '<latitude>.*<\/latitude>'|sed -e 's/<\/\?latitude>//g' )
longitude=$( echo $xml_data |grep -o '<longitude>.*<\/longitude>'|sed -e 's/<\/\?longitude>//g' )
#Check for netmon default coordinates
if [ "$latitude" -eq 0 ] && [ "$longitude" -eq 0 ]; then
echo "Unable to retrieve coordinates from Netmon."
echo "Maybe the coordinates are suppressed."
delete_myself
fi
uci set system.@system[0]=system
echo "Setting hostname $hostname"
uci set system.@system[0].hostname="$hostname"
echo "Setting description $description"
uci set system.@system[0].description="$description"
echo "Setting latitude $latitude"
uci set system.@system[0].latitude="$latitude"
echo "Setting longitude $longitude"
uci set system.@system[0].longitude="$longitude"
uci commit
echo "Coordinates are now copied from Netmon. Router will be rebooted."
reboot
exit 0