]> git.ipfire.org Git - thirdparty/systemd.git/blame - mkosi.build
Merge pull request #22550 from medhefgo/boot-mixed
[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
7211773a
LP
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.
068d1338 14if [ ! -x /usr/bin/ld ] && [ -x /usr/bin/ld.bfd ]; then
7211773a
LP
15 mkdir -p "$HOME"/bin
16 ln -s /usr/bin/ld.bfd "$HOME"/bin/ld
17 PATH="$HOME/bin:$PATH"
18fi
19
70e760e3
LP
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
2ea09665
FB
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:
068d1338 29if [ "$(locale charmap 2>/dev/null)" != "UTF-8" ] ; then
2ea09665
FB
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.)
5e577e17
DDM
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
2ea09665 39 export LC_CTYPE=en_US.UTF-8
5e577e17
DDM
40 else
41 # If nothing works, fail early.
42 echo "*** Could not find a valid locale that supports UTF-8. ***" >&2
43 exit 1
2ea09665
FB
44 fi
45fi
9400405b 46
c81a2569 47if [ ! -f "$BUILDDIR"/build.ninja ] ; then
068d1338 48 sysvinit_path=$(realpath /etc/init.d)
8da0592c 49
068d1338 50 init_path=$(realpath /sbin/init 2>/dev/null)
bac567a5
MK
51 if [ -z "$init_path" ] ; then
52 rootprefix=""
53 else
54 rootprefix=${init_path%/lib/systemd/systemd}
55 rootprefix=/${rootprefix#/}
56 fi
57
db52af5a
DDM
58 meson "$BUILDDIR" \
59 -D "sysvinit-path=$sysvinit_path" \
60 -D "rootprefix=$rootprefix" \
61 -D man=false \
ef1bd234
DDM
62 -D translations=false \
63 -D version-tag="${VERSION_TAG}"
c82ce4f2
LP
64fi
65
c3e2dc71 66cd "$BUILDDIR"
44bc7f4f 67ninja "$@"
ff549982
MK
68if [ "$WITH_TESTS" = 1 ] ; then
69 for id in 1 2 3; do
068d1338 70 getent group $id >/dev/null || groupadd -g $id testgroup$id
ff549982
MK
71 done
72
c3e2dc71 73 ninja test
ff549982 74fi
c3e2dc71 75cd "$SRCDIR"
fe2b7631
DDM
76
77# Ubuntu Focal is stuck with meson 0.53.0.
78if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then
2234c6a0 79 meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
fe2b7631 80else
2234c6a0 81 meson install -C "$BUILDDIR" --no-rebuild --only-changed
fe2b7631 82fi
6344a7eb 83
70e760e3 84mkdir -p "$DESTDIR"/etc
6344a7eb 85
068d1338 86cat >"$DESTDIR"/etc/issue <<EOF
6344a7eb
LP
87\S (built from systemd tree)
88Kernel \r on an \m (\l)
89
90EOF
d10ba83a 91
f533cda5
LP
92if [ -n "$IMAGE_ID" ] ; then
93 mkdir -p "$DESTDIR"/usr/lib
94 sed -n \
95 -e '/^IMAGE_ID=/!p' \
068d1338 96 -e "\$aIMAGE_ID=$IMAGE_ID" <"/usr/lib/os-release" >"${DESTDIR}/usr/lib/os-release"
f533cda5
LP
97
98 OSRELEASEFILE="$DESTDIR"/usr/lib/os-release
99else
100 OSRELEASEFILE=/usr/lib/os-release
101fi
102
103
104if [ -n "$IMAGE_VERSION" ] ; then
105 mkdir -p "$DESTDIR"/usr/lib
106 sed -n \
107 -e '/^IMAGE_VERSION=/!p' \
068d1338 108 -e "\$aIMAGE_VERSION=$IMAGE_VERSION" <$OSRELEASEFILE >"/tmp/os-release.tmp"
f533cda5
LP
109
110 cat /tmp/os-release.tmp > "$DESTDIR"/usr/lib/os-release
111 rm /tmp/os-release.tmp
112fi
24acd406
FS
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
116if [ -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"
121fi