summaryrefslogblamecommitdiff
path: root/checkapk.in
blob: e95249e4a739b3c7c21d504c91a635d24dcd04b3 (plain) (tree)
1
2
3
4
5
6
7
8

         





                                                            




                                                   
              

                         
 
 
 
 



                                                               














                                                                   

                              
 
                                                                                                      



































                                                                                                                                
#!/bin/sh

# checkapk - find ABI breakages in package upgrades
# Copyright (c) 2012 Natanael Copa <natanael.copa@gmail.com>
#
# Distributed under GPL-2
#

abuild_ver=@VERSION@
datadir=@datadir@

if ! [ -f "$datadir/functions.sh" ]; then
	echo "$datadir/functions.sh: not found" >&2
	exit 1
fi
. "$datadir/functions.sh"





if ! [ -f "$abuild_conf" ] && ! [ -f "$abuild_userconf" ]; then
	die "no abuild.conf found"
fi

if ! [ -f APKBUILD ]; then
	die 'This must be run in the directory of a built package.'
fi

. ./APKBUILD

startdir="$PWD"
tmpdir=$(mktemp -d -t checkpkg-script.XXXXXX)
cd "$tmpdir" || die "Failed to create temp dir"

for i in $pkgname $subpackages; do
	_pkgname=${i%:*}
	pkg=${_pkgname}-$pkgver-r$pkgrel
	pkgfile=${pkg}.apk
	repodir=${startdir%/*}
	repo=${repodir##*/}

	for filepath in "$PKGDEST"/$pkgfile "$REPODEST"/$repo/$CARCH/$pkgfile "$startdir"/$pkgfile; do
		if [ -f "$filepath" ]; then
			break
		fi
	done
	[ -f "$filepath" ] || die "could not find $pkgfile"

	# generate a temp repositories file with only the http repos
	grep ^http: /etc/apk/repositories > $tmpdir/repositories

	oldpkg=$(apk fetch --repositories-file $tmpdir/repositories --simulate 2>&1 | sed 's/^Downloading //')
	if [ "${oldpkg}" = "${pkg}" ]; then
		die "The built package ($_pkgname) is the one in the repo right now!"
	fi

	apk fetch --repositories-file $tmpdir/repositories --stdout $_pkgname \
		| tar -zt | grep -v '^\.SIGN\.' | sort > filelist-$_pkgname-old \
		|| die "Failed to download old pkg. Maybe run 'apk update'?"

	tar -ztf "$filepath" | grep -v '^\.SIGN\.' | sort > "filelist-$_pkgname"

	diff -u "filelist-$_pkgname-old" "filelist-$_pkgname"

	if diff "filelist-$_pkgname-old" "filelist-$_pkgname" | grep '\.so' > /dev/null 2>&1; then
		mkdir -p pkg
		cd pkg
		tar -zxf "$filepath" > /dev/null
		diff "../filelist-$_pkgname-old" "../filelist-$_pkgname" | awk '/>.*\.so/{$1 = ""; print $0}' | while read i; do
			echo "${i}: " "$(objdump -p "$i" | grep SONAME)"
		done
		cd ..
	else
		msg "No soname differences for $_pkgname."
	fi
done

msg "Files saved to $tmpdir"