+mkdir /opt/chroot/$chrootdir
+
+# argh apt with broken proxies and unreliable ISPs, getting fed up with it
+if [ -e /tmp/brokenproxy ]; then
+ echo "Temp file containing apt proxy fix configuration already exists, skipping!"
+else
+ cat <<EOF >/tmp/brokenproxy
+APT::Acquire::Retries "20";
+APT::Get::Fix-Broken "true";
+Acquire::http::Pipeline-Depth "0";
+Acquire::http::No-Cache=True;
+Acquire::BrokenProxy=true;
+EOF
+fi
+
+if [ -e /etc/apt/apt.conf.d/80-retries ]; then
+ echo "Host system apt.conf.d already has 80-retries, skipping!"
+else
+ cp /tmp/brokenproxy /etc/apt/apt.conf.d/80-retries
+fi
+
+# No need to check if exists, this script always runs with new chroot
+cp /tmp/brokenproxy /opt/chroot/$chrootdir/etc/apt/apt.conf.d/80-retries
+
+
+# Install debootstrap and schroot
+if [ -e /etc/debian_version ]; then
+ # Debian detected: use apt
+ apt install -y debootstrap schroot
+elif [ -e /etc/arch-release ]; then
+ # Arch Linux detected: use pacman
+ pacman -S --needed debootstrap schroot
+fi
+