2022-10-27 12:22:53 +00:00
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
export SOURCE_DATE_EPOCH={{ SOURCE_DATE_EPOCH }}
trap "rm -f /tmp/chrootless.tar /tmp/root.tar" EXIT INT TERM
2023-02-02 06:57:58 +00:00
[ {{ MODE }} = chrootless ]
prefix=
if [ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && [ "{{ MODE }}" != "auto" ]; then
2023-02-09 09:04:22 +00:00
if ! id "${SUDO_USER:-user}" >/dev/null 2>&1; then
2023-02-02 06:57:58 +00:00
if [ ! -e /mmdebstrap-testenv ]; then
echo "this test modifies the system and should only be run inside a container" >&2
exit 1
fi
useradd --home-dir "/home/${SUDO_USER:-user}" --create-home "${SUDO_USER:-user}"
2022-10-27 12:22:53 +00:00
fi
2023-02-02 06:57:58 +00:00
prefix="runuser -u ${SUDO_USER:-user} --"
2022-10-27 12:22:53 +00:00
fi
2023-02-02 06:57:58 +00:00
2024-01-08 21:27:35 +00:00
MMTARFILTER=
[ -x /usr/bin/mmtarfilter ] && MMTARFILTER=/usr/bin/mmtarfilter
[ -x ./tarfilter ] && MMTARFILTER=./tarfilter
2022-10-27 12:22:53 +00:00
# we need --hook-dir=./hooks/merged-usr because usrmerge does not understand
# DPKG_ROOT
# permissions drwxr-sr-x and extended attributes of ./var/log/journal/ cannot
# be preserved under fakeroot
2024-01-08 21:27:35 +00:00
# this applies to 'z' lines in files in /usr/lib/tmpfiles.d/
2023-01-16 07:14:36 +00:00
for INCLUDE in '' 'apt' 'apt,build-essential' 'systemd-sysv'; do
2022-10-27 12:22:53 +00:00
{{ CMD }} --variant={{ VARIANT }} --hook-dir=./hooks/merged-usr \
2024-01-08 21:27:35 +00:00
--customize-hook="if [ \"$INCLUDE\" = systemd-sysv ]; then for f in var/log/journal etc/credstore etc/credstore.encrypted; do chmod 00755 \"\$1/\$f\"; done; fi" \
2022-10-27 12:22:53 +00:00
${INCLUDE:+--include="$INCLUDE"} \
2024-01-08 21:27:35 +00:00
{{ DIST }} - {{ MIRROR }} | "$MMTARFILTER" --pax-exclude='*' >/tmp/root.tar
2023-02-02 06:57:58 +00:00
$prefix fakeroot {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} --hook-dir=./hooks/merged-usr \
2022-10-27 12:22:53 +00:00
${INCLUDE:+--include="$INCLUDE"} \
2024-01-08 21:27:35 +00:00
{{ DIST }} - {{ MIRROR }} | "$MMTARFILTER" > /tmp/chrootless.tar
2023-02-10 03:10:23 +00:00
cmp /tmp/root.tar /tmp/chrootless.tar || diffoscope /tmp/root.tar /tmp/chrootless.tar
2022-10-27 12:22:53 +00:00
rm /tmp/chrootless.tar /tmp/root.tar
done