Skip to content

Commit

Permalink
hooks: introduce post_armbian_repo_customize_image and `post_repo_c…
Browse files Browse the repository at this point in the history
…ustomize_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
  • Loading branch information
rpardini authored and igorpecovnik committed Jan 19, 2025
1 parent 5014f05 commit c469eeb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/functions/main/rootfs-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
31 changes: 29 additions & 2 deletions lib/functions/rootfs/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}

0 comments on commit c469eeb

Please sign in to comment.