contrib/package: Add update script for freifunkmap
This commit is contained in:
parent
bf49f78599
commit
42a129f669
6 changed files with 111 additions and 0 deletions
39
contrib/package/freifunk-mapupdate/Makefile
Normal file
39
contrib/package/freifunk-mapupdate/Makefile
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# Copyright (C) 2011 Manuel Munz <freifunk at somakoma de>
|
||||||
|
# This is free software, licensed under the Apache 2.0 license.
|
||||||
|
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=freifunk-mapupdate
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
define Package/freifunk-mapupdate
|
||||||
|
SECTION:=luci
|
||||||
|
CATEGORY:=LuCI
|
||||||
|
SUBMENU:=Freifunk
|
||||||
|
TITLE:=Update script for freifunkmap
|
||||||
|
DEPENDS:=+olsrd-mod-nameservice
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/freifunk-mapupdate/description
|
||||||
|
This script updates the freifunkmap (also known as the global map, see http://map.berlin.freifunk.net) every hour. Config file is /etc/config/freifunk-mapupdate.
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Prepare
|
||||||
|
mkdir -p $(PKG_BUILD_DIR)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Configure
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Compile
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/freifunk-mapupdate/install
|
||||||
|
$(CP) ./files/* $(1)/
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,freifunk-mapupdate))
|
|
@ -0,0 +1,3 @@
|
||||||
|
config 'mapupdate' 'mapupdate'
|
||||||
|
option 'enabled' '1'
|
||||||
|
option 'mapserver' 'http://map.berlin.freifunk.net/freifunkmap.php'
|
54
contrib/package/freifunk-mapupdate/files/usr/sbin/ff_mapupdate.sh
Executable file
54
contrib/package/freifunk-mapupdate/files/usr/sbin/ff_mapupdate.sh
Executable file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ ! "$(uci -q get freifunk-mapupdate.mapupdate.enabled)" == 1 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
MAPSERVER="$(uci -q get freifunk-mapupdate.mapupdate.mapserver)"
|
||||||
|
[ -z "$MAPSERVER" ] && logger -t "freifunk-mapupdate:" "No mapserver configured" && exit 1
|
||||||
|
|
||||||
|
#check if nameservice plugin is installed and enabled, else exit
|
||||||
|
nslib=`uci show olsrd |grep olsrd_nameservice.so |awk {' FS="."; print $1"."$2 '}`
|
||||||
|
if [ -n "$nslib" ]; then
|
||||||
|
LATLONFILE="$(uci -q get $nslib.latlon_file)"
|
||||||
|
if [ -z "$LATLONFILE" ]; then
|
||||||
|
LATLONFILE="/var/run/latlon.js"
|
||||||
|
fi
|
||||||
|
if [ ! -p "$LATLONFILE" ]; then
|
||||||
|
logger -t "freifunk-mapupdate:" "latlon_file not found."; exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
logger -t "freifunk-mapupdate:" "nameservice plugin not found in olsrd config."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HOSTNAME="$(uci show system |grep hostname |cut -d "=" -f 2)"
|
||||||
|
HF_INFO=""
|
||||||
|
|
||||||
|
# Get info for myself
|
||||||
|
SELF=$(cat $LATLONFILE |grep ^Self | sed -e 's/Self(//' -e 's/);//' -e "s/'//g")
|
||||||
|
OLSR_IP="$(echo $SELF |awk '{ FS=",";print $1 }')"
|
||||||
|
LOCATION="$(uci show system |grep .location |cut -d "=" -f 2)"
|
||||||
|
[ -n "$LOCATION" ] && NOTE="$LOCATION<br>"
|
||||||
|
FFNOTE="$(uci -q get freifunk.contact.note)"
|
||||||
|
[ -n "$FFNOTE" ] && NOTE="$NOTE $FFNOTE"
|
||||||
|
NOTE="<h3><a href='http://$OLSR_IP' target='_blank'>$HOSTNAME</a></h3><p>$NOTE"
|
||||||
|
NOTE=`echo -e "$NOTE" | sed -e 's/\ /%20/g' -e 's/&/%26/g' -e 's/"/%22/g'`
|
||||||
|
UPDATESTRING="$(echo $SELF |awk '{ FS=",";print $2 }'), $(echo $SELF |awk '{ FS=",";print $3 }')"
|
||||||
|
|
||||||
|
# get neighbor Info (lat, lon, lq)
|
||||||
|
while read line; do
|
||||||
|
NEIGHUPD="$(echo $line |awk '{ FS=","; print $6 }'), $(echo $line |awk '{ FS=","; print $7 }'), $(echo $line |awk '{ FS=",";print $4 }')"
|
||||||
|
UPDATESTRING="${UPDATESTRING}, ${NEIGHUPD}"
|
||||||
|
done << EOF
|
||||||
|
`grep "PLink('$OLSR_IP" $LATLONFILE | sed -e 's/PLink(//' -e 's/);//' -e "s/'//g"`
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Send UPDATESTRING
|
||||||
|
UPDATE=`echo -e "$UPDATESTRING" | sed s/\ /%20/g`
|
||||||
|
result="$(wget "$MAPSERVER?update=$UPDATE&updateiv=3600&olsrip=$OLSR_IP¬e=${NOTE}${HF_INFO}" -qO -)"
|
||||||
|
|
||||||
|
if [ ! "$result" == "success update" ]; then
|
||||||
|
logger -t "freifunk-mapupdate:" "Update failed: $result"
|
||||||
|
fi
|
||||||
|
|
4
contrib/package/freifunk-mapupdate/ipkg/postinst
Normal file
4
contrib/package/freifunk-mapupdate/ipkg/postinst
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
[ -n "${IPKG_INSTROOT}" ] || {
|
||||||
|
( . /etc/uci-defaults/freifunk-mapupdate ) && rm -f /etc/uci-defaults/freifunk-mapupdate
|
||||||
|
}
|
5
contrib/package/freifunk-mapupdate/ipkg/postrm
Normal file
5
contrib/package/freifunk-mapupdate/ipkg/postrm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
[ -n "${IPKG_INSTROOT}" ] || {
|
||||||
|
sed -i '/ff_mapupdate.sh/d' /etc/crontabs/root
|
||||||
|
/etc/init.d/cron restart
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
test -f /etc/crontabs/root || touch /etc/crontabs/root
|
||||||
|
SEED="$( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi )"
|
||||||
|
MIN="$(( $SEED % 59 ))"
|
||||||
|
grep -q "ff_mapupdate.sh" /etc/crontabs/root || echo "$MIN * * * * /usr/sbin/ff_mapupdate.sh" >> /etc/crontabs/root
|
||||||
|
/etc/init.d/cron restart
|
Loading…
Reference in a new issue