udd-query.sh 2.93 KB
Newer Older
1 2 3
#!/bin/bash

# Copyright 2012-2014 Holger Levsen <holger@layer-acht.org>
4 5
# multiarch_versionskew UDD query by Stuart Prescott <stuart@debian.org>
# orphaned_without_o_bug by Johannes Schauer <j.schauer@email.de>
6 7 8 9 10 11
# released under the GPLv=2

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

12 13 14 15
udd_query() {
	#
	# Actually query UDD and save result in $UDD file
	#
Holger Levsen's avatar
Holger Levsen committed
16
	echo "$(date -u) - querying UDD using ${SQL_QUERY}"
17
	echo
18 19 20
	PGPASSWORD=udd-mirror \
		psql -U udd-mirror \
		-h udd-mirror.debian.net -p 5432 \
21 22 23
		-t \
		udd -c"${SQL_QUERY}" > $UDD
}
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
multiarch_versionskew() {
	if [ -z "$1" ] ; then
		echo "Warning: no distro supplied, assuming sid."
		DISTR=sid
	else
		DISTRO=$1
	fi
	#
	# SQL query for detecting multi-arch version skew
	#
	SQL_QUERY="SELECT DISTINCT source FROM
		(SELECT DISTINCT source, package, version
			FROM packages WHERE
				release='$DISTRO' AND
				multi_arch='same' AND
					architecture IN ('amd64', 'arm64', 'armel', 'armhf', 'i386',
					'kfreebsd-amd64', 'kfreebsd-i386', 'mips', 'mipsel',
42
					'mips64el', 'powerpc', 'ppc64el', 's390x')
43 44 45 46
				ORDER BY source) AS all_versions
				GROUP BY source, package
				HAVING count(*) > 1
			ORDER BY source ;"
47

48
	udd_query
49 50
	local PKGS=($(< "$UDD"))
	if [ ${#PKGS[@]} -gt 0 ] ; then
51 52 53 54 55 56
		if [ "$DISTRO" != "sid" ] ; then
			echo "Warning: multi-arch version skew in $DISTRO detected."
		else
			# multiarch version skew in sid is inevitable
			echo "Multi-arch version skew in $DISTRO detected."
		fi
57
		echo
58 59
		printf  "         Package          |           Tracker\n"
		printf -- "--------------------------------------------------------------------------\n"
60
		for pkg in "${PKGS[@]}" ; do
61
			printf "%25s | %s\n" "$pkg" "https://tracker.debian.org/$pkg"
62
		# TODO: show versions (per arch) too
63
		done
64
	fi
65
}
66

67 68 69 70
orphaned_without_o_bug() {
	WNPPRM=$(mktemp)
	SORTED_UDD=$(mktemp)

71 72 73
	SQL_QUERY="
		SELECT DISTINCT s.source
		FROM sources AS s
74
		JOIN (
75 76 77 78 79 80
				SELECT source, max(version) AS version
				FROM sources
				WHERE release IN ('sid','experimental')
				GROUP BY source
			) AS foo ON foo.source=s.source AND foo.version=s.version
		WHERE s.maintainer_email = 'packages@qa.debian.org';"
81 82 83 84 85

	udd_query
	cat $UDD | tr -d ' ' | sort | uniq > "$SORTED_UDD"
	curl --silent https://qa.debian.org/data/bts/wnpp_rm \
		| cut -d ' ' -f 1 | tr -d ':' | sort | uniq > "$WNPPRM"
86
	RES=$(comm -23 "$SORTED_UDD" "$WNPPRM")
87

88
	if [ -n "$RES" ] ; then
89 90 91
		echo "Warning: The following packages are maintained by packages@qa.debian.org"
		echo "but are missing a wnpp bug according to https://qa.debian.org/data/bts/wnpp_rm"
		echo
92 93 94
		for i in $RES ; do
			echo "https://tracker.debian.org/$i"
		done
95
	fi
96

97
	rm -f "$WNPPRM" "$SORTED_UDD"
98
}
99 100

#
101
# main
102
#
103
UDD=$(mktemp)
104 105
function rmtmpfile { rm -f "$UDD"; }
trap rmtmpfile exit
106
case $1 in
107 108 109 110 111 112 113 114 115 116
	orphaned_without_o_bug)
			orphaned_without_o_bug
			;;
	multiarch_versionskew)
			multiarch_versionskew $2
			;;
	*)
			echo "unknown query requested, exiting... please provide patches :)"
			;;
esac
117
echo