diffoscope_distribution_test.sh 4.04 KB
Newer Older
1 2
#!/bin/bash

3
# Copyright 2014-2019 Holger Levsen <holger@layer-acht.org>
4 5 6 7 8 9
# released under the GPLv=2

DEBUG=false
. /srv/jenkins/bin/common-functions.sh
common_init "$@"

10 11 12
# common code (used for irc_message)
. /srv/jenkins/bin/reproducible_common.sh

13 14 15 16 17 18
send_irc_warning() {
	local WARNING=$1
	irc_message reproducible-builds "$WARNING"
	echo "Warning: $WARNING"
}

19 20 21
check_pypi() {
	TMPPYPI=$(mktemp -t diffoscope-distribution-XXXXXXXX)
	# the following two lines are a bit fragile…
22 23
	curl https://pypi.org/project/diffoscope/ -o $TMPPYPI
	DIFFOSCOPE_IN_PYPI=$(sed -ne 's@.*diffoscope \([0-9][0-9]*\).*@\1@gp' $TMPPYPI)
24 25 26 27 28 29 30 31
	rm -f $TMPPYPI > /dev/null
	echo
	echo
	if [ "$DIFFOSCOPE_IN_DEBIAN" = "$DIFFOSCOPE_IN_PYPI" ] ; then
		echo "Yay. diffoscope in Debian has the same version as on PyPI: $DIFFOSCOPE_IN_DEBIAN"
	elif dpkg --compare-versions "$DIFFOSCOPE_IN_DEBIAN" gt "$DIFFOSCOPE_IN_PYPI" ; then
		echo "Fail: diffoscope in Debian: $DIFFOSCOPE_IN_DEBIAN"
		echo "Fail: diffoscope in PyPI:   $DIFFOSCOPE_IN_PYPI"
32
		send_irc_warning "It seems diffoscope $DIFFOSCOPE_IN_DEBIAN is not available on PyPI, which only has $DIFFOSCOPE_IN_PYPI."
33
		exit 0
34 35 36 37 38 39 40 41 42
	else
		echo "diffoscope in Debian: $DIFFOSCOPE_IN_DEBIAN"
		echo "diffoscope in PyPI:   $DIFFOSCOPE_IN_PYPI"
		echo
		echo "Failure is the default action…"
		exit 1
	fi
}

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
check_github_macports() {
	TMPPORT=$(mktemp -t diffoscope-distribution-XXXXXXXX)
	# the following two lines are a bit fragile…
	curl https://raw.githubusercontent.com/macports/macports-ports/master/sysutils/diffoscope/Portfile -o $TMPPORT
	DIFFOSCOPE_IN_MACPORTS=$(grep ^version $TMPPORT | sed -E 's#version( )+##' )
	rm -f $TMPPORT > /dev/null
	echo
	echo
	if [ "$DIFFOSCOPE_IN_DEBIAN" = "$DIFFOSCOPE_IN_MACPORTS" ] ; then
		echo "Yay. diffoscope in Debian has the same version as on MacPorts: $DIFFOSCOPE_IN_DEBIAN"
	elif dpkg --compare-versions "$DIFFOSCOPE_IN_DEBIAN" gt "$DIFFOSCOPE_IN_MACPORTS" ; then
		echo "Fail: diffoscope in Debian:   $DIFFOSCOPE_IN_DEBIAN"
		echo "Fail: diffoscope on MacPorts: $DIFFOSCOPE_IN_MACPORTS"
		send_irc_warning "It seems diffoscope $DIFFOSCOPE_IN_DEBIAN is not available on MacPorts, which only has $DIFFOSCOPE_IN_MACPORTS."
		exit 0
	else
		echo "diffoscope in Debian: $DIFFOSCOPE_IN_DEBIAN"
		echo "diffoscope in MacPorts:   $DIFFOSCOPE_IN_MACPORTS"
		echo
		echo "Failure is the default action…"
		exit 1
	fi
}


68
check_whohas() {
69 70
	# the following is "broken" (but good enough for now)
	# as sort doesn't do proper version comparison
71
	DIFFOSCOPE_IN_WHOHAS=$(whohas -d $DISTRIBUTION diffoscope | grep -v "href=" | awk '{print $3}' | sort -n | tail -1)
72 73 74 75 76 77
	echo
	echo
	if [ "$DIFFOSCOPE_IN_DEBIAN" = "$DIFFOSCOPE_IN_WHOHAS" ] ; then
		echo "Yay. diffoscope in Debian has the same version as $DISTRIBUTION has: $DIFFOSCOPE_IN_DEBIAN"
	elif dpkg --compare-versions "$DIFFOSCOPE_IN_DEBIAN" gt "$DIFFOSCOPE_IN_WHOHAS" ; then
		echo "Fail: diffoscope in Debian: $DIFFOSCOPE_IN_DEBIAN"
78
		echo "Fail: diffoscope in $DISTRIBUTION: $DIFFOSCOPE_IN_WHOHAS"
Holger Levsen's avatar
Holger Levsen committed
79
		send_irc_warning "It seems diffoscope $DIFFOSCOPE_IN_DEBIAN is not available on $DISTRIBUTION, which only has $DIFFOSCOPE_IN_WHOHAS."
80
		exit 0
81 82 83 84
	elif [ "${DIFFOSCOPE_IN_DEBIAN}-1" = "$DIFFOSCOPE_IN_WHOHAS" ] ; then
		# archlinux package version can greater than Debian: 52-1 vs 52
		# workaround this above...
		echo "Yay. diffoscope in Debian has the same version as $DISTRIBUTION has: $DIFFOSCOPE_IN_DEBIAN (Debian) and $DIFFOSCOPE_IN_WHOHAS ($DISTRIBUTION)"
85 86
	else
		echo "diffoscope in Debian: $DIFFOSCOPE_IN_DEBIAN"
87
		echo "diffoscope in $DISTRIBUTION: $DIFFOSCOPE_IN_WHOHAS"
88 89 90 91 92 93 94
		echo
		echo "Failure is the default action…"
		exit 1
	fi
}


95 96 97
#
# main
#
98 99
for SUITE in 'experimental' 'unstable|sid'
do
100
	DIFFOSCOPE_IN_DEBIAN=$(rmadison diffoscope|egrep " ${SUITE} "| awk '{print $3}' | sort -r | head -1 || true)
101 102 103 104 105

	if [ "$DIFFOSCOPE_IN_DEBIAN" != "" ] ; then
		break
	fi
done
106 107

case $1 in
108 109
	PyPI)	check_pypi
		;;
110
	FreeBSD|NetBSD|Arch)
111
		DISTRIBUTION=$1
112
		check_whohas
113
		# missing tests: Fedora, openSUSE, maybe OpenBSD, Guix…
114
		;;
115 116 117
	MacPorts)
		check_github_macports
		;;
118 119 120 121 122
	*)
		echo "Unsupported distribution."
		exit 1
		;;
esac