summaryrefslogtreecommitdiffstats
path: root/bin/reproducible_schedule_on_demand.sh
blob: f95ae4540f5d4dbe5c358d447aaf1447ed9de725 (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
#!/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

schedule_packages() {
	# these packages are manually scheduled, so should have high priority,
	# so schedule them in the past, so they are picked earlier :)
	DATE="2014-10-01 00:23"
	TMPFILE=$(mktemp)
	for PKG in $PACKAGES ; do
		echo "REPLACE INTO schedule (package_id, date_scheduled, date_build_started) VALUES ('$PKG', '$DATE', '');" >> $TMPFILE
	done
	cat $TMPFILE | sqlite3 -init $INIT ${PACKAGES_DB}
	rm $TMPFILE
}

check_candidates() {
	PACKAGES=""
	PACKAGES_NAMES=""
	TOTAL=0
	for PKG in $CANDIDATES ; do
		RESULT=$(sqlite3 -init $INIT ${PACKAGES_DB} "SELECT id, name from sources WHERE name='$PKG' AND suite='$SUITE';")
		if [ ! -z "$RESULT" ] ; then
			PACKAGES="$PACKAGES $(echo $RESULT|cut -d '|' -f 1)"
			PACKAGES_NAMES="$PACKAGES_NAMES $(echo $RESULT|cut -d '|' -f 2)"
			let "TOTAL+=1"
		fi
	done
	case $TOTAL in
	0)
		echo "No packages to schedule, exiting."
		exit 0
		;;
	1)
		PACKAGES_TXT="package"
		;;
	*)
		PACKAGES_TXT="packages"
		;;
	esac
}

#
# main
#
set +x
SUITE="$1"
shift
CANDIDATES="$@"
check_candidates
if [ ${#PACKAGES} -gt 256 ] ; then
	BLABLABLA="..."
fi
PACKAGES=$(echo $PACKAGES)
ACTION="manually rescheduled"
if [ -n "${BUILD_URL:-}" ] ; then
	ACTION="rescheduled by $BUILD_URL"
fi
MESSAGE="$TOTAL $PACKAGES_TXT $ACTION for $SUITE: ${PACKAGES_NAMES:0:256}$BLABLABLA"

# finally
schedule_packages
cd /srv/jenkins/bin
python3 -c "from reproducible_html_indexes import build_page; build_page('scheduled')"
echo
echo "$MESSAGE"
kgb-client --conf /srv/jenkins/kgb/debian-reproducible.conf --relay-msg "$MESSAGE"
echo "============================================================================="
echo "The following $TOTAL source $PACKAGES_TXT $ACTION for $SUITE: $PACKAGES_NAMES"
echo "============================================================================="
echo