summaryrefslogtreecommitdiff
path: root/debootstrap.sh
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2017-08-29 06:08:31 -0400
committerAndrew Cady <d@jerkface.net>2017-08-29 06:08:31 -0400
commitbf6a545b4eefd65e5c55a43087c6021b19a5ce0d (patch)
treed1312ad5b032001113cac598c7966e1bfa35ef12 /debootstrap.sh
parent965e80da28ff4075eeb4c13c5a6b9c17ab195bb0 (diff)
debootstrap.sh: add command 'sh'
Diffstat (limited to 'debootstrap.sh')
-rwxr-xr-xdebootstrap.sh26
1 files changed, 21 insertions, 5 deletions
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()
103 printf '%s/%s-%s-%s.%s.btrfs\n' "$imgdir" "$suite" "$variant" "$arch" "$name" 103 printf '%s/%s-%s-%s.%s.btrfs\n' "$imgdir" "$suite" "$variant" "$arch" "$name"
104} 104}
105 105
106chroot_image() 106sh_image()
107{ 107{
108 suite=$1 108 suite=$1
109 name=$2 109 name=$2
110 shift 2
111 if [ $# = 0 ]; then
112 set -- /bin/bash
113 fi
110 [ "$suite" -a "$name" ] || usage 114 [ "$suite" -a "$name" ] || usage
111 imagename=$(suite_name_to_imagename "$suite" "$name") 115 imagename=$(suite_name_to_imagename "$suite" "$name")
112 [ -e "$imagename" ] || die "no such file: $imagename" 116 [ -e "$imagename" ] || die "no such file: $imagename"
113 [ -d "$imagename".mnt ] || mkdir "$imagename".mnt || die "mkdir" 117 [ -d "$imagename".mnt ] || mkdir "$imagename".mnt || die "mkdir"
114 mountpoint -q "$imagename".mnt || mount "$imagename" "$imagename".mnt || die "mount" 118 mountpoint -q "$imagename".mnt || mount "$imagename" "$imagename".mnt || die "mount"
115 119
116 unshare -f -m -p \ 120 (cd "$imagename".mnt; "$@")
117 chroot "$imagename".mnt \
118 /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec /bin/bash'
119 121
120 r=$? 122 r=$?
121 umount "$imagename".mnt 123 umount "$imagename".mnt
@@ -123,6 +125,20 @@ chroot_image()
123 return $r 125 return $r
124} 126}
125 127
128chroot_image()
129{
130 suite=$1
131 name=$2
132 shift 2
133 [ $# = 0 ] && set -- /bin/bash
134 set -- \
135 unshare -f -m -p \
136 chroot . \
137 /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec "$@"' sh \
138 "$@"
139 sh_image "$suite" "$name" "$@"
140}
141
126clone() 142clone()
127{ 143{
128 suite=$1 144 suite=$1
@@ -202,6 +218,6 @@ debootstrap_efficiently()
202 218
203case "$1" in 219case "$1" in
204 init|new|clone|list) cmd=$1; shift; $cmd "$@" ;; 220 init|new|clone|list) cmd=$1; shift; $cmd "$@" ;;
205 chroot) cmd=chroot_image; shift; $cmd "$@" ;; 221 chroot|sh) cmd=${1}_image; shift; $cmd "$@" ;;
206 *) usage ;; 222 *) usage ;;
207esac 223esac