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
This commit is contained in:
Lyndon Brown 2020-04-01 05:22:39 +01:00 committed by Raphaël Hertzog
parent fc88358b29
commit e22bd27170
7 changed files with 95 additions and 104 deletions

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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 "${@}"

69
scripts/build/chroot_prep Executable file
View File

@ -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

View File

@ -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"

View File

@ -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"