Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (32 sloc) 938 Bytes
#!/bin/bash
#
# resolve ELF library deps to pacman packages
#
declare -r lddregex=$'(.+) => (.+) \(0x[a-fA-F0-9]+\)$'
resolve_bin() {
declare -A depmap
declare -a linkage
# leverage the linker to do lib => path resolution
local lddout=$(ldd "$1" 2>/dev/null) || return
while read -r line; do
[[ $line =~ $lddregex ]] || continue
depmap["${BASH_REMATCH[1]}"]=${BASH_REMATCH[2]}
done <<< "$lddout"
# dump directly linked deps, printing paths from our ldd "map"
objdump -p "$1" 2>/dev/null | while read section soname; do
[[ $section == NEEDED && ${depmap[$soname]} ]] && printf '%s\n' "${depmap[$soname]}"
done | pacman -Qqo - 2>/dev/null
}
resolve_dir() {
local bin
while read -rd '' bin; do
resolve_bin "$bin"
done < <(find "$1" -type f -executable -print0)
}
for bin; do
if [[ -f $bin ]]; then
resolve_bin "$bin"
elif [[ -d $bin ]]; then
resolve_dir "$bin"
fi
done | sort -u