bleep_blop | 7629744 | 2017-12-24 06:53:20 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | set -ex |
Lennart Poettering | 1b0ff61 | 2016-07-16 02:00:44 +0200 | [diff] [blame] | 3 | |
Lennart Poettering | 1b0ff61 | 2016-07-16 02:00:44 +0200 | [diff] [blame] | 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 | |
Filipe Brandenburger | b454cfb | 2018-03-20 09:21:36 -0700 | [diff] [blame] | 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 | |
Lennart Poettering | 70e760e | 2017-07-12 19:58:53 +0200 | [diff] [blame] | 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 | |
Filipe Brandenburger | 2ea0966 | 2018-03-05 08:03:52 -0800 | [diff] [blame] | 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 |
Lennart Poettering | 9400405 | 2017-07-18 10:30:52 +0200 | [diff] [blame] | 41 | |
Lennart Poettering | c81a256 | 2018-02-09 19:22:40 +0100 | [diff] [blame] | 42 | if [ ! -f "$BUILDDIR"/build.ninja ] ; then |
| 43 | sysvinit_path=`realpath /etc/init.d` |
Lennart Poettering | 8da0592 | 2017-10-25 20:42:38 +0200 | [diff] [blame] | 44 | |
Michal Koutný | bac567a | 2020-04-21 18:08:23 +0200 | [diff] [blame] | 45 | init_path=`realpath /sbin/init 2>/dev/null` |
| 46 | if [ -z "$init_path" ] ; then |
| 47 | rootprefix="" |
| 48 | else |
| 49 | rootprefix=${init_path%/lib/systemd/systemd} |
| 50 | rootprefix=/${rootprefix#/} |
| 51 | fi |
| 52 | |
Lennart Poettering | c81a256 | 2018-02-09 19:22:40 +0100 | [diff] [blame] | 53 | nobody_user=`id -u -n 65534 2> /dev/null` |
| 54 | if [ "$nobody_user" != "" ] ; then |
| 55 | # Validate that we can translate forth and back |
| 56 | if [ "`id -u $nobody_user`" != 65534 ] ; then |
| 57 | nobody_user="" |
| 58 | fi |
Lennart Poettering | c82ce4f | 2017-12-06 13:53:39 +0100 | [diff] [blame] | 59 | fi |
Lennart Poettering | c81a256 | 2018-02-09 19:22:40 +0100 | [diff] [blame] | 60 | if [ "$nobody_user" = "" ] ; then |
| 61 | if id -u nobody 2> /dev/null ; then |
| 62 | # The "nobody" user is defined already for something else, pick the Fedora name |
| 63 | nobody_user=nfsnobody |
| 64 | else |
| 65 | # The "nobody" user name is free, use it |
| 66 | nobody_user=nobody |
| 67 | fi |
Lennart Poettering | c82ce4f | 2017-12-06 13:53:39 +0100 | [diff] [blame] | 68 | fi |
Lennart Poettering | c81a256 | 2018-02-09 19:22:40 +0100 | [diff] [blame] | 69 | |
| 70 | nobody_group=`id -g -n 65534 2> /dev/null` |
| 71 | if [ "$nobody_group" != "" ] ; then |
| 72 | # Validate that we can translate forth and back |
| 73 | if [ "`id -g $nobody_group`" != 65534 ] ; then |
| 74 | nobody_group="" |
| 75 | fi |
| 76 | fi |
| 77 | if [ "$nobody_group" = "" ] ; then |
| 78 | if id -u nobody 2> /dev/null ; then |
| 79 | # The "nobody" group is defined already for something else, pick the Fedora name |
| 80 | nobody_group=nfsnobody |
| 81 | else |
| 82 | # The "nobody" group name is free, use it |
| 83 | nobody_group=nobody |
| 84 | fi |
| 85 | fi |
| 86 | |
Michal Koutný | bac567a | 2020-04-21 18:08:23 +0200 | [diff] [blame] | 87 | meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D "rootprefix=$rootprefix" -D default-hierarchy=unified -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group" |
Lennart Poettering | c82ce4f | 2017-12-06 13:53:39 +0100 | [diff] [blame] | 88 | fi |
| 89 | |
Lennart Poettering | 70e760e | 2017-07-12 19:58:53 +0200 | [diff] [blame] | 90 | ninja -C "$BUILDDIR" all |
Michal Koutný | ff54998 | 2020-04-22 01:58:44 +0200 | [diff] [blame] | 91 | if [ "$WITH_TESTS" = 1 ] ; then |
| 92 | for id in 1 2 3; do |
| 93 | groupadd -g $id testgroup$id || : |
| 94 | done |
| 95 | |
| 96 | ninja -C "$BUILDDIR" test |
| 97 | fi |
Lennart Poettering | 70e760e | 2017-07-12 19:58:53 +0200 | [diff] [blame] | 98 | ninja -C "$BUILDDIR" install |
Lennart Poettering | 6344a7e | 2016-12-06 23:17:57 +0100 | [diff] [blame] | 99 | |
Lennart Poettering | 70e760e | 2017-07-12 19:58:53 +0200 | [diff] [blame] | 100 | mkdir -p "$DESTDIR"/etc |
Lennart Poettering | 6344a7e | 2016-12-06 23:17:57 +0100 | [diff] [blame] | 101 | |
Lennart Poettering | 70e760e | 2017-07-12 19:58:53 +0200 | [diff] [blame] | 102 | cat > "$DESTDIR"/etc/issue <<EOF |
Lennart Poettering | 6344a7e | 2016-12-06 23:17:57 +0100 | [diff] [blame] | 103 | \S (built from systemd tree) |
| 104 | Kernel \r on an \m (\l) |
| 105 | |
| 106 | EOF |
Lennart Poettering | d10ba83 | 2018-06-21 18:47:33 +0200 | [diff] [blame] | 107 | |
| 108 | # Manually update the boot loader from the one we just built |
| 109 | mkdir -p "$DESTDIR"/boot/efi/EFI/systemd "$DESTDIR"/boot/efi/EFI/BOOT |
| 110 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/systemd/systemd-bootx64.efi |
| 111 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/boot/efi/EFI/BOOT/bootx64.efi |
Lennart Poettering | 1b14a4b | 2019-02-08 17:19:15 +0100 | [diff] [blame] | 112 | |
| 113 | mkdir -p "$DESTDIR"/efi/EFI/systemd "$DESTDIR"/efi/EFI/BOOT |
| 114 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/systemd/systemd-bootx64.efi |
| 115 | cp "$DESTDIR"/usr/lib/systemd/boot/efi/systemd-bootx64.efi "$DESTDIR"/efi/EFI/BOOT/bootx64.efi |