From bf6a545b4eefd65e5c55a43087c6021b19a5ce0d Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 29 Aug 2017 06:08:31 -0400 Subject: debootstrap.sh: add command 'sh' --- debootstrap.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'debootstrap.sh') diff --git a/debootstrap.sh b/debootstrap.sh index e0bbc4b..d76db93 100755 --- a/debootstrap.sh +++ b/debootstrap.sh @@ -103,19 +103,21 @@ suite_name_to_imagename() printf '%s/%s-%s-%s.%s.btrfs\n' "$imgdir" "$suite" "$variant" "$arch" "$name" } -chroot_image() +sh_image() { suite=$1 name=$2 + shift 2 + if [ $# = 0 ]; then + set -- /bin/bash + fi [ "$suite" -a "$name" ] || usage imagename=$(suite_name_to_imagename "$suite" "$name") [ -e "$imagename" ] || die "no such file: $imagename" [ -d "$imagename".mnt ] || mkdir "$imagename".mnt || die "mkdir" mountpoint -q "$imagename".mnt || mount "$imagename" "$imagename".mnt || die "mount" - unshare -f -m -p \ - chroot "$imagename".mnt \ - /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec /bin/bash' + (cd "$imagename".mnt; "$@") r=$? umount "$imagename".mnt @@ -123,6 +125,20 @@ chroot_image() return $r } +chroot_image() +{ + suite=$1 + name=$2 + shift 2 + [ $# = 0 ] && set -- /bin/bash + set -- \ + unshare -f -m -p \ + chroot . \ + /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec "$@"' sh \ + "$@" + sh_image "$suite" "$name" "$@" +} + clone() { suite=$1 @@ -202,6 +218,6 @@ debootstrap_efficiently() case "$1" in init|new|clone|list) cmd=$1; shift; $cmd "$@" ;; - chroot) cmd=chroot_image; shift; $cmd "$@" ;; + chroot|sh) cmd=${1}_image; shift; $cmd "$@" ;; *) usage ;; esac -- cgit v1.2.3