diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-06-26 19:48:07 +0200 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-06-26 19:48:07 +0200 |
commit | c6bff4f7fc3ffc0e1e9883a812e05b53995514d4 (patch) | |
tree | cf2390732397fab5970cc2da41c2b1d7426460d8 /build-chroot | |
parent | 69afa1b8b067231c0daec9bd255763b7a3fc245b (diff) | |
download | scripts-c6bff4f7fc3ffc0e1e9883a812e05b53995514d4.tar.gz |
build-chroot: support interpreter detection
Diffstat (limited to 'build-chroot')
-rwxr-xr-x | build-chroot | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/build-chroot b/build-chroot index cd608e6..dd0edee 100755 --- a/build-chroot +++ b/build-chroot @@ -1,6 +1,6 @@ #!/bin/bash VERSION=0.1 -find_libs=~/scripts/find-libs +find_libs=$(dirname "$(readlink -f "$0")")/find-libs usage() { cat <<HELP Copies binaries and their dependencies for chroot usage. @@ -58,6 +58,28 @@ if [ $# -eq 0 ]; then exit 1 fi +resolve_interpreter() { + local file="$1" + local interp + interp=$(head -c 256 "$file" | awk -F '[#! \t]+' 'NR==1 && /^#!/{print $2;exit}') + [ -n "$interp" ] || return + + echo "$interp" + + # /usr/bin/env python2 -> python2 + case "$interp" in + env|/usr/bin/env) + awk -F '[#! \t]+' '{ + for (i=3;i<NF;i++) + if ($i !~ /^-/) { + print $i;exit + } + }' + ;; + esac +} + +errors=0 subjects=() for subject; do realsubject="$subject" @@ -65,14 +87,22 @@ for subject; do [ -e "$realsubject" ] || realsubject="$(which "$subject" 2>/dev/null)" || true if [ -n "$realsubject" ]; then subjects[${#subjects[@]}]="$realsubject" + for extra in $(resolve_interpreter "$realsubject"); do + if path="$(which "$extra" 2>/dev/null)"; then + subjects[${#subjects[@]}]="$path" + else + echo "Missing program: $extra" + ((errors++)) + fi + done else echo "Missing file: $subject" + ((errors++)) fi done -if ! [ $# = ${#subjects[@]} ]; then - echo "Some files could not be found" - echo "Expected $#, got ${#subjects[@]} valid args." +if [ $errors -ne 0 ]; then + echo "$errors files could not be found" if ! $CONT_ON_ERR; then echo "Aborting. To ignore this, pass the '--continue' option." exit 255 |