summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-04-01 05:22:39 +0100
committerRaphaƫl Hertzog <hertzog@debian.org>2020-04-23 09:38:02 +0000
commite22bd27170bba862239c41ebdd9a6f23ef865caf (patch)
treeef5e94ab59d716835f21a8e706ef80bc909e3dcc
parentfc88358b29bc353b15879d611cc25fc74ae91442 (diff)
downloadvyos-live-build-e22bd27170bba862239c41ebdd9a6f23ef865caf.tar.gz
vyos-live-build-e22bd27170bba862239c41ebdd9a6f23ef865caf.zip
add bulk chroot preparation script execution helper
rather than explicitly running one helper after another in the major build stages, or by hand (e.g. while testing things during development), they can be run in bulk via this new helper. it essentially just takes a list of helpers to run and runs them one by one. it supports running all helpers except chroot_archives because that one has different parameter requirements to the rest and supporting it would make things messier. helper scripts can either be named by their full script name or without the 'chroot_' prefix for brevity. you can also just specify 'all' to refer to all helpers (except chroot_archives, per above). it automatically reverses the order of the list when run in remove mode. Gbp-Dch: Short
-rw-r--r--manpages/en/live-build.74
-rwxr-xr-xscripts/build/binary32
-rwxr-xr-xscripts/build/bootstrap26
-rwxr-xr-xscripts/build/chroot26
-rwxr-xr-xscripts/build/chroot_prep69
-rwxr-xr-xscripts/build/installer32
-rwxr-xr-xscripts/build/source10
7 files changed, 95 insertions, 104 deletions
diff --git a/manpages/en/live-build.7 b/manpages/en/live-build.7
index 4c3f81f66..af6e62696 100644
--- a/manpages/en/live-build.7
+++ b/manpages/en/live-build.7
@@ -196,6 +196,10 @@ compiles the final source image into a tar archive
The notes above under the section regarding build-stage specific low-level plumbing commands also apply here.
.PP
The following chroot_ prefixed commands are used throughout the various primary stages of the build process to apply and remove modifications to a chroot root filesystem. Generally these are used to apply modification that setup the chroot for use (execution of programs within it) during the build process, and later to remove those modification, unmounting things that were mounted, and making the chroot suitable for use as the root filesystem of the live OS to be bundled into the live image.
+.PP
+Note that the \fBlb chroot_prep\fR(1) command can be used to run these components in bulk.
+.IP "\fBlb chroot_prep\fR(1)" 4
+a helper to run the below components in bulk, usable for all those that can be controlled with a single parameter of 'install' or 'remove' (thus excluding \fBlb chroot_archives\fR(1) and also \fBlb chroot_apt\fR(1) when run with 'install-binary'). The first parameter it takes is the execution mode - install or remove - to pass along. The second parameter is the set of helpers to run (they can be space or comma separated; remember to quote if space separated). Any remaining parameters (i.e. options like --force) are passed along. The second can be simply 'all' in which case a default set of all (applicable) components are used. Components can be specified without their filename 'chroot_' prefix for brevity. In remove mode the list of components are run in reverse order, so no need to provide them in reverse order yourself.
.IP "\fBlb chroot_apt\fR(1)" 4
manages apt configuration; in apply mode it applies configuration for use during build process, and in remove mode removes that configuration
.IP "\fBlb chroot_archives\fR(1)" 4
diff --git a/scripts/build/binary b/scripts/build/binary
index ac24a4f4a..49e0e994b 100755
--- a/scripts/build/binary
+++ b/scripts/build/binary
@@ -30,18 +30,16 @@ Setup_clean_exit
# Preparing root filesystem
lb binary_chroot "${@}"
+# Chroot preparation component lists
+# We deliberately exclude 'debianchroot' and 'tmpfs'
+CHROOT_PREP_MOUNTS="devpts proc selinuxfs sysfs"
+CHROOT_PREP_OTHER="dpkg sysv-rc hosts resolv hostname"
+
if [ "${LB_BUILD_WITH_CHROOT}" = "true" ]
then
# Configuring chroot
- lb chroot_devpts install "${@}"
- lb chroot_proc install "${@}"
- lb chroot_selinuxfs install "${@}"
- lb chroot_sysfs install "${@}"
- lb chroot_hosts install "${@}"
- lb chroot_resolv install "${@}"
- lb chroot_hostname install "${@}"
- lb chroot_dpkg install "${@}"
- lb chroot_sysv-rc install "${@}"
+ lb chroot_prep install "${CHROOT_PREP_MOUNTS}" "${@}"
+ lb chroot_prep install "${CHROOT_PREP_OTHER}" "${@}"
lb chroot_apt install-binary "${@}"
lb chroot_archives chroot install "${@}"
fi
@@ -68,10 +66,7 @@ lb binary_checksums "${@}"
if [ "${LB_BUILD_WITH_CHROOT}" != "true" ]
then
- lb chroot_devpts install "${@}"
- lb chroot_proc install "${@}"
- lb chroot_selinuxfs install "${@}"
- lb chroot_sysfs install "${@}"
+ lb chroot_prep install "${CHROOT_PREP_MOUNTS}" "${@}"
fi
# Building images
@@ -89,16 +84,9 @@ then
Remove_stagefile chroot_archives
lb chroot_apt remove "${@}"
- lb chroot_hostname remove "${@}"
- lb chroot_resolv remove "${@}"
- lb chroot_hosts remove "${@}"
- lb chroot_sysv-rc remove "${@}"
- lb chroot_dpkg remove "${@}"
+ lb chroot_prep remove "${CHROOT_PREP_OTHER}" "${@}"
fi
-lb chroot_sysfs remove "${@}"
-lb chroot_selinuxfs remove "${@}"
-lb chroot_proc remove "${@}"
-lb chroot_devpts remove "${@}"
+lb chroot_prep remove "${CHROOT_PREP_MOUNTS}" "${@}"
Echo_message "Binary stage completed"
diff --git a/scripts/build/bootstrap b/scripts/build/bootstrap
index dcb4f710b..8ec5d237c 100755
--- a/scripts/build/bootstrap
+++ b/scripts/build/bootstrap
@@ -33,33 +33,11 @@ lb bootstrap_debootstrap "${@}"
lb bootstrap_cache save "${@}"
# Configuring chroot
-lb chroot_devpts install "${@}"
-lb chroot_proc install "${@}"
-lb chroot_selinuxfs install "${@}"
-lb chroot_sysfs install "${@}"
-lb chroot_debianchroot install "${@}"
-lb chroot_dpkg install "${@}"
-lb chroot_tmpfs install "${@}"
-lb chroot_sysv-rc install "${@}"
-lb chroot_hosts install "${@}"
-lb chroot_resolv install "${@}"
-lb chroot_hostname install "${@}"
-lb chroot_apt install "${@}"
+lb chroot_prep install all "${@}"
lb bootstrap_archives binary "${@}"
# Deconfiguring chroot
-lb chroot_apt remove "${@}"
-lb chroot_hostname remove "${@}"
-lb chroot_resolv remove "${@}"
-lb chroot_hosts remove "${@}"
-lb chroot_sysv-rc remove "${@}"
-lb chroot_tmpfs remove "${@}"
-lb chroot_dpkg remove "${@}"
-lb chroot_debianchroot remove "${@}"
-lb chroot_sysfs remove "${@}"
-lb chroot_selinuxfs remove "${@}"
-lb chroot_proc remove "${@}"
-lb chroot_devpts remove "${@}"
+lb chroot_prep remove all "${@}"
Echo_message "Bootstrap stage completed"
diff --git a/scripts/build/chroot b/scripts/build/chroot
index ad15ff0a2..f6ac8901f 100755
--- a/scripts/build/chroot
+++ b/scripts/build/chroot
@@ -31,18 +31,7 @@ Setup_clean_exit
lb chroot_cache restore "${@}"
# Configuring chroot
-lb chroot_devpts install "${@}"
-lb chroot_proc install "${@}"
-lb chroot_selinuxfs install "${@}"
-lb chroot_sysfs install "${@}"
-lb chroot_debianchroot install "${@}"
-lb chroot_dpkg install "${@}"
-lb chroot_tmpfs install "${@}"
-lb chroot_sysv-rc install "${@}"
-lb chroot_hosts install "${@}"
-lb chroot_resolv install "${@}"
-lb chroot_hostname install "${@}"
-lb chroot_apt install "${@}"
+lb chroot_prep install all "${@}"
lb chroot_archives chroot install "${@}"
# Customizing chroot
@@ -68,18 +57,7 @@ Chroot chroot "dpkg-query -W" > chroot.packages.live
# Deconfiguring chroot
lb chroot_archives chroot remove "${@}"
-lb chroot_apt remove "${@}"
-lb chroot_hostname remove "${@}"
-lb chroot_resolv remove "${@}"
-lb chroot_hosts remove "${@}"
-lb chroot_sysv-rc remove "${@}"
-lb chroot_tmpfs remove "${@}"
-lb chroot_dpkg remove "${@}"
-lb chroot_debianchroot remove "${@}"
-lb chroot_sysfs remove "${@}"
-lb chroot_selinuxfs remove "${@}"
-lb chroot_proc remove "${@}"
-lb chroot_devpts remove "${@}"
+lb chroot_prep remove all "${@}"
# Saving live OS chroot to cache
lb chroot_cache save "${@}"
diff --git a/scripts/build/chroot_prep b/scripts/build/chroot_prep
new file mode 100755
index 000000000..8bb456b8b
--- /dev/null
+++ b/scripts/build/chroot_prep
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2020 The Debian Live team
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="Prep chroot"
+USAGE="${PROGRAM} {install|remove} {all|\"HELPERS\"} [--force]"
+
+# Processing arguments and configuration files
+Init_config_data "${@}"
+
+# Requiring stage file
+Require_stagefiles config bootstrap
+
+ACTION="${1}"
+HELPERS="${2}"
+shift 2
+
+if ! In_list "${ACTION}" install remove; then
+ Echo_error "Invalid action parameter"
+ exit 1
+fi
+
+if [ -z "${HELPERS}" ]; then
+ Echo_error "You must specify which helpers to run"
+ exit 1
+fi
+
+if [ "${HELPERS}" = "all" ]; then
+ # Use default set of all helpers (except chroot_archives which cannot be supported due to different parameter needs)
+ HELPERS="devpts proc selinuxfs sysfs debianchroot dpkg tmpfs sysv-rc hosts resolv hostname apt"
+else
+ # Support both comma and space separation
+ # Support with and without 'chroot_' script filename prefix
+ HELPERS="$(echo "${HELPERS}" | sed -e 's|,| |g' -e 's|^chroot_||g')"
+fi
+
+if In_list "prep" ${HELPERS}; then
+ Echo_error "Recursive!"
+ exit 1
+fi
+
+if In_list "archives" ${HELPERS}; then
+ Echo_error "The chroot_archives helper cannot be used through chroot_prep!"
+ exit 1
+fi
+
+if [ "${_ACTION}" = "remove" ]; then
+ HELPERS_REVERSED=""
+ for HELPER in $HELPERS; do
+ HELPERS_REVERSED="${HELPER}${HELPERS_REVERSED:+ $HELPERS_REVERSED}"
+ done
+ HELPERS="${HELPERS_REVERSED}"
+fi
+
+for HELPER in $HELPERS; do
+ lb "chroot_${HELPER}" "${ACTION}" "${@}"
+done
diff --git a/scripts/build/installer b/scripts/build/installer
index 3054861dc..bab2a6d32 100755
--- a/scripts/build/installer
+++ b/scripts/build/installer
@@ -27,21 +27,9 @@ Init_config_data "${@}"
# Setting up cleanup function
Setup_clean_exit
-if [ "${LB_BUILD_WITH_CHROOT}" = "true" ]
-then
+if [ "${LB_BUILD_WITH_CHROOT}" = "true" ]; then
# Configuring chroot
- lb chroot_devpts install "${@}"
- lb chroot_proc install "${@}"
- lb chroot_selinuxfs install "${@}"
- lb chroot_sysfs install "${@}"
- lb chroot_debianchroot install "${@}"
- lb chroot_dpkg install "${@}"
- lb chroot_tmpfs install "${@}"
- lb chroot_sysv-rc install "${@}"
- lb chroot_hosts install "${@}"
- lb chroot_resolv install "${@}"
- lb chroot_hostname install "${@}"
- lb chroot_apt install "${@}"
+ lb chroot_prep install all "${@}"
lb chroot_archives chroot install "${@}"
fi
@@ -49,22 +37,10 @@ fi
lb installer_debian-installer "${@}"
lb installer_preseed "${@}"
-if [ "${LB_BUILD_WITH_CHROOT}" = "true" ]
-then
+if [ "${LB_BUILD_WITH_CHROOT}" = "true" ]; then
# Deconfiguring chroot
lb chroot_archives chroot remove "${@}"
- lb chroot_apt remove "${@}"
- lb chroot_hostname remove "${@}"
- lb chroot_resolv remove "${@}"
- lb chroot_hosts remove "${@}"
- lb chroot_sysv-rc remove "${@}"
- lb chroot_tmpfs remove "${@}"
- lb chroot_dpkg remove "${@}"
- lb chroot_debianchroot remove "${@}"
- lb chroot_sysfs remove "${@}"
- lb chroot_selinuxfs remove "${@}"
- lb chroot_proc remove "${@}"
- lb chroot_devpts remove "${@}"
+ lb chroot_prep remove all "${@}"
fi
Echo_message "Installer stage completed"
diff --git a/scripts/build/source b/scripts/build/source
index 7e03c337c..9fe0dc8e0 100755
--- a/scripts/build/source
+++ b/scripts/build/source
@@ -32,10 +32,10 @@ fi
# Setting up cleanup function
Setup_clean_exit
+CHROOT_PREP="hosts resolv hostname"
+
# Configuring chroot (enabling networking)
-lb chroot_hosts install "${@}"
-lb chroot_resolv install "${@}"
-lb chroot_hostname install "${@}"
+lb chroot_prep install "${CHROOT_PREP}" "${@}"
lb chroot_archives source install "${@}"
# Preparing images
@@ -52,8 +52,6 @@ lb source_hdd "${@}"
# Deconfiguring chroot
lb chroot_archives source remove "${@}"
-lb chroot_hostname remove "${@}"
-lb chroot_resolv remove "${@}"
-lb chroot_hosts remove "${@}"
+lb chroot_prep remove "${CHROOT_PREP}" "${@}"
Echo_message "Source stage completed"