tinderbox_build 6.5 KB

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