@@ -8,10 +8,11 @@ export LC_ALL=C
8
8
# # Helper functions
9
9
# is_lxc_container succeeds if we're running inside a LXC container
10
10
is_lxc_container () {
11
- grep -qa container=lxc /proc/1/environ
11
+ grep -q --text container=lxc /proc/1/environ
12
12
}
13
13
14
14
is_lxc_privileged_container () {
15
+ # The full positive 32-bit range is available
15
16
grep -qw 4294967295$ /proc/self/uid_map
16
17
}
17
18
@@ -40,9 +41,10 @@ is_in_path() {
40
41
fix_ro_paths () {
41
42
mkdir -p " /run/systemd/system/$1 .d"
42
43
cat << -EOF > "/run/systemd/system/$1 .d/zzz-lxc-ropath.conf"
43
- [Service]
44
- BindReadOnlyPaths=/sys /proc
45
- EOF
44
+ # This file was created by distrobuilder
45
+ [Service]
46
+ BindReadOnlyPaths=/sys /proc
47
+ EOF
46
48
}
47
49
48
50
# fix_nm_link_state forces the network interface to a DOWN state ahead of NetworkManager starting up
@@ -57,19 +59,22 @@ fix_nm_link_state() {
57
59
return 0
58
60
fi
59
61
cat << -EOF > /run/systemd/system/network-device-down.service
60
- [Unit]
61
- Description=Turn off network device
62
- Before=NetworkManager.service
63
- Before=systemd-networkd.service
64
- [Service]
65
- # do not turn off if there is a default route to 169.254.0.1, i.e. the device is a routed nic
66
- ExecCondition=/bin/sh -c '! /usr/bin/grep -qs 00000000.0100FEA9 /proc/net/route'
67
- ExecStart=-${ip_path} link set $1 down
68
- Type=oneshot
69
- RemainAfterExit=true
70
- [Install]
71
- WantedBy=default.target
72
- EOF
62
+ # This file was created by distrobuilder
63
+ [Unit]
64
+ Description=Turn off network device
65
+ Before=NetworkManager.service
66
+ Before=systemd-networkd.service
67
+
68
+ [Service]
69
+ # do not turn off if there is a default route to 169.254.0.1, i.e. the device is a routed nic
70
+ ExecCondition=/bin/sh -c '! /usr/bin/grep -qs 00000000.0100FEA9 /proc/net/route'
71
+ ExecStart=-${ip_path} link set $1 down
72
+ Type=oneshot
73
+ RemainAfterExit=true
74
+
75
+ [Install]
76
+ WantedBy=default.target
77
+ EOF
73
78
mkdir -p /run/systemd/system/default.target.wants
74
79
ln -sf /run/systemd/system/network-device-down.service /run/systemd/system/default.target.wants/network-device-down.service
75
80
}
@@ -125,11 +130,12 @@ fix_systemd_udev_trigger() {
125
130
126
131
mkdir -p /run/systemd/system/systemd-udev-trigger.service.d
127
132
cat << -EOF > /run/systemd/system/systemd-udev-trigger.service.d/zzz-lxc-override.conf
128
- [Service]
129
- ExecStart=
130
- ExecStart=-${cmd} trigger --type=subsystems --action=add
131
- ExecStart=-${cmd} trigger --type=devices --action=add
132
- EOF
133
+ # This file was created by distrobuilder
134
+ [Service]
135
+ ExecStart=
136
+ ExecStart=-${cmd} trigger --type=subsystems --action=add
137
+ ExecStart=-${cmd} trigger --type=devices --action=add
138
+ EOF
133
139
}
134
140
135
141
# fix_systemd_sysctl overrides the systemd-sysctl.service to use "ExecStart=-" instead of "ExecStart=".
@@ -138,10 +144,11 @@ fix_systemd_sysctl() {
138
144
! [ -e " ${cmd} " ] && cmd=/lib/systemd/systemd-sysctl
139
145
mkdir -p /run/systemd/system/systemd-sysctl.service.d
140
146
cat << -EOF > /run/systemd/system/systemd-sysctl.service.d/zzz-lxc-override.conf
141
- [Service]
142
- ExecStart=
143
- ExecStart=-${cmd}
144
- EOF
147
+ # This file was created by distrobuilder
148
+ [Service]
149
+ ExecStart=
150
+ ExecStart=-${cmd}
151
+ EOF
145
152
}
146
153
147
154
# # Main logic
167
174
# Determine distro name and release
168
175
ID=" "
169
176
if [ -e /etc/os-release ]; then
177
+ # shellcheck disable=SC1091
170
178
. /etc/os-release
171
179
fi
172
180
211
219
if [ -d /etc/udev ]; then
212
220
mkdir -p /run/udev/rules.d
213
221
cat << -EOF > /run/udev/rules.d/90-lxc-net.rules
214
- # This file was created by distrobuilder.
215
- #
216
- # Its purpose is to convince NetworkManager to treat the eth0 veth
217
- # interface like a regular Ethernet. NetworkManager ordinarily doesn't
218
- # like to manage the veth interfaces, because they are typically configured
219
- # by container management tooling for specialized purposes.
220
-
221
- ACTION=="add|change|move", ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="eth[0-9]*", ENV{NM_UNMANAGED}="0"
222
- EOF
222
+ # This file was created by distrobuilder.
223
+ #
224
+ # Its purpose is to convince NetworkManager to treat the eth0 veth
225
+ # interface like a regular Ethernet. NetworkManager ordinarily doesn't
226
+ # like to manage the veth interfaces, because they are typically configured
227
+ # by container management tooling for specialized purposes.
228
+
229
+ ACTION=="add|change|move", ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="eth[0-9]*", ENV{NM_UNMANAGED}="0"
230
+ EOF
223
231
fi
224
232
225
233
# Workarounds for NetworkManager in containers
0 commit comments