#!/bin/sh -x
# /bin/setnewip
# David Rowe Nov 18 2007
#
# Sets a new IP based on DTMF digits collected by Asterisk
# Asterisk places it's collected IP in /tmp/newip.txt

if [ ! -f /tmp/newip.txt ]; then
  exit
fi

# convert * seperated IP like 192*168*1*32 to 192.168.1.32

cat /tmp/newip.txt | sed 's/\*/\./g' > /tmp/newip_dot.txt

# Modify /etc/asterisk/rc.conf static IP, so we reboot with
# the correct IP

NEWIP=`cat /tmp/newip_dot.txt`
#cat /etc/asterisk/rc.conf | sed "s/IPADDRESS=\".*\..*\..*\..*\"/IPADDRESS=\"${NEWIP}\"/" > /tmp/rc.conf
cat /etc/init.d/meshnetwork | sed "s/ifconfig ath0 .* netmask/ifconfig ath0 ${NEWIP} netmask/" > /tmp/meshnetwork
cp /tmp/meshnetwork /etc/init.d/meshnetwork

# restart batman
killall -9 batmand
/etc/init.d/meshnetwork 



