]> git.ipfire.org Git - thirdparty/systemd.git/blob - mkosi.build
unit: use alias name of man page
[thirdparty/systemd.git] / mkosi.build
1 #!/bin/sh
2 set -e
3
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
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 if ! mountpoint -q "$SRCDIR"; then
13 chmod -R u+w,go-w,a+rX .
14 umask 022
15 fi
16
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
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
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:
38 if [ "$(locale charmap 2> /dev/null)" != "UTF-8" ] ; then
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.)
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
48 export LC_CTYPE=en_US.UTF-8
49 else
50 # If nothing works, fail early.
51 echo "*** Could not find a valid locale that supports UTF-8. ***" >&2
52 exit 1
53 fi
54 fi
55
56 if [ ! -f "$BUILDDIR"/build.ninja ] ; then
57 sysvinit_path=`realpath /etc/init.d`
58
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
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
73 fi
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
82 fi
83
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
90 fi
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
99 fi
100
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" \
107 -D translations=false \
108 -D version-tag="${VERSION_TAG}"
109 fi
110
111 cd "$BUILDDIR"
112 ninja "$@"
113 if [ "$WITH_TESTS" = 1 ] ; then
114 for id in 1 2 3; do
115 getent group $id > /dev/null || groupadd -g $id testgroup$id
116 done
117
118 ninja test
119 fi
120 cd "$SRCDIR"
121
122 # Ubuntu Focal is stuck with meson 0.53.0.
123 if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then
124 meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
125 else
126 meson install -C "$BUILDDIR" --no-rebuild --only-changed
127 fi
128
129 mkdir -p "$DESTDIR"/etc
130
131 cat > "$DESTDIR"/etc/issue <<EOF
132 \S (built from systemd tree)
133 Kernel \r on an \m (\l)
134
135 EOF
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
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