StatusUpdates

Aus Freifunk Potsdam | Wiki
Version vom 22. April 2013, 14:49 Uhr von Wohngut (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „=== Freifunk Potsdam Accesspoints Update installieren === * auf dem Accesspoint einloggen * mit einem Editor folgende Datei anlegen /etc/init.d/ffp-apdb * Dat…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Freifunk Potsdam Accesspoints Update installieren

  • auf dem Accesspoint einloggen
  • mit einem Editor folgende Datei anlegen /etc/init.d/ffp-apdb
  • Datei öffnen und den Inhalt (siehe unten) reinkopieren
  • es müssen keine Änderungen vorgeneommen werden
  • script ausführbar machen mit: chmod 755 /etc/init.d/ffp-apdb
  • bootbar machen: /etc/init.d/ffp-apdb enable
  • starten: /etc/init.d/ffp-apdb start
  • fertig!

ffp-apdb Script

  1. !/bin/sh /etc/rc.common
  2. this version only works with "Backfire"!
  3. /etc/init.d/ffp-apdb enable

START=99 EXTRA_COMMANDS="update status"

INTERVAL=30 # run cron every x minutes (max 59?) URL='http://freifunk-potsdam.de/apdb/' # with / at the end! SCRIPTVERSION='120801-bf3'

HOSTNAME=$(cat /etc/config/system| awk '/hostname/ {print $3}'|sed 's/ /%20/g') IP=$(ifconfig wlan0|grep 'inet addr'|awk '{print $2}'| sed 's/addr://'|sed 's/ /%20/g') GWIP=$(ip route | awk '/default via/ {print $3}') # awk nicht installiert :( LATITUDE=$(grep 'latitude' /etc/config/system| awk '{$1=$2="";print}'|sed 's/ /%20/g') LONGITUDE=$(grep 'longitude' /etc/config/system| awk '{$1=$2="";print}'|sed 's/ /%20/g') GEOLOC="${LATITUDE};${LONGITUDE}" LOCATION=$(grep 'location' /etc/config/system|awk '{$1=$2="";print}'|sed 's/ /%20/g')

  1. LOCATION=$(uci show system.system.location|sed 's/system.system.location=//'|sed 's/ /%20/g')

CONTACT=$(grep 'mail' /etc/config/freifunk|awk '{$1=$2="";print}'|sed 's/ /%20/g'|sed 's/#/%23/g') UPTIME=$(cat /proc/uptime|sed 's/ /%20/g') FIRMWARE=$(cat /etc/openwrt_version|sed 's/ /%20/g') MACHINE=$(grep 'machine' /proc/cpuinfo|awk '{$1=$2=""; print}'| sed 's/\ \ //'|sed 's/ /%20/g') SYSTEMTYPE=$(grep 'system type' /proc/cpuinfo|awk '{$1=$2=""; print}'| sed 's/  : //'|sed 's/ /%20/g')

start() { update="*/$INTERVAL * * * * /etc/init.d/ffp-apdb update # every $INTERVAL minutes" sed -ie '/\/etc\/init.d\/ffp-apdb/d' /var/spool/cron/crontabs/root echo "$update" >> /var/spool/cron/crontabs/root echo "root" > /var/spool/cron/crontabs/cron.update logger -t 'ffp-apdb' "cron job added (/etc/init.d/ffp-apdb start)" update }

stop() { if grep -q /etc/init.d/ffp-apdb /var/spool/cron/crontabs/root;then sed -ie '/\/etc\/init.d\/ffp-apdb/d' /var/spool/cron/crontabs/root echo "root" > /var/spool/cron/crontabs/cron.update logger -t 'ffp-apdb' "cron job removed (/etc/init.d/ffp-apdb stop)" fi }

status() { echo "check status of the Freifunk Potsdam AP database" echo "" IFS=\;\,\: set - $(nvram get ff_adm_latlon) unset IFS if [ -z "$1" ] || [ -z "$2" ]; then echo "ERROR no coordinates configured, ff_adm_latlon is empty" elif [ -z "$(nvram get ff_map_server)" ]; then echo "ERROR no map server configured, ff_map_server is empty" else echo "STATUS everything fine: ff_map_server is $(nvram get ff_map_server), coords are $1, $2" COORDS_ON_SERVER="$1, $2" UPDATERUN=`wget "$(nvram get ff_map_server)?dumpdatabase" -qO - 2> /tmp/freifunkmap_status | cut -f3 | grep "${COORDS_ON_SERVER}" | wc -l` CONNERROR=`cat /tmp/freifunkmap_status` if [ ! -z "$CONNERROR" ]; then echo "ERROR could not connect map server: ${CONNERROR}" else if [ ${UPDATERUN} -eq 0 ]; then echo "STATUS connection to map server seems to be ok, but no update run so far" elif [ ${UPDATERUN} -eq 1 ]; then echo "STATUS connection to map server seems to be ok, and your node should be visible in the map" else echo "ERROR something unexpected happend, your node should be more then one time visible in the map??? But this can't be" fi fi rm /tmp/freifunkmap_status fi

CRONTABENTRY=$(grep -c "/etc/init.d/S70freifunkmap update" /var/spool/cron/crontabs/root) if [ $CRONTABENTRY -eq 0 ]; then echo "ERROR no crontab entry for freifunkmap found, the update with the server will not run, try /etc/init.d/S70freifunkmap start" elif [ $CRONTABENTRY -eq 1 ]; then echo "STATUS everything fine: found one entry for freifunkmap in the crontab" else [ $CRONTABENTRY -gt 1 ] echo "WARN found more then one entry for freifunkmap in crontab, but the update should work anyway" fi }

update() { # only one instance should be running at time # if exists an other one kill them and all wgets PID_FILE="/tmp/run/ffp-apdb.pid" if [ -f $PID_FILE ]; then PID="$(cat ${PID_FILE} 2> /dev/null)" if [ ! -z $PID ]; then kill $PID >/dev/null 2> /dev/null fi fi

# get rid of wget-s hanging arround for f in /proc/[0-9]*/cmdline; do if grep -sq 'ap.php' "$f"; then WGET_PID="${f#/proc/}"; WGET_PID="${WGET_PID%%/*}" kill "${WGET_PID}" 2>/dev/null fi done

echo "$$" > $PID_FILE

KEY=$(wget -q -O - ${URL}ap.php?mode=get) PARAM="&key=${KEY}&ip=%22${IP}%22&host=%22${HOSTNAME}%22&geoloc=%22${GEOLOC}%22&location=%22${LOCATION}%22&contact=%22${CONTACT}%22&gw_ip=%22${GWIP}%22&uptime=%22${UPTIME}%22&machine=%22${MACHINE}%22&systemtype=%22${SYSTEMTYPE}%22&scriptversion=%22${SCRIPTVERSION}%22&firmware=%22${FIRMWARE}%22" wget -q -O - ${URL}ap.php?mode=put"${PARAM}" #echo ${URL}ap.php?mode=put"${PARAM}" logger -t 'ffp-apdb' "AP information transfered to AP database (/etc/init.d/ffp-apdb update)"

# everything looks fine rm $PID_FILE }