From 06d994ca36e1c489925daeadd20c58357c2a22fa Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 12 Jun 2018 19:01:13 -0400 Subject: new command "add" to add packages --- debootstrap.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 12 deletions(-) (limited to 'debootstrap.sh') diff --git a/debootstrap.sh b/debootstrap.sh index 1b88a86..736d608 100755 --- a/debootstrap.sh +++ b/debootstrap.sh @@ -1,5 +1,9 @@ #!/bin/sh imgdir=./debootstrap +default_sh_command=bash +default_chroot_command=/bin/bash +default_image_size=1G # truncate(1) format + warn() { printf 'Warning: %s\n' "$*" >&2; } die() { printf 'Error: %s\n' "$*" >&2; exit 1; } [ -d "$imgdir" ] || die "directory does not exist: $imgdir" @@ -12,6 +16,7 @@ Usage: $0 new $0 clone $0 chroot + $0 add [packages...] $0 list $0 show unpackaged $0 show unpackaged-du ["filtered"] @@ -134,21 +139,17 @@ show_unpackaged_du() fi } -sh_image() +run_command_with_mountpoint() { - suite=$1 - name=$2 - shift 2 - if [ $# = 0 ]; then - set -- /bin/bash - fi + local suite="$1" name="$2" command="$3" + shift 3 [ "$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" - (cd "$imagename".mnt; "$@") + "$command" "$imagename".mnt "$@" r=$? umount "$imagename".mnt @@ -156,7 +157,58 @@ sh_image() return $r } -default_chroot_command=/bin/bash +rotate_args_left() +{ + local fst="$1" snd="$2" + shift 2 + "$snd" "$@" "$fst" +} + +add() +{ + export SKIP_UPDATE=y + suite=$1 + name=$2 + shift 2 + running_suite=$(lsb_release -cs) || die 'lsb_release failed' + if [ "$suite" = "$running_suite" -a -x ./src/selfstrap ]; then + run_mp "$suite" "$name" ./src/selfstrap "$@" -t + else + exit 1 + fi +} + +run_mp() +{ + suite=$1 + name=$2 + shift 2 + if [ $# = 0 ]; then + cmd=echo + else + cmd=$1 + shift + fi + run_command_with_mountpoint "$suite" "$name" rotate_args_left "$cmd" "$@" +} + + + +cd_then_run() +{ + (cd "$1"; shift; "$@") +} + +sh_image() +{ + suite=$1 + name=$2 + shift 2 + if [ $# = 0 ]; then + set -- $default_sh_command + fi + run_command_with_mountpoint "$suite" "$name" cd_then_run "$@" +} chroot_image() { @@ -253,7 +305,7 @@ init() arch=$(dpkg-architecture -q DEB_HOST_ARCH) || die "command 'dpkg-architecture' failed" running_suite=$(lsb_release -cs) || die 'lsb_release failed' - size=1G # truncate(1) format + size=$default_image_size i_am_root || die 'you are not root' @@ -271,7 +323,11 @@ init() trap 'umount "$target.mnt"' EXIT if [ "$suite" = "$running_suite" -a -x ./src/selfstrap ]; then - ./src/selfstrap -t "$target.mnt" + # TODO: + # 1. Use a --chroot arg that will set up cgroups + # 2. Use --packages arg to implement variant + # 3. Allow selfstrap to run on already-initialized image + ./src/selfstrap -t "$target.mnt" || die "selfstrap failed" else debootstrap_efficiently "$arch" "$variant" "$suite" \ "$target".mnt "${target%.btrfs}".debs.txt || die "debootstrap failed" @@ -307,7 +363,7 @@ show() } case "$1" in - init|new|clone|list|show) cmd=$1; shift; $cmd "$@" ;; + init|new|clone|list|show|add|run_mp) cmd=$1; shift; $cmd "$@" ;; chroot|sh|rm) cmd=${1}_image; shift; $cmd "$@" ;; *) usage ;; esac -- cgit v1.2.3