#!/bin/sh

# We only do anything in here if the interface is set to manual config 
# in /etc/network/interfaces
if [ "$METHOD" == "manual" ]; then
    exec 1>/dev/ttymxc0
    exec 2>/dev/ttymxc0

    # Get the network settings from the netsettings.sh script
    source /app/bin/netsettings.sh

    # Are we using static or DHCP for the network?
    if [ "$NET_MODE" == "dhcp" ]; then
        echo "S01ifconfig: DHCP Mode (DOWN)"

        # Stop DHCP if it is started
        if [ -f /var/run/udhcpc.$IFACE.pid ]; then
            kill $(cat /var/run/udhcpc.$IFACE.pid)
        fi
        
        # Bring the interface down
        ifconfig $IFACE down
    else
        echo "S01ifconfig: Static Mode (DOWN)"

	    # Bring down DHCPD
		if [ "$DHCPSERVER_ENABLED" = "Y" ]; then
			start-stop-daemon -K -p /var/run/udhcpd.$IFACE.pid
		fi
		
        # Bring the interface down
        ifconfig $IFACE down
    fi        
fi
