summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-26 22:54:43 +0200
committerDave Reisner <dreisner@archlinux.org>2012-06-01 15:36:28 +0200
commit9a20048c6279cd5a037108980069bb46b4a6299d (patch)
tree5c06924f840978fe175912f0acd45d70f59f8fa9 /functions
parent01b4ec4fef66c164cad1bf35eeda83bd3c53f2d1 (diff)
downloadmkinitcpio-9a20048c6279cd5a037108980069bb46b4a6299d.tar.gz
mkinitcpio-9a20048c6279cd5a037108980069bb46b4a6299d.tar.xz
move running of hooks to separate function
This allows us to declare sourced variables that we want to shield from stomping on our config variables, and without needing to use a subshell. Incidentally, this also fixes FS#29992 in a more permanent way. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'functions')
-rw-r--r--functions37
1 files changed, 37 insertions, 0 deletions
diff --git a/functions b/functions
index b37ac87..2dcfe11 100644
--- a/functions
+++ b/functions
@@ -570,4 +570,41 @@ write_image_config() {
) >"$BUILDROOT/config"
}
+run_build_hook() {
+ local hook=$1 script= realscript=
+ local MODULES= BINARIES= FILES= SCRIPT=
+
+ # find script in install dirs
+ if ! script=$(find_in_dirs "$hook" "${INSTDIR[@]}"); then
+ error "Hook '$hook' cannot be found"
+ return 1
+ fi
+
+ # check for deprecation
+ if [[ -L $script ]]; then
+ if ! realscript=$(readlink -e "$script"); then
+ error "$script is a broken symlink to $(readlink "$script")"
+ return 1
+ fi
+ warning "Hook '%s' is deprecated. Replace it with '%s' in your config" "$script" "$realscript"
+ script=$realscript
+ fi
+
+ # source
+ if ! . "$script"; then
+ error 'Failed to read %s' "$script"
+ return 1
+ fi
+
+ if [[ $(type -t build) != function ]]; then
+ error 'Hook '$script' has no build function'
+ return 1
+ fi
+
+ # run
+ msg2 "Running build hook: [%s]" "${script##*/}"
+ build
+ parse_hook
+}
+
# vim: set ft=sh ts=4 sw=4 et: