# Barix configuration interface
# (c) 2012 Barix AG
#
# meta-file for automatic config-file generation

# -------- create /etc/network/interfaces

# destination file for the configuration (absolute path)
DST_FILE[0]=/etc/network/interfaces

# template file located in /barix/config/templates/templates
TEMPLATE_FILE[0]=network.interfaces

# comments are prefixed with this character
COMMENT_PREFIX[0]="#"

# function to create dynamic content
DYNAMIC_CONTENT_FN[0]=create_network_interfaces

# function to create dynamic content
function create_network_interfaces()
{
	if cfg_string_compare network.eth0.proto "dhcp" ; then
		# DHCP configuration, get all auto
		echo "iface eth0 inet dhcp"
		if cfg_string_compare network.eth0.dhcpname "" ; then 
			true
		else
			echo -n "	hostname '"
			cfg_print_param network.eth0.dhcpname
			echo -n "'"
		fi
	else
		# DHCP configuration, set all static
		ipaddr=`cfg_print_param network.eth0.ipaddr`
		netmask=`cfg_print_param network.eth0.netmask`
		gateway=`cfg_print_param network.eth0.gateway`

		echo "iface eth0 inet static"
		echo "	address $ipaddr"
		echo "	netmask $netmask"
		if [ -n "$gateway" ]; then
			echo "	gateway $gateway"
		fi

	fi

        echo "auto eth1"
        echo "iface eth1 inet dhcp"

}


# -------- create /etc/resolv.conf

# destination file for the configuration (absolute path)
DST_FILE[1]=/etc/resolv.conf

# template file located in /barix/config/templates/templates
TEMPLATE_FILE[1]=

# comments are prefixed with this character
COMMENT_PREFIX[1]="#"

# function to create dynamic content
DYNAMIC_CONTENT_FN[1]=create_resolv_conf

# function to create dynamic content
function create_resolv_conf()
{
	if cfg_string_compare network.eth0.proto "static" ; then
		dns1=`cfg_print_param network.eth0.dns1`
		dns2=`cfg_print_param network.eth0.dns2`

		if [ "X$dns1" != "X" ] ; then echo "nameserver $dns1" ; fi
		if [ "X$dns2" != "X" ] ; then echo "nameserver $dns2" ; fi
	fi

	# no action for DHCP
}


# -------- create /etc/sonic-ip.conf 
# destination file for the configuration (absolute path)             
DST_FILE[2]=/etc/sonic-ip.conf                                         
                                                                     
# template file located in /barix/config/templates/templates                   
TEMPLATE_FILE[2]=                                                    
                                                                                                                                          
# comments are prefixed with this character                          
COMMENT_PREFIX[2]="#"                                         
                                                                                                                                                           
# function to create dynamic content                          
DYNAMIC_CONTENT_FN[2]=create_sonicip_conf                      
                                                                                                                                                                                                                                                                      
# function to create dynamic content                          
function create_sonicip_conf() 
{	
	sonic_vol=`cfg_print_param network.sonic_ip.volume`
	if [ "X$sonic_vol" != "X" ] ; then echo "SONICIP_VOLUME=$sonic_vol" ; fi
}


