]> git.donarmstrong.com Git - wannabuild.git/blob - trigger.daily
catch-up commit
[wannabuild.git] / trigger.daily
1 #!/bin/bash -x
2 #
3 # Updates wanna-build databases after the archive maintenance
4 # finishes
5 #
6 # Files:
7 #     Sources-* == upstream fetched file
8 #     Sources.* == uncompressed, concat'd version
9
10 LANG=C
11 PATH="/bin:/usr/bin"
12 #testing must be before unstable so late upld don't build for testing needlessly
13 DISTS="oldstable-security stable-security testing-security oldstable stable testing unstable"
14 # While oldstable is purged
15 #DISTS="stable-security testing-security stable testing unstable"
16 STATS_DISTS="unstable testing stable"
17 SECTIONS="main contrib non-free"
18 TMPDIR="/org/wanna-build/tmp"
19 LIBTRIGGER="/org/wanna-build/libtrigger.sh"
20 LOCKFILE="/org/wanna-build/tmp/DB_Maintenance_In_Progress"
21 MASTER="http://incoming.debian.org/debian/dists"
22 MASTERBUILDD="http://incoming.debian.org/buildd"
23 SECMASTER="http://security-master.debian.org/debian-security/dists"
24 SECMASTERBUILDD=http://security-master.debian.org/buildd
25 NEWARCH=""
26
27 . "$LIBTRIGGER"
28
29 DAY=`date +%w`
30
31 if lockfile -! -l 3600 $LOCKFILE; then
32     echo "Cannot lock $LOCKFILE"
33     exit 1
34 fi
35
36 cleanup() {
37     rm -f "$LOCKFILE"
38 }
39 trap cleanup 0
40
41 echo Updating wanna-build databases...
42 umask 027
43
44 if [ "$DAY" = "0" ]; then
45         savelog -c 64 -p /srv/wanna-build/db/merge.log
46 fi
47
48 exec 3<&1 >> /srv/wanna-build/db/merge.log 2>&1
49
50 echo -------------------------------------------------------------------------
51 echo "merge triggered: `date`"
52 echo "merge triggered          : `date -u`" >&3
53
54 cd $TMPDIR
55
56 #
57 # Make one big Packages and Sources file.
58 #
59 for d in $DISTS; do
60     dist=`echo $d | sed s/-.*$//`
61     case "$dist" in
62         oldstable)
63             ARCHS="$ARCHS_oldstable"
64             ;;
65         stable)
66             ARCHS="$ARCHS_stable"
67             ;;
68         testing)
69             ARCHS="$ARCHS_testing"
70             ;;
71         *)
72             ARCHS="$ARCHS_unstable"
73             ;;
74     esac
75     rm -f Sources.$d Sources.$d-p-u
76
77     for a in $ARCHS; do
78         rm -f Packages.$d.$a Packages.$d-p-u.$a quinn-$d-p-u.$a
79     done
80
81     for s in $SECTIONS; do
82         if echo $d | grep -qv -- -security; then
83             curl_index "$MASTER/$dist/$s/source/Sources.gz" "Sources-$d.$s.gz" "Sources.$d"
84             if [ "$d" != "unstable" ]; then
85                 curl_index "$MASTER/$dist-proposed-updates/$s/source/Sources.gz" "Sources-$d-proposed-updates.$s.gz" "Sources.$d-p-u"
86             fi
87
88             for a in $ARCHS; do
89                 curl_index "$MASTER/$dist/$s/binary-$a/Packages.gz" "Packages-$d.$s.$a.gz" "Packages.$d.$a"
90                 if [ "$d" != "unstable" ]; then
91                     curl_index "$MASTER/$dist-proposed-updates/$s/binary-$a/Packages.gz" "Packages-$d-proposed-updates.$s.$a.gz" "Packages.$d-p-u.$a"
92                     if [ "$d" != "oldstable" -o "$s" = "main" ]; then
93                         curl_index "$MASTER/$dist-proposed-updates/$s/debian-installer/binary-$a/Packages.gz" "Packages-$d-proposed-updates-debian-installer.$s.$a.gz" "Packages.$d-p-u.$a"
94                     fi
95                 fi
96                 if [ "$d" != "oldstable" -o "$s" = "main" ]; then
97                     curl_index "$MASTER/$d/$s/debian-installer/binary-$a/Packages.gz" "Packages-$d-debian-installer.$s.$a.gz" "Packages.$d.$a"
98                 fi
99             done
100         else
101             curl_index "$SECMASTER/$dist/updates/$s/source/Sources.gz" "Sources-$d.$s.gz" "Sources.$d"
102             if [ "$s" = "main" ]; then
103                 curl_index "$SECMASTERBUILDD/$dist/Sources.gz" "Sources-$d.accepted.gz" "Sources.$d"
104                 curl_index "$SECMASTERBUILDD/$dist/Packages.gz" "Packages-$d.accepted.gz" "/dev/null"
105             fi
106             for a in $ARCHS ; do
107                 curl_index "$SECMASTER/$dist/updates/$s/binary-$a/Packages.gz" "Packages-$d.$s.$a.gz" "Packages.$d.$a"
108                 if [ "$s" = "main" ]; then
109                     gzip -dc "Packages-$d.accepted.gz" >> "Packages.$d.$a"
110                 fi
111             done
112         fi
113     done
114
115 #
116 # It's important that the accepted file is rebuilt before the daily run,
117 # and that you have that should-be-empty version, to avoid unaccepts and
118 # double builds.
119 #
120     if [ "$d" = "unstable" ]; then
121         rm -f "Sources.$d.base"
122         cp "Sources.$d" "Sources.$d.base"
123         curl_index "$MASTERBUILDD/Sources.gz" "Sources-$d.accepted.gz" "Sources.$d"
124         curl_index "$MASTERBUILDD/Packages.gz" "Packages-$d.accepted.gz" "/dev/null"
125
126         for a in $ARCHS; do
127             rm -f "Packages.$d.$a.base"
128             cp "Packages.$d.$a" "Packages.$d.$a.base"
129             gzip -dc "Packages-$d.accepted.gz" >> "Packages.$d.$a"
130         done
131     else
132         if [ -e "Sources.$d-p-u" ]; then
133             cat "Sources.$d" >> "Sources.$d-p-u"
134         fi
135     fi
136
137     for a in $ARCHS; do
138         quinn-diff -A $a -a /srv/buildd.debian.org/web/quinn-diff/$dist/Packages-arch-specific -s Sources.$d -p Packages.$d.$a >> quinn-$d.$a 2>/dev/null
139         if echo $d | grep -qv -- -security; then
140             if [ "$d" != "unstable" ]; then
141                 cat "Packages.$d.$a" >> "Packages.$d-p-u.$a"
142                 quinn-diff -A $a -a /srv/buildd.debian.org/web/quinn-diff/$dist/Packages-arch-specific -s Sources.$d-p-u -p Packages.$d-p-u.$a >> quinn-$d-p-u.$a 2>/dev/null
143                 sed -e 's/\[[-a-z]*:[-a-z]*\]$//' quinn-$d.$a > quinn-$d.$a.grep
144                 if [ ! -z quinn-$d.$a.grep ]; then
145                     fgrep -vf quinn-$d.$a.grep quinn-$d-p-u.$a > quinn-$d.$a
146                 else
147                     cp quinn-$d-p-u.$a quinn-$d.$a
148                 fi
149                 rm quinn-$d.$a.grep
150                 mv "Packages.$d-p-u.$a" "Packages.$d.$a"
151             fi
152         fi
153     done
154     if [ -e "Sources.$d-p-u" ]; then
155         mv "Sources.$d-p-u" "Sources.$d"
156     fi
157 done
158 echo "fetch and quinn completed: `date -u`"
159 echo "fetch and quinn completed: `date -u`" >&3
160
161 umask 002
162 # Gross hack: we need a list of all architectures, because this loop
163 # insists on iterating on arches and then suites, instead of the
164 # opposite.
165 ALL_ARCHES=$(echo $ARCHS_oldstable $ARCHS_stable $ARCHS_testing $ARCHS_unstable \
166              | tr ' ' '\n' | sort -u)
167 for a in $ALL_ARCHES ; do
168         wanna-build --create-maintenance-lock --database=$a/build-db
169
170         for d in $DISTS ; do
171                 dist=`echo $d | sed s/-.*$//`
172                 case "$dist" in
173                         oldstable)
174                                 if echo $ARCHS_oldstable | grep -q -v "\b$a\b"; then
175                                         continue
176                                 fi
177                                 ;;
178                         stable)
179                                 if echo $ARCHS_stable | grep -q -v "\b$a\b"; then
180                                         continue
181                                 fi
182                                 ;;
183                         testing)
184                                 if echo $ARCHS_testing | grep -q -v "\b$a\b"; then
185                                         continue
186                                 fi
187                                 ;;
188                         *)
189                                 if echo $ARCHS_unstable | grep -q -v "\b$a\b"; then
190                                         continue
191                                 fi
192                                 ;;
193                 esac
194                 # non-free is excluded for legal reasons.  buildd needs to
195                 # confirm on a per-package and per-buildd basis whether or not
196                 # it is buildable
197                 perl -pi -e 's#^(non-free)/.*$##msg' quinn-$d.$a
198                 if [ "$a" = "$NEWARCH" ]; then
199                 wanna-build -v --merge-all --arch=$a --dist=$d --database=$a/build-db Packages.$d.$a quinn-$d.$a Sources.unstable.$NEWARCH
200                 else
201                 wanna-build -v --merge-all --arch=$a --dist=$d --database=$a/build-db Packages.$d.$a quinn-$d.$a Sources.$d
202                 fi
203                 mv Packages.$d.$a Packages.$d.$a-old
204                 mv quinn-$d.$a quinn-$d.$a-old
205         done
206         if [ "$DAY" = "0" ]; then
207                 savelog -p -c 128 /srv/wanna-build/db/$a/transactions.log
208         fi
209         wanna-build --remove-maintenance-lock --database=$a/build-db
210 done
211 umask 022
212 for d in $DISTS; do
213     mv Sources.$d Sources.$d-old
214 done
215
216 echo "merge ended: `date`"
217 #
218 # Only update stats if it's been at least 20h since the last time.
219 #
220 interval=72000
221 last=`stat --format="%Y" /srv/wanna-build/etc/graph-data`
222 now=`date +%s`
223 if (( $last + $interval < $now )); then
224         echo "stats start: `date`"
225         /srv/wanna-build/bin/wb-graph >> /srv/wanna-build/etc/graph-data
226         /srv/wanna-build/bin/wb-graph -p >> /srv/wanna-build/etc/graph2-data
227         rm -f "$LOCKFILE"
228         trap - 0
229         /srv/buildd.debian.org/bin/makegraph
230         for a in $ARCHS_stable; do
231             echo Last Updated: `date -u` > /srv/buildd.debian.org/web/stats/$a.txt
232             for d in $STATS_DISTS; do
233                 /srv/wanna-build/bin/wanna-build-statistics --database=$a/build-db --dist=$d >> /srv/buildd.debian.org/web/stats/$a.txt
234             done
235         done
236         echo "stats ended: `date`"
237 fi