aboutsummaryrefslogtreecommitdiff
path: root/bwrap-files/make-chroot.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bwrap-files/make-chroot.sh')
-rwxr-xr-xbwrap-files/make-chroot.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/bwrap-files/make-chroot.sh b/bwrap-files/make-chroot.sh
new file mode 100755
index 0000000..d29d1af
--- /dev/null
+++ b/bwrap-files/make-chroot.sh
@@ -0,0 +1,31 @@
+#!/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[@]}"