From b44e4e7cfd88fc5e2bd95fa9d0dbc36b1bd64483 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 22 May 2012 10:03:12 -0400 Subject: add hookpoints to --hookhelp output Generalize the awk program embedded in add_runscript and create a separate function which can be reused to display the specific hooks that a script has. Signed-off-by: Dave Reisner --- functions | 30 ++++++++++++++++++++++++------ mkinitcpio | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 2dcfe11..80286e0 100644 --- a/functions +++ b/functions @@ -181,6 +181,29 @@ in_array() { return 1 # Not Found } +funcgrep() { + awk -v funcmatch="$1" ' + /^[[:space:]]*[[:alnum:]_]+[[:space:]]*\([[:space:]]*\)/ { + match($1, funcmatch) + print substr($1, RSTART, RLENGTH) + }' "$2" +} + +list_hookpoints() { + local funcs + + [[ -e ${1/install/hooks} ]] || return 0 + + mapfile -t funcs < <(funcgrep '^run_[[:alnum:]_]+' "${1/install/hooks}") + + echo + msg "This hook has runtime scripts:" + in_array run_earlyhook "${funcs[@]}" && msg2 "early hook" + in_array run_hook "${funcs[@]}" && msg2 "pre-mount hook" + in_array run_latehook "${funcs[@]}" && msg2 "post-mount hook" + in_array run_cleanuphook "${funcs[@]}" && msg2 "cleanup hook" +} + auto_modules() { # Perform auto detection of modules via sysfs. @@ -441,12 +464,7 @@ add_runscript() { add_file "$script" "/hooks/$hookname" 755 - mapfile -t funcs < \ - <(awk ' - /^[[:space:]]*[[:alnum:]_]+[[:space:]]*\([[:space:]]*\)/ { - match($1, /[[:alnum:]_]+/) - print substr($1, RSTART, RLENGTH) - }' "$script") + mapfile -t funcs < <(funcgrep '^run_[[:alnum:]_]+' "$script") for fn in "${funcs[@]}"; do case $fn in diff --git a/mkinitcpio b/mkinitcpio index 8762991..7497b7c 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -188,6 +188,7 @@ while :; do fi msg "Help for hook '$1':" help + list_hookpoints "$script" exit 0 ;; -L|--listhooks) msg "Available hooks" -- cgit v1.2.3-24-g4f1b