#!/bin/sh

set -exu

SRC="$(pwd)"

cat >/etc/sudoers.d/autopkgtest <<EOF
$AUTOPKGTEST_NORMAL_USER ALL = (ALL:ALL) NOPASSWD: ALL
EOF

# enable unprivileged user namespaces
sysctl -w kernel.unprivileged_userns_clone=1

# change to temporary directory to not interfere with the source
cd "$AUTOPKGTEST_TMP"

# make sure that everybody can create files here
chmod 777 "$AUTOPKGTEST_TMP"

# test.sh expects the script to be in the current directory
ln -s "$SRC/make_mirror.sh" make_mirror.sh

# running as normal user to test unshare mode
# the mmdebstrap environment variable points to the *installed* binary
sudo -u $AUTOPKGTEST_NORMAL_USER mmdebstrap="/usr/bin/mmdebstrap" "$SRC/test.sh"
