2021-11-23 19:57:18 +01:00
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1-or-later
2023-06-02 15:42:14 +02:00
set -e
2021-11-23 19:57:18 +01:00
2023-02-21 15:23:15 +01:00
if [ "$1" = "build" ]; then
exit 0
fi
if [ -n "$SANITIZERS" ]; then
LD_PRELOAD=$(ldd /usr/lib/systemd/systemd | grep libasan.so | awk '{print $3}')
2023-02-21 15:09:38 +01:00
2023-02-21 15:23:15 +01:00
mkdir -p /etc/systemd/system.conf.d
2023-02-21 15:09:38 +01:00
2023-02-21 15:23:15 +01:00
cat >/etc/systemd/system.conf.d/10-asan.conf <<EOF
2023-02-21 15:09:38 +01:00
[Manager]
ManagerEnvironment=ASAN_OPTIONS=$MKOSI_ASAN_OPTIONS\\
UBSAN_OPTIONS=$MKOSI_UBSAN_OPTIONS\\
LD_PRELOAD=$LD_PRELOAD
DefaultEnvironment=ASAN_OPTIONS=$MKOSI_ASAN_OPTIONS\\
UBSAN_OPTIONS=$MKOSI_UBSAN_OPTIONS\\
LD_PRELOAD=$LD_PRELOAD
2022-07-19 13:45:24 +02:00
EOF
2023-02-21 15:23:15 +01:00
# ASAN logs to stderr by default. However, journald's stderr is connected to /dev/null, so we lose
# all the ASAN logs. To rectify that, let's connect journald's stdout to the console so that any
# sanitizer failures appear directly on the user's console.
mkdir -p /etc/systemd/system/systemd-journald.service.d
cat >/etc/systemd/system/systemd-journald.service.d/10-stdout-tty.conf <<EOF
2023-02-21 15:09:38 +01:00
[Service]
StandardOutput=tty
EOF
2023-02-21 15:23:15 +01:00
# Both systemd and util-linux's login call vhangup() on /dev/console which disconnects all users.
# This means systemd-journald can't log to /dev/console even if we configure `StandardOutput=tty`. As
# a workaround, we modify console-getty.service to disable systemd's vhangup() and disallow login
# from calling vhangup() so that journald's ASAN logs correctly end up in the console.
2023-02-21 15:09:38 +01:00
2023-02-21 15:23:15 +01:00
mkdir -p /etc/systemd/system/console-getty.service.d
cat >/etc/systemd/system/console-getty.service.d/10-no-vhangup.conf <<EOF
2023-02-21 15:09:38 +01:00
[Service]
TTYVHangup=no
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
EOF
2023-02-21 15:23:15 +01:00
# ASAN and syscall filters aren't compatible with each other.
find / -name '*.service' -type f -exec sed -i 's/^\(MemoryDeny\|SystemCall\)/# \1/' {} +
2022-07-15 02:26:52 +02:00
2023-02-21 15:23:15 +01:00
# `systemd-hwdb update` takes > 50s when built with sanitizers so let's not run it by default.
systemctl mask systemd-hwdb-update.service
fi
2022-08-22 13:21:07 +02:00
2023-02-21 15:23:15 +01:00
if [ -n "$IMAGE_ID" ] ; then
sed -n \
-i \
-e '/^IMAGE_ID=/!p' \
-e "\$aIMAGE_ID=$IMAGE_ID" \
/usr/lib/os-release
fi
2023-02-21 15:09:38 +01:00
2023-02-21 15:23:15 +01:00
if [ -n "$IMAGE_VERSION" ] ; then
sed -n \
-i \
-e '/^IMAGE_VERSION=/!p' \
-e "\$aIMAGE_VERSION=$IMAGE_VERSION" \
/usr/lib/os-release
2021-11-23 19:57:18 +01:00
fi
2023-04-18 14:35:48 +02:00
2023-04-20 10:13:37 +02:00
if command -v authselect >/dev/null; then
2024-01-22 12:04:45 +01:00
# authselect 1.5.0 renamed the minimal profile to the local profile without keeping backwards compat so
# let's use the new name if it exists.
if [ -d /usr/share/authselect/default/local ]; then
PROFILE=local
else
PROFILE=minimal
fi
authselect select "$PROFILE"
2023-04-20 10:13:37 +02:00
2024-01-22 12:04:45 +01:00
if authselect list-features "$PROFILE" | grep -q "with-homed"; then
2023-04-20 10:13:37 +02:00
authselect enable-feature with-homed
fi
fi
2023-04-23 13:02:06 +01:00
2023-08-07 20:17:41 +02:00
# Let tmpfiles.d/systemd-resolve.conf handle the symlink. /etc/resolv.conf might be mounted over so undo that
# if that's the case.
mountpoint -q /etc/resolv.conf && umount /etc/resolv.conf
2023-04-23 13:02:06 +01:00
rm -f /etc/resolv.conf
2023-04-25 16:04:49 +02:00
2023-08-04 10:40:30 +02:00
. /usr/lib/os-release
2023-04-25 16:04:49 +02:00
if [ "$ID" = "centos" ] && [ "$VERSION" = "8" ]; then
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
alternatives --set python3 /usr/bin/python3.9
fi
2023-11-27 17:50:49 +00:00
mkdir -p /usr/lib/sysusers.d
cat >/usr/lib/sysusers.d/testuser.conf <<EOF
u testuser 4711 "Test User" /home/testuser
EOF
mkdir -p /usr/lib/tmpfiles.d
cat >/usr/lib/tmpfiles.d/testuser.conf <<EOF
q /home/testuser 0700 4711 4711
EOF