summaryrefslogtreecommitdiffstats
path: root/find-sodeps.sh
blob: 8836906cfb0f6e69ee6d9a450af11c8f6135873c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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 | while read filename
do
 soarch=$(objdump -a "$filename" 2>/dev/null | sed -rn 's/.* file format (.*)$/\1/p' | tr - _)
	[ -n "$soarch" ] || continue
	for sofile in $(readelf -d "$filename" 2> /dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
	do
	soname=$(sed -rn 's/(.*)\.so.*/\1.so/p' <<< "$sofile")
	if ! in_array "${soname}" ${sodepends[@]}; then
    echo "${soname}"
    sodepends=(${sodepends[@]} "${soname}")
	fi
	done
done