+INTERFACE_DEFAULTS="auto eth0
+iface eth0 inet dhcp"
+
+generate_network_config() {
+ if [ "$NETWORK_CONFIG" == "" ]; then
+ echo "$INTERFACE_DEFAULTS"
+ return 0
+ fi
+
+ ETH0_HEADER="auto eth0"
+ ETH0_IPV4=""
+ ETH0_IPV6=""
+
+ echo "auto eth0"
+ # see if there's a type
+ network_type=${NETWORK_CONFIG/,*}
+ other_params=${NETWORK_CONFIG#*,}
+
+ v4_configured=no
+ v6_configured=no
+
+ if [ "$network_type" == "dhcp" ]; then
+ ETH0_IPV4="iface eth0 inet dhcp"
+ ETH0_IPV6="iface eth0 inet6 dhcp"
+ v4_configured=yes
+ v6_configured=yes
+ elif [ "$network_type" == "dhcp4" ]; then
+ ETH0_IPV4="iface eth0 inet dhcp"
+ v4_configured=yes
+ elif [ "$network_type" == "dhcp6" ]; then
+ ETH0_IPV6="iface eth0 inet6 dhcp"
+ v6_configured=yes
+ elif [ "$network_type" != "static" ]; then
+ echo "Unknown network type: $network_type" 1>&2
+ echo 1>&2
+ usage 1>&2
+ exit 1
+ fi
+
+ [ "$network_type" == "$other_params" ] && return 0
+
+ v4_static=${other_params/,*}
+ other_params=${other_params#*,}
+
+ if [ "$v4_static" != "" ]; then
+ if [ "$v4_configured" == "yes" ]; then
+ echo "Both v4 DHCP and Static - giving up." 1>&2
+ echo 1>&2
+ usage 1>&2
+ exit 1
+ fi
+ fi
+
+ if [ "$v4_static" == "$other_params" ]; then
+ if [ "$v4_static" != "" ]; then
+ echo "iface eth0 inet static"
+ echo " address $v4_static"
+ fi
+ fi
+
+ v6_static=${other_params/,*}
+ other_params=${other_params#*,}
+
+ if [ "$v6_static" != "" ]; then
+ if [ "$v6_configured" == "yes" ]; then
+ echo "Both v6 DHCP and Static - giving up." 1>&2
+ echo 1>&2
+ usage 1>&2
+ exit 1
+ fi
+ fi
+
+ if [ "$v6_static" == "$other_params" ]; then
+ if [ "$v4_static" ]; then
+ echo "iface eth0 inet static"
+ echo " address $v4_static"
+ echo
+ fi
+
+ echo "iface eth0 inet6 static"
+ echo " address $v6_static"
+
+ return 0
+ fi
+
+ v4_gateway=${other_params/,*}
+ other_params=${other_params#*,}
+
+ if [ "$v4_gateway" == "$other_params" ]; then
+ if [ "$v4_static" != "" ]; then
+ echo "iface eth0 inet static"
+ echo " address $v4_static"
+ [ "$v4_gateway" != "" ] && echo " gateway $v4_gateway"
+
+ if [ "$v6_static" != "" ]; then
+ echo "iface eth0 inet6 static"
+ echo " address $v6_static"
+ fi
+
+ return 0
+ fi
+
+ if [ "$v4_configured" == "yes" ]; then
+ echo "DHCP and static gateway not supported, giving up." 1>&2
+ echo 1>&2
+ usage 1>&2
+ exit 1
+ fi
+ fi
+
+ v6_gateway=${other_params/,*}
+
+ if [ "$v4_static" != "" ]; then
+ echo "iface eth0 inet static"
+ echo " address $v4_static"
+ [ "$v4_gateway" != "" ] && echo " gateway $v4_gateway"
+ echo
+ fi
+
+ if [ "$v6_static" != "" ]; then
+ echo "iface eth0 inet6 static"
+ echo " address $v6_static"
+ [ "$v6_gateway" != "" ] && echo " gateway $v6_gateway"
+ fi
+
+ return 0
+}
+
+INTERFACE_DETAILS="$(generate_network_config)"