diff options
Diffstat (limited to 'bin/finddep.sh')
-rwxr-xr-x | bin/finddep.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/finddep.sh b/bin/finddep.sh new file mode 100755 index 0000000..bfad7c0 --- /dev/null +++ b/bin/finddep.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +if [[ -z $1 ]]; then + echo "$(basename "$0") <package file>" + exit 1 +fi + +tmpdir=$(mktemp -d /tmp/find-sodeps.XXXXXXX) +trap "rm -rf '$tmpdir'" EXIT INT TERM + +tar -C $tmpdir -xf "$1" + +cd $tmpdir + +in_array() { + local needle=$1; shift + [[ -z $1 ]] && return 1 # Not Found + local item + for item in "$@"; do + [[ $item = $needle ]] && return 0 # Found + done + return 1 # Not Found +} + +find . -type f -perm -u+x | while read filename; do + # get architecture of the file; if soarch is empty it's not an ELF binary + soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') + [ -n "$soarch" ] || continue + # process all libraries needed by the binary + for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p') + do + # extract the library name: libfoo.so + soname="${sofile%%\.so\.*}.so" + # extract the major version: 1 + soversion="${sofile##*\.so\.}" + if ! in_array "${soname}=${soversion}-${soarch}" ${sodepends[@]}; then + # libfoo.so=1-64 + echo "${soname}=${soversion}-${soarch}" + sodepends=(${sodepends[@]} "${soname}=${soversion}-${soarch}") + fi + done +done |