#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" basedir=ubuntu-base [[ ($# -le 0 || "$1" != "-f") && -d "$basedir" ]] && { echo >&2 "Warning: base directory already exists, use -f to force" exit 1 } mkdir -p "$basedir" curl -L 'http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.1-base-amd64.tar.gz' | tar -C "$basedir" -xz args=( --bind ubuntu-base / --ro-bind /etc/resolv.conf /etc/resolv.conf --tmpfs /tmp --dev /dev --proc /proc --new-session --unshare-all --share-net --die-with-parent --gid 0 --uid 0 --chdir / --ro-bind chroot-initialise.sh /tmp/chinit.sh /bin/bash /tmp/chinit.sh ) bwrap "${args[@]}"