]>
Commit | Line | Data |
---|---|---|
7629744a | 1 | #!/bin/sh |
1394a3ec | 2 | set -e |
1b0ff615 | 3 | |
1b0ff615 LP |
4 | # This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi). |
5 | # Simply invoke "mkosi" in the project directory to build an OS image. | |
6 | ||
b454cfb0 FB |
7 | # Reset the permissions of the tree. Since Meson keeps the permissions |
8 | # all the way to the installed files, reset them to one of 0644 or 0755 | |
9 | # so the files keep those permissions, otherwise details of what umask | |
10 | # was set at the time the git tree was cloned will leak all the way | |
11 | # through. Also set umask explicitly during the build. | |
e2ebc406 DDM |
12 | if ! mountpoint -q "$SRCDIR"; then |
13 | chmod -R u+w,go-w,a+rX . | |
14 | umask 022 | |
15 | fi | |
b454cfb0 | 16 | |
70e760e3 LP |
17 | # If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it |
18 | # as out-of-tree build dir. Otherwise, let's make up our own builddir. | |
19 | [ -z "$BUILDDIR" ] && BUILDDIR=build | |
20 | ||
2ea09665 FB |
21 | # Meson uses Python 3 and requires a locale with an UTF-8 character map. |
22 | # Not running under UTF-8 makes the `ninja test` step break with a CodecError. | |
23 | # So let's ensure we're running under UTF-8. | |
24 | # | |
25 | # If our current locale already is UTF-8, then we don't need to do anything: | |
5e577e17 | 26 | if [ "$(locale charmap 2> /dev/null)" != "UTF-8" ] ; then |
2ea09665 FB |
27 | # Try using C.UTF-8 locale, if available. This locale is not shipped |
28 | # by upstream glibc, so it's not available in all distros. | |
29 | # (In particular, it's not available in Arch Linux.) | |
5e577e17 DDM |
30 | if locale -a | grep -q -E "C.UTF-8|C.utf8"; then |
31 | export LC_CTYPE=C.UTF-8 | |
32 | # Finally, try something like en_US.UTF-8, which should be | |
33 | # available in Arch Linux, but is not present in Debian's | |
34 | # minimal image in our mkosi config. | |
35 | elif locale -a | grep -q en_US.utf8; then | |
2ea09665 | 36 | export LC_CTYPE=en_US.UTF-8 |
5e577e17 DDM |
37 | else |
38 | # If nothing works, fail early. | |
39 | echo "*** Could not find a valid locale that supports UTF-8. ***" >&2 | |
40 | exit 1 | |
2ea09665 FB |
41 | fi |
42 | fi | |
9400405b | 43 | |
c81a2569 LP |
44 | if [ ! -f "$BUILDDIR"/build.ninja ] ; then |
45 | sysvinit_path=`realpath /etc/init.d` | |
8da0592c | 46 | |
bac567a5 MK |
47 | init_path=`realpath /sbin/init 2>/dev/null` |
48 | if [ -z "$init_path" ] ; then | |
49 | rootprefix="" | |
50 | else | |
51 | rootprefix=${init_path%/lib/systemd/systemd} | |
52 | rootprefix=/${rootprefix#/} | |
53 | fi | |
54 | ||
c81a2569 LP |
55 | nobody_user=`id -u -n 65534 2> /dev/null` |
56 | if [ "$nobody_user" != "" ] ; then | |
57 | # Validate that we can translate forth and back | |
58 | if [ "`id -u $nobody_user`" != 65534 ] ; then | |
59 | nobody_user="" | |
60 | fi | |
c82ce4f2 | 61 | fi |
c81a2569 LP |
62 | if [ "$nobody_user" = "" ] ; then |
63 | if id -u nobody 2> /dev/null ; then | |
64 | # The "nobody" user is defined already for something else, pick the Fedora name | |
65 | nobody_user=nfsnobody | |
66 | else | |
67 | # The "nobody" user name is free, use it | |
68 | nobody_user=nobody | |
69 | fi | |
c82ce4f2 | 70 | fi |
c82ce4f2 | 71 | |
c81a2569 LP |
72 | nobody_group=`id -g -n 65534 2> /dev/null` |
73 | if [ "$nobody_group" != "" ] ; then | |
74 | # Validate that we can translate forth and back | |
75 | if [ "`id -g $nobody_group`" != 65534 ] ; then | |
76 | nobody_group="" | |
77 | fi | |
c82ce4f2 | 78 | fi |
c81a2569 LP |
79 | if [ "$nobody_group" = "" ] ; then |
80 | if id -u nobody 2> /dev/null ; then | |
81 | # The "nobody" group is defined already for something else, pick the Fedora name | |
82 | nobody_group=nfsnobody | |
83 | else | |
84 | # The "nobody" group name is free, use it | |
85 | nobody_group=nobody | |
86 | fi | |
c82ce4f2 | 87 | fi |
c81a2569 | 88 | |
db52af5a DDM |
89 | meson "$BUILDDIR" \ |
90 | -D "sysvinit-path=$sysvinit_path" \ | |
91 | -D "rootprefix=$rootprefix" \ | |
92 | -D man=false \ | |
93 | -D "nobody-user=$nobody_user" \ | |
94 | -D "nobody-group=$nobody_group" \ | |
ef1bd234 DDM |
95 | -D translations=false \ |
96 | -D version-tag="${VERSION_TAG}" | |
c82ce4f2 LP |
97 | fi |
98 | ||
c3e2dc71 | 99 | cd "$BUILDDIR" |
44bc7f4f | 100 | ninja "$@" |
ff549982 MK |
101 | if [ "$WITH_TESTS" = 1 ] ; then |
102 | for id in 1 2 3; do | |
1e48ef3f | 103 | getent group $id > /dev/null || groupadd -g $id testgroup$id |
ff549982 MK |
104 | done |
105 | ||
c3e2dc71 | 106 | ninja test |
ff549982 | 107 | fi |
c3e2dc71 | 108 | cd "$SRCDIR" |
fe2b7631 DDM |
109 | |
110 | # Ubuntu Focal is stuck with meson 0.53.0. | |
111 | if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then | |
2234c6a0 | 112 | meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed |
fe2b7631 | 113 | else |
2234c6a0 | 114 | meson install -C "$BUILDDIR" --no-rebuild --only-changed |
fe2b7631 | 115 | fi |
6344a7eb | 116 | |
70e760e3 | 117 | mkdir -p "$DESTDIR"/etc |
6344a7eb | 118 | |
70e760e3 | 119 | cat > "$DESTDIR"/etc/issue <<EOF |
6344a7eb LP |
120 | \S (built from systemd tree) |
121 | Kernel \r on an \m (\l) | |
122 | ||
123 | EOF | |
d10ba83a LP |
124 | |
125 | # Manually update the boot loader from the one we just built | |
126 | mkdir -p "$DESTDIR"/boot/efi/EFI/systemd "$DESTDIR"/boot/efi/EFI/BOOT | |
127 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/systemd/systemd-bootx64.efi | |
128 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/BOOT/bootx64.efi | |
1b14a4b0 LP |
129 | |
130 | mkdir -p "$DESTDIR"/efi/EFI/systemd "$DESTDIR"/efi/EFI/BOOT | |
131 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/systemd/systemd-bootx64.efi | |
132 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/BOOT/bootx64.efi |