2012-12-30 14:09:57 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-07-05 04:21:12 +00:00
|
|
|
# checkapk - find ABI breakages in package upgrades
|
|
|
|
# Copyright (c) 2012 Natanael Copa <natanael.copa@gmail.com>
|
|
|
|
#
|
2020-10-23 14:39:18 +00:00
|
|
|
# Distributed under GPL-2.0-only
|
2013-07-05 04:21:12 +00:00
|
|
|
#
|
|
|
|
|
2013-10-25 07:26:05 +00:00
|
|
|
program_version=@VERSION@
|
2019-11-07 11:28:37 +00:00
|
|
|
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2019-11-07 11:21:32 +00:00
|
|
|
if ! [ -f "$sharedir/functions.sh" ]; then
|
|
|
|
echo "$sharedir/functions.sh: not found" >&2
|
2012-12-30 14:09:57 +00:00
|
|
|
exit 1
|
2013-07-05 04:21:16 +00:00
|
|
|
fi
|
2019-11-07 11:21:32 +00:00
|
|
|
. "$sharedir/functions.sh"
|
2012-12-30 14:09:57 +00:00
|
|
|
|
|
|
|
|
2013-07-05 04:21:19 +00:00
|
|
|
usage() {
|
2023-10-18 09:07:24 +00:00
|
|
|
cat <<-__EOF__
|
2016-08-20 13:16:48 +00:00
|
|
|
$program $program_version - find ABI breakages in package upgrades
|
2023-10-18 09:07:24 +00:00
|
|
|
Usage: $program [-h|--help]
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2016-08-20 13:16:48 +00:00
|
|
|
Run in the directory of a built package.
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2023-10-18 09:07:24 +00:00
|
|
|
Options:
|
|
|
|
-h, --help Print this help
|
|
|
|
|
2016-08-20 13:16:48 +00:00
|
|
|
__EOF__
|
2013-07-05 04:21:19 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 09:07:24 +00:00
|
|
|
args=$(getopt -o h --long help \
|
|
|
|
-n "$program" -- "$@")
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
usage >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
eval set -- "$args"
|
|
|
|
while true; do
|
|
|
|
case $1 in
|
|
|
|
-h|--help) usage; exit 0;;
|
|
|
|
--) shift; break;;
|
|
|
|
*) exit 1;; # getopt error
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2013-07-05 04:21:19 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
2023-10-18 09:07:24 +00:00
|
|
|
usage >&2
|
2013-07-05 04:21:19 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2023-10-18 09:22:47 +00:00
|
|
|
if ! [ -f "$ABUILD_CONF" ] && ! [ -f "$ABUILD_USERCONF" ] && ! [ -f "$ABUILD_DEFCONF" ]; then
|
2013-07-05 04:21:16 +00:00
|
|
|
die "no abuild.conf found"
|
|
|
|
fi
|
2012-12-30 14:09:57 +00:00
|
|
|
|
|
|
|
if ! [ -f APKBUILD ]; then
|
2013-07-05 04:21:37 +00:00
|
|
|
die 'must be run in the directory of a built package'
|
2012-12-30 14:09:57 +00:00
|
|
|
fi
|
|
|
|
|
2013-10-25 07:19:30 +00:00
|
|
|
if ! [ -n "$CARCH" ]; then
|
|
|
|
die "failed to detect CARCH"
|
|
|
|
fi
|
|
|
|
|
2012-12-30 14:09:57 +00:00
|
|
|
. ./APKBUILD
|
|
|
|
|
|
|
|
startdir="$PWD"
|
|
|
|
tmpdir=$(mktemp -d -t checkpkg-script.XXXXXX)
|
2023-07-11 13:37:24 +00:00
|
|
|
trap "rm -rf '$tmpdir'; exit" INT EXIT
|
2013-07-05 04:21:37 +00:00
|
|
|
cd "$tmpdir" || die "failed to create temp dir"
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2023-06-26 01:17:31 +00:00
|
|
|
# storage for downloaded/copied apks
|
|
|
|
mkdir -p apks
|
|
|
|
|
2023-06-22 11:40:37 +00:00
|
|
|
# default to pigz for unpacking
|
|
|
|
gunzip="$(command -v pigz || echo gzip) -d"
|
|
|
|
|
2012-12-30 14:09:57 +00:00
|
|
|
for i in $pkgname $subpackages; do
|
2016-07-27 11:50:15 +00:00
|
|
|
_pkgname=${i%%:*}
|
2012-12-30 14:09:57 +00:00
|
|
|
pkg=${_pkgname}-$pkgver-r$pkgrel
|
|
|
|
pkgfile=${pkg}.apk
|
2013-02-13 07:30:09 +00:00
|
|
|
repodir=${startdir%/*}
|
|
|
|
repo=${repodir##*/}
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2013-02-13 07:30:09 +00:00
|
|
|
for filepath in "$PKGDEST"/$pkgfile "$REPODEST"/$repo/$CARCH/$pkgfile "$startdir"/$pkgfile; do
|
2012-12-30 14:09:57 +00:00
|
|
|
if [ -f "$filepath" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2013-07-05 04:21:37 +00:00
|
|
|
[ -f "$filepath" ] || die "can't find $pkgfile"
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2016-08-09 13:02:17 +00:00
|
|
|
# generate a temp repositories file with only the http(s) repos
|
2023-06-26 01:17:31 +00:00
|
|
|
grep -E "^https?:" /etc/apk/repositories > "$tmpdir"/repositories
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2023-06-26 01:17:31 +00:00
|
|
|
oldpkg=$(apk fetch --repositories-file "$tmpdir"/repositories --simulate $_pkgname 2>&1 | sed 's/^Downloading //')
|
2012-12-30 14:09:57 +00:00
|
|
|
if [ "${oldpkg}" = "${pkg}" ]; then
|
2013-07-05 04:21:37 +00:00
|
|
|
die "the built package ($_pkgname) is already in the repo"
|
2012-12-30 14:09:57 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-09 11:26:55 +00:00
|
|
|
# For our local repo (newsize) apk info might return multiple packages, e.g. if different
|
2023-06-29 04:00:22 +00:00
|
|
|
# version of the package where built previously. However, for a repo only one of pkgname=pkgver-rpkgrel can exist.
|
|
|
|
# Filter out this specific pkgver with grep, as it can have only one match, then take the second line:
|
|
|
|
# 7zip-23.01-r0 installed size:
|
|
|
|
# 1668 KiB
|
|
|
|
newsize="$(apk info --repositories-file /dev/null --repository "$REPODEST"/$repo --size $_pkgname | \
|
|
|
|
grep -F "$pkg" -A1 | \
|
|
|
|
tail -n1)"
|
|
|
|
oldsize="$(apk info --repositories-file "$tmpdir"/repositories --size "$_pkgname" | \
|
|
|
|
grep -F "$_pkgname" -A1 | \
|
|
|
|
tail -n1)"
|
2020-04-09 11:26:55 +00:00
|
|
|
|
|
|
|
if [ "$oldsize" = "$newsize" ]; then
|
|
|
|
msg "No size differences for $_pkgname."
|
|
|
|
else
|
|
|
|
msg "Size difference for $_pkgname: $oldsize -> $newsize"
|
|
|
|
fi
|
|
|
|
|
2023-06-26 01:17:31 +00:00
|
|
|
apk fetch --quiet --repositories-file "$tmpdir"/repositories --stdout "$_pkgname" > apks/old.apk \
|
2023-11-22 14:27:56 +00:00
|
|
|
|| msg2 "Old apk for $_pkgname missing. (new package/arch? broken internet?)"
|
2012-12-30 14:09:57 +00:00
|
|
|
|
2023-06-26 01:17:31 +00:00
|
|
|
# pre-uncompress to not decompress twice
|
|
|
|
# we do a decompression + tar -t for the file list, but then later we might do a full extraction for sodiff.
|
|
|
|
# to not decompress here and then later again, store the intermediate tar
|
2023-06-26 05:52:28 +00:00
|
|
|
$gunzip -c 2>/dev/null < apks/old.apk > apks/old.tar &
|
|
|
|
$gunzip -c "$filepath" < "$filepath" > apks/new.tar &
|
|
|
|
wait
|
|
|
|
tar -t -f apks/old.tar 2>/dev/null | grep -v '^\.SIGN\.' | sort > "filelist-$_pkgname-old" &
|
|
|
|
tar -t -f apks/new.tar | grep -v '^\.SIGN\.' | sort > "filelist-$_pkgname-new" &
|
|
|
|
wait
|
2023-06-26 01:17:31 +00:00
|
|
|
|
|
|
|
diff -U3 "filelist-$_pkgname-old" "filelist-$_pkgname-new"
|
|
|
|
|
|
|
|
if diff -U0 "filelist-$_pkgname-old" "filelist-$_pkgname-new" | grep -q '\.so'; then
|
|
|
|
echo "SODIFF:"
|
|
|
|
|
|
|
|
mkdir -p "$_pkgname-pkg-old" "$_pkgname-pkg-new"
|
2023-06-26 05:52:28 +00:00
|
|
|
tar -C "$_pkgname-pkg-old" 2>/dev/null -x -f apks/old.tar > /dev/null &
|
|
|
|
tar -C "$_pkgname-pkg-new" -x -f apks/new.tar > /dev/null &
|
|
|
|
wait
|
2023-06-26 01:17:31 +00:00
|
|
|
|
|
|
|
# filter to things that start with -+ but strip the header (---/+++)
|
2023-07-17 04:12:56 +00:00
|
|
|
diff -U0 "filelist-$_pkgname-old" "filelist-$_pkgname-new" | grep -E '^(\+|-)[A-Za-z0-9]+' | grep '\.so' | while read -r diff_sofile; do
|
2023-06-26 01:17:31 +00:00
|
|
|
case "$diff_sofile" in
|
2024-03-29 11:18:11 +00:00
|
|
|
-*) path="$_pkgname-pkg-old"; sofile="${diff_sofile#\-}" ;;
|
|
|
|
+*) path="$_pkgname-pkg-new"; sofile="${diff_sofile#\+}" ;;
|
2023-06-26 01:17:31 +00:00
|
|
|
esac
|
2023-06-26 02:22:26 +00:00
|
|
|
|
2023-06-26 08:30:49 +00:00
|
|
|
# skip symlinks (only adds duplicate output or is dangling), and things that aren't valid elfs
|
|
|
|
# matching .so above matches anything with .so in the name, e.g. xyz.sourceforge
|
|
|
|
if ! [ -L "$path"/"$sofile" ] && readelf -h "$path"/"$sofile" >/dev/null 2>&1; then
|
2023-06-26 02:22:26 +00:00
|
|
|
echo "$diff_sofile: " "$(objdump -p "$path"/"$sofile" | grep SONAME)"
|
|
|
|
fi
|
2012-12-30 14:09:57 +00:00
|
|
|
done
|
|
|
|
else
|
|
|
|
msg "No soname differences for $_pkgname."
|
|
|
|
fi
|
|
|
|
done
|