-
Notifications
You must be signed in to change notification settings - Fork 0
/
initrd-network_install
56 lines (51 loc) · 1.35 KB
/
initrd-network_install
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
#!/usr/bin/env bash
check_systemd_hook()
{
declare -F add_systemd_unit > /dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "systemd hook is not enabled; exit"
return 1
fi
}
check_network_file()
{
ls /etc/systemd/network/*.initramfs > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "network hook is enabled, but there are no .initramfs files under\
/etc/systemd/network; exit"
return 1
fi
}
add_network_user()
{
cat << EOF >> "${BUILDROOT}/etc/passwd"
systemd-network:x:1999:1999:systemd Network Management:/:/usr/bin/nologin
EOF
cat << EOF >> "${BUILDROOT}/etc/group"
systemd-network:x:1999:
EOF
cat << EOF >> "${BUILDROOT}/etc/shadow"
systemd-network:!*:18420::::::
EOF
}
build ()
{
check_systemd_hook || return 0
check_network_file || return 0
add_systemd_unit initrd-network.service
systemctl --root "${BUILDROOT}" enable initrd-network.service
add_network_user
mkdir -p "${BUILDROOT}/etc/systemd/network"
for network in /etc/systemd/network/*.initramfs; do
initramfs_strip=${network//\.initramfs/}
echo "Added ${network} to ${initramfs_strip}"
add_file "${network}" "${initramfs_strip}"
done
}
help ()
{
cat << EOF
This hook sets up the `systemd-networkd.service` systemd service and copies
over any `*.initramfs` files in `/etc/systemd/network`.
EOF
}