]> git.donarmstrong.com Git - wannabuild.git/blob - trigger.daily
36d166a7a55b1189a0348c6ef016e19a842b3c16
[wannabuild.git] / trigger.daily
1 #!/bin/bash
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 STATS_DISTS="unstable testing stable"
15 SECTIONS="main contrib non-free"
16 ARCHS_oldstable="m68k arm sparc alpha powerpc i386 mips mipsel ia64 hppa s390"
17 ARCHS_stable="arm sparc alpha powerpc i386 amd64 mips mipsel ia64 hppa s390"
18 ARCHS_testing="$ARCHS_stable armel"
19 ARCHS_unstable="$ARCHS_testing hurd-i386 m68k"
20 TMPDIR="/org/wanna-build/tmp"
21 LOCKFILE="/org/wanna-build/tmp/DB_Maintenance_In_Progress"
22 MASTER="http://incoming.debian.org/debian/dists"
23 MASTERBUILDD="http://incoming.debian.org/buildd"
24 SECMASTER="http://security-master.debian.org/debian-security/dists"
25 SECMASTERBUILDD=http://security-master.debian.org/buildd
26 CURLOPT="-q -s -S -R -f -Y 10 -y 120 -K /srv/wanna-build/trigger.curlrc"
27 NEWARCH=""
28
29 curl_index () {
30     local url tmpname destname appendname curlopt
31     url="$1"
32     destname="$2"
33     appendname="$3"
34     tmpname=".$destname"
35     rc=0
36     rm -f "$tmpname"
37     if [ -e "$destname" ]; then
38         refdate=`perl -e "print scalar gmtime(((stat ('$destname'))[9]))"`
39         curl $CURLOPT -z "$refdate" "$url" -o "$tmpname"
40         rc=$?
41     else
42         curl $CURLOPT "$url" -o "$tmpname"
43         rc=$?
44     fi
45     if [ $rc -eq 0 -a -e "$tmpname" ]; then
46         if gzip -t "$tmpname"; then
47             mv "$tmpname" "$destname"
48         else
49             rc=$?
50         fi
51     fi
52     gzip -dc "$destname" >> "$appendname"
53     return $rc
54 }
55
56 DAY=`date +%w`
57
58 if lockfile -! -l 3600 $LOCKFILE; then
59     echo "Cannot lock $LOCKFILE"
60     exit 1
61 fi
62
63 cleanup() {
64     rm -f "$LOCKFILE"
65 }
66 trap cleanup 0
67
68 echo Updating wanna-build databases...
69 umask 027
70
71 if [ "$DAY" = "0" ]; then
72         savelog -c 26 -p /srv/wanna-build/db/merge.log
73 fi
74
75 exec 3<&1 >> /srv/wanna-build/db/merge.log 2>&1
76
77 echo -------------------------------------------------------------------------
78 echo "merge triggered: `date`"
79 echo "merge triggered          : `date -u`" >&3
80
81 cd $TMPDIR
82
83 #
84 # Make one big Packages and Sources file.
85 #
86 for d in $DISTS; do
87     dist=`echo $d | sed s/-.*$//`
88     case "$dist" in
89         oldstable)
90             ARCHS="$ARCHS_oldstable"
91             ;;
92         stable)
93             ARCHS="$ARCHS_stable"
94             ;;
95         testing)
96             ARCHS="$ARCHS_testing"
97             ;;
98         *)
99             ARCHS="$ARCHS_unstable"
100             ;;
101     esac
102     rm -f Sources.$d Sources.$d-p-u
103
104     for a in $ARCHS; do
105         rm -f Packages.$d.$a Packages.$d-p-u.$a quinn-$d-p-u.$a
106     done
107
108     for s in $SECTIONS; do
109         if echo $d | grep -qv -- -security; then
110             curl_index "$MASTER/$dist/$s/source/Sources.gz" "Sources-$d.$s.gz" "Sources.$d"
111             if [ "$d" != "unstable" ]; then
112                 curl_index "$MASTER/$dist-proposed-updates/$s/source/Sources.gz" "Sources-$d-proposed-updates.$s.gz" "Sources.$d-p-u"
113             fi
114
115             for a in $ARCHS; do
116                 curl_index "$MASTER/$dist/$s/binary-$a/Packages.gz" "Packages-$d.$s.$a.gz" "Packages.$d.$a"
117                 if [ "$d" != "unstable" ]; then
118                     curl_index "$MASTER/$dist-proposed-updates/$s/binary-$a/Packages.gz" "Packages-$d-proposed-updates.$s.$a.gz" "Packages.$d-p-u.$a"
119                     if [ "$d" != "oldstable" -o "$s" = "main" ]; then
120                         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"
121                     fi
122                 fi
123                 if [ "$d" != "oldstable" -o "$s" = "main" ]; then
124                     curl_index "$MASTER/$d/$s/debian-installer/binary-$a/Packages.gz" "Packages-$d-debian-installer.$s.$a.gz" "Packages.$d.$a"
125                 fi
126             done
127         else
128             curl_index "$SECMASTER/$dist/updates/$s/source/Sources.gz" "Sources-$d.$s.gz" "Sources.$d"
129             if [ "$s" = "main" ]; then
130                 curl_index "$SECMASTERBUILDD/$dist/Sources.gz" "Sources-$d.accepted.gz" "Sources.$d"
131                 curl_index "$SECMASTERBUILDD/$dist/Packages.gz" "Packages-$d.accepted.gz" "/dev/null"
132             fi
133             for a in $ARCHS ; do
134                 curl_index "$SECMASTER/$dist/updates/$s/binary-$a/Packages.gz" "Packages-$d.$s.$a.gz" "Packages.$d.$a"
135                 if [ "$s" = "main" ]; then
136                     gzip -dc "Packages-$d.accepted.gz" >> "Packages.$d.$a"
137                 fi
138             done
139         fi
140     done
141
142 #
143 # It's important that the accepted file is rebuilt before the daily run,
144 # and that you have that should-be-empty version, to avoid unaccepts and
145 # double builds.
146 #
147     if [ "$d" = "unstable" ]; then
148         rm -f "Sources.$d.base"
149         cp "Sources.$d" "Sources.$d.base"
150         curl_index "$MASTERBUILDD/Sources.gz" "Sources-$d.accepted.gz" "Sources.$d"
151         curl_index "$MASTERBUILDD/Packages.gz" "Packages-$d.accepted.gz" "/dev/null"
152
153         for a in $ARCHS; do
154             rm -f "Packages.$d.$a.base"
155             cp "Packages.$d.$a" "Packages.$d.$a.base"
156             gzip -dc "Packages-$d.accepted.gz" >> "Packages.$d.$a"
157         done
158     else
159         if [ -e "Sources.$d-p-u" ]; then
160             cat "Sources.$d" >> "Sources.$d-p-u"
161         fi
162     fi
163
164     for a in $ARCHS; do
165         quinn-diff -A $a -a /srv/buildd.debian.org/web/quinn-diff/Packages-arch-specific -s Sources.$d -p Packages.$d.$a >> quinn-$d.$a 2>/dev/null
166         if echo $d | grep -qv -- -security; then
167             if [ "$d" != "unstable" ]; then
168                 cat "Packages.$d.$a" >> "Packages.$d-p-u.$a"
169                 quinn-diff -A $a -a /srv/buildd.debian.org/web/quinn-diff/Packages-arch-specific -s Sources.$d-p-u -p Packages.$d-p-u.$a >> quinn-$d-p-u.$a 2>/dev/null
170                 sed -e 's/\[[-a-z]*:[-a-z]*\]$//' quinn-$d.$a > quinn-$d.$a.grep
171                 if [ ! -z quinn-$d.$a.grep ]; then
172                     fgrep -vf quinn-$d.$a.grep quinn-$d-p-u.$a > quinn-$d.$a
173                 else
174                     cp quinn-$d-p-u.$a quinn-$d.$a
175                 fi
176                 rm quinn-$d.$a.grep
177                 mv "Packages.$d-p-u.$a" "Packages.$d.$a"
178             fi
179         fi
180     done
181     if [ -e "Sources.$d-p-u" ]; then
182         mv "Sources.$d-p-u" "Sources.$d"
183     fi
184 done
185 echo "fetch and quinn completed: `date -u`"
186 echo "fetch and quinn completed: `date -u`" >&3
187
188 umask 002
189 for a in $ARCHS_unstable ; do
190         wanna-build --create-maintenance-lock --database=$a/build-db
191
192         for d in $DISTS ; do
193                 dist=`echo $d | sed s/-.*$//`
194                 case "$dist" in
195                         oldstable)
196                                 if echo $ARCHS_oldstable | grep -q -v "\b$a\b"; then
197                                         continue
198                                 fi
199                                 ;;
200                         stable)
201                                 if echo $ARCHS_stable | grep -q -v "\b$a\b"; then
202                                         continue
203                                 fi
204                                 ;;
205                         testing)
206                                 if echo $ARCHS_testing | grep -q -v "\b$a\b"; then
207                                         continue
208                                 fi
209                                 ;;
210                         *)
211                                 if echo $ARCHS_unstable | grep -q -v "\b$a\b"; then
212                                         continue
213                                 fi
214                                 ;;
215                 esac
216                 # non-free is excluded for legal reasons.  buildd needs to
217                 # confirm on a per-package and per-buildd basis whether or not
218                 # it is buildable
219                 perl -pi -e 's#^(non-free)/.*$##msg' quinn-$d.$a
220                 if [ "$a" = "$NEWARCH" ]; then
221                 wanna-build -v --merge-all --arch=$a --dist=$d --database=$a/build-db Packages.$d.$a quinn-$d.$a Sources.unstable.$NEWARCH
222                 else
223                 wanna-build -v --merge-all --arch=$a --dist=$d --database=$a/build-db Packages.$d.$a quinn-$d.$a Sources.$d
224                 fi
225                 mv Packages.$d.$a Packages.$d.$a-old
226                 mv quinn-$d.$a quinn-$d.$a-old
227         done
228         if [ "$DAY" = "0" ]; then
229                 savelog -p -c 26 /srv/wanna-build/db/$a/transactions.log
230         fi
231         wanna-build --remove-maintenance-lock --database=$a/build-db
232 done
233 umask 022
234 for d in $DISTS; do
235     mv Sources.$d Sources.$d-old
236 done
237
238 echo "merge ended: `date`"
239 #
240 # Only update stats if it's been at least 20h since the last time.
241 #
242 interval=72000
243 last=`stat --format="%Y" /srv/wanna-build/etc/graph-data`
244 now=`date +%s`
245 if (( $last + $interval < $now )); then
246         echo "stats start: `date`"
247         /srv/wanna-build/bin/wb-graph >> /srv/wanna-build/etc/graph-data
248         /srv/wanna-build/bin/wb-graph -p >> /srv/wanna-build/etc/graph2-data
249         rm -f "$LOCKFILE"
250         trap - 0
251         /srv/buildd.debian.org/bin/makegraph
252         for a in $ARCHS_stable; do
253             echo Last Updated: `date -u` > /srv/buildd.debian.org/web/stats/$a.txt
254             for d in $STATS_DISTS; do
255                 /srv/wanna-build/bin/wanna-build-statistics --database=$a/build-db --dist=$d >> /srv/buildd.debian.org/web/stats/$a.txt
256             done
257         done
258         echo "stats ended: `date`"
259 fi