Skip to content

Instantly share code, notes, and snippets.

@rpardini
Created May 6, 2021 05:03
Show Gist options
  • Save rpardini/9a2b61c93345feb635c873e86ab361a7 to your computer and use it in GitHub Desktop.
Save rpardini/9a2b61c93345feb635c873e86ab361a7 to your computer and use it in GitHub Desktop.
Example sample-fragment.sh produced by Armbian
# Sample Armbian build system fragment with all hooks.
# This file is auto-generated from the build system.
# Please, always use the latest available version of this file as a starting point for your own fragments.
# Read more about the build extensibility system at https://todo
#### *give the config a chance to override the family/arch defaults*
### This hook is called after the family configuration ("sources/families/xxx.conf") is sourced.
### Since the family can override values from the user configuration and the board configuration,
### it is often used to in turn override those.
post_family_config__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 1/18" "making 'post_family_config' more awesome" "info"
export PROGRESS_DISPLAY=verysilent # Example: export a variable. This one silences the built.
# @TODO: Please also remember to rename this function, but preserve the "post_family_config__" prefix.
} # end of function post_family_config__be_more_awesome()
#### *Invoke function with user override*
### Allows for overriding configuration values set anywhere else.
### It is called after sourcing the "lib.config" file if it exists,
### but before assembling any package lists.
user_config__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 2/18" "making 'user_config' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "user_config__" prefix.
} # end of function user_config__be_more_awesome()
#### *For final user override, using a function, after all aggregations are done*
### Called after aggregating all package lists, before the end of "compilation.sh".
### Packages will still be installed after this is called, so it is the last chance
### to confirm or change any packages.
post_aggregate_packages__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 3/18" "making 'post_aggregate_packages' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_aggregate_packages__" prefix.
} # end of function post_aggregate_packages__be_more_awesome()
#### *give config a chance modify CTHREADS programatically. A build server may work better with hyperthreads-1 for example.*
### Called early, before any compilation work starts.
post_determine_cthreads__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 4/18" "making 'post_determine_cthreads' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_determine_cthreads__" prefix.
} # end of function post_determine_cthreads__be_more_awesome()
#### *give config a chance to act before install_distribution_specific*
### Called after "create_rootfs_cache" (_prepare basic rootfs: unpack cache or create from scratch_) but before "install_distribution_specific" (_install distribution and board specific applications_).
pre_install_distribution_specific__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 5/18" "making 'pre_install_distribution_specific' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "pre_install_distribution_specific__" prefix.
} # end of function pre_install_distribution_specific__be_more_awesome()
#### *allow config to do more with the installed kernel/headers*
### Called after packages, u-boot, kernel and headers installed in the chroot, but before the BSP is installed.
post_install_kernel_debs__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 6/18" "making 'post_install_kernel_debs' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_install_kernel_debs__" prefix.
} # end of function post_install_kernel_debs__be_more_awesome()
#### *customize the tweaks made by $LINUXFAMILY-specific family_tweaks*
### It is run after packages are installed in the rootfs, but before enabling additional services.
### It allows implementors access to the rootfs ("${SDCARD}") in its pristine state after packages are installed.
post_family_tweaks__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 7/18" "making 'post_family_tweaks' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_family_tweaks__" prefix.
} # end of function post_family_tweaks__be_more_awesome()
#### *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".
pre_customize_image__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 8/18" "making 'pre_customize_image' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "pre_customize_image__" prefix.
} # end of function pre_customize_image__be_more_awesome()
#### *post customize-image.sh hook*
### Run after the customize-image.sh script is run, and the overlay is unmounted.
post_customize_image__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 9/18" "making 'post_customize_image' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_customize_image__" prefix.
} # end of function post_customize_image__be_more_awesome()
#### *run after removing diversions and qemu with chroot unmounted*
### Last chance to touch the "${SDCARD}" filesystem before it is copied to the final media.
### It is too late to run any chrooted commands, since the supporting filesystems are already unmounted.
post_post_debootstrap_tweaks__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 10/18" "making 'post_post_debootstrap_tweaks' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_post_debootstrap_tweaks__" prefix.
} # end of function post_post_debootstrap_tweaks__be_more_awesome()
#### *allow custom options for mkfs*
### Called after "chroot_installpackages" (_install from apt.armbian.com_) but before "customize_image" (_user customization script_).
pre_prepare_partitions__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 11/18" "making 'pre_prepare_partitions' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "pre_prepare_partitions__" prefix.
} # end of function pre_prepare_partitions__be_more_awesome()
#### *allow dynamically determining the size based on the $rootfs_size*
### Called after "${rootfs_size}" is known, but before "${FIXED_IMAGE_SIZE}" is taken into account.
### A good spot to determine "FIXED_IMAGE_SIZE" based on "rootfs_size".
prepare_image_size__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 12/18" "making 'prepare_image_size' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "prepare_image_size__" prefix.
} # end of function prepare_image_size__be_more_awesome()
#### *allow config to hack into the initramfs create process*
### Called after rsync has synced both "/root" and "/root" on the target, but before calling "update_initramfs".
pre_update_initramfs__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 13/18" "making 'pre_update_initramfs' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "pre_update_initramfs__" prefix.
} # end of function pre_update_initramfs__be_more_awesome()
#### *allow config to hack into the image before the unmount*
### Called before unmounting both "/root" and "/boot".
pre_umount_final_image__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 14/18" "making 'pre_umount_final_image' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "pre_umount_final_image__" prefix.
} # end of function pre_umount_final_image__be_more_awesome()
#### *allow config to hack into the image after the unmount*
### Called after unmounting both "/root" and "/boot".
post_umount_final_image__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 15/18" "making 'post_umount_final_image' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_umount_final_image__" prefix.
} # end of function post_umount_final_image__be_more_awesome()
#### *custom post build hook*
### Called after the final .img file is built, before it is (possibly) written to an SD writer.
### - *NOTE*: this hook used to take an argument ($1) for the final image produced.
### - Now it is passed as an environment variable "${FINAL_IMAGE_FILE}"
### It is the last possible chance to modify "$CARD_DEVICE".
post_build_image__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 16/18" "making 'post_build_image' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "post_build_image__" prefix.
} # end of function post_build_image__be_more_awesome()
#### *hook for function to run after build, i.e. to change owner of "$SRC"*
### Really one of the last hooks ever called. The build has ended. Congratulations.
### - *NOTE:* this will run only if there were no errors during build process.
run_after_build__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 17/18" "making 'run_after_build' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "run_after_build__" prefix.
} # end of function run_after_build__be_more_awesome()
#### *meta-Meta time!*
### Implement this hook to work with/on the meta-data made available by the fragment manager.
### Interesting stuff to process:
### - ""${FRAGMENT_MANAGER_TMP_DIR}/hook_point_calls.txt"" contains a list of all hook points called, in order.
### - For each hook_point in the list, more files will have metadata about that hook point.
### - "${FRAGMENT_MANAGER_TMP_DIR}/hook_point.orig.md" contains the hook documentation at the call site (inline docs), hopefully in Markdown format.
### - "${FRAGMENT_MANAGER_TMP_DIR}/hook_point.compat" contains the compatibility names for the hooks.
### - "${FRAGMENT_MANAGER_TMP_DIR}/hook_point.exports" contains _exported_ environment variables.
### - "${FRAGMENT_MANAGER_TMP_DIR}/hook_point.vars" contains _all_ environment variables.
### - "${defined_hook_point_functions}" is a map of _all_ the defined hook point functions and their fragment information.
### - "${hook_point_function_trace_sources}" is a map of all the hook point functions _that were really called during the build_ and their BASH_SOURCE information.
### - "${hook_point_function_trace_lines}" is the same, but BASH_LINENO info.
### After this hook is done, the "${FRAGMENT_MANAGER_TMP_DIR}" will be removed.
fragment_metadata_ready__be_more_awesome() {
# @TODO: Here goes your code. As an example, here's a call to display_message. Bask in its colorful glory.
display_alert "AWESOME Sample hook 18/18" "making 'fragment_metadata_ready' more awesome" "info"
# @TODO: Please also remember to rename this function, but preserve the "fragment_metadata_ready__" prefix.
} # end of function fragment_metadata_ready__be_more_awesome()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment