Add support for local package repositories

live-build has been able to install packages from a local deb repo for
a while now, but this functionality simply installs everything placed
under the packages.chroot folder. This is unsuitable for usecases where
one only wants to install specific local packages, allowing their
dependencies to be marked as automatically installed. The workaround of
hosting a deb repo is both difficult and unsuitable for usecases where
an end-user is expected to be able to build all local packages from
source and then use them to build the final ISO.

To support this edge case, allow the user to point live-build to one or
more local apt repositories by passing their paths to lb_config with a
--chroot-localrepos argument. live-build will bind-mount the specified
directories into the chroot, install temporary sources.list files for
them, and then proceed with package installation, allowing those
packages to be used like any other apt repo. The sources.list files for
these temporary files are deleted and the bind-mounts removed once they
are no longer necessary.
This commit is contained in:
Aaron Rainbolt 2024-10-15 01:03:21 -05:00
parent ccf1f49bb9
commit eeb0629efa
No known key found for this signature in database
GPG Key ID: A709160D73C79109
4 changed files with 76 additions and 1 deletions

View File

@ -65,6 +65,8 @@
[\fB\-\-checksums\fR md5|sha1|sha224|sha256|sha384|sha512|none]
.br
[\fB\-\-chroot\-filesystem\fR ext2|ext3|ext4|squashfs|jffs2|none|plain]
.br
[\fB\-\-chroot\-localrepos\fR \fIPARAMETER\fR|"\fIPARAMETERS\fR"]
.br
[\fB\-\-chroot\-squashfs\-compression\-level\fR LEVEL]
.br
@ -298,6 +300,8 @@ sets which stages should be cached (a comma or space separated list). By default
defines if the binary image should contain a file called XXXsums.txt, where XXX is one of the mentioned checksum types. This file lists all files on the image together with their checksums. This in turn can be used by \fIlive\-boot\fR(7)'s built\-in integrity\-check to verify the medium if specified at boot prompt. In general, this should not be 'none' and is an important feature of live system released to the public. However, during development of very big images it can save some time by not calculating the checksums.
.IP "\fB\-\-chroot\-filesystem\fR ext2|ext3|ext4|squashfs|jffs2|none|plain" 4
defines which filesystem type should be used for the root filesystem image. If you use 'none' or 'plain', then no filesystem image is created and the root filesystem content is copied on the binary image filesystem as flat files. Depending on what binary filesystem you have chosen, it may not be possible to build with such a plain root filesystem, e.g. fat16/fat32 will not work as linux does not support running directly on them.
.IP "\fB\-\-chroot\-localrepos\fR \fIPARAMETER\fR|""\fIPARAMETERS\fR""" 4
specifies one more more space-separated paths to use as local apt repositories. The repositories will be treated the same as remote apt repositories. This is mainly useful if you have a number of local packages you wish to install onto the live ISO, but want to ensure dependency packages are properly marked as automatically installed so they can be autoremoved later if needed.
.IP "\fB\-\-chroot\-squashfs\-compression\-level\fR LEVEL" 4
defines the compression level that is used for the root filesystem image if squashfs is used. Each compression algorithm supports different levels (or none). You can look them up in the \fImksquashfs\fR help. Defaults to the default setting in \fImksquashfs\fR.
.IP "\fB\-\-chroot\-squashfs\-compression\-type\fR gzip|lzma|lzo|lz4|xz|zstd" 4

View File

@ -30,6 +30,9 @@ Setup_clean_exit
# Restoring cached live OS chroot from cache
lb chroot_cache restore "${@}"
# Enable use of a local package repo if it is present
lb chroot_local-repos configure "${@}"
# Configuring chroot
lb chroot_prep install all mode-archives-chroot "${@}"
@ -56,6 +59,7 @@ lb chroot_interactive "${@}"
Chroot chroot "dpkg-query -W" > chroot.packages.live
# Deconfiguring chroot
lb chroot_local-repos deconfigure "${@}"
lb chroot_prep remove all mode-archives-chroot "${@}"
# Saving live OS chroot to cache

View File

@ -0,0 +1,58 @@
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## 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="Enable use of local deb repository"
USAGE="${PROGRAM} {configure|deconfigure} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
_ACTION="${1}"
shift
Echo_message "Begin enabling use of temporary local deb repository"
Require_stagefiles config bootstrap
if [ -z "${LB_LOCALREPOS}" ]
then
exit 0
fi
for _LOCALREPO_PATH in ${LB_LOCALREPOS}
do
case "${_ACTION}" in
configure)
_LOCALREPO_FILE="$(basename "${_LOCALREPO_PATH}")"
mkdir -p chroot/root/localrepos/"${_LOCALREPO_FILE}"
mount --bind "${_LOCALREPO_PATH}" chroot/root/localrepos/"${_LOCALREPO_FILE}"
echo "deb [trusted=yes] file:/root/localrepos/${_LOCALREPO_FILE} ./" > chroot/etc/apt/sources.list.d/"${_LOCALREPO_FILE}".list
;;
deconfigure)
_LOCALREPO_FILE="$(basename "${_LOCALREPO_PATH}")"
rm chroot/etc/apt/sources.list.d/"${_LOCALREPO_FILE}".list
umount chroot/root/localrepos/"${_LOCALREPO_FILE}"
rm -rf chroot/root/localrepos/"${_LOCALREPO_FILE}"
;;
*)
Echo_error "Invalid action parameter: '${_ACTION}'"
Usage --fail
;;
esac
done

View File

@ -45,6 +45,7 @@ USAGE="${PROGRAM} [--apt apt|apt-get|aptitude]\n\
\t [--cache-stages STAGE|\"STAGES\"]\n\
\t [--checksums md5|sha1|sha224|sha256|sha384|sha512|none]\n\
\t [--chroot-filesystem ext2|ext3|ext4|squashfs|jffs2|none]\n\
\t [--chroot-localrepos PARAMETER|\"PARAMETERS\"]\n\
\t [--chroot-squashfs-compression-level LEVEL]\n\
\t [--chroot-squashfs-compression-type gzip|lzma|lzo|lz4|xz|zstd]\n\
\t [--clean]\n\
@ -142,7 +143,7 @@ Local_arguments ()
bootloader:,bootloaders:,bootstrap-qemu-arch:,bootstrap-qemu-exclude:,
bootstrap-qemu-static:,breakpoints,build-with-chroot:,
cache:,cache-indices:,cache-packages:,cache-stages:,checksums:,
chroot-filesystem:,chroot-squashfs-compression-level:,
chroot-filesystem:,chroot-localrepos:,chroot-squashfs-compression-level:,
chroot-squashfs-compression-type:,clean,color,compression:,conffile:,
config:,debconf-frontend:,debconf-priority:,debian-installer:,
debian-installer-distribution:,debian-installer-gui:,
@ -420,6 +421,11 @@ Local_arguments ()
shift 2
;;
--chroot-localrepos)
LB_LOCALREPOS="${2}"
shift 2
;;
--chroot-squashfs-compression-level)
LB_CHROOT_SQUASHFS_COMPRESSION_LEVEL="${2}"
shift 2
@ -1188,6 +1194,9 @@ LB_UPDATES="${LB_UPDATES}"
# Enable backports updates
LB_BACKPORTS="${LB_BACKPORTS}"
# Set path to one or more local deb repositories
LB_LOCALREPOS="${LB_LOCALREPOS}"
EOF
# Creating lb_binary_* configuration