chiark / gitweb /
* WIP adt-testreport-onepackage
[autopkgtest.git] / runner / adt-testreport-onepackage
1 #!/bin/bash
2
3 set -e
4
5 mirror=http://mirror.relativity.greenend.org.uk/mirror/ubuntu.good
6 distro=feisty
7 suite=main
8 salt=''
9 tmp=tmp
10 var=var
11 administrator_email=ian@davenant.greenend.org.uk
12 maintainer_email_override="$administrator_email"
13 salutation="Ian"
14 from="$salutation Jackson <ian@davenant.greenend.org.uk>"
15 rsync=rsync
16
17 destdirtail=autopkgtest-output/$distro
18 destrsynchead=ijackson@chiark:public-html/
19 desthttphead=http://www.chiark.greenend.org.uk/~ijackson/
20
21 rm -rf "$tmp"
22 mkdir "$tmp"
23
24 exec >"$tmp"/log
25
26 progress () {
27         echo "++++++ $1 ++++++"
28 }
29
30 gurl () {
31         progress "fetching $1"
32         curl -sS "$1" >"$2"
33 }
34
35 gurl "$mirror/dists/$distro/$suite/source/Sources.gz" "$tmp"/sources.gz
36 zcat "$tmp"/sources.gz >"$tmp"/sources-in
37
38 sed -n 's/^Package: \([-+.0-9a-z][-+.0-9a-z]*\)$/\1/p' \
39  <"$tmp"/sources-in >"$tmp"/sources-packages
40
41 if test -f "$var"/last; then
42         sed -e 's/$/ _/' "$var"/last >>"$tmp"/sources-packages
43 else
44         echo ' _' >>"$tmp"/sources-packages
45 fi
46
47 sort <"$tmp"/sources-packages >"$tmp"/all-sorted
48 pkg="`
49         perl -ne '
50                 if ($now) { print or die $!; $now++; exit; }
51                 $now = m/ _$/;
52                 END { die unless $now>1; }
53         ' <"$tmp"/all-sorted
54 `"
55
56 progress "selected $pkg"
57
58 sed -n "/^Package: $pkg\$/,/^\$/p" \
59  <"$tmp"/sources-in >"$tmp"/this-stanza
60
61 cat "$tmp"/this-stanza
62
63 getfield () {
64         eval 'p'$1'="`
65                 sed -n '\''s/^'$1': //p'\'' \
66                  <"$tmp"/this-stanza
67         `"'
68 }
69
70 getfield Directory
71
72 leafnames="`
73         sed -n '/^Files:/,/^([^ ].*)?$/{ /^ /{
74                 s/^ [0-9a-z][0-9a-z]*  *[0-9][0-9]* //; p
75                 }}' \
76          <"$tmp"/this-stanza
77 `"
78
79 tp="$tmp/$pkg"
80 mkdir "$tp" "$tp/src" "$tp/tmp" "$tp/out"
81
82 for leafname in $leafnames; do
83         df="$tp/src/$leafname"
84         case "$leafname" in
85         */*|.*) echo >&2 "bad leafname: $leafname"; exit 1;;
86         *.dsc) dsc="$df";;
87         esac
88         gurl "$mirror/pool/$suite/$pDirectory/$leafname" "$df"
89 done
90
91 if [ "x$maintainer_email_override" = x ]; then
92         getfield Maintainer
93         maintainer_email=pMaintainer
94 else
95         maintainer_email=maintainer_email_override
96 fi
97
98 progress "starting test"
99
100 xrc () {
101         printf "+ %s\n" "$*"
102         set +e
103         "$@"
104         rc=$?
105         set -e
106 }
107
108 xrc adt-run --tmp-dir "$tp"/tmp                         \
109         --output-dir "$tp"/out                          \
110         --log-file "$tp"/log                            \
111         --source "$dsc"                                 \
112  ---                                                    \
113  adt-virt-xenlvm                                        \
114         distro="$distro"                                \
115  2>&1
116
117 case "$rc" in
118 0)      summary='all OK';                       email=''                ;;
119 2)      summary='OK (some skipped)';            email=''                ;;
120 8)      summary='package declares no tests';    email=''                ;;
121 4|6)    summary='test(s) failed!';      email="$maintainer_email"       ;;
122 12)     summary='erroneous package!';   email="$maintainer_email"       ;;
123 16)     summary='testbed failed!';      email="administrator_email"     ;;
124 *)      summary='unexpected failure!';  email="administrator_email"     ;;
125 esac
126
127 progress "RESULTS $summary"
128 progress "contacting $email"
129
130 for odir in tmp out; do
131         if test -d "$tp"/$odir; then
132                 GZIP=-2 tar -f "$tp"/$odir.tar.gz -C "$tp" -zc $odir
133                 rm -r "$tp"/$odir
134         fi
135 done
136
137 $rsync -rltH --safe-links --delete "$tp" "$destrsynchead/$destdirtail/"
138
139 if [ "x$email" != x ]; then
140         eval "email_addr=\$$email"
141         cat >"$tmp"/email <<END
142 From: $from
143 To: $email_addr
144 Subject: autopkgtest $distro $pkg: $summary
145
146  Test executed for:  $distro  $pkg
147  Outcome: $summary
148
149 This message is automatically generated by the autopkgtest package
150 testing system.  You are receiving it because:
151 END
152         case "$email" in
153                 pMaintainer)
154                         cat >>"$tmp"/email <<END
155  You are listed in the Maintainer field of the $pkg package in $distro
156   and the test results appear to indicate a problem with the package.
157 END
158                         ;;
159                 maintainer_email_override)
160                         cat >>"$tmp"/email <<END
161  The test results appear to indicate a problem with the package
162   and reports for package maintainers for $distro are being directed to
163   $maintainer_email_override
164 END
165                         ;;
166                 administrator_email)
167                         cat >>"$tmp"/email <<END
168  You are the administrator for the autopkgtest installation.
169 END
170                         ;;
171                 *)
172                         echo >&2 "huh email $email is what why?"
173                         exit 1
174                         ;;
175         esac
176         cat >>"$tmp/email" <<END
177
178 The test log, which is intended to be sufficient to diagnose most
179 failures, can be found below.  However, in case this is not
180 sufficient, another copy can be found along with output files, saved
181 temporary files, and so on, at:
182  $desthttphead/$destdirtail/
183
184 If you have any questions about this service please contact me at:
185  $from
186
187 Regards,
188 $salutation
189
190 -8<-
191 END
192         cat >>"$tmp"/email 2>&1 "$tmp"/log ||:
193         sendmail -odq -oem -t -oi <"$tmp"/email
194 fi
195
196 printf >>"$var"/log "package=%s rc=%s emailed='%s'\n" \
197         "$pkg" $rc "$email_addr"
198 echo $pkg >"$var"/last.new
199 mv "$var"/last.new "$var"/last
200
201 progress "done."