]>
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 | |
7211773a LP |
17 | # On Fedora "ld" is (unfortunately — if you ask me) managed via |
18 | # "alternatives". Since we'd like to support building images in environments | |
19 | # with only /usr/ around (e.g. mkosi's UsrOnly=1 option), we have the problem | |
20 | # that /usr/bin/ld is a symlink that points to a non-existing file in | |
21 | # /etc/alternative/ in this mode. Let's work around this for now by manually | |
22 | # redirect "ld" to "ld.bfd", i.e. circumventing the /usr/bin/ld symlink. | |
23 | if [ ! -x /usr/bin/ld -a -x /usr/bin/ld.bfd ] ; then | |
24 | mkdir -p "$HOME"/bin | |
25 | ln -s /usr/bin/ld.bfd "$HOME"/bin/ld | |
26 | PATH="$HOME/bin:$PATH" | |
27 | fi | |
28 | ||
70e760e3 LP |
29 | # If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it |
30 | # as out-of-tree build dir. Otherwise, let's make up our own builddir. | |
31 | [ -z "$BUILDDIR" ] && BUILDDIR=build | |
32 | ||
2ea09665 FB |
33 | # Meson uses Python 3 and requires a locale with an UTF-8 character map. |
34 | # Not running under UTF-8 makes the `ninja test` step break with a CodecError. | |
35 | # So let's ensure we're running under UTF-8. | |
36 | # | |
37 | # If our current locale already is UTF-8, then we don't need to do anything: | |
5e577e17 | 38 | if [ "$(locale charmap 2> /dev/null)" != "UTF-8" ] ; then |
2ea09665 FB |
39 | # Try using C.UTF-8 locale, if available. This locale is not shipped |
40 | # by upstream glibc, so it's not available in all distros. | |
41 | # (In particular, it's not available in Arch Linux.) | |
5e577e17 DDM |
42 | if locale -a | grep -q -E "C.UTF-8|C.utf8"; then |
43 | export LC_CTYPE=C.UTF-8 | |
44 | # Finally, try something like en_US.UTF-8, which should be | |
45 | # available in Arch Linux, but is not present in Debian's | |
46 | # minimal image in our mkosi config. | |
47 | elif locale -a | grep -q en_US.utf8; then | |
2ea09665 | 48 | export LC_CTYPE=en_US.UTF-8 |
5e577e17 DDM |
49 | else |
50 | # If nothing works, fail early. | |
51 | echo "*** Could not find a valid locale that supports UTF-8. ***" >&2 | |
52 | exit 1 | |
2ea09665 FB |
53 | fi |
54 | fi | |
9400405b | 55 | |
c81a2569 LP |
56 | if [ ! -f "$BUILDDIR"/build.ninja ] ; then |
57 | sysvinit_path=`realpath /etc/init.d` | |
8da0592c | 58 | |
bac567a5 MK |
59 | init_path=`realpath /sbin/init 2>/dev/null` |
60 | if [ -z "$init_path" ] ; then | |
61 | rootprefix="" | |
62 | else | |
63 | rootprefix=${init_path%/lib/systemd/systemd} | |
64 | rootprefix=/${rootprefix#/} | |
65 | fi | |
66 | ||
c81a2569 LP |
67 | nobody_user=`id -u -n 65534 2> /dev/null` |
68 | if [ "$nobody_user" != "" ] ; then | |
69 | # Validate that we can translate forth and back | |
70 | if [ "`id -u $nobody_user`" != 65534 ] ; then | |
71 | nobody_user="" | |
72 | fi | |
c82ce4f2 | 73 | fi |
c81a2569 LP |
74 | if [ "$nobody_user" = "" ] ; then |
75 | if id -u nobody 2> /dev/null ; then | |
76 | # The "nobody" user is defined already for something else, pick the Fedora name | |
77 | nobody_user=nfsnobody | |
78 | else | |
79 | # The "nobody" user name is free, use it | |
80 | nobody_user=nobody | |
81 | fi | |
c82ce4f2 | 82 | fi |
c82ce4f2 | 83 | |
c81a2569 LP |
84 | nobody_group=`id -g -n 65534 2> /dev/null` |
85 | if [ "$nobody_group" != "" ] ; then | |
86 | # Validate that we can translate forth and back | |
87 | if [ "`id -g $nobody_group`" != 65534 ] ; then | |
88 | nobody_group="" | |
89 | fi | |
c82ce4f2 | 90 | fi |
c81a2569 LP |
91 | if [ "$nobody_group" = "" ] ; then |
92 | if id -u nobody 2> /dev/null ; then | |
93 | # The "nobody" group is defined already for something else, pick the Fedora name | |
94 | nobody_group=nfsnobody | |
95 | else | |
96 | # The "nobody" group name is free, use it | |
97 | nobody_group=nobody | |
98 | fi | |
c82ce4f2 | 99 | fi |
c81a2569 | 100 | |
db52af5a DDM |
101 | meson "$BUILDDIR" \ |
102 | -D "sysvinit-path=$sysvinit_path" \ | |
103 | -D "rootprefix=$rootprefix" \ | |
104 | -D man=false \ | |
105 | -D "nobody-user=$nobody_user" \ | |
106 | -D "nobody-group=$nobody_group" \ | |
ef1bd234 DDM |
107 | -D translations=false \ |
108 | -D version-tag="${VERSION_TAG}" | |
c82ce4f2 LP |
109 | fi |
110 | ||
c3e2dc71 | 111 | cd "$BUILDDIR" |
44bc7f4f | 112 | ninja "$@" |
ff549982 MK |
113 | if [ "$WITH_TESTS" = 1 ] ; then |
114 | for id in 1 2 3; do | |
1e48ef3f | 115 | getent group $id > /dev/null || groupadd -g $id testgroup$id |
ff549982 MK |
116 | done |
117 | ||
c3e2dc71 | 118 | ninja test |
ff549982 | 119 | fi |
c3e2dc71 | 120 | cd "$SRCDIR" |
fe2b7631 DDM |
121 | |
122 | # Ubuntu Focal is stuck with meson 0.53.0. | |
123 | if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then | |
2234c6a0 | 124 | meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed |
fe2b7631 | 125 | else |
2234c6a0 | 126 | meson install -C "$BUILDDIR" --no-rebuild --only-changed |
fe2b7631 | 127 | fi |
6344a7eb | 128 | |
70e760e3 | 129 | mkdir -p "$DESTDIR"/etc |
6344a7eb | 130 | |
70e760e3 | 131 | cat > "$DESTDIR"/etc/issue <<EOF |
6344a7eb LP |
132 | \S (built from systemd tree) |
133 | Kernel \r on an \m (\l) | |
134 | ||
135 | EOF | |
d10ba83a LP |
136 | |
137 | # Manually update the boot loader from the one we just built | |
138 | mkdir -p "$DESTDIR"/boot/efi/EFI/systemd "$DESTDIR"/boot/efi/EFI/BOOT | |
139 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/systemd/systemd-bootx64.efi | |
140 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/BOOT/bootx64.efi | |
1b14a4b0 LP |
141 | |
142 | mkdir -p "$DESTDIR"/efi/EFI/systemd "$DESTDIR"/efi/EFI/BOOT | |
143 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/systemd/systemd-bootx64.efi | |
144 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/BOOT/bootx64.efi |