]> git.ipfire.org Git - thirdparty/systemd.git/blame - mkosi.build
mkosi: add back packages removed from OpenSUSE build
[thirdparty/systemd.git] / mkosi.build
CommitLineData
7629744a 1#!/bin/sh
8f5bcd61 2# SPDX-License-Identifier: LGPL-2.1-or-later
1394a3ec 3set -e
1b0ff615 4
1b0ff615
LP
5# This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
6# Simply invoke "mkosi" in the project directory to build an OS image.
7
69d638e6
DDM
8ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:disable_coredump=0:use_madv_dontdump=1
9UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1
10
7211773a
LP
11# On Fedora "ld" is (unfortunately — if you ask me) managed via
12# "alternatives". Since we'd like to support building images in environments
13# with only /usr/ around (e.g. mkosi's UsrOnly=1 option), we have the problem
14# that /usr/bin/ld is a symlink that points to a non-existing file in
15# /etc/alternative/ in this mode. Let's work around this for now by manually
16# redirect "ld" to "ld.bfd", i.e. circumventing the /usr/bin/ld symlink.
068d1338 17if [ ! -x /usr/bin/ld ] && [ -x /usr/bin/ld.bfd ]; then
7211773a
LP
18 mkdir -p "$HOME"/bin
19 ln -s /usr/bin/ld.bfd "$HOME"/bin/ld
20 PATH="$HOME/bin:$PATH"
21fi
22
70e760e3
LP
23# If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
24# as out-of-tree build dir. Otherwise, let's make up our own builddir.
25[ -z "$BUILDDIR" ] && BUILDDIR=build
26
2ea09665
FB
27# Meson uses Python 3 and requires a locale with an UTF-8 character map.
28# Not running under UTF-8 makes the `ninja test` step break with a CodecError.
29# So let's ensure we're running under UTF-8.
30#
31# If our current locale already is UTF-8, then we don't need to do anything:
068d1338 32if [ "$(locale charmap 2>/dev/null)" != "UTF-8" ] ; then
2ea09665
FB
33 # Try using C.UTF-8 locale, if available. This locale is not shipped
34 # by upstream glibc, so it's not available in all distros.
35 # (In particular, it's not available in Arch Linux.)
5e577e17
DDM
36 if locale -a | grep -q -E "C.UTF-8|C.utf8"; then
37 export LC_CTYPE=C.UTF-8
38 # Finally, try something like en_US.UTF-8, which should be
39 # available in Arch Linux, but is not present in Debian's
40 # minimal image in our mkosi config.
41 elif locale -a | grep -q en_US.utf8; then
2ea09665 42 export LC_CTYPE=en_US.UTF-8
5e577e17
DDM
43 else
44 # If nothing works, fail early.
45 echo "*** Could not find a valid locale that supports UTF-8. ***" >&2
46 exit 1
2ea09665
FB
47 fi
48fi
9400405b 49
37d35150
DDM
50# The bpftool script shipped by Ubuntu tries to find the actual program to run via querying `uname -r` and
51# using the current kernel version. This obviously doesn't work in containers. As a workaround, we override
52# the ubuntu script with a symlink to the first bpftool program we can find.
53for bpftool in /usr/lib/linux-tools/*/bpftool; do
54 [ -x "$bpftool" ] || continue
55 ln -sf "$bpftool" /usr/sbin/bpftool
56 break
57done
58
c81a2569 59if [ ! -f "$BUILDDIR"/build.ninja ] ; then
068d1338 60 sysvinit_path=$(realpath /etc/init.d)
8da0592c 61
068d1338 62 init_path=$(realpath /sbin/init 2>/dev/null)
bac567a5 63 if [ -z "$init_path" ] ; then
2401c9ac 64 rootprefix=""
bac567a5 65 else
2401c9ac
DDM
66 rootprefix=${init_path%/lib/systemd/systemd}
67 rootprefix=/${rootprefix#/}
bac567a5
MK
68 fi
69
db52af5a
DDM
70 meson "$BUILDDIR" \
71 -D "sysvinit-path=$sysvinit_path" \
72 -D "rootprefix=$rootprefix" \
73 -D man=false \
ef1bd234 74 -D translations=false \
c0daae3a 75 -D version-tag="${VERSION_TAG}" \
69d638e6 76 -D mode=developer \
819a2502 77 -D b_sanitize="${SANITIZERS:-none}" \
37d35150
DDM
78 -D install-tests=true \
79 -D tests=unsafe \
80 -D slow-tests=true \
81 -D utmp=true \
82 -D hibernate=true \
83 -D ldconfig=true \
84 -D resolve=true \
85 -D efi=true \
86 -D tpm=true \
87 -D environment-d=true \
88 -D binfmt=true \
89 -D repart=true \
90 -D sysupdate=true \
91 -D coredump=true \
92 -D pstore=true \
93 -D oomd=true \
94 -D logind=true \
95 -D hostnamed=true \
96 -D localed=true \
97 -D machined=true \
98 -D portabled=true \
99 -D sysext=true \
100 -D userdb=true \
101 -D homed=true \
102 -D networkd=true \
103 -D timedated=true \
104 -D timesyncd=true \
105 -D remote=true \
106 -D nss-myhostname=true \
107 -D nss-mymachines=true \
108 -D nss-resolve=true \
109 -D nss-systemd=true \
110 -D firstboot=true \
111 -D randomseed=true \
112 -D backlight=true \
113 -D vconsole=true \
114 -D quotacheck=true \
115 -D sysusers=true \
116 -D tmpfiles=true \
117 -D importd=true \
118 -D hwdb=true \
119 -D rfkill=true \
120 -D xdg-autostart=true \
121 -D translations=true \
122 -D polkit=true \
123 -D acl=true \
124 -D audit=true \
125 -D blkid=true \
126 -D fdisk=true \
127 -D kmod=true \
128 -D pam=true \
129 -D pwquality=true \
130 -D microhttpd=true \
131 -D libcryptsetup=true \
132 -D libcurl=true \
133 -D idn=true \
134 -D libidn2=true \
135 -D qrencode=true \
136 -D gcrypt=true \
137 -D gnutls=true \
138 -D openssl=true \
139 -D cryptolib=openssl \
140 -D p11kit=true \
141 -D libfido2=true \
142 -D tpm2=true \
143 -D elfutils=true \
144 -D zstd=true \
145 -D xkbcommon=true \
146 -D pcre2=true \
147 -D glib=true \
148 -D dbus=true \
149 -D gnu-efi=true \
150 -D kernel-install=true \
151 -D analyze=true \
152 -D bpf-framework=true
c82ce4f2
LP
153fi
154
c3e2dc71 155cd "$BUILDDIR"
44bc7f4f 156ninja "$@"
ff549982
MK
157if [ "$WITH_TESTS" = 1 ] ; then
158 for id in 1 2 3; do
80c2f3e4 159 getent group $id >/dev/null || echo "g testgroup$id $id -" | ./systemd-sysusers -
ff549982
MK
160 done
161
69d638e6
DDM
162 if [ -n "$SANITIZERS" ]; then
163 export ASAN_OPTIONS="$ASAN_OPTIONS"
164 export UBSAN_OPTIONS="$UBSAN_OPTIONS"
165 TIMEOUT_MULTIPLIER=3
166 else
167 TIMEOUT_MULTIPLIER=1
168 fi
169
de9b57a1 170 meson test --print-errorlogs --timeout-multiplier=$TIMEOUT_MULTIPLIER
ff549982 171fi
c3e2dc71 172cd "$SRCDIR"
fe2b7631
DDM
173
174# Ubuntu Focal is stuck with meson 0.53.0.
175if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then
2234c6a0 176 meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
fe2b7631 177else
2234c6a0 178 meson install -C "$BUILDDIR" --no-rebuild --only-changed
fe2b7631 179fi
6344a7eb 180
70e760e3 181mkdir -p "$DESTDIR"/etc
6344a7eb 182
068d1338 183cat >"$DESTDIR"/etc/issue <<EOF
6344a7eb
LP
184\S (built from systemd tree)
185Kernel \r on an \m (\l)
186
187EOF
d10ba83a 188
f533cda5 189if [ -n "$IMAGE_ID" ] ; then
2401c9ac
DDM
190 mkdir -p "$DESTDIR"/usr/lib
191 sed -n \
192 -e '/^IMAGE_ID=/!p' \
193 -e "\$aIMAGE_ID=$IMAGE_ID" <"/usr/lib/os-release" >"${DESTDIR}/usr/lib/os-release"
f533cda5 194
2401c9ac 195 OSRELEASEFILE="$DESTDIR"/usr/lib/os-release
f533cda5 196else
2401c9ac 197 OSRELEASEFILE=/usr/lib/os-release
f533cda5
LP
198fi
199
200
201if [ -n "$IMAGE_VERSION" ] ; then
2401c9ac
DDM
202 mkdir -p "$DESTDIR"/usr/lib
203 sed -n \
204 -e '/^IMAGE_VERSION=/!p' \
205 -e "\$aIMAGE_VERSION=$IMAGE_VERSION" <$OSRELEASEFILE >"/tmp/os-release.tmp"
f533cda5 206
2401c9ac
DDM
207 cat /tmp/os-release.tmp > "$DESTDIR"/usr/lib/os-release
208 rm /tmp/os-release.tmp
f533cda5 209fi
24acd406
FS
210
211# If $CI_BUILD is set, copy over the CI service which executes a service check
212# after boot and then shuts down the machine
213if [ -n "$CI_BUILD" ]; then
2401c9ac
DDM
214 mkdir -p "$DESTDIR/usr/lib/systemd/system"
215 cp -v "$SRCDIR/test/mkosi-check-and-shutdown.service" "$DESTDIR/usr/lib/systemd/system/mkosi-check-and-shutdown.service"
216 cp -v "$SRCDIR/test/mkosi-check-and-shutdown.sh" "$DESTDIR/usr/lib/systemd/mkosi-check-and-shutdown.sh"
217 chmod +x "$DESTDIR/usr/lib/systemd/mkosi-check-and-shutdown.sh"
24acd406 218fi
69d638e6
DDM
219
220if [ -n "$SANITIZERS" ]; then
221 LD_PRELOAD=$(ldd $BUILDDIR/systemd | grep libasan.so | awk '{print $3}')
222
223 mkdir -p "$DESTDIR/etc/systemd/system.conf.d"
224
225 cat > "$DESTDIR/etc/systemd/system.conf.d/10-asan.conf" <<EOF
226[Manager]
227ManagerEnvironment=ASAN_OPTIONS=$ASAN_OPTIONS\\
228 UBSAN_OPTIONS=$UBSAN_OPTIONS\\
229 LD_PRELOAD=$LD_PRELOAD
230DefaultEnvironment=ASAN_OPTIONS=$ASAN_OPTIONS\\
231 UBSAN_OPTIONS=$UBSAN_OPTIONS\\
232 LD_PRELOAD=$LD_PRELOAD
233EOF
234
235 # ASAN logs to stderr by default. However, journald's stderr is connected to /dev/null, so we lose
236 # all the ASAN logs. To rectify that, let's connect journald's stdout to the console so that any
237 # sanitizer failures appear directly on the user's console.
238 mkdir -p "$DESTDIR/etc/systemd/system/systemd-journald.service.d"
239
240 cat > "$DESTDIR/etc/systemd/system/systemd-journald.service.d/10-stdout-tty.conf" <<EOF
241[Service]
242StandardOutput=tty
243EOF
244
245 # Both systemd and util-linux's login call vhangup() on /dev/console which disconnects all users.
246 # This means systemd-journald can't log to /dev/console even if we configure `StandardOutput=tty`. As
247 # a workaround, we modify console-getty.service to disable systemd's vhangup() and disallow login
248 # from calling vhangup() so that journald's ASAN logs correctly end up in the console.
249
250 mkdir -p "$DESTDIR/etc/systemd/system/console-getty.service.d"
251
252 cat > "$DESTDIR/etc/systemd/system/console-getty.service.d/10-no-vhangup.conf" <<EOF
253[Service]
254TTYVHangup=no
255CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
256EOF
257fi
37d35150
DDM
258
259# Make sure services aren't enabled by default on Debian/Ubuntu.
260mkdir -p "$DESTDIR/etc/systemd/system-preset"
261echo "disable *" > "$DESTDIR/etc/systemd/system-preset/99-mkosi.preset"