]> git.ipfire.org Git - thirdparty/systemd.git/blob - mkosi.build
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / mkosi.build
1 #!/bin/sh
2 set -ex
3
4 # Copyright 2016 Lennart Poettering
5
6 # This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
7 # Simply invoke "mkosi" in the project directory to build an OS image.
8
9 # Reset the permissions of the tree. Since Meson keeps the permissions
10 # all the way to the installed files, reset them to one of 0644 or 0755
11 # so the files keep those permissions, otherwise details of what umask
12 # was set at the time the git tree was cloned will leak all the way
13 # through. Also set umask explicitly during the build.
14 chmod -R u+w,go-w,a+rX .
15 umask 022
16
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
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:
26 if [ "$(locale charmap)" != "UTF-8" ] ; then
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.)
30 export LC_CTYPE=C.UTF-8
31 if [ "$(locale charmap)" != "UTF-8" ] ; then
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 export LC_CTYPE=en_US.UTF-8
36 if [ "$(locale charmap)" != "UTF-8" ] ; then
37 # If nothing works, fail early.
38 echo "*** Could not find a valid locale that supports UTF-8. ***" >&2
39 exit 1
40 fi
41 fi
42 fi
43
44 if [ ! -f "$BUILDDIR"/build.ninja ] ; then
45 sysvinit_path=`realpath /etc/init.d`
46
47 nobody_user=`id -u -n 65534 2> /dev/null`
48 if [ "$nobody_user" != "" ] ; then
49 # Validate that we can translate forth and back
50 if [ "`id -u $nobody_user`" != 65534 ] ; then
51 nobody_user=""
52 fi
53 fi
54 if [ "$nobody_user" = "" ] ; then
55 if id -u nobody 2> /dev/null ; then
56 # The "nobody" user is defined already for something else, pick the Fedora name
57 nobody_user=nfsnobody
58 else
59 # The "nobody" user name is free, use it
60 nobody_user=nobody
61 fi
62 fi
63
64 nobody_group=`id -g -n 65534 2> /dev/null`
65 if [ "$nobody_group" != "" ] ; then
66 # Validate that we can translate forth and back
67 if [ "`id -g $nobody_group`" != 65534 ] ; then
68 nobody_group=""
69 fi
70 fi
71 if [ "$nobody_group" = "" ] ; then
72 if id -u nobody 2> /dev/null ; then
73 # The "nobody" group is defined already for something else, pick the Fedora name
74 nobody_group=nfsnobody
75 else
76 # The "nobody" group name is free, use it
77 nobody_group=nobody
78 fi
79 fi
80
81 meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D default-hierarchy=unified -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group"
82 fi
83
84 ninja -C "$BUILDDIR" all
85 [ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test
86 ninja -C "$BUILDDIR" install
87
88 mkdir -p "$DESTDIR"/etc
89
90 cat > "$DESTDIR"/etc/issue <<EOF
91 \S (built from systemd tree)
92 Kernel \r on an \m (\l)
93
94 EOF