#!/bin/sh

export ROOT=/www
CONFIG=$ROOT/config
SCRIPT=$ROOT/script

touch /tmp/installing

backupDir="/tmp/backup"
rm -rf $backupDir
mkdir -p $backupDir
cp /etc/config/network /etc/config/wireless /etc/config/dhcp $backupDir
sh -x $SCRIPT/init.sh
cp $backupDir/* /etc/config
rm -rf $backupDir

sh -x $SCRIPT/update/post-update.sh # setup ng_ap2
echo >> $CONFIG/ng.conf # force update config
sh -x $SCRIPT/update/update-ng-config.sh
if [ $? -eq 0 ] ; then
  touch /etc/installed

  rm -rf $ROOT/wget-log*
  rm -rf /tmp/installing

  killall tcpdump 2>/dev/null
  killall tcpdump 2>/dev/null
  /etc/init.d/ng_ap2 stop job
  kill -9 `ps | grep -e monitor -e collector | grep -v grep` 2>/dev/null

  $SCRIPT/monitor.sh 2>/dev/null >/dev/null &
  rm -f /tmp/installing
fi
