2 # This shell script produces an email comparing current broken status
3 # to that of the last run of this script
5 # Copyright (C) Vance Lankhaar <vance@samba.org> 2005
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 BASEDIR="/home/build/master"
22 RESULT_CACHE="$BASEDIR/cache/broken_results.txt"
23 RESULT_URL="http://build.samba.org/?function=Text_Summary"
24 FULL_RESULT_URL="http://build.samba.org/"
26 # split into two parts to obfuscate from spam engines
27 RESULT_EMAIL_USER="samba-cvs"
28 RESULT_EMAIL_DOMAIN="lists.samba.org"
30 # End editable variables
31 ##################################################
34 # exit immediately on failure
37 # fail on attempting to use unassigned variable
40 # clean up environment a little
41 PATH="/usr/local/bin:/usr/bin:/bin"
46 ##################################################
47 # get the broken report from the build farm
48 function get_results {
52 wget --output-file="$RESULT_CACHE".log \
53 --output-document="$RESULT_CACHE" \
57 echo "Could not retrieve results:" >&2
58 cat "$RESULT_CACHE".log >&2
61 rm -rf "$RESULT_CACHE".log
65 ##################################################
66 # compare the results of build
67 function compare_results {
69 if [ ! -e "$RESULT_CACHE" ]; then
70 echo "Could not locate currrent results. $RESULT_CACHE not found" >&2
74 if [ ! -e "$RESULT_CACHE".old ]; then
75 echo "Could not locate old results. $RESULT_CACHE.old not found" >&2
79 diff -u "$RESULT_CACHE".old "$RESULT_CACHE" >> "$RESULT_CACHE".report || true
84 ##################################################
85 # send report to the above-set email address
86 function send_report {
88 if [ ! -e "$RESULT_CACHE".report ]; then
89 echo "Results ($RESULT_CACHE.report) not found" >&2
94 if [ x"$subject" = x ]; then
95 subject="Build Farm Status"
98 mail -s "$subject" "$RESULT_EMAIL_USER"@"$RESULT_EMAIL_DOMAIN" < "$RESULT_CACHE".report
101 ##################################################
102 ##################################################
104 if [ $# -gt 0 ]; then
105 if [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
106 echo "Usage: broken_report.sh"
108 echo "This shell script produces an email comparing current broken"
109 echo "status to that of the last run of this script."
111 echo "The source and destination are configurable within the script."
117 ##################################################
118 # prepares the report, including subject and "blurb"
119 rm -f "$RESULT_CACHE".report "$RESULT_CACHE".old
121 if [ -e "$RESULT_CACHE" ]; then
122 mv -f "$RESULT_CACHE" "$RESULT_CACHE".old
124 # get results if they don't exist
131 if [ $? -ne 0 ]; then
132 echo "Failed to get the results. Bailing." >&2
134 # remove any new results, as they're almost certainly foul
135 rm -f "$RESULT_CACHE"
136 mv -f "$RESULT_CACHE".old "$RESULT_CACHE"
143 # set report subject to show updated time
144 echo "URL: $FULL_RESULT_URL"
146 ) > "$RESULT_CACHE".report
150 if [ $? -ne 0 ]; then
151 echo "Failed to compare results. Bailing." >&2
156 subject=$(head -n 1 "$RESULT_CACHE")
157 send_report "$subject"