diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-11-25 02:39:46 +0100 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-11-26 02:08:57 +0100 |
commit | 78fb526649cc730d9c20be47112db945a4a8427b (patch) | |
tree | ca02d1169cacbd9e88d54cd5152d4ece89a722ee | |
parent | b9d81a088ad0aa694b335118cf4ee70ad3ad1712 (diff) | |
download | mkinitcpio-78fb526649cc730d9c20be47112db945a4a8427b.tar.gz mkinitcpio-78fb526649cc730d9c20be47112db945a4a8427b.tar.xz |
replace find_in_dirs with PATH= manipulation
Declaring our lookup paths like normal colon delimited PATHs lets us
reuse them for builtins like source and type to do the same work that
this function previously did.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | functions | 23 | ||||
-rwxr-xr-x | mkinitcpio | 15 |
3 files changed, 14 insertions, 28 deletions
@@ -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 @@ -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 @@ -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 |