summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-11 19:10:31 +0200
committerDave Reisner <dreisner@archlinux.org>2012-05-18 15:39:04 +0200
commit261b731e8fb918309f2740b5262d9678378491fa (patch)
treeb228794c61cfb1745050557e2334b47fc1eb21bf
parent01cb8b7a20ab53967a68e56a64152c357e12ff41 (diff)
downloadmkinitcpio-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>
-rw-r--r--functions48
-rwxr-xr-xmkinitcpio1
2 files changed, 45 insertions, 4 deletions
diff --git a/functions b/functions
index 97b401c..d9ba4d2 100644
--- a/functions
+++ b/functions
@@ -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
}
diff --git a/mkinitcpio b/mkinitcpio
index 0cf17fb..e346169 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -26,6 +26,7 @@ declare MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT=
declare NC= BOLD= BLUE= GREEN= RED= YELLOW=
declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1
declare -a SKIPHOOKS ADDED_MODULES MODPATHS
+declare -A RUNHOOKS
# export a sane PATH
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'