#!/bin/sh
# To put on /usr/local/sbin
echo ""
echo "--------------------------------------------------------------"
echo "Creating a default config file for Aastra phones"
echo "--------------------------------------------------------------"
echo ""
echo "Creating /tftpboot/aastra.cfg..."
echo ""

IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`

cat > /tftpboot/aastra.cfg <<EOF
# Setup DHCP mode
dhcp: 1

# Setup TFTP server address
tftp server: $IPADDR

# Time server
time server disabled: 0
time server1: pool.ntp.org
time server2: $IPADDR

# Startup URI
action uri startup: http://$IPADDR/xml/startup/startup.php

EOF

chmod 666 /tftpboot/aastra.cfg

echo "Created /tftpboot/aastra.cfg using $IPADDR for the proxy. If the"
echo "IP address of your Asterisk system changes run this script again and reboot."
echo "Reboot your Aastra phones by disconnectiong the power to the phone."
echo ""
