aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2021-02-07 13:27:58 +0100
committerDavid Runge <dave@sleepmap.de>2021-02-07 13:27:58 +0100
commit1c6351e48c86570610090c75914ce6d50bfff8bd (patch)
tree2166b9c9a5ed5f989619a56e4b282f098c602fb8
parentc1e70f3907d56e5f8c62c0786b3dbf8148a21de7 (diff)
downloaddotfiles-1c6351e48c86570610090c75914ce6d50bfff8bd.tar.gz
dotfiles-1c6351e48c86570610090c75914ce6d50bfff8bd.tar.bz2
dotfiles-1c6351e48c86570610090c75914ce6d50bfff8bd.tar.xz
dotfiles-1c6351e48c86570610090c75914ce6d50bfff8bd.zip
Add scimmia's pkg-list-linked-libraries helper
bin/pkg-list-linked-libraries: Add Scimmia's helper for identifying per-file sodeps in packages.
-rwxr-xr-xbin/pkg-list-linked-libraries89
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/pkg-list-linked-libraries b/bin/pkg-list-linked-libraries
new file mode 100755
index 0000000..472f0a6
--- /dev/null
+++ b/bin/pkg-list-linked-libraries
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+# Bugtracker helper utility from Scimmia
+# https://gist.github.com/Scimmia22/0fcca58fe0f7c2b5eb906fafc1f32a62
+
+source /usr/share/makepkg/util/message.sh
+colorize
+
+usage() {
+ cat <<- _EOF_
+ Usage: pkg-list-linked-libraries [-s] PACKAGE [LIBNAME|SYMBOL]
+ Check a package to see what libraries or symbols it links against.
+ Alternatively check against a specific library.
+ If PACKAGE is not an existing file, pacman will resolve it
+ as a package name and attempt to download it to the cache.
+ This respects repo/pkgname syntax.
+ OPTIONS
+ -s, --symbols Show symbols instead of libraries
+ -h, --help Show this help text
+_EOF_
+}
+
+checklibs() {
+ msg "checking linked libraries for ${pkgfile##*/} ..."
+ while read -rd '' file; do
+ liblist="$(objdump -p "$file" 2> /dev/null | grep -E "NEEDED\s+$1")"
+ [[ -n "$liblist" ]] && printf "%s\n%s\n" "${file#$workdir}" "$liblist" && found=1
+ done
+ [[ $found ]]
+}
+
+checksyms() {
+ msg "checking linked symbols for ${pkgfile##*/} ..."
+ while read -rd '' file; do
+ liblist="$(nm --with-symbol-versions -D "$file" 2>/dev/null | awk 'NF>1 && $NF ~ /'"$1"'/{printf "\t%s\n",$NF}')"
+ [[ -n "$liblist" ]] && printf "%s\n%s\n" "${file#$workdir}" "$liblist" && found=1
+ done
+ [[ $found ]]
+}
+
+die() {
+ error "$@"
+ exit 1
+}
+
+clean_up() {
+ if [[ -d "$workdir" ]]; then
+ rm -rf "$workdir"
+ fi
+}
+trap 'clean_up' EXIT
+
+func=checklibs
+
+case $1 in
+ -s|--symbols)
+ func=checksyms
+ shift
+ ;;
+ -h|--help)
+ usage
+ exit
+ ;;
+esac
+
+if [[ -f "$1" ]]; then
+ pkgfile="$1"
+else
+ pkgfile_remote="$(pacman -Sddp "$1" 2>/dev/null)" || die "package name not in repos"
+ pkgfile="${pkgfile_remote#file://}"
+ if [[ ! -f "$pkgfile" ]]; then
+ msg "Downloading package '%s' into pacman's cache" "$1"
+ sudo pacman -Swdd --logfile /dev/null "$1" || exit 1
+ pkgfile_remote="$(pacman -Sddp "$1" 2>/dev/null)"
+ pkgfile="${pkgfile_remote#file://}"
+ fi
+fi
+
+workdir="$(mktemp -d)"
+bsdtar xf "$pkgfile" -C "$workdir"
+find "$workdir" -type f -print0 | sort -z | $func "$2"
+
+(( $? == 0 )) && exit 0
+
+if [[ -n $2 ]]; then
+ error "No file in %s is linked to %s" "${pkgfile##*/}" "$2"
+else
+ error "Uhhh... nothing in %s links to anything whatsoever..." "${pkgfile##*/}"
+fi