summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functions37
-rwxr-xr-xmkinitcpio44
2 files changed, 39 insertions, 42 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:
diff --git a/mkinitcpio b/mkinitcpio
index 4804a67..eae27fe 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -353,52 +353,12 @@ declare -i builderrors=0
set -o functrace
trap '(( $? )) && [[ $FUNCNAME = add_* ]] && (( ++builderrors ))' RETURN
-# save vars from $CONFIG; they will be parsed last
-for var in MODULES BINARIES FILES; do
- declare "cfg_$var=${!var}"
-done
-
for hook in "${hooks[@]}"; do
- unset MODULES BINARIES FILES SCRIPT
- build() { error "$hook: no build function..."; return 1; }
-
- # find script in install dirs
- if ! script=$(find_in_dirs "$hook" "${INSTDIR[@]}"); then
- error "Hook '$hook' cannot be found."
- (( ++builderrors ))
- continue
- fi
-
- # check for deprecation
- if [[ -L $script ]]; then
- if ! realscript=$(readlink -e "$script"); then
- error "$script is a broken symlink to $(realpath "$script")"
- (( ++builderrors ))
- continue
- 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"
- (( ++builderrors ))
- continue
- fi
-
- # run
- msg2 "Parsing hook: [%s]" "${script##*/}"
- build
- parse_hook
+ run_build_hook "$hook" || (( ++builderrors ))
done
-# restore $CONFIG vars add to image
-for var in cfg_{MODULES,BINARIES,FILES}; do
- declare "${var#cfg_}=${!var}"
-done
+# process config file
parse_hook
-
write_image_config
# switch out the error handler to catch all errors