]>
Commit | Line | Data |
---|---|---|
7629744a | 1 | #!/bin/sh |
8f5bcd61 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
1394a3ec | 3 | set -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 | 14 | if [ ! -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" | |
18 | fi | |
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 | 29 | if [ "$(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 |
45 | fi | |
9400405b | 46 | |
c81a2569 | 47 | if [ ! -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 |
64 | fi |
65 | ||
c3e2dc71 | 66 | cd "$BUILDDIR" |
44bc7f4f | 67 | ninja "$@" |
ff549982 MK |
68 | if [ "$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 | 74 | fi |
c3e2dc71 | 75 | cd "$SRCDIR" |
fe2b7631 DDM |
76 | |
77 | # Ubuntu Focal is stuck with meson 0.53.0. | |
78 | if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then | |
2234c6a0 | 79 | meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed |
fe2b7631 | 80 | else |
2234c6a0 | 81 | meson install -C "$BUILDDIR" --no-rebuild --only-changed |
fe2b7631 | 82 | fi |
6344a7eb | 83 | |
70e760e3 | 84 | mkdir -p "$DESTDIR"/etc |
6344a7eb | 85 | |
068d1338 | 86 | cat >"$DESTDIR"/etc/issue <<EOF |
6344a7eb LP |
87 | \S (built from systemd tree) |
88 | Kernel \r on an \m (\l) | |
89 | ||
90 | EOF | |
d10ba83a | 91 | |
f533cda5 LP |
92 | if [ -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 | |
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' \ | |
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 | |
112 | fi | |
113 | ||
d10ba83a LP |
114 | # Manually update the boot loader from the one we just built |
115 | mkdir -p "$DESTDIR"/boot/efi/EFI/systemd "$DESTDIR"/boot/efi/EFI/BOOT | |
116 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/systemd/systemd-bootx64.efi | |
117 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/BOOT/bootx64.efi | |
1b14a4b0 LP |
118 | |
119 | mkdir -p "$DESTDIR"/efi/EFI/systemd "$DESTDIR"/efi/EFI/BOOT | |
120 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/systemd/systemd-bootx64.efi | |
121 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/BOOT/bootx64.efi |