summaryrefslogtreecommitdiff
path: root/debootstrap.sh
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-12 19:01:13 -0400
committerAndrew Cady <d@jerkface.net>2018-06-13 17:13:53 -0400
commit06d994ca36e1c489925daeadd20c58357c2a22fa (patch)
treeefc70e199c42015f499e4d3fbfef5707abceb79c /debootstrap.sh
parent9978ef7b4a692eb961d396b80a51bd1f9a88cad6 (diff)
new command "add" to add packages
Diffstat (limited to 'debootstrap.sh')
-rwxr-xr-xdebootstrap.sh80
1 files changed, 68 insertions, 12 deletions
diff --git a/debootstrap.sh b/debootstrap.sh
index 1b88a86..736d608 100755
--- a/debootstrap.sh
+++ b/debootstrap.sh
@@ -1,5 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2imgdir=./debootstrap 2imgdir=./debootstrap
3default_sh_command=bash
4default_chroot_command=/bin/bash
5default_image_size=1G # truncate(1) format
6
3warn() { printf 'Warning: %s\n' "$*" >&2; } 7warn() { printf 'Warning: %s\n' "$*" >&2; }
4die() { printf 'Error: %s\n' "$*" >&2; exit 1; } 8die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
5[ -d "$imgdir" ] || die "directory does not exist: $imgdir" 9[ -d "$imgdir" ] || die "directory does not exist: $imgdir"
@@ -12,6 +16,7 @@ Usage:
12 $0 new <suite> <new-name> 16 $0 new <suite> <new-name>
13 $0 clone <suite> <source-name> <new-name> 17 $0 clone <suite> <source-name> <new-name>
14 $0 chroot <suite> <name> 18 $0 chroot <suite> <name>
19 $0 add <suite> <name> <package> [packages...]
15 $0 list 20 $0 list
16 $0 show unpackaged <suite> <name> 21 $0 show unpackaged <suite> <name>
17 $0 show unpackaged-du <suite> <name> ["filtered"] 22 $0 show unpackaged-du <suite> <name> ["filtered"]
@@ -134,21 +139,17 @@ show_unpackaged_du()
134 fi 139 fi
135} 140}
136 141
137sh_image() 142run_command_with_mountpoint()
138{ 143{
139 suite=$1 144 local suite="$1" name="$2" command="$3"
140 name=$2 145 shift 3
141 shift 2
142 if [ $# = 0 ]; then
143 set -- /bin/bash
144 fi
145 [ "$suite" -a "$name" ] || usage 146 [ "$suite" -a "$name" ] || usage
146 imagename=$(suite_name_to_imagename "$suite" "$name") 147 imagename=$(suite_name_to_imagename "$suite" "$name")
147 [ -e "$imagename" ] || die "no such file: $imagename" 148 [ -e "$imagename" ] || die "no such file: $imagename"
148 [ -d "$imagename".mnt ] || mkdir "$imagename".mnt || die "mkdir" 149 [ -d "$imagename".mnt ] || mkdir "$imagename".mnt || die "mkdir"
149 mountpoint -q "$imagename".mnt || mount "$imagename" "$imagename".mnt || die "mount" 150 mountpoint -q "$imagename".mnt || mount "$imagename" "$imagename".mnt || die "mount"
150 151
151 (cd "$imagename".mnt; "$@") 152 "$command" "$imagename".mnt "$@"
152 153
153 r=$? 154 r=$?
154 umount "$imagename".mnt 155 umount "$imagename".mnt
@@ -156,7 +157,58 @@ sh_image()
156 return $r 157 return $r
157} 158}
158 159
159default_chroot_command=/bin/bash 160rotate_args_left()
161{
162 local fst="$1" snd="$2"
163 shift 2
164 "$snd" "$@" "$fst"
165}
166
167add()
168{
169 export SKIP_UPDATE=y
170 suite=$1
171 name=$2
172 shift 2
173 running_suite=$(lsb_release -cs) || die 'lsb_release failed'
174 if [ "$suite" = "$running_suite" -a -x ./src/selfstrap ]; then
175 run_mp "$suite" "$name" ./src/selfstrap "$@" -t
176 else
177 exit 1
178 fi
179}
180
181run_mp()
182{
183 suite=$1
184 name=$2
185 shift 2
186 if [ $# = 0 ]; then
187 cmd=echo
188 else
189 cmd=$1
190 shift
191 fi
192 run_command_with_mountpoint "$suite" "$name" rotate_args_left "$cmd" "$@"
193}
194
195
196
197cd_then_run()
198{
199 (cd "$1"; shift; "$@")
200}
201
202sh_image()
203{
204 suite=$1
205 name=$2
206 shift 2
207 if [ $# = 0 ]; then
208 set -- $default_sh_command
209 fi
210 run_command_with_mountpoint "$suite" "$name" cd_then_run "$@"
211}
160 212
161chroot_image() 213chroot_image()
162{ 214{
@@ -253,7 +305,7 @@ init()
253 arch=$(dpkg-architecture -q DEB_HOST_ARCH) || die "command 'dpkg-architecture' failed" 305 arch=$(dpkg-architecture -q DEB_HOST_ARCH) || die "command 'dpkg-architecture' failed"
254 running_suite=$(lsb_release -cs) || die 'lsb_release failed' 306 running_suite=$(lsb_release -cs) || die 'lsb_release failed'
255 307
256 size=1G # truncate(1) format 308 size=$default_image_size
257 309
258 i_am_root || die 'you are not root' 310 i_am_root || die 'you are not root'
259 311
@@ -271,7 +323,11 @@ init()
271 trap 'umount "$target.mnt"' EXIT 323 trap 'umount "$target.mnt"' EXIT
272 324
273 if [ "$suite" = "$running_suite" -a -x ./src/selfstrap ]; then 325 if [ "$suite" = "$running_suite" -a -x ./src/selfstrap ]; then
274 ./src/selfstrap -t "$target.mnt" 326 # TODO:
327 # 1. Use a --chroot arg that will set up cgroups
328 # 2. Use --packages arg to implement variant
329 # 3. Allow selfstrap to run on already-initialized image
330 ./src/selfstrap -t "$target.mnt" || die "selfstrap failed"
275 else 331 else
276 debootstrap_efficiently "$arch" "$variant" "$suite" \ 332 debootstrap_efficiently "$arch" "$variant" "$suite" \
277 "$target".mnt "${target%.btrfs}".debs.txt || die "debootstrap failed" 333 "$target".mnt "${target%.btrfs}".debs.txt || die "debootstrap failed"
@@ -307,7 +363,7 @@ show()
307} 363}
308 364
309case "$1" in 365case "$1" in
310 init|new|clone|list|show) cmd=$1; shift; $cmd "$@" ;; 366 init|new|clone|list|show|add|run_mp) cmd=$1; shift; $cmd "$@" ;;
311 chroot|sh|rm) cmd=${1}_image; shift; $cmd "$@" ;; 367 chroot|sh|rm) cmd=${1}_image; shift; $cmd "$@" ;;
312 *) usage ;; 368 *) usage ;;
313esac 369esac