tinderbox_build 6.3 KB

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