ff_mapupdate.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. if [ ! "$(uci -q get freifunk-mapupdate.mapupdate.enabled)" == 1 ]; then
  3. exit 1
  4. fi
  5. MAPSERVER="$(uci -q get freifunk-mapupdate.mapupdate.mapserver)"
  6. [ -z "$MAPSERVER" ] && logger -t "freifunk-mapupdate:" "No mapserver configured" && exit 1
  7. #check if nameservice plugin is installed and enabled, else exit
  8. nslib=`uci show olsrd |grep olsrd_nameservice.so |awk {' FS="."; print $1"."$2 '}`
  9. if [ -n "$nslib" ]; then
  10. LATLONFILE="$(uci -q get $nslib.latlon_file)"
  11. if [ -z "$LATLONFILE" ]; then
  12. LATLONFILE="/var/run/latlon.js"
  13. fi
  14. if [ ! -p "$LATLONFILE" ]; then
  15. logger -t "freifunk-mapupdate:" "latlon_file not found."; exit 1
  16. fi
  17. else
  18. logger -t "freifunk-mapupdate:" "nameservice plugin not found in olsrd config."
  19. exit 1
  20. fi
  21. HOSTNAME="$(uci show system |grep hostname |cut -d "=" -f 2)"
  22. HF_INFO=""
  23. # Get info for myself
  24. SELF=$(cat $LATLONFILE |grep ^Self | sed -e 's/Self(//' -e 's/);//' -e "s/'//g")
  25. OLSR_IP="$(echo $SELF |awk '{ FS=",";print $1 }')"
  26. LOCATION="$(uci show system |grep .location |cut -d "=" -f 2)"
  27. [ -n "$LOCATION" ] && NOTE="$LOCATION<br>"
  28. FFNOTE="$(uci -q get freifunk.contact.note)"
  29. [ -n "$FFNOTE" ] && NOTE="$NOTE $FFNOTE"
  30. NOTE="<h3><a href='http://$OLSR_IP' target='_blank'>$HOSTNAME</a></h3><p>$NOTE"
  31. NOTE=`echo -e "$NOTE" | sed -e 's/\ /%20/g' -e 's/&/%26/g' -e 's/"/%22/g'`
  32. UPDATESTRING="$(echo $SELF |awk '{ FS=",";print $2 }'), $(echo $SELF |awk '{ FS=",";print $3 }')"
  33. # write our coordinates to mygooglemapscoords.txt to make Freifunk Firmware happy
  34. echo "$UPDATESTRING" > /tmp/mygooglemapscoords.txt
  35. [ ! -L /www/mygooglemapscoords.txt ] && ln -s /tmp/mygooglemapscoords.txt /www/mygooglemapscoords.txt
  36. # get neighbor Info (lat, lon, lq)
  37. while read line; do
  38. NEIGHUPD="$(echo $line |awk '{ FS=","; print $6 }'), $(echo $line |awk '{ FS=","; print $7 }'), $(echo $line |awk '{ FS=",";print $4 }')"
  39. UPDATESTRING="${UPDATESTRING}, ${NEIGHUPD}"
  40. done << EOF
  41. `grep "PLink('$OLSR_IP" $LATLONFILE | sed -e 's/PLink(//' -e 's/);//' -e "s/'//g"`
  42. EOF
  43. # Send UPDATESTRING
  44. UPDATE=`echo -e "$UPDATESTRING" | sed s/\ /%20/g`
  45. result="$(wget "$MAPSERVER?update=$UPDATE&updateiv=3600&olsrip=$OLSR_IP&note=${NOTE}${HF_INFO}" -qO -)"
  46. if [ ! "$result" == "success update" ]; then
  47. logger -t "freifunk-mapupdate:" "Update failed: $result"
  48. fi