6ec1bfc4ff9b490af6e983550b6a59c5c5bc6932
[libguestfs.git] / contrib / autobuild / autobuild.sh
1 #!/bin/bash -
2 # libguestfs autobuild script
3 # Copyright (C) 2009-2011 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # This script is used to download and test the latest tarball on
20 # Debian and other platforms.  It runs from a cron job and sends email
21 # to the mailing list about the status.
22
23 set -e
24
25 # Subject line of email prefix.
26 prefix="${1:-[autobuild]}"
27
28 # Where we send mail.
29 mailto="rjones@redhat.com"
30
31 # Move to temporary directory for building.
32 tmpdir="$(mktemp -d --tmpdir=/var/tmp)"
33 cd "$tmpdir"
34
35 # The libguestfs index page contains some hidden fields to help us
36 # find the latest version programmatically.
37 version=$(wget --no-cache -O- -q http://libguestfs.org |
38           grep '^LATEST-VERSION:' | awk '{print $2}')
39 url=$(wget --no-cache -O- -q http://libguestfs.org |
40       grep '^LATEST-URL:' | awk '{print $2}')
41 filename=$(basename "$url")
42 directory=$(basename "$url" .tar.gz)
43
44 echo "--------------------------------------------------"
45 echo "prefix     $prefix"
46 echo "libguestfs $version"
47 echo "url        $url"
48 echo "build dir  $tmpdir/$directory"
49 echo "--------------------------------------------------"
50
51 # Grab the latest tarball from upstream.
52 wget "$url"
53
54 # Unpack the tarball.
55 tar zxf "$filename"
56
57 # Enter directory.
58 cd "$directory"
59
60 # This function is called if any step fails.
61 failed ()
62 {
63     mutt -s "$prefix libguestfs $version FAILED $1" "$mailto" -a ../build.log <<EOF
64 Autobuild failed.  See the attached log file.
65 EOF
66 }
67
68 # This function is called if the build is successful.
69 ok ()
70 {
71     mutt -s "$prefix libguestfs $version ok" "$mailto" -a ../build.log <<EOF
72 Autobuild was successful.  The full log file is attached.
73 EOF
74 }
75
76 # Ensure that we get full debugging output.
77 export LIBGUESTFS_DEBUG=1
78 export LIBGUESTFS_TRACE=1
79
80 # Configure and build.
81 echo "configure"
82 ./configure > ../build.log 2>&1 || {
83     failed "configure"
84     exit 1
85 }
86 echo "make"
87 make >> ../build.log 2>&1 || {
88     failed "make"
89     exit 1
90 }
91
92 # Run the tests.
93 echo "make check"
94 make check >> ../build.log 2>&1 || {
95     failed "make check"
96     exit 1
97 }
98
99 echo "finished"
100 ok