...
 
Commits (2)
...@@ -5,6 +5,26 @@ The APDB consists of two parts: ...@@ -5,6 +5,26 @@ The APDB consists of two parts:
A productive used installation is available at http://freifunk-potsdam.de/apdb/. A productive used installation is available at http://freifunk-potsdam.de/apdb/.
## Installation (at Access Point)
* `ssh` into your AP
* execute the following commands (copy-paste-ready)
```bash
wget -q -O - 'http://freifunk-potsdam.de/ffp-apdb.php' > /etc/init.d/ffp-apdb && \
chmod +x /etc/init.d/ffp-apdb; \
/etc/init.d/ffp-apdb start
```
## Configuration
* edit `/etc/init.d/ffp-apdb`for your needs
## (Self-)Upgrade
* `ssh` into your AP
```bash
/etc/init.d/ffp-apdb upgrade
```
## Legal ## Legal
APDB is free software: you can redistribute it and/or modify it under the APDB is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
...@@ -33,24 +53,3 @@ A productive used installation is available at http://freifunk-potsdam.de/apdb/. ...@@ -33,24 +53,3 @@ A productive used installation is available at http://freifunk-potsdam.de/apdb/.
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>. Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
## Installation (at Access Point)
* `ssh` into your AP
* execute the following commands (copy-paste-ready)
```bash
wget -q -O - 'http://freifunk-potsdam.de/ffp-apdb.php' > /etc/init.d/ffp-apdb && \
chmod +x /etc/init.d/ffp-apdb; \
/etc/init.d/ffp-apdb enable; \
/etc/init.d/ffp-apdb start
```
## Configuration
* edit `/etc/init.d/ffp-apdb`for your needs
## Upgrade
* `ssh` into your AP
```bash
/etc/init.d/ffp-apdb upgrade
```
...@@ -52,25 +52,36 @@ SYSTEMTYPE=$(grep 'system type' /proc/cpuinfo|awk '{$1=$2=""; print}'| sed 's/ ...@@ -52,25 +52,36 @@ SYSTEMTYPE=$(grep 'system type' /proc/cpuinfo|awk '{$1=$2=""; print}'| sed 's/
#CLIENTS=$(cat /tmp/dhcp.leases|wc -l) #CLIENTS=$(cat /tmp/dhcp.leases|wc -l)
start() { start() {
# INFO: enable init script AND add update cron job
if [ ! -f "/etc/rc.d/S${START}${SCRIPTNAME}" ]; then
enable
logger -t ${SCRIPTNAME} "init scrip enabled (${SCRIPT} start)"
fi
if ! $(grep -q ${SCRIPT} ${CRONTAB}); then if ! $(grep -q ${SCRIPT} ${CRONTAB}); then
CRONJOB="${UPDATEINTERVAL} * * * * ${SCRIPT} update # FreiFunkPotsdam-AccessPointsDataBase" CRONJOB="${UPDATEINTERVAL} * * * * ${SCRIPT} update # FreiFunkPotsdam-AccessPointsDataBase (v${SCRIPTVERSION})"
echo "${CRONJOB}" >> ${CRONTAB} echo "${CRONJOB}" >> ${CRONTAB}
echo "${CRONTABUSER}" > ${CRONTABPATH}cron.update # reload crontab echo "${CRONTABUSER}" > ${CRONTABPATH}cron.update # reload crontab
logger -t ${SCRIPTNAME} "update cron job (every ${UPDATEINTERVAL} minute past every hour) for user ${CRONTABUSER} added (${SCRIPT} start)" logger -t ${SCRIPTNAME} "update cron job (every ${UPDATEINTERVAL}th minute past every hour) for user ${CRONTABUSER} added (${SCRIPT} start)"
update update
fi fi
} }
stop() { stop() {
# INFO: remove update cron job AND disable init script
if $(grep -q ${SCRIPT} ${CRONTAB}) ;then if $(grep -q ${SCRIPT} ${CRONTAB}) ;then
# better grep than sed with unescaped file pathes ... -> http://stackoverflow.com/a/5413132/338049 # better grep than sed with unescaped file pathes ... -> http://stackoverflow.com/a/5413132/338049
grep -v ${SCRIPT} ${CRONTAB} > /tmp/crontab.temp && mv /tmp/crontab.temp ${CRONTAB} && chmod 600 ${CRONTAB} grep -v ${SCRIPT} ${CRONTAB} > /tmp/crontab.temp && mv /tmp/crontab.temp ${CRONTAB} && chmod 600 ${CRONTAB}
echo "root" > /var/spool/cron/crontabs/cron.update # reload crontab echo "root" > /var/spool/cron/crontabs/cron.update # reload crontab
logger -t ${SCRIPTNAME} "cron job removed (${SCRIPT} stop)" logger -t ${SCRIPTNAME} "cron job removed (${SCRIPT} stop)"
fi fi
if [ -f "/etc/rc.d/S${START}${SCRIPTNAME}" ]; then
disable
logger -t ${SCRIPTNAME} "init scrip disabled (${SCRIPT} stop)"
fi
} }
update() { update() {
# INFO: updates own status to remote database
# only one instance should be running at time # only one instance should be running at time
# if exists an other one kill them and all wgets # if exists an other one kill them and all wgets
PID_FILE="/tmp/run/${SCRIPTNAME}.pid" PID_FILE="/tmp/run/${SCRIPTNAME}.pid"
...@@ -103,7 +114,7 @@ update() { ...@@ -103,7 +114,7 @@ update() {
} }
upgrade() { upgrade() {
## self-upgrade of this script # INFO: self-upgrade of this script
NEWSCRIPT="/tmp/${SCRIPTNAME}" NEWSCRIPT="/tmp/${SCRIPTNAME}"
wget -q -O ${NEWSCRIPT} ${UPGRADEURL} 2>/dev/null wget -q -O ${NEWSCRIPT} ${UPGRADEURL} 2>/dev/null
...@@ -111,17 +122,16 @@ upgrade() { ...@@ -111,17 +122,16 @@ upgrade() {
if [ -f ${NEWSCRIPT} ]; then if [ -f ${NEWSCRIPT} ]; then
# remove current script # remove current script
stop stop
disable
# install new script # install new script
chmod +x ${NEWSCRIPT} chmod +x ${NEWSCRIPT}
mv ${NEWSCRIPT} ${SCRIPT} mv ${NEWSCRIPT} ${SCRIPT}
${SCRIPT} enable
${SCRIPT} start
VERSION=$(grep 'SCRIPTVERSION=' ${SCRIPT} -m 1 | cut -f2 -d'='|sed 's/ /%20/g'|sed "s/'//g") VERSION=$(grep 'SCRIPTVERSION=' ${SCRIPT} -m 1 | cut -f2 -d'='|sed 's/ /%20/g'|sed "s/'//g")
SUCCESS="version (${VERSION}) installed at ${SCRIPT} (${SCRIPT} upgrade)" SUCCESS="version (${VERSION}) installed at ${SCRIPT} (${SCRIPT} upgrade)"
echo ${SUCCESS} echo ${SUCCESS}
logger -t ${SCRIPTNAME} ${SUCCESS} logger -t ${SCRIPTNAME} ${SUCCESS}
exec ${SCRIPT} start && exit
else else
ERROR="download wasn't successful, so current version remains at ${SCRIPT} (${SCRIPT} upgrade)" ERROR="download wasn't successful, so current version remains at ${SCRIPT} (${SCRIPT} upgrade)"
echo ${ERROR} echo ${ERROR}
......