Commit 0efd2f90 authored by sokai's avatar sokai

initial commit with last version from Wiki (120801-bf3)

#!/bin/sh /etc/rc.common
# this version only works with "Backfire"!
# /etc/init.d/ffp-apdb enable
EXTRA_COMMANDS="update status"
INTERVAL=30 # run cron every x minutes (max 59?)
URL='' # with / at the end!
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')
LOCATION=$(grep 'location' /etc/config/system|awk '{$1=$2="";print}'|sed 's/ /%20/g')
#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')
CLIENTS=$(iw dev wlan0 station dump|grep -c Station)
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)"
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)"
status() {
echo "NOT IMPLEMENTED ! 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"
# 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
if [ -f $PID_FILE ]; then
PID="$(cat ${PID_FILE} 2> /dev/null)"
if [ ! -z $PID ]; then
kill $PID >/dev/null 2> /dev/null
# get rid of wget-s hanging arround
for f in /proc/[0-9]*/cmdline; do
if grep -sq 'ap.php' "$f"; then
kill "${WGET_PID}" 2>/dev/null
echo "$$" > $PID_FILE
KEY=$(wget -q -O - ${URL}ap.php?mode=get)
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
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment