| 1 | #!/bin/sh |
| 2 | |
| 3 | # checkapk - find ABI breakages in package upgrades |
| 4 | # Copyright (c) 2012 Natanael Copa <[email protected]> |
| 5 | # |
| 6 | # Distributed under GPL-2 |
| 7 | # |
| 8 | |
| 9 | abuild_ver=@VERSION@ |
| 10 | datadir=@datadir@ |
| 11 | |
| 12 | if ! [ -f "$datadir/functions.sh" ]; then |
| 13 | echo "$datadir/functions.sh: not found" >&2 |
| 14 | exit 1 |
| 15 | fi |
| 16 | . "$datadir/functions.sh" |
| 17 | |
| 18 | |
| 19 | usage() { |
| 20 | cat >&2 <<__EOF__ |
| 21 | $prog $abuild_ver - find ABI breakages in package upgrades |
| 22 | Usage: $prog |
| 23 | |
| 24 | Run in the directory of a built package. |
| 25 | |
| 26 | __EOF__ |
| 27 | } |
| 28 | |
| 29 | if [ $# -gt 0 ]; then |
| 30 | usage |
| 31 | exit 2 |
| 32 | fi |
| 33 | |
| 34 | if ! [ -f "$ABUILD_CONF" ] && ! [ -f "$ABUILD_USERCONF" ]; then |
| 35 | die "no abuild.conf found" |
| 36 | fi |
| 37 | |
| 38 | if ! [ -f APKBUILD ]; then |
| 39 | die 'must be run in the directory of a built package' |
| 40 | fi |
| 41 | |
| 42 | . ./APKBUILD |
| 43 | |
| 44 | startdir="$PWD" |
| 45 | tmpdir=$(mktemp -d -t checkpkg-script.XXXXXX) |
| 46 | cd "$tmpdir" || die "failed to create temp dir" |
| 47 | |
| 48 | for i in $pkgname $subpackages; do |
| 49 | _pkgname=${i%:*} |
| 50 | pkg=${_pkgname}-$pkgver-r$pkgrel |
| 51 | pkgfile=${pkg}.apk |
| 52 | repodir=${startdir%/*} |
| 53 | repo=${repodir##*/} |
| 54 | |
| 55 | for filepath in "$PKGDEST"/$pkgfile "$REPODEST"/$repo/$CARCH/$pkgfile "$startdir"/$pkgfile; do |
| 56 | if [ -f "$filepath" ]; then |
| 57 | break |
| 58 | fi |
| 59 | done |
| 60 | [ -f "$filepath" ] || die "can't find $pkgfile" |
| 61 | |
| 62 | # generate a temp repositories file with only the http repos |
| 63 | grep ^http: /etc/apk/repositories > $tmpdir/repositories |
| 64 | |
| 65 | oldpkg=$(apk fetch --repositories-file $tmpdir/repositories --simulate 2>&1 | sed 's/^Downloading //') |
| 66 | if [ "${oldpkg}" = "${pkg}" ]; then |
| 67 | die "the built package ($_pkgname) is already in the repo" |
| 68 | fi |
| 69 | |
| 70 | apk fetch --repositories-file $tmpdir/repositories --stdout $_pkgname \ |
| 71 | | tar -zt | grep -v '^\.SIGN\.' | sort > filelist-$_pkgname-old \ |
| 72 | || die "failed to download old pkg, maybe run 'apk update'?" |
| 73 | |
| 74 | tar -ztf "$filepath" | grep -v '^\.SIGN\.' | sort > "filelist-$_pkgname" |
| 75 | |
| 76 | diff -u "filelist-$_pkgname-old" "filelist-$_pkgname" |
| 77 | |
| 78 | if diff "filelist-$_pkgname-old" "filelist-$_pkgname" | grep '\.so' > /dev/null 2>&1; then |
| 79 | mkdir -p pkg |
| 80 | cd pkg |
| 81 | tar -zxf "$filepath" > /dev/null |
| 82 | diff "../filelist-$_pkgname-old" "../filelist-$_pkgname" | awk '/>.*\.so/{$1 = ""; print $0}' | while read i; do |
| 83 | echo "${i}: " "$(objdump -p "$i" | grep SONAME)" |
| 84 | done |
| 85 | cd .. |
| 86 | else |
| 87 | msg "No soname differences for $_pkgname." |
| 88 | fi |
| 89 | done |
| 90 | |
| 91 | msg "Files saved to $tmpdir" |