X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fusr%2Fbin%2Fparse-interfaces;fp=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fusr%2Fbin%2Fparse-interfaces;h=e576c3f81de8393eefcd7430fce117a1108daaf8;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/src/usr/bin/parse-interfaces b/cirros-testvm/src-cirros/src/usr/bin/parse-interfaces new file mode 100755 index 0000000..e576c3f --- /dev/null +++ b/cirros-testvm/src-cirros/src/usr/bin/parse-interfaces @@ -0,0 +1,80 @@ +#!/bin/sh + +ENABLE=yes +NAME=Ethernet +IPADDRESS=192.168.1.20 +CIDRLEN= +NETWORK=192.168.1.0 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +BROADCAST= +DHCP=no +CIDRLEN=24 +NETWORK=192.168.1.0 + +netinfo() { + local ipaddr=$1 netmask=$2 oifs=${IFS} mask=255 + local ipb1 ipb2 ipb3 ipb4 nmb1 nmb2 nmb3 nmb4 + IFS=. + set -- ${ipaddr}; ipb1=${1}; ipb2=${2}; ipb3=${3}; ipb4=${4} + set -- ${netmask}; nmb1=${1}; nmb2=${2}; nmb3=${3}; nmb4=${4} + IFS=$SaveIFS + + local network bcast + network=$(($ipb1 & $nmb1)).$(($ipb2 & $nmb2)).$(($ipb3 & $nmb3)).$(($ipb4 & $nmb4)) + bcast=$(($ipb1 | ($mask ^ $nmb1))).$(($ipb2 | ($mask ^ $nmb2))).$(($ipb3 | ($mask ^ $nmb3))).$(($ipb4 | ($mask ^ $nmb4))) + + _RET_NETWORK=${network} + _RET_BCAST=${bcast} +} + +iface="${1:-eth0}" +file=${2:-/etc/network/interfaces} +[ "$file" = "-" ] || exec <"$file" + +hash="#" +cur_iface="" +found=0 +while read line; do + line=${line%%${hash}*} + [ -n "$line" ] || continue + set -- ${line} + case $1 in + auto) [ "$2" = "$iface" ] && ENABLE=yes;; + iface) + [ "$2" = "$iface" ] || continue; + # if its not static, let the default path handle + [ "$4" = "static" ] || { DHCP=yes; continue; } + cur_iface=$2 + found=1 + ;; + *) + [ "$cur_iface" = "$iface" ] || continue; + case $1 in + address) IPADDRESS=${2};; + netmask) NETMASK=${2};; + gateway) GATEWAY=${2};; + address) IPADDRESS=${2};; + esac + ;; + esac +done + +[ -n "$IPADDRESS" -a -n "$NETMASK" ] && netinfo "$IPADDRESS" "$NETMASK" && + BROADCAST=${_RET_BCAST} + +cat <