Commit df5933cd authored by sokai's avatar sokai

v160122: indention fix + hints for usage of uci for values

parent 00335359
#!/bin/sh /etc/rc.common
# this version only works with OpenWrt Backfire and up!
# this version only works with OpenWrt Backfire and up (> r20728)!
# /etc/init.d/ffp-apdb enable
# DEBUG?
......@@ -12,7 +12,7 @@ EXTRA_COMMANDS="update status"
INTERVAL=55 # run cron every x minutes (max 59?)
URL='http://freifunk-potsdam.de/apdb/' # with / at the end!
SCRIPTVERSION='160119-bf'
SCRIPTVERSION='160122-bf'
WIF=$(ifconfig | awk '/10\.22\.[0-9]{1,3}\.[0-9]{1,3}/ {print $1}' RS="\n\n" | grep wlan) # http://stackoverflow.com/a/18344694/338049
#WIFI= uci show = [email protected][0].ifname=wlan0-adhoc-2
......@@ -39,89 +39,89 @@ CLIENTS=$(iw dev ${WIF} station dump|grep -c Station)
#CLIENTS=$(cat /tmp/dhcp.leases|wc -l)
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
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
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 "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"
# 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
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"
# 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
# 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
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
# 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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment