2022-11-14 08:59:59 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
export SOURCE_DATE_EPOCH={{ SOURCE_DATE_EPOCH }}
|
|
|
|
trap "rm -f /tmp/chroot1.tar /tmp/chroot2.tar /tmp/chroot3.tar /tmp/mmdebstrap" EXIT INT TERM
|
|
|
|
|
|
|
|
prefix=
|
2023-02-02 06:57:58 +00:00
|
|
|
if [ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && [ "{{ MODE }}" != "auto" ]; then
|
|
|
|
if ! id "${SUDO_USER:-user}" 2>/dev/null; then
|
|
|
|
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}"
|
|
|
|
fi
|
|
|
|
prefix="runuser -u ${SUDO_USER:-user} --"
|
|
|
|
fi
|
2022-11-14 08:59:59 +00:00
|
|
|
|
|
|
|
$prefix {{ CMD }} --mode={{ MODE }} --variant=apt \
|
2024-06-09 22:12:16 +00:00
|
|
|
--include=mount,perl \
|
2022-11-14 08:59:59 +00:00
|
|
|
{{ DIST }} /tmp/chroot1.tar {{ MIRROR }}
|
|
|
|
|
|
|
|
if [ {{ MODE }} = "unshare" ]; then
|
|
|
|
# calling pivot_root in root mode does not work for mysterious reasons:
|
|
|
|
# pivot_root: failed to change root from `.' to `mnt': Invalid argument
|
2024-06-09 22:12:16 +00:00
|
|
|
$prefix {{ CMD }} --mode={{ MODE }} --variant=apt --include=mount,perl \
|
2023-02-10 12:01:37 +00:00
|
|
|
--customize-hook='mkdir -p "$1/mnt" "$1/oldroot"' \
|
|
|
|
--customize-hook='[ ! -e /usr/bin/mmdebstrap ] || cp -aT /usr/bin/mmdebstrap "$1/usr/bin/mmdebstrap"' \
|
|
|
|
--customize-hook='[ ! -e ./mmdebstrap ] || cp -aT ./mmdebstrap "$1/mnt/mmdebstrap"' \
|
|
|
|
--customize-hook='mount -o rbind "$1" /mnt && cd /mnt && /sbin/pivot_root . oldroot' \
|
2022-11-14 08:59:59 +00:00
|
|
|
--customize-hook='unshare -U echo nested unprivileged unshare' \
|
2024-06-09 22:12:16 +00:00
|
|
|
--customize-hook='env --chdir=/mnt {{ CMD }} --mode=unshare --variant=apt --include=mount,perl {{ DIST }} /tmp/chroot3.tar {{ MIRROR }}' \
|
2022-11-14 08:59:59 +00:00
|
|
|
--customize-hook='copy-out /tmp/chroot3.tar /tmp' \
|
2023-02-10 12:01:37 +00:00
|
|
|
--customize-hook='rm -f "/usr/bin/mmdebstrap" "/mnt/mmdebstrap"' \
|
|
|
|
--customize-hook='umount -l oldroot sys' \
|
|
|
|
--customize-hook='rmdir /oldroot' \
|
2022-11-14 08:59:59 +00:00
|
|
|
{{ DIST }} /tmp/chroot2.tar {{ MIRROR }}
|
|
|
|
|
2023-02-10 03:10:23 +00:00
|
|
|
cmp /tmp/chroot1.tar /tmp/chroot2.tar || diffoscope /tmp/chroot1.tar /tmp/chroot2.tar
|
|
|
|
cmp /tmp/chroot1.tar /tmp/chroot3.tar || diffoscope /tmp/chroot1.tar /tmp/chroot3.tar
|
2022-11-14 08:59:59 +00:00
|
|
|
rm /tmp/chroot2.tar /tmp/chroot3.tar
|
|
|
|
fi
|
|
|
|
|
2024-06-09 22:12:16 +00:00
|
|
|
$prefix {{ CMD }} --mode={{ MODE }} --variant=apt --include=mount,perl \
|
2023-02-10 12:01:37 +00:00
|
|
|
--customize-hook='mkdir -p "$1/mnt"' \
|
|
|
|
--customize-hook='[ ! -e /usr/bin/mmdebstrap ] || cp -aT /usr/bin/mmdebstrap "$1/usr/bin/mmdebstrap"' \
|
|
|
|
--customize-hook='[ ! -e ./mmdebstrap ] || cp -aT ./mmdebstrap "$1/mnt/mmdebstrap"' \
|
2024-06-09 22:12:16 +00:00
|
|
|
--chrooted-customize-hook='env --chdir=/mnt {{ CMD }} --mode=unshare --variant=apt --include=mount,perl {{ DIST }} /tmp/chroot3.tar {{ MIRROR }}' \
|
2022-11-14 08:59:59 +00:00
|
|
|
--customize-hook='copy-out /tmp/chroot3.tar /tmp' \
|
2023-02-10 12:01:37 +00:00
|
|
|
--customize-hook='rm -f "$1/usr/bin/mmdebstrap" "$1/mnt/mmdebstrap"' \
|
2022-11-14 08:59:59 +00:00
|
|
|
{{ DIST }} /tmp/chroot2.tar {{ MIRROR }}
|
|
|
|
|
2023-02-10 03:10:23 +00:00
|
|
|
cmp /tmp/chroot1.tar /tmp/chroot2.tar || diffoscope /tmp/chroot1.tar /tmp/chroot2.tar
|
|
|
|
cmp /tmp/chroot1.tar /tmp/chroot3.tar || diffoscope /tmp/chroot1.tar /tmp/chroot3.tar
|