]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - mkosi.images/system/mkosi.postinst.chroot
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / mkosi.images / system / mkosi.postinst.chroot
... / ...
CommitLineData
1#!/bin/sh
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -e
4
5if [ "$1" = "build" ]; then
6 exit 0
7fi
8
9if [ -n "$SANITIZERS" ]; then
10 LD_PRELOAD=$(ldd /usr/lib/systemd/systemd | grep libasan.so | awk '{print $3}')
11
12 mkdir -p /etc/systemd/system.conf.d
13
14 cat >/etc/systemd/system.conf.d/10-asan.conf <<EOF
15[Manager]
16ManagerEnvironment=ASAN_OPTIONS=$MKOSI_ASAN_OPTIONS\\
17 UBSAN_OPTIONS=$MKOSI_UBSAN_OPTIONS\\
18 LD_PRELOAD=$LD_PRELOAD
19DefaultEnvironment=ASAN_OPTIONS=$MKOSI_ASAN_OPTIONS\\
20 UBSAN_OPTIONS=$MKOSI_UBSAN_OPTIONS\\
21 LD_PRELOAD=$LD_PRELOAD
22EOF
23
24 # ASAN logs to stderr by default. However, journald's stderr is connected to /dev/null, so we lose
25 # all the ASAN logs. To rectify that, let's connect journald's stdout to the console so that any
26 # sanitizer failures appear directly on the user's console.
27 mkdir -p /etc/systemd/system/systemd-journald.service.d
28 cat >/etc/systemd/system/systemd-journald.service.d/10-stdout-tty.conf <<EOF
29[Service]
30StandardOutput=tty
31EOF
32
33 # Both systemd and util-linux's login call vhangup() on /dev/console which disconnects all users.
34 # This means systemd-journald can't log to /dev/console even if we configure `StandardOutput=tty`. As
35 # a workaround, we modify console-getty.service to disable systemd's vhangup() and disallow login
36 # from calling vhangup() so that journald's ASAN logs correctly end up in the console.
37
38 mkdir -p /etc/systemd/system/console-getty.service.d
39 cat >/etc/systemd/system/console-getty.service.d/10-no-vhangup.conf <<EOF
40[Service]
41TTYVHangup=no
42CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
43EOF
44 # ASAN and syscall filters aren't compatible with each other.
45 find / -name '*.service' -type f -exec sed -i 's/^\(MemoryDeny\|SystemCall\)/# \1/' {} +
46
47 # `systemd-hwdb update` takes > 50s when built with sanitizers so let's not run it by default.
48 systemctl mask systemd-hwdb-update.service
49fi
50
51if [ -n "$IMAGE_ID" ] ; then
52 sed -n \
53 -i \
54 -e '/^IMAGE_ID=/!p' \
55 -e "\$aIMAGE_ID=$IMAGE_ID" \
56 /usr/lib/os-release
57fi
58
59if [ -n "$IMAGE_VERSION" ] ; then
60 sed -n \
61 -i \
62 -e '/^IMAGE_VERSION=/!p' \
63 -e "\$aIMAGE_VERSION=$IMAGE_VERSION" \
64 /usr/lib/os-release
65fi
66
67if command -v authselect >/dev/null; then
68 authselect select minimal
69
70 if authselect list-features minimal | grep -q "with-homed"; then
71 authselect enable-feature with-homed
72 fi
73fi
74
75# Let tmpfiles.d/systemd-resolve.conf handle the symlink. /etc/resolv.conf might be mounted over so undo that
76# if that's the case.
77mountpoint -q /etc/resolv.conf && umount /etc/resolv.conf
78rm -f /etc/resolv.conf
79
80. /usr/lib/os-release
81
82if [ "$ID" = "centos" ] && [ "$VERSION" = "8" ]; then
83 alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
84 alternatives --set python3 /usr/bin/python3.9
85fi
86
87mkdir -p /usr/lib/sysusers.d
88cat >/usr/lib/sysusers.d/testuser.conf <<EOF
89u testuser 4711 "Test User" /home/testuser
90EOF
91mkdir -p /usr/lib/tmpfiles.d
92cat >/usr/lib/tmpfiles.d/testuser.conf <<EOF
93q /home/testuser 0700 4711 4711
94EOF