summaryrefslogtreecommitdiffstats
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
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>
-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