From 111abbd9fcab6b50ee43329f19560b674c6ac97f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 23 Jul 2011 12:20:42 -0400 Subject: 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 --- functions | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/functions b/functions index 2f5797a..8ce24ea 100644 --- a/functions +++ b/functions @@ -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; } -- cgit v1.2.3-24-g4f1b