From c469eeba7a751464f9613cd92aaf77c7208869ce Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 19 Jan 2025 13:53:10 +0100 Subject: [PATCH] hooks: introduce `post_armbian_repo_customize_image` and `post_repo_customize_image` - `post_repo_customize_image`: runs after repos have been enabled - `post_armbian_repo_customize_image`: same, but only if Armbian repo is enabled - both run after apt update, so packages can be directly installed from repos --- lib/functions/main/rootfs-image.sh | 15 +++++++++++++-- lib/functions/rootfs/customize.sh | 31 ++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/functions/main/rootfs-image.sh b/lib/functions/main/rootfs-image.sh index 89f1bd2b6..455b774aa 100644 --- a/lib/functions/main/rootfs-image.sh +++ b/lib/functions/main/rootfs-image.sh @@ -28,7 +28,7 @@ function build_rootfs_and_image() { # install distribution and board specific applications LOG_SECTION="install_distribution_specific_${RELEASE}" do_with_logging install_distribution_specific - LOG_SECTION="install_distribution_agnostic" do_with_logging install_distribution_agnostic + LOG_SECTION="install_distribution_agnostic" do_with_logging install_distribution_agnostic # does apt update # install locally built packages # @TODO: armbian-nextify this eventually #[[ $EXTERNAL_NEW == compile ]] && LOG_SECTION="packages_local" do_with_logging chroot_installpackages_local @@ -40,9 +40,10 @@ function build_rootfs_and_image() { # stage: user customization script # NOTE: installing too many packages may fill tmpfs mount + # NOTE(rpardini): hooks run _without_ the standard Armbian repo (sources.list) enabled. LOG_SECTION="customize_image" do_with_logging customize_image - # Deploy the full apt lists, including the Armbian repo. + # Deploy the full apt lists, including the Armbian repo. Hook: "custom_apt_repo" create_sources_list_and_deploy_repo_key "image-late" "${RELEASE}" "${SDCARD}/" # We call this above method too many times. @TODO: find out why and fix the same @@ -51,6 +52,16 @@ function build_rootfs_and_image() { rm "${SDCARD}"/etc/apt/sources.list.d/armbian.list.disabled fi + LOG_SECTION="post_repo_apt_update" do_with_logging post_repo_apt_update + + ## stage: further customization; hooks only run _with_ Armbian repo enabled, or not at all. + if [[ "${SKIP_ARMBIAN_REPO}" != "yes" ]]; then + LOG_SECTION="post_armbian_repo_customize_image" do_with_logging run_hooks_post_armbian_repo_customize_image + fi + + ## stage: late customization script; hooks always run; either with or without Armbian repo enabled. + LOG_SECTION="post_repo_customize_image" do_with_logging run_hooks_post_repo_customize_image + # remove packages that are no longer needed. rootfs cache + uninstall might have leftovers. LOG_SECTION="apt_purge_unneeded_packages_and_clean_apt_caches" do_with_logging apt_purge_unneeded_packages_and_clean_apt_caches diff --git a/lib/functions/rootfs/customize.sh b/lib/functions/rootfs/customize.sh index 1085dcf3a..f861b64ca 100644 --- a/lib/functions/rootfs/customize.sh +++ b/lib/functions/rootfs/customize.sh @@ -7,8 +7,7 @@ # This file is a part of the Armbian Build Framework # https://github.com/armbian/build/ -customize_image() { - +function customize_image() { # for users that need to prepare files at host # shellcheck source=/dev/null [[ -f $USERPATCHES_PATH/customize-image-host.sh ]] && source "$USERPATCHES_PATH"/customize-image-host.sh @@ -17,6 +16,8 @@ customize_image() { *run before customize-image.sh* This hook is called after `customize-image-host.sh` is called, but before the overlay is mounted. It thus can be used for the same purposes as `customize-image-host.sh`. + Attention: only the Distro default repos are enabled at this point; no packages from Armbian or custom repos can be used. + If you need repos, please consider `post_armbian_repo_customize_image` or `post_repo_customize_image`. PRE_CUSTOMIZE_IMAGE cp "$USERPATCHES_PATH"/customize-image.sh "${SDCARD}"/tmp/customize-image.sh @@ -41,7 +42,33 @@ customize_image() { call_extension_method "post_customize_image" "image_tweaks_post_customize" <<- 'POST_CUSTOMIZE_IMAGE' *post customize-image.sh hook* Run after the customize-image.sh script is run, and the overlay is unmounted. + Attention: only the Distro default repos are enabled at this point; no Armbian or custom repos can be used. POST_CUSTOMIZE_IMAGE return 0 } + +function post_repo_apt_update() { + # update package lists after customizing the image + display_alert "Updating APT package lists" "after customization" "info" + do_with_retries 3 chroot_sdcard_apt_get_update +} + +function run_hooks_post_armbian_repo_customize_image() { + call_extension_method "post_armbian_repo_customize_image" <<- 'post_armbian_repo_customize_image' + *run after post_customize_image, after and only if Armbian standard repos have been enabled* + All repos have been enabled, including the Armbian repo and custom ones. + You can install packages from the Armbian repo here. + post_armbian_repo_customize_image + return 0 +} + +function run_hooks_post_repo_customize_image() { + call_extension_method "post_repo_customize_image" <<- 'post_repo_customize_image' + *run after post_customize_image, after repos have been enabled* + All repos have been enabled, including custom ones; Armbian repo is not guaranteed to be enabled. + You can install packages from the default Debian/Ubuntu repos, or custom repos, here. + To install packages from the Armbian repo, use the post_armbian_repo_customize_image hook. + post_repo_customize_image + return 0 +}