summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--functions23
-rwxr-xr-xmkinitcpio15
3 files changed, 14 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 7bf70cf..aa3ef6f 100644
--- a/Makefile
+++ b/Makefile
@@ -26,8 +26,8 @@ install: all
sed -e 's|^_f_config=.*|_f_config=/etc/mkinitcpio.conf|' \
-e 's|^_f_functions=.*|_f_functions=/usr/lib/initcpio/functions|' \
- -e 's|^_d_hooks=.*|_d_hooks=({/usr,}/lib/initcpio/hooks)|' \
- -e 's|^_d_install=.*|_d_install=({/usr,}/lib/initcpio/install)|' \
+ -e 's|^_d_hooks=.*|_d_hooks=/usr/lib/initcpio/hooks:/lib/initcpio/hooks|' \
+ -e 's|^_d_install=.*|_d_install=/usr/lib/initcpio/install:/lib/initcpio/install|' \
-e 's|^_d_presets=.*|_d_presets=/etc/mkinitcpio.d|' \
-e 's|%VERSION%|$(VERSION)|g' \
< mkinitcpio > $(DESTDIR)/usr/bin/mkinitcpio
diff --git a/functions b/functions
index e79d057..f46a9ae 100644
--- a/functions
+++ b/functions
@@ -202,11 +202,11 @@ funcgrep() {
}
list_hookpoints() {
- local funcs
+ local funcs script
- [[ -e ${1/install/hooks} ]] || return 0
+ script=$(PATH=$_d_hooks type -p "$1") || return 0
- mapfile -t funcs < <(funcgrep '^run_[[:alnum:]_]+' "${1/install/hooks}")
+ mapfile -t funcs < <(funcgrep '^run_[[:alnum:]_]+' "$script")
echo
msg "This hook has runtime scripts:"
@@ -455,7 +455,7 @@ add_runscript() {
local funcs fn script hookname=${BASH_SOURCE[1]##*/}
- if ! script=$(find_in_dirs "$hookname" "${_d_hooks[@]}"); then
+ if ! script=$(PATH=$_d_hooks type -p "$hookname"); then
error "runtime script for \`%s' not found" "$hookname"
return
fi
@@ -564,19 +564,6 @@ parse_config() {
} >"$BUILDROOT/config"
}
-find_in_dirs() {
- local dir
-
- for dir in "${@:2}"; do
- if [[ -e $dir/$1 ]]; then
- printf '%s' "$dir/$1"
- return 0
- fi
- done
-
- return 1
-}
-
initialize_buildroot() {
# creates a temporary directory for the buildroot and initialize it with a
# basic set of necessary directories and symlinks
@@ -616,7 +603,7 @@ run_build_hook() {
local MODULES= BINARIES= FILES= SCRIPT=
# find script in install dirs
- if ! script=$(find_in_dirs "$hook" "${_d_install[@]}"); then
+ if ! script=$(PATH=$_d_install type -p "$hook"); then
error "Hook '$hook' cannot be found"
return 1
fi
diff --git a/mkinitcpio b/mkinitcpio
index 7c75572..fbcef82 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -12,8 +12,8 @@ shopt -s extglob
# needed files/directories
_f_functions=functions
_f_config=mkinitcpio.conf
-_d_hooks=(hooks /usr/lib/initcpio/hooks /lib/initcpio/hooks)
-_d_install=(install /usr/lib/initcpio/install /lib/initcpio/install)
+_d_hooks="$PWD/hooks:/usr/lib/initcpio/hooks:/lib/initcpio/hooks"
+_d_install="$PWD/install:/usr/lib/initcpio/install:/lib/initcpio/install"
_d_presets=mkinitcpio.d
# options and runtime data
@@ -315,8 +315,7 @@ while :; do
unset skip ;;
-H|--hookhelp)
shift
- if script=$(find_in_dirs "$1" "${_d_install[@]}"); then
- . "$script"
+ if PATH=$_d_install . "$1"; then
if ! declare -f help >/dev/null; then
error "No help for hook $1"
exit 1
@@ -327,11 +326,12 @@ while :; do
fi
msg "Help for hook '$1':"
help
- list_hookpoints "$script"
+ list_hookpoints "$1"
exit 0 ;;
-L|--listhooks)
msg "Available hooks"
- for dir in "${_d_install[@]}"; do
+ IFS=: read -ra _dirs <<<"$_d_install"
+ for dir in "${_dirs[@]}"; do
( cd "$dir" &>/dev/null && printf ' %s\n' * )
done | sort -u | column -c$(tput cols)
exit 0 ;;
@@ -400,8 +400,7 @@ fi
if (( _optshowautomods )); then
msg "Modules autodetected"
- _f_autodetect_hook=$(find_in_dirs 'autodetect' "${_d_install[@]}")
- . "$_f_autodetect_hook"
+ PATH=$_d_install . 'autodetect'
build
printf '%s\n' "${!_autodetect_cache[@]}" | sort
cleanup 0