diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-05-11 19:10:31 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-05-18 15:39:04 +0200 |
commit | 261b731e8fb918309f2740b5262d9678378491fa (patch) | |
tree | b228794c61cfb1745050557e2334b47fc1eb21bf /functions | |
parent | 01cb8b7a20ab53967a68e56a64152c357e12ff41 (diff) | |
download | mkinitcpio-261b731e8fb918309f2740b5262d9678378491fa.tar.gz mkinitcpio-261b731e8fb918309f2740b5262d9678378491fa.tar.xz |
functions: introduce add_runscript
This function adds a runtime script to the /hooks directory on the
initramfs image. Note that this function will also install hooks with
executable permissions for use by a later change to early init.
With this commit, there are now methods available which can be used in
place of the MODULES, FILES, BINARIES, and SCRIPT variables, as we now
offer error checking on the add_* functions. Usage of the variables is
deprecated, and these will no longer be read in a future version of
mkinitcpio.
This commit also lays the groundwork for the addition of more early
userspace hooks. Runtime hook files are parsed for specific functions
and variables (not yet used) are populated. These will eventually be
written to the image config so that early userspace knows exactly
what to run.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 48 |
1 files changed, 44 insertions, 4 deletions
@@ -422,8 +422,49 @@ add_file() { command install -Dm$mode "$src" "$BUILDROOT$dest" } +add_runscript() { + # Adds a runtime script to the initcpio image. The name is derived from the + # script which calls it, though it can be overriden by passing the name of + # the runtime hook as the first argument to the function. This shouldn't be + # needed and is only left for legacy compatability reasons. It may not work + # in future versions of mkinitcpio. + + local funcs fn script hookname=${SCRIPT:-${BASH_SOURCE[1]##*/}} + + if ! script=$(find_in_dirs "$hookname" "${HOOKDIR[@]}"); then + error "runtime script for \`%s' not found" "$hookname" + return + fi + + add_file "$script" "/hooks/$hookname" 755 + + mapfile -t funcs < \ + <(awk ' + /^[[:space:]]*[[:alnum:]_]+[[:space:]]*\([[:space:]]*\)/ { + match($1, /[[:alnum:]_]+/) + print substr($1, RSTART, RLENGTH) + }' "$script") + + for fn in "${funcs[@]}"; do + case $fn in + run_earlyhook) + RUNHOOKS['early']+=" $hookname" + ;; + run_hook) + RUNHOOKS['hooks']+=" $hookname" + ;; + run_latehook) + RUNHOOKS['late']+=" $hookname" + ;; + run_cleanuphook) + RUNHOOKS['cleanup']="$hookname ${RUNHOOKS['cleanup']}" + ;; + esac + done +} + add_binary() { - # add a binary file to the initcpio image. library dependencies will + # Add a binary file to the initcpio image. library dependencies will # be discovered and added. # $1: path to binary # $2: destination on initcpio (optional, defaults to same as source) @@ -474,7 +515,7 @@ parse_hook() { # prior to the start of hook processing, and after each hook's build # function is run. - local item= script= + local item= for item in $MODULES; do add_module "$item" @@ -489,8 +530,7 @@ parse_hook() { done if [[ $SCRIPT ]]; then - script=$(find_in_dirs "$SCRIPT" "${HOOKDIR[@]}") && - add_file "$script" "/hooks/$SCRIPT" + add_runscript "$SCRIPT" fi } |