]> git.ipfire.org Git - thirdparty/systemd.git/blob - mkosi.build
units: don't install dbus-org.freedesktop.oom1.service alias
[thirdparty/systemd.git] / mkosi.build
1 #!/bin/sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
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
8 # On Fedora "ld" is (unfortunately — if you ask me) managed via
9 # "alternatives". Since we'd like to support building images in environments
10 # with only /usr/ around (e.g. mkosi's UsrOnly=1 option), we have the problem
11 # that /usr/bin/ld is a symlink that points to a non-existing file in
12 # /etc/alternative/ in this mode. Let's work around this for now by manually
13 # redirect "ld" to "ld.bfd", i.e. circumventing the /usr/bin/ld symlink.
14 if [ ! -x /usr/bin/ld ] && [ -x /usr/bin/ld.bfd ]; then
15 mkdir -p "$HOME"/bin
16 ln -s /usr/bin/ld.bfd "$HOME"/bin/ld
17 PATH="$HOME/bin:$PATH"
18 fi
19
20 # If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
21 # as out-of-tree build dir. Otherwise, let's make up our own builddir.
22 [ -z "$BUILDDIR" ] && BUILDDIR=build
23
24 # Meson uses Python 3 and requires a locale with an UTF-8 character map.
25 # Not running under UTF-8 makes the `ninja test` step break with a CodecError.
26 # So let's ensure we're running under UTF-8.
27 #
28 # If our current locale already is UTF-8, then we don't need to do anything:
29 if [ "$(locale charmap 2>/dev/null)" != "UTF-8" ] ; then
30 # Try using C.UTF-8 locale, if available. This locale is not shipped
31 # by upstream glibc, so it's not available in all distros.
32 # (In particular, it's not available in Arch Linux.)
33 if locale -a | grep -q -E "C.UTF-8|C.utf8"; then
34 export LC_CTYPE=C.UTF-8
35 # Finally, try something like en_US.UTF-8, which should be
36 # available in Arch Linux, but is not present in Debian's
37 # minimal image in our mkosi config.
38 elif locale -a | grep -q en_US.utf8; then
39 export LC_CTYPE=en_US.UTF-8
40 else
41 # If nothing works, fail early.
42 echo "*** Could not find a valid locale that supports UTF-8. ***" >&2
43 exit 1
44 fi
45 fi
46
47 if [ ! -f "$BUILDDIR"/build.ninja ] ; then
48 sysvinit_path=$(realpath /etc/init.d)
49
50 init_path=$(realpath /sbin/init 2>/dev/null)
51 if [ -z "$init_path" ] ; then
52 rootprefix=""
53 else
54 rootprefix=${init_path%/lib/systemd/systemd}
55 rootprefix=/${rootprefix#/}
56 fi
57
58 meson "$BUILDDIR" \
59 -D "sysvinit-path=$sysvinit_path" \
60 -D "rootprefix=$rootprefix" \
61 -D man=false \
62 -D translations=false \
63 -D version-tag="${VERSION_TAG}"
64 fi
65
66 cd "$BUILDDIR"
67 ninja "$@"
68 if [ "$WITH_TESTS" = 1 ] ; then
69 for id in 1 2 3; do
70 getent group $id >/dev/null || groupadd -g $id testgroup$id
71 done
72
73 ninja test
74 fi
75 cd "$SRCDIR"
76
77 # Ubuntu Focal is stuck with meson 0.53.0.
78 if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then
79 meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
80 else
81 meson install -C "$BUILDDIR" --no-rebuild --only-changed
82 fi
83
84 mkdir -p "$DESTDIR"/etc
85
86 cat >"$DESTDIR"/etc/issue <<EOF
87 \S (built from systemd tree)
88 Kernel \r on an \m (\l)
89
90 EOF
91
92 if [ -n "$IMAGE_ID" ] ; then
93 mkdir -p "$DESTDIR"/usr/lib
94 sed -n \
95 -e '/^IMAGE_ID=/!p' \
96 -e "\$aIMAGE_ID=$IMAGE_ID" <"/usr/lib/os-release" >"${DESTDIR}/usr/lib/os-release"
97
98 OSRELEASEFILE="$DESTDIR"/usr/lib/os-release
99 else
100 OSRELEASEFILE=/usr/lib/os-release
101 fi
102
103
104 if [ -n "$IMAGE_VERSION" ] ; then
105 mkdir -p "$DESTDIR"/usr/lib
106 sed -n \
107 -e '/^IMAGE_VERSION=/!p' \
108 -e "\$aIMAGE_VERSION=$IMAGE_VERSION" <$OSRELEASEFILE >"/tmp/os-release.tmp"
109
110 cat /tmp/os-release.tmp > "$DESTDIR"/usr/lib/os-release
111 rm /tmp/os-release.tmp
112 fi
113
114 # If $CI_BUILD is set, copy over the CI service which executes a service check
115 # after boot and then shuts down the machine
116 if [ -n "$CI_BUILD" ]; then
117 mkdir -p "$DESTDIR/usr/lib/systemd/system"
118 cp -v "$SRCDIR/test/mkosi-check-and-shutdown.service" "$DESTDIR/usr/lib/systemd/system/mkosi-check-and-shutdown.service"
119 cp -v "$SRCDIR/test/mkosi-check-and-shutdown.sh" "$DESTDIR/usr/lib/systemd/mkosi-check-and-shutdown.sh"
120 chmod +x "$DESTDIR/usr/lib/systemd/mkosi-check-and-shutdown.sh"
121 fi