if ! ab_match_archgroup retro; then
    abinfo "Installing systemd legacy tmpfiles.d configuration ..."
    install -Dvm644 "$BLDDIR"/tmpfiles.d/legacy.conf \
        "$PKGDIR"/usr/lib/tmpfiles.d

    abinfo "Tweaking /etc/pam.d/systemd-user ..."
    sed -e 's|system-auth|system-login|g' \
        -i "$PKGDIR"/usr/lib/pam.d/systemd-user
fi

abinfo "Setting permissions for /var/log/journal ..."
chown -v root:systemd-journal "$PKGDIR"/var/log/journal
chmod -v 2755 "$PKGDIR"/var/log/journal

abinfo "Creating default preset ..."
echo 'disable *' \
    > "$PKGDIR"/usr/lib/systemd/system-preset/99-default.preset

abinfo "Preparing autovt@.service for alternatives ..."
mkdir -pv "$PKGDIR"/usr/lib/systemd/system-alternatives
rm -v "$PKGDIR"/usr/lib/systemd/system/autovt@.service
mv -v "$PKGDIR"/usr/lib/systemd/system/getty@.service \
    "$PKGDIR"/usr/lib/systemd/system-alternatives/autovt-systemd.service

if ab_match_archgroup retro; then
    abinfo "Dropping unnecessary unit autostarts..."
    (
        cd "$PKGDIR"/usr/lib/systemd/system
        for i in local-fs.target.wants/tmp.mount \
                 multi-user.target.wants/systemd-ask-password-wall.path \
                 sysinit.target.wants/{dev-hugepages.mount,systemd-tmpfiles-setup.service} \
                 sysinit.target.wants/{dev-mqueue.mount,sys-kernel-debug.mount,systemd-ask-password-console.path} \
                 sysinit.target.wants/sys-fs-fuse-connections.mount \
                 sysinit.target.wants/sys-kernel-{config,tracing}.mount \
                 sysinit.target.wants/systemd-update-done.service \
                 sysinit.target.wants/kmod-static-nodes.service; do
            rm -v ${i}
        done
    )
fi

if ab_match_archgroup retro; then
    abinfo "Dropping tmp.mount to further reduce memory stress ..."
    rm -v "$PKGDIR"/usr/lib/systemd/system/tmp.mount
fi

# systemd-sysctl only reads /etc/sysctl.d, but not /etc/sysctl.conf
# However, procps reads both and the latter takes precedence
# In order to reduce confusion, create symlink to align the behavior
abinfo "Creating symlink for systemd-sysctl to read /etc/sysctl.conf ..."
ln -svf ../sysctl.conf "$PKGDIR"/etc/sysctl.d/99-sysctl.conf

# FIXME: OSC;8003, as implemented in systemd 258, is known to cause
# extraneous "garbage" output via systemd-osc-context on SecureCRT,
# FinalShell, etc. This is a bug on those clients, but for the sake of
# compatibility and for the current buggy versions to flush out, and that
# there is "no terminal application is known that consumes these
# sequences"... strip this feature for now.
#
# FIXME: There is no Meson option to disable OSC;8003.
#
# Link: https://systemd.io/OSC_CONTEXT/
# Link: https://github.com/systemd/systemd/issues/39114
abinfo "Removing OSC;8003 components that causes extraneous command prompt outputs with SecureCRT and more ..."
rm -v "${PKGDIR}"/etc/profile.d/80-systemd-osc-context.sh
rm -v "${PKGDIR}"/usr/lib/tmpfiles.d/20-systemd-osc-context.conf
