The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / usr / bin / parse-interfaces
1 #!/bin/sh
2
3 ENABLE=yes
4 NAME=Ethernet
5 IPADDRESS=192.168.1.20
6 CIDRLEN=
7 NETWORK=192.168.1.0
8 NETMASK=255.255.255.0
9 GATEWAY=192.168.1.1
10 BROADCAST=
11 DHCP=no
12 CIDRLEN=24
13 NETWORK=192.168.1.0
14
15 netinfo() {
16    local ipaddr=$1 netmask=$2 oifs=${IFS} mask=255
17    local ipb1 ipb2 ipb3 ipb4 nmb1 nmb2 nmb3 nmb4
18    IFS=.
19    set -- ${ipaddr}; ipb1=${1}; ipb2=${2}; ipb3=${3}; ipb4=${4}
20    set -- ${netmask}; nmb1=${1}; nmb2=${2}; nmb3=${3}; nmb4=${4}
21    IFS=$SaveIFS
22
23    local network bcast
24    network=$(($ipb1 & $nmb1)).$(($ipb2 & $nmb2)).$(($ipb3 & $nmb3)).$(($ipb4 & $nmb4))
25    bcast=$(($ipb1 | ($mask ^ $nmb1))).$(($ipb2 | ($mask ^ $nmb2))).$(($ipb3 | ($mask ^ $nmb3))).$(($ipb4 | ($mask ^ $nmb4)))
26
27    _RET_NETWORK=${network}
28    _RET_BCAST=${bcast}
29 }
30
31 iface="${1:-eth0}"
32 file=${2:-/etc/network/interfaces}
33 [ "$file" = "-" ] || exec <"$file"
34
35 hash="#"
36 cur_iface=""
37 found=0
38 while read line; do
39         line=${line%%${hash}*}
40         [ -n "$line" ] || continue
41         set -- ${line}
42         case $1 in
43                 auto) [ "$2" = "$iface" ] && ENABLE=yes;;
44                 iface)
45                         [ "$2" = "$iface" ] || continue;
46                         # if its not static, let the default path handle
47                         [ "$4" = "static" ] || { DHCP=yes; continue; }
48                         cur_iface=$2
49                         found=1
50                         ;;
51                 *)
52                         [ "$cur_iface" = "$iface" ] || continue;
53                         case $1 in
54                                 address) IPADDRESS=${2};;
55                                 netmask) NETMASK=${2};;
56                                 gateway) GATEWAY=${2};;
57                                 address) IPADDRESS=${2};;
58                         esac
59                         ;;
60         esac
61 done 
62
63 [ -n "$IPADDRESS" -a -n "$NETMASK" ] && netinfo "$IPADDRESS" "$NETMASK" &&
64         BROADCAST=${_RET_BCAST}
65
66 cat <<EOF
67 # this file was written by: $0 $iface $file
68 # some short experimentation shows that you must define
69 # ENABLE NAME CIDRLEN NETWORK and DHCP to get working DHCP
70 ENABLE=$ENABLE
71 NAME=Ethernet
72 IPADDRESS=$IPADDRESS
73 NETMASK=$NETMASK
74 GATEWAY=$GATEWAY
75 BROADCAST=$BROADCAST
76 DHCP=$DHCP
77 # the following are not set right, but not believed to matter
78 CIDRLEN=$CIDRLEN;
79 NETWORK=$NETWORK
80 EOF