Commit 5f19ce60 by sokai

better upgrade (start the new script after upgrade) + start enables init script …

…+ stop disables init script + cosmetic
1 parent d41d5b4a
Showing with 16 additions and 6 deletions
......@@ -52,25 +52,36 @@ SYSTEMTYPE=$(grep 'system type' /proc/cpuinfo|awk '{$1=$2=""; print}'| sed 's/
#CLIENTS=$(cat /tmp/dhcp.leases|wc -l)
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
CRONJOB="${UPDATEINTERVAL} * * * * ${SCRIPT} update # FreiFunkPotsdam-AccessPointsDataBase"
CRONJOB="${UPDATEINTERVAL} * * * * ${SCRIPT} update # FreiFunkPotsdam-AccessPointsDataBase (v${SCRIPTVERSION})"
echo "${CRONJOB}" >> ${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
fi
}
stop() {
# INFO: remove update cron job AND disable init script
if $(grep -q ${SCRIPT} ${CRONTAB}) ;then
# 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}
echo "root" > /var/spool/cron/crontabs/cron.update # reload crontab
logger -t ${SCRIPTNAME} "cron job removed (${SCRIPT} stop)"
fi
if [ -f "/etc/rc.d/S${START}${SCRIPTNAME}" ]; then
disable
logger -t ${SCRIPTNAME} "init scrip disabled (${SCRIPT} stop)"
fi
}
update() {
# INFO: updates own status to remote database
# only one instance should be running at time
# if exists an other one kill them and all wgets
PID_FILE="/tmp/run/${SCRIPTNAME}.pid"
......@@ -103,7 +114,7 @@ update() {
}
upgrade() {
## self-upgrade of this script
# INFO: self-upgrade of this script
NEWSCRIPT="/tmp/${SCRIPTNAME}"
wget -q -O ${NEWSCRIPT} ${UPGRADEURL} 2>/dev/null
......@@ -111,17 +122,16 @@ upgrade() {
if [ -f ${NEWSCRIPT} ]; then
# remove current script
stop
disable
# install new script
chmod +x ${NEWSCRIPT}
mv ${NEWSCRIPT} ${SCRIPT}
${SCRIPT} enable
${SCRIPT} start
VERSION=$(grep 'SCRIPTVERSION=' ${SCRIPT} -m 1 | cut -f2 -d'='|sed 's/ /%20/g'|sed "s/'//g")
SUCCESS="version (${VERSION}) installed at ${SCRIPT} (${SCRIPT} upgrade)"
echo ${SUCCESS}
logger -t ${SCRIPTNAME} ${SUCCESS}
exec ${SCRIPT} start && exit
else
ERROR="download wasn't successful, so current version remains at ${SCRIPT} (${SCRIPT} upgrade)"
echo ${ERROR}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!