|
|
|
@ -41,7 +41,7 @@ Setup_cleanup
|
|
|
|
|
|
|
|
|
|
. config/functions
|
|
|
|
|
|
|
|
|
|
lb_chroot_remove_packages() {
|
|
|
|
|
lb_chroot_remove_packages () {
|
|
|
|
|
# Remove packages from the chroot specific to this layer
|
|
|
|
|
#
|
|
|
|
|
# $1: Name of the pass*
|
|
|
|
@ -54,28 +54,28 @@ lb_chroot_remove_packages() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Create the snap list specific to this layer
|
|
|
|
|
lb_chroot_snap_lists() {
|
|
|
|
|
lb_chroot_snap_lists () {
|
|
|
|
|
local pass=$1
|
|
|
|
|
local prevpass=$2
|
|
|
|
|
|
|
|
|
|
# This assumes that the prefix is unique for a given project
|
|
|
|
|
local snap_for_pass=$(ls config/package-lists/*.snaplist.chroot_${pass}.full 2>/dev/null || true)
|
|
|
|
|
local snap_for_prevpass=$(ls config/package-lists/*.snaplist.chroot_${prevpass}.full 2>/dev/null || true)
|
|
|
|
|
parent_pass=$(get_parent_pass $pass)
|
|
|
|
|
local snap_for_parent_pass=$(ls config/package-lists/*.snaplist.chroot_${parent_pass}.full 2>/dev/null || true)
|
|
|
|
|
|
|
|
|
|
if [ -z "${snap_for_pass}" ]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "${snap_for_prevpass}" ]; then
|
|
|
|
|
if [ -z "${snap_for_parent_pass}" ]; then
|
|
|
|
|
cp ${snap_for_pass} ${snap_for_pass%.full}
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Generate a list of snaps added to a layer.
|
|
|
|
|
diff -NU0 ${snap_for_prevpass} ${snap_for_pass}|grep -Ev '^(---|\+\+\+|@@)'|cut -c2- > ${snap_for_pass%.full}
|
|
|
|
|
diff -NU0 ${snap_for_parent_pass} ${snap_for_pass}|grep -Ev '^(---|\+\+\+|@@)'|cut -c2- > ${snap_for_pass%.full}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lb_chroot_install_snaps() {
|
|
|
|
|
lb_chroot_install_snaps () {
|
|
|
|
|
# Prepare the snap environment and install snaps into a chroot
|
|
|
|
|
#
|
|
|
|
|
# $1: Name of the pass
|
|
|
|
@ -93,7 +93,7 @@ lb_chroot_install_snaps() {
|
|
|
|
|
done < $snaplist_file
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lb_chroot_includes() {
|
|
|
|
|
lb_chroot_includes () {
|
|
|
|
|
# Copying includes from pass subdirectory
|
|
|
|
|
local pass="$1"
|
|
|
|
|
|
|
|
|
@ -106,30 +106,47 @@ lb_chroot_includes() {
|
|
|
|
|
cd "${OLDPWD}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_chroot_pass() {
|
|
|
|
|
create_chroot_pass () {
|
|
|
|
|
local pass=$1
|
|
|
|
|
local prevpass=$2
|
|
|
|
|
local lowerlayers=$3
|
|
|
|
|
local passtype=$4 # "first"|"last"|"" empty string
|
|
|
|
|
shift 4 # restore ${*}
|
|
|
|
|
shift 1 # restore ${*}
|
|
|
|
|
|
|
|
|
|
# We have already treated that pass
|
|
|
|
|
if [ -d "overlay.${pass}/" ]; then
|
|
|
|
|
Echo_message "lb_chroot_layered: treating pass $pass"
|
|
|
|
|
|
|
|
|
|
# We have already treated that pass just return.
|
|
|
|
|
local overlay_dir="overlay.${pass}"
|
|
|
|
|
if [ -d "$overlay_dir/" ]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
export PASS=${pass}
|
|
|
|
|
|
|
|
|
|
if [ "${passtype}" != "first" ]; then
|
|
|
|
|
mkdir overlay.${pass}
|
|
|
|
|
mount_overlay ${lowerlayers} "overlay.${pass}/" chroot/
|
|
|
|
|
# Only get some function executed on root passes
|
|
|
|
|
# Copy bootstrap on root layers
|
|
|
|
|
if [ -z "$(get_parent_pass $pass)" ]; then
|
|
|
|
|
rm -f .build/chroot_linux-image .build/chroot_preseed .build/chroot_hacks
|
|
|
|
|
cp -a chroot.bootstrap/ "$overlay_dir/"
|
|
|
|
|
fi
|
|
|
|
|
# Others have to be executed on every pass
|
|
|
|
|
rm -f .build/chroot_early_hooks .build/chroot_hooks .build/chroot_interactive
|
|
|
|
|
|
|
|
|
|
mkdir -p "$overlay_dir/"
|
|
|
|
|
lowerdirs=$(get_lowerdirs_for_pass $pass)
|
|
|
|
|
if [ -n "$lowerdirs" ]; then
|
|
|
|
|
mkdir -p chroot/
|
|
|
|
|
mount_overlay "$lowerdirs" "$overlay_dir" chroot/
|
|
|
|
|
else
|
|
|
|
|
ln -s "$overlay_dir/" chroot
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
export PASS=${pass}
|
|
|
|
|
setenv_file PASS "${pass}" config/environment.chroot
|
|
|
|
|
|
|
|
|
|
# Configuring chroot
|
|
|
|
|
lb chroot_cache restore ${*}
|
|
|
|
|
lb chroot_devpts install ${*}
|
|
|
|
|
lb chroot_proc install ${*}
|
|
|
|
|
lb chroot_sysfs install ${*}
|
|
|
|
|
# We run chroot_hacks only on root layers (update-initramfs diverted)
|
|
|
|
|
if [ -z "$(get_parent_pass $pass)" ]; then
|
|
|
|
|
divert_update_initramfs
|
|
|
|
|
fi
|
|
|
|
|
lb chroot_debianchroot install ${*}
|
|
|
|
|
lb chroot_dpkg install ${*}
|
|
|
|
|
lb chroot_tmpfs install ${*}
|
|
|
|
@ -140,10 +157,11 @@ create_chroot_pass() {
|
|
|
|
|
# Note: this triggers an upgrade + dist-ugprade; which may impact sublayers with more
|
|
|
|
|
# diff content than desired. However, we still need to setup the archive and teardown
|
|
|
|
|
# for each layer.
|
|
|
|
|
# We could modify livebuild if necessary to have conditional upgrade (first pass only).
|
|
|
|
|
# We could modify livebuild if necessary to have conditional upgrade (root pass only).
|
|
|
|
|
lb chroot_archives chroot install ${*}
|
|
|
|
|
|
|
|
|
|
if [ "${passtype}" = "first" ]; then
|
|
|
|
|
# Only configure universe on root passes
|
|
|
|
|
if [ -z "$(get_parent_pass $pass)" ]; then
|
|
|
|
|
configure_universe
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@ -157,23 +175,22 @@ create_chroot_pass() {
|
|
|
|
|
lb_chroot_remove_packages ${pass} ${*}
|
|
|
|
|
|
|
|
|
|
# Snap management
|
|
|
|
|
lb_chroot_snap_lists ${pass} ${prevpass}
|
|
|
|
|
lb_chroot_snap_lists ${pass} ${*}
|
|
|
|
|
lb_chroot_install_snaps ${pass} ${*}
|
|
|
|
|
|
|
|
|
|
# Kernel should be in first layer
|
|
|
|
|
if [ "${passtype}" = "first" ]; then
|
|
|
|
|
configure_network_manager
|
|
|
|
|
|
|
|
|
|
# Mark kernel headers as autoremovable
|
|
|
|
|
Chroot chroot "dpkg -l linux-headers-3* linux-headers-4*" 2>/dev/null \
|
|
|
|
|
| awk '/^i/ {print $2}' > chroot.headers
|
|
|
|
|
for i in $(cat chroot.headers); do
|
|
|
|
|
Chroot chroot "apt-mark auto $i"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
Chroot chroot "apt-get --purge -y autoremove"
|
|
|
|
|
|
|
|
|
|
# Add live packages to top layer
|
|
|
|
|
if [ "${passtype}" = "last" ]; then
|
|
|
|
|
# Add live packages to live layers
|
|
|
|
|
if echo $pass | grep -Eq '\.live*'; then
|
|
|
|
|
lb chroot_live-packages ${*}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@ -181,7 +198,14 @@ create_chroot_pass() {
|
|
|
|
|
lb_chroot_includes ${pass} ${*}
|
|
|
|
|
|
|
|
|
|
lb chroot_hooks ${*}
|
|
|
|
|
|
|
|
|
|
# Run chroot_hacks only on root layers.
|
|
|
|
|
# chroot_hacks changes the mode of boot/initrd*. The side effect in
|
|
|
|
|
# layered mode is to create an initrd on each layer with a significant
|
|
|
|
|
# impact on image size (+30MB per layer). This is an issue even with
|
|
|
|
|
# update-initramfs disabled.
|
|
|
|
|
lb chroot_hacks ${*}
|
|
|
|
|
|
|
|
|
|
lb chroot_interactive ${*}
|
|
|
|
|
|
|
|
|
|
# Misc ubuntu cleanup and post-layer configuration
|
|
|
|
@ -202,45 +226,19 @@ create_chroot_pass() {
|
|
|
|
|
lb chroot_sysfs remove ${*}
|
|
|
|
|
lb chroot_proc remove ${*}
|
|
|
|
|
lb chroot_devpts remove ${*}
|
|
|
|
|
lb chroot_cache save ${*}
|
|
|
|
|
|
|
|
|
|
if [ "${passtype}" = "first" ]; then
|
|
|
|
|
mv chroot overlay.${pass}
|
|
|
|
|
mkdir chroot
|
|
|
|
|
else
|
|
|
|
|
if [ -n "$lowerdirs" ]; then
|
|
|
|
|
umount chroot
|
|
|
|
|
rmdir chroot
|
|
|
|
|
else
|
|
|
|
|
rm chroot
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Handle direct sublayer of current one
|
|
|
|
|
# Extract the name of the pass corresponding to the sublayer
|
|
|
|
|
for subpass in $(ls config/package-lists/*list.chroot_${pass}_* 2>/dev/null | sed -e "s/.*list\.chroot_\(${pass}_[^_]\+\).*/\1/"); do
|
|
|
|
|
lowerlayers_for_subpass="overlay.${pass}:${lowerlayers}"
|
|
|
|
|
lowerlayers_for_subpass="${lowerlayers_for_subpass%:}"
|
|
|
|
|
create_chroot_pass "${subpass}" "${pass}" "${lowerlayers_for_subpass}" "" ${*}
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PASSES="${PASSES:-install live}"
|
|
|
|
|
CURPASS=1
|
|
|
|
|
PREVPASS=""
|
|
|
|
|
LASTPASS=$(echo $PASSES|wc -w)
|
|
|
|
|
LOWER_LAYERS=""
|
|
|
|
|
if [ ! -d chroot.bootstrap/ ]; then
|
|
|
|
|
mv chroot/ chroot.bootstrap/
|
|
|
|
|
fi
|
|
|
|
|
for _PASS in $PASSES
|
|
|
|
|
do
|
|
|
|
|
PASSTYPE=""
|
|
|
|
|
if [ $CURPASS -eq 1 ]; then
|
|
|
|
|
PASSTYPE="first"
|
|
|
|
|
elif [ $CURPASS -eq $LASTPASS ]; then
|
|
|
|
|
PASSTYPE="last"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
create_chroot_pass "$_PASS" "$PREVPASS" "$LOWER_LAYERS" "$PASSTYPE" ${*}
|
|
|
|
|
|
|
|
|
|
LOWER_LAYERS="overlay.${_PASS}:$LOWER_LAYERS"
|
|
|
|
|
LOWER_LAYERS="${LOWER_LAYERS%:}"
|
|
|
|
|
PREVPASS=${_PASS}
|
|
|
|
|
|
|
|
|
|
CURPASS=$(( CURPASS + 1 ))
|
|
|
|
|
create_chroot_pass "$_PASS" ${*}
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
rmdir chroot
|
|
|
|
|