summaryrefslogtreecommitdiffstats
path: root/bin/reproducible_blacklist.sh
blob: a22b48f721d77cf52ffc36397b4258231b965292 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash

# Copyright 2014 Holger Levsen <holger@layer-acht.org>
#         © 2015 Mattia Rizzolo <mattia@mapreri.org>
# released under the GPLv=2

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

# common code defining db access
. /srv/jenkins/bin/reproducible_common.sh

blacklist_packages() {
	DATE=$(date +'%Y-%m-%d %H:%M')
	for PKG in $PACKAGES ; do
		VERSION=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT version FROM sources WHERE name='$PKG' AND suite='$SUITE' AND architecture='$ARCH';")
		PKGID=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT id FROM sources WHERE name='$PKG' AND suite='$SUITE' AND architecture='$ARCH';")
		cleanup_pkg_files
		sqlite3 -init $INIT ${PACKAGES_DB} "REPLACE INTO results (package_id, version, status, build_date, job) VALUES ('$PKGID', '$VERSION', 'blacklisted', '$DATE', '');"
		sqlite3 -init $INIT ${PACKAGES_DB} "DELETE FROM schedule WHERE package_id='$PKGID'"
	done
}

revert_blacklisted_packages() {
	DATE=$(date +'%Y-%m-%d %H:%M')
	for PKG in $PACKAGES ; do
		VERSION=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT version FROM sources WHERE name='$PKG' AND suite='$SUITE' AND architecture='$ARCH';")
		PKGID=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT id FROM sources WHERE name='$PKG' AND suite='$SUITE' AND architecture='$ARCH';")
		sqlite3 -init $INIT ${PACKAGES_DB} "DELETE FROM results WHERE package_id='$PKGID' AND status='blacklisted';"
	done
}

check_candidates() {
	PACKAGES=""
	TOTAL=0
	for PKG in $CANDIDATES ; do
		RESULT=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT name from sources WHERE name='$PKG' AND suite='$SUITE' AND architecture='$ARCH';")
		if [ ! -z "$RESULT" ] ; then
			PACKAGES="$PACKAGES $RESULT"
			let "TOTAL+=1"
		fi
	done
}

explain_syntax() {
	echo "$0 has to be called with three or more params:"
	echo "     $0 \$arch \$suite pkg1 pkg2..."
	echo "optionally it's possible to revert like this:"
	echo "     $0 \$arch \$suite --revert pkg1 pkg2..."
	echo
	echo "Changing order of options is not possible and this should be improved."
	echo
}

#
# main
#
set +x
ARCH="$1"
shift
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "armhf" ] ; then
	explain_syntax
	exit 1
fi
SUITE="$1"
shift
case $SUITE in
	sid) 	echo "WARNING: sid has been renamed to unstable."
		SUITE=unstable
		;;
	unstable|experimental) ;;
	testing)	if [ "$ARCH" = "armhf" ] ; then echo "Testing is not yet tested on $ARCH, exiting." ; exit 0 ; fi
				;;
	*)	echo "$SUITE is not a valid suite".
		explain_syntax
		exit 1
		;;
esac

if [ "$1" != "--revert" ] ; then
	REVERT=false
	ACTION="blacklisted"
else
	shift
	REVERT=true
	ACTION="removed from blacklist"
fi

CANDIDATES="$@"
check_candidates
PACKAGES=$(echo $PACKAGES)
MESSAGE="$TOTAL package(s) $ACTION in $SUITE/$ARCH: ${PACKAGES}"
if [ $TOTAL -lt 1 ] ; then
	exit 1
fi

# main
if [ "$1" != "--revert" ] ; then
	blacklist_packages
else
	revert_blacklisted_packages
fi

for PACKAGE in "$PACKAGES" ; do
    gen_package_html $PACKAGE
done
echo
# notify
echo "$MESSAGE"
kgb-client --conf /srv/jenkins/kgb/debian-reproducible.conf --relay-msg "$MESSAGE"
echo
echo "============================================================================="
echo "The following $TOTAL source packages from $SUITE/$ARCH have been $ACTION: $PACKAGES"
echo "============================================================================="
echo
echo "Probably edit notes.git/packages.yml now and enter/remove reasons for blacklisting there."

# finally, let's re-schedule them if the blacklisted was reverted
if [ "$1" = "--revert" ] ; then
	/srv/jenkins/bin/reproducible_schedule_on_demand.sh -s $SUITE -a $ARCH $PACKAGES
fi