summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/systemd-networkd-ext/module-setup.sh
blob: be50973d33c17e584fb07f4dbdcc6d6e70786d09 (plain) (blame)
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
#!/bin/bash
# shameless hacked version of dracut's systemd-networkd module
# called by dracut
check() {
	[[ $mount_needs ]] && return 1

	if dracut_module_included "network"; then
		derror "The module 'systemd-networkd' conflicts with 'network'. Use either one not both!"
		return 1
	fi
	return 255
}

# called by dracut
depends() {
	echo "systemd kernel-network-modules"
}

installkernel() {
	return 0
}

# called by dracut
install() {
	# need initqueue to get a clean network start
	dracut_need_initqueue

	# install required systemd units
	inst_multiple -o \
		$systemdutildir/systemd-networkd \
		$systemdutildir/systemd-networkd-wait-online \
		$systemdutildir/systemd-resolved \
		$systemdsystemunitdir/systemd-networkd-wait-online.service \
		$systemdsystemunitdir/systemd-networkd.service \
		$systemdsystemunitdir/systemd-networkd.socket \
		$systemdsystemunitdir/systemd-resolved.service \
		networkctl ip

	# active them
	for i in \
		systemd-networkd-wait-online.service \
		systemd-networkd.service \
		systemd-networkd.socket \
		systemd-resolved.service
	do
		systemctl --root "$initdir" enable "$i"
	done
	mkdir $initdir/$systemdsystemunitdir/network.target.wants
	ln -s $systemdsystemunitdir/systemd-resolved.service \
		$initdir/$systemdsystemunitdir/network.target.wants/systemd-resolved.service
	ln -sf /run/systemd/resolve/resolv.conf $initdir/etc/resolv.conf

	# create system users needed
	for user in \
		systemd-network \
		systemd-resolve
	do
		grep "^${user}:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
		grep "^${user}:" /etc/group >> "$initdir/etc/group"
	done

	# install basic dns libs
	_arch=$(uname -m)
	inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
					{"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" \
					{"tls/$_arch/",tls/,"$_arch/",}"libnss_myhostname.so.*" \
					{"tls/$_arch/",tls/,"$_arch/",}"libnss_resolve.so.*" \
					{"tls/$_arch/",tls/,"$_arch/",}"libresolve.so.*"

	# the hook script that will parse the "ip=" kernel command line
	# parameter and generate the .link and .network files needed
	# by systemd-networkd.
	inst_hook cmdline 10 "$moddir/hooks/parse-kcl-for-networkd.sh"
	inst_hook pre-pivot 10 "$moddir/hooks/copy-networkd-files-to-newroot.sh"
	inst_hook pre-pivot 20 "$moddir/hooks/configure-dhcp-for-newroot.sh"
}