From 32e3a80c2a8bd9c1278db3e33ea9b5963db0218a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 5 Jun 2011 13:17:19 -0400 Subject: functions: cleanup and refactor add_binary Modify the sed filter to remove PIC addresses and ignore the first line which will always be the vdso. Also remove the tls filter, as glibc has had threaded support mainlined for many years now. If a user has a glibc this old, we don't have support for them elsewhere (udev, kernel). We also cleanup the logical flow through this function and remove a lot of cruft that would always return true, or that didn't quite make sense. Signed-off-by: Dave Reisner --- functions | 52 +++++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) (limited to 'functions') diff --git a/functions b/functions index 4da4d4e..f58e42f 100644 --- a/functions +++ b/functions @@ -152,7 +152,7 @@ add_file () add_symlink "${fil}" "${lnk}" fil="${lnk}" fi - if [ $# -eq 2 ]; then + if [[ $2 ]]; then dest="${2}" else dest="${fil##$BASEDIR}" @@ -221,48 +221,34 @@ add_module () add_binary () { - local bin dest type lib - bin=$(which "${1}") - if [ $? -ne 0 ]; then - bin="${1}" - fi + local bin dest lib - dest="" - if [ $# -eq 2 ]; then - dest=${2} - fi + bin=$(type -P "$1") + dest=$2 - if [ ! -f "${bin}" ]; then - err "'${bin}' is not a file" + if [[ ! -f "$bin" ]]; then + err "'$1' is not a file" return 1 fi - if [ $? -eq 0 ]; then - type=$(file -b "${bin}") - case "${type}" in - *script*) + case "$(file -b "$bin")" in + *script*) msg " adding '${type}' script, ensure proper interp exists..." - add_file "${bin}" ${dest} + add_file "$bin" ${dest+"$dest"} ;; - *executable*|*shared\ object*|*symbolic\ link*) - add_file "${bin}" ${dest} - #note, this will also handle 'not a dynamic executable' spit out by - # static binaries... the deps will produce nothing - for lib in $(ldd ${bin} 2>/dev/null | sed "s|.*=>\(.*\)|\1|"); do - if [ -n "${lib}" ]; then - #remove TLS libraries - notls=$(echo ${lib} | sed 's|/lib/tls.*/\(lib.*\)|/lib/\1|') - [ -e "${notls}" ] && lib="${notls}" - [ -f "${lib}" ] && add_file "${lib}" - fi - done + *executable*|*shared\ object*|*symbolic\ link*) + add_file "$bin" ${dest+"$dest"} + # note, this will also handle 'not a dynamic executable' spit out + # by static binaries... the deps will produce nothing + while read -r lib; do + [[ -f "$lib" ]] && add_file "$lib" + done < <(ldd "$bin" 2>/dev/null | sed '1d;s|.*=>\(.*\)|\1|;s/(0x[0-9a-f]\+)//') ;; - *) - err "unknown type '${type}' for binary '${bin}'" + *) + err "unknown type '$type' for binary '$bin'" return 1 ;; - esac - fi + esac } parse_hook () -- cgit v1.2.3-24-g4f1b