diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/tinderbox_build | 279 |
1 files changed, 279 insertions, 0 deletions
diff --git a/tools/tinderbox_build b/tools/tinderbox_build new file mode 100755 index 00000000..0fdaf038 --- /dev/null +++ b/tools/tinderbox_build | |||
@@ -0,0 +1,279 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # tinderbox_build.pl | ||
3 | # This script builds the nagiosplugins and then sends | ||
4 | # logs back to the master tinderbox server | ||
5 | # | ||
6 | # This script is based on mozilla-unix.pl which comes with tinderbox2 | ||
7 | # | ||
8 | # See http://tinderbox.altinity.org for more details | ||
9 | |||
10 | require 5.000; | ||
11 | |||
12 | use strict; | ||
13 | use Sys::Hostname; | ||
14 | use Cwd; | ||
15 | use Time::Local; | ||
16 | |||
17 | my $Version = '$Revision$'; | ||
18 | |||
19 | my $myhost = hostname; | ||
20 | chomp($myhost); | ||
21 | my ($host, $junk) = split(/\./, $myhost); | ||
22 | |||
23 | my $BuildAdministrator = $ENV{TINDERBOX_BUILD_ADMIN} || "$ENV{'USER'}\@$myhost"; | ||
24 | |||
25 | #Default values of cmdline opts | ||
26 | my $ReportStatus = 0; # Do not send results to server | ||
27 | |||
28 | # Set these to what makes sense for your system | ||
29 | |||
30 | # Set these proper values for your tinderbox server | ||
31 | my $Tinderbox_server = 'tinderbox2@tinderbox.altinity.org'; | ||
32 | |||
33 | # These shouldn't really need to be changed | ||
34 | my $BuildTree = 'nagiosplug'; | ||
35 | my $BuildName = ''; | ||
36 | my $ConfigureArgs = $ENV{CONFIGURE_ARGS}; | ||
37 | |||
38 | my $OS = `uname -s`; | ||
39 | my $OSVer = `uname -r`; | ||
40 | |||
41 | chop($OS, $OSVer); | ||
42 | |||
43 | if ( $OS eq 'AIX' ) { | ||
44 | $OSVer = `uname -v`; | ||
45 | chop($OSVer); | ||
46 | $OSVer = $OSVer . "." . `uname -r`; | ||
47 | chop($OSVer); | ||
48 | } | ||
49 | |||
50 | if ( $OS eq 'IRIX64' ) { | ||
51 | $OS = 'IRIX'; | ||
52 | } | ||
53 | |||
54 | if ( $OS eq 'SCO_SV' ) { | ||
55 | $OS = 'SCOOS'; | ||
56 | $OSVer = '5.0'; | ||
57 | } | ||
58 | |||
59 | if ( "$host" ne "" ) { | ||
60 | $BuildName = $host . ' '; | ||
61 | } | ||
62 | $BuildName .= $OS . ' ' . $OSVer; | ||
63 | $_ = $BuildName; | ||
64 | s/ /_/g; | ||
65 | |||
66 | my $logfile = "$_.log"; | ||
67 | |||
68 | sub BuildIt { | ||
69 | my ($fe, @felist, $EarlyExit, $LastTime); | ||
70 | |||
71 | my $StartDir = getcwd(); | ||
72 | $LastTime = 0; | ||
73 | |||
74 | print "Starting dir is : $StartDir\n"; | ||
75 | |||
76 | my $EarlyExit = 0; | ||
77 | |||
78 | chdir("$StartDir"); | ||
79 | |||
80 | my $StartTime = time; | ||
81 | if (-e (my $file = "nagios-plugins.spec")) { | ||
82 | open F, $file; | ||
83 | while (<F>) { | ||
84 | if (/^Version: HEAD-(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) { | ||
85 | $StartTime = timelocal(0, $5, $4, $3, ($2 - 1), ($1 - 1900)); | ||
86 | last; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | print "Start time is $StartTime",$/; | ||
92 | |||
93 | my $CurrentDir = getcwd(); | ||
94 | if ( $CurrentDir ne $StartDir ) { | ||
95 | print "startdir: $StartDir, curdir $CurrentDir\n"; | ||
96 | die "curdir != startdir"; | ||
97 | } | ||
98 | |||
99 | unlink( "$logfile" ); | ||
100 | |||
101 | print "opening $logfile\n"; | ||
102 | open( LOG, ">$logfile" ) || print "can't open $?\n"; | ||
103 | print LOG "current dir is -- $host:$CurrentDir\n"; | ||
104 | print LOG "Build Administrator is $BuildAdministrator\n"; | ||
105 | &PrintEnv; | ||
106 | |||
107 | my $BuildStatus; | ||
108 | if (&configure) { | ||
109 | if (&make) { | ||
110 | if (&maketest) { | ||
111 | $BuildStatus = "success"; | ||
112 | } else { | ||
113 | $BuildStatus = "test_failed"; | ||
114 | } | ||
115 | } else { | ||
116 | $BuildStatus = "build_failed"; | ||
117 | } | ||
118 | } else { | ||
119 | $BuildStatus = "busted"; | ||
120 | } | ||
121 | |||
122 | print LOG "\nBuild Status = $BuildStatus\n"; | ||
123 | |||
124 | close(LOG); | ||
125 | chdir("$StartDir"); | ||
126 | |||
127 | # TV: Leaving this in, because process mail program probably has some | ||
128 | # limitation retained | ||
129 | |||
130 | # this fun line added on 2/5/98. do not remove. Translated to english, | ||
131 | # that's "take any line longer than 1000 characters, and split it into less | ||
132 | # than 1000 char lines. If any of the resulting lines is | ||
133 | # a dot on a line by itself, replace that with a blank line." | ||
134 | # This is to prevent cases where a <cr>.<cr> occurs in the log file. Sendmail | ||
135 | # interprets that as the end of the mail, and truncates the log before | ||
136 | # it gets to Tinderbox. (terry weismann, chris yeh) | ||
137 | # | ||
138 | # This was replaced by a perl 'port' of the above, writen by | ||
139 | # preed@netscape.com; good things: no need for system() call, and now it's | ||
140 | # all in perl, so we don't have to do OS checking like before. | ||
141 | |||
142 | open(LOG, "$logfile") || die "Couldn't open logfile: $!\n"; | ||
143 | open(OUTLOG, ">${logfile}.last") || die "Couldn't open logfile: $!\n"; | ||
144 | |||
145 | print OUTLOG $/; | ||
146 | print OUTLOG "tinderbox: tree: $BuildTree\n"; | ||
147 | print OUTLOG "tinderbox: builddate: $StartTime\n"; | ||
148 | print OUTLOG "tinderbox: status: $BuildStatus\n"; | ||
149 | print OUTLOG "tinderbox: build: $BuildName $fe\n"; | ||
150 | print OUTLOG "tinderbox: errorparser: unix\n"; | ||
151 | print OUTLOG "tinderbox: buildfamily: unix\n"; | ||
152 | print OUTLOG "tinderbox: END\n"; | ||
153 | print OUTLOG $/; | ||
154 | |||
155 | while (<LOG>) { | ||
156 | my $q = 0; | ||
157 | |||
158 | for (;;) { | ||
159 | my $val = $q * 1000; | ||
160 | my $Output = substr($_, $val, 1000); | ||
161 | |||
162 | last if $Output eq undef; | ||
163 | |||
164 | $Output =~ s/^\.$//g; | ||
165 | $Output =~ s/\n//g; | ||
166 | print OUTLOG "$Output\n"; | ||
167 | $q++; | ||
168 | } #EndFor | ||
169 | |||
170 | } #EndWhile | ||
171 | |||
172 | close(LOG); | ||
173 | close(OUTLOG); | ||
174 | |||
175 | if ($ReportStatus) { | ||
176 | system( "ssh $Tinderbox_server tinderbox_receive < ${logfile}.last" ) | ||
177 | } else { | ||
178 | print "Not sending logs to tinderbox",$/; | ||
179 | } | ||
180 | |||
181 | unlink("$logfile"); | ||
182 | print "Finished building for tinderbox",$/; | ||
183 | |||
184 | } #EndSub-BuildIt | ||
185 | |||
186 | sub ParseArgs { | ||
187 | my($i); | ||
188 | |||
189 | $i = 0; | ||
190 | while( $i < @ARGV ) { | ||
191 | if ($ARGV[$i] eq '--version' || $ARGV[$i] eq '-v') { | ||
192 | die "$0: version $Version\n"; | ||
193 | } elsif ($ARGV[$i] eq '-y') { | ||
194 | $ReportStatus = 1; | ||
195 | } else { | ||
196 | &PrintUsage; | ||
197 | } | ||
198 | |||
199 | $i++; | ||
200 | } #EndWhile | ||
201 | |||
202 | } #EndSub-ParseArgs | ||
203 | |||
204 | sub PrintUsage { | ||
205 | die "usage: $0 [-v | --version ] [-t do not send report to tinderbox server]\n"; | ||
206 | } | ||
207 | |||
208 | sub PrintEnv { | ||
209 | my ($key); | ||
210 | foreach $key (keys %ENV) { | ||
211 | print LOG "$key = $ENV{$key}\n"; | ||
212 | print "$key = $ENV{$key}\n"; | ||
213 | } | ||
214 | |||
215 | # Print the NPTest variables | ||
216 | if (-e "/var/tmp/NPTest.cache") { | ||
217 | open F, "/var/tmp/NPTest.cache"; | ||
218 | print LOG "NPTest variables:\n"; | ||
219 | print LOG <F>; | ||
220 | close F; | ||
221 | } | ||
222 | |||
223 | } #EndSub-PrintEnv | ||
224 | |||
225 | sub SetupPath { | ||
226 | my($Path); | ||
227 | $Path = $ENV{PATH}; | ||
228 | print "Path before: $Path\n"; | ||
229 | |||
230 | if ( $OS eq 'SunOS' ) { | ||
231 | $ENV{'PATH'} = '/usr/ccs/bin:' . $ENV{'PATH'}; | ||
232 | } | ||
233 | |||
234 | $Path = $ENV{PATH}; | ||
235 | print "Path After: $Path\n"; | ||
236 | } #EndSub-SetupPath | ||
237 | |||
238 | sub configure { | ||
239 | # Configure | ||
240 | print LOG "./configure $ConfigureArgs\n"; | ||
241 | open (CONFIGURE, "./configure $ConfigureArgs 2>&1 |") || die "../configure: $!\n"; | ||
242 | while (<CONFIGURE>) { | ||
243 | print $_; | ||
244 | print LOG $_; | ||
245 | } | ||
246 | close(CONFIGURE); | ||
247 | return ! $?; | ||
248 | } | ||
249 | |||
250 | sub make { | ||
251 | # Building | ||
252 | print LOG "make 2>&1\n"; | ||
253 | open( MAKE, "make 2>&1 |"); | ||
254 | while ( <MAKE> ) { | ||
255 | print $_; | ||
256 | print LOG $_; | ||
257 | } | ||
258 | close( MAKE); | ||
259 | return ! $?; | ||
260 | } | ||
261 | |||
262 | sub maketest { | ||
263 | # Tests | ||
264 | print LOG "LANG=C make test 2>&1\n"; | ||
265 | open( MAKE, "LANG=C make test 2>&1 |"); | ||
266 | while ( <MAKE> ) { | ||
267 | print $_; | ||
268 | print LOG $_; | ||
269 | } | ||
270 | close( MAKE); | ||
271 | return ! $?; | ||
272 | } | ||
273 | |||
274 | # Main function | ||
275 | &ParseArgs; | ||
276 | &SetupPath; | ||
277 | &BuildIt; | ||
278 | |||
279 | 1; | ||