diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-07-23 18:20:42 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-09-27 12:18:04 +0200 |
commit | 111abbd9fcab6b50ee43329f19560b674c6ac97f (patch) | |
tree | 0284c5605a5007522065d53ccf4c61dee9eadd24 | |
parent | 06331559487ccc6cca1b770b2e21c5e3f7bec5c3 (diff) | |
download | mkinitcpio-111abbd9fcab6b50ee43329f19560b674c6ac97f.tar.gz mkinitcpio-111abbd9fcab6b50ee43329f19560b674c6ac97f.tar.xz |
functions: perform path lookup for binaries if needed
We used to do this, but it was lost somewhere along the way in fixing up
basedir support. Add in a 'pathlookup' function which can do a search
within any given basedir.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r-- | functions | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -55,6 +55,26 @@ in_array() { return 1 # Not Found } +pathlookup() { + # a basedir aware 'type -P' (or which) for executables + # $1: binary to find + + local path= + local -a paths= + + IFS=: read -r -a paths <<< "$PATH" + + for path in "${paths[@]}"; do + [[ ${path:0:1} = [.~] ]] && continue + if [[ -x $BASEDIR$path/$1 ]]; then + printf '%s' "$BASEDIR$path/$1" + return 0 + fi + done + + return 1 +} + _add_file() { # add a file to $BUILDROOT # $1: pathname on initcpio @@ -259,7 +279,11 @@ add_binary() { local -a sodeps local regex binary dest mode sodep resolved dirname - binary=$BASEDIR$1 + if [[ ${1:0:1} != '/' ]]; then + binary=$(pathlookup "$1") + else + binary=$BASEDIR$1 + fi [[ -f "$binary" ]] || { error "file not found: \`%s'" "$binary"; return 1; } |