File: cloud-initramfs-dyn-netconf

package info (click to toggle)
cloud-initramfs-tools 0.18.debian8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 240 kB
  • sloc: sh: 852; makefile: 33
file content (90 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
set -e

PREREQS=""
case $1 in
	prereqs) echo "${PREREQS}"; exit 0;;
esac

. /scripts/functions

PATH=/usr/sbin:/usr/bin:/sbin:/bin

# doc in klibc-utils /usr/share/doc/libklibc/README.ipconfig.gz
# example below:
#DEVICE='eth0'
#PROTO='dhcp'                    ## none, off, static. not present in precise
#IPV4ADDR='192.168.122.89'
#IPV4BROADCAST='192.168.122.255'
#IPV4NETMASK='255.255.255.0'
#IPV4GATEWAY='192.168.122.1'
#IPV4DNS0='192.168.122.1'        ## only come from dhcp
#IPV4DNS1='0.0.0.0'
#HOSTNAME=''
#DNSDOMAIN=''
#NISDOMAIN=''
#ROOTSERVER='192.168.122.1'
#ROOTPATH=''
#filename=''
#UPTIME='21'
#DHCPLEASETIME='3600'
#DOMAINSEARCH=''

error() { echo "${0##*/}:" "$@" 1>&2; }
tmpf="/tmp/${0##*/}.ni"

{
echo "## This file is generated by cloud-initramfs-dyn-netconf"
echo "auto lo"
echo "iface lo inet loopback"
} > "$tmpf"

seen=","
for f in /run/net-*.conf /tmp/net-*.conf; do
	[ -f "$f" ] || continue
	dev=${f#*/net-}; dev=${dev%.conf};
	# perhaps we saw this device from /run and now we're in /tmp
	[ "${seen#*,${dev},}" = "${seen}" ] || continue

	seen="${seen}${dev},"

	DEVICE=""; PROTO=""; IPV4ADDR=""; IPV4NETMASK=""; IPV4GATEWAY="";
	IPV4DNS0=""; IPV4DNS1=""; DNSDOMAIN=""; DOMAINSEARCH=""; filename="";
	. "$f"

	if [ -z "$DEVICE" ]; then
		error "WARNING: $f had no 'DEVICE' set"
		continue
	fi
	# ipconfig on precise does not write PROTO.
	if [ -z "$PROTO" ]; then
		if [ -n "$filename" ]; then
			PROTO="dhcp"
		else
			PROTO="static"
		fi
	fi

	echo "manual $DEVICE"
	if [ "$PROTO" = "dhcp" ]; then
		echo "iface $DEVICE inet dhcp"
	elif [ "$PROTO" = "static" ]; then
		echo "iface $DEVICE inet static"
		[ -n "$IPV4ADDR" ] && printf "\t%s\n" "address $IPV4ADDR"
		[ -n "$IPV4NETMASK" ] && printf "\t%s\n" "netmask $IPV4NETMASK"
		[ -n "$IPV4GATEWAY" ] && printf "\t%s\n" "gateway $IPV4GATEWAY"
	fi
	if [ -n "$IPV4DNS0" -a "$IPV4DNS0" != "0.0.0.0" ]; then
		nsline="dns-nameservers ${IPV4DNS0}"
		[ -n "$IPV4DNS1" -a "$IPV4DNS1" != "0.0.0.0" ] &&
			nsline="${nsline} ${IPV4DNS1}"
		printf "\t%s\n" "$nsline"
	fi
	[ -n "$DNSDOMAIN" -o -n "$DOMAINSEARCH" ] &&
		printf "\t%s\n" "dns-search ${DNSDOMAIN} ${DOMAINSEARCH}"
done >> "$tmpf"

[ -d /run/network ] || mkdir /run/network
mv "$tmpf" /run/network/dynamic-interfaces

# vi: ts=4 noexpandtab