summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-22 16:03:12 +0200
committerDave Reisner <dreisner@archlinux.org>2012-06-01 15:37:47 +0200
commitb44e4e7cfd88fc5e2bd95fa9d0dbc36b1bd64483 (patch)
tree27fa4df1eeb3ea107638fdb8c6b9f6b520a9be55 /functions
parent015d482ce8394acd2f8bc9da2cd70339ebbcc3f9 (diff)
downloadmkinitcpio-b44e4e7cfd88fc5e2bd95fa9d0dbc36b1bd64483.tar.gz
mkinitcpio-b44e4e7cfd88fc5e2bd95fa9d0dbc36b1bd64483.tar.xz
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 <dreisner@archlinux.org>
Diffstat (limited to 'functions')
-rw-r--r--functions30
1 files changed, 24 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