]>
Commit | Line | Data |
---|---|---|
7629744a | 1 | #!/bin/sh |
2 | set -ex | |
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. | |
12 | chmod -R u+w,go-w,a+rX . | |
13 | umask 022 | |
14 | ||
70e760e3 LP |
15 | # If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it |
16 | # as out-of-tree build dir. Otherwise, let's make up our own builddir. | |
17 | [ -z "$BUILDDIR" ] && BUILDDIR=build | |
18 | ||
2ea09665 FB |
19 | # Meson uses Python 3 and requires a locale with an UTF-8 character map. |
20 | # Not running under UTF-8 makes the `ninja test` step break with a CodecError. | |
21 | # So let's ensure we're running under UTF-8. | |
22 | # | |
23 | # If our current locale already is UTF-8, then we don't need to do anything: | |
24 | if [ "$(locale charmap)" != "UTF-8" ] ; then | |
25 | # Try using C.UTF-8 locale, if available. This locale is not shipped | |
26 | # by upstream glibc, so it's not available in all distros. | |
27 | # (In particular, it's not available in Arch Linux.) | |
28 | export LC_CTYPE=C.UTF-8 | |
29 | if [ "$(locale charmap)" != "UTF-8" ] ; then | |
30 | # Finally, try something like en_US.UTF-8, which should be | |
31 | # available in Arch Linux, but is not present in Debian's | |
32 | # minimal image in our mkosi config. | |
33 | export LC_CTYPE=en_US.UTF-8 | |
34 | if [ "$(locale charmap)" != "UTF-8" ] ; then | |
35 | # If nothing works, fail early. | |
36 | echo "*** Could not find a valid locale that supports UTF-8. ***" >&2 | |
37 | exit 1 | |
38 | fi | |
39 | fi | |
40 | fi | |
9400405b | 41 | |
c81a2569 LP |
42 | if [ ! -f "$BUILDDIR"/build.ninja ] ; then |
43 | sysvinit_path=`realpath /etc/init.d` | |
8da0592c | 44 | |
c81a2569 LP |
45 | nobody_user=`id -u -n 65534 2> /dev/null` |
46 | if [ "$nobody_user" != "" ] ; then | |
47 | # Validate that we can translate forth and back | |
48 | if [ "`id -u $nobody_user`" != 65534 ] ; then | |
49 | nobody_user="" | |
50 | fi | |
c82ce4f2 | 51 | fi |
c81a2569 LP |
52 | if [ "$nobody_user" = "" ] ; then |
53 | if id -u nobody 2> /dev/null ; then | |
54 | # The "nobody" user is defined already for something else, pick the Fedora name | |
55 | nobody_user=nfsnobody | |
56 | else | |
57 | # The "nobody" user name is free, use it | |
58 | nobody_user=nobody | |
59 | fi | |
c82ce4f2 | 60 | fi |
c82ce4f2 | 61 | |
c81a2569 LP |
62 | nobody_group=`id -g -n 65534 2> /dev/null` |
63 | if [ "$nobody_group" != "" ] ; then | |
64 | # Validate that we can translate forth and back | |
65 | if [ "`id -g $nobody_group`" != 65534 ] ; then | |
66 | nobody_group="" | |
67 | fi | |
c82ce4f2 | 68 | fi |
c81a2569 LP |
69 | if [ "$nobody_group" = "" ] ; then |
70 | if id -u nobody 2> /dev/null ; then | |
71 | # The "nobody" group is defined already for something else, pick the Fedora name | |
72 | nobody_group=nfsnobody | |
73 | else | |
74 | # The "nobody" group name is free, use it | |
75 | nobody_group=nobody | |
76 | fi | |
c82ce4f2 | 77 | fi |
c81a2569 LP |
78 | |
79 | meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D default-hierarchy=unified -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group" | |
c82ce4f2 LP |
80 | fi |
81 | ||
70e760e3 | 82 | ninja -C "$BUILDDIR" all |
5b3325fe | 83 | [ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test |
70e760e3 | 84 | ninja -C "$BUILDDIR" install |
6344a7eb | 85 | |
70e760e3 | 86 | mkdir -p "$DESTDIR"/etc |
6344a7eb | 87 | |
70e760e3 | 88 | cat > "$DESTDIR"/etc/issue <<EOF |
6344a7eb LP |
89 | \S (built from systemd tree) |
90 | Kernel \r on an \m (\l) | |
91 | ||
92 | EOF | |
d10ba83a LP |
93 | |
94 | # Manually update the boot loader from the one we just built | |
95 | mkdir -p "$DESTDIR"/boot/efi/EFI/systemd "$DESTDIR"/boot/efi/EFI/BOOT | |
96 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/systemd/systemd-bootx64.efi | |
97 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/BOOT/bootx64.efi |