tinderbox_build 6.4 KB

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