FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
BuildandInstall.php
1 #!/usr/bin/php
2 <?php
3 /***********************************************************
4  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
41 require_once('TestRun.php');
42 require_once('mailTo.php');
43 
44 global $mailTo;
45 
46 $usage = "$argv[0] [-h] [-p <path>]\n" .
47  "h: help, this message\n" .
48  "p path: the path to the fossology sources to test\n";
49 
50 $path = NULL;
51 
52 $options = getopt('hp:');
53 if(array_key_exists('h', $options))
54 {
55  echo $usage;
56  exit(0);
57 }
58 if(array_key_exists('p', $options))
59 {
60  $path = $options['p'];
61 }
62 
73 function reportError($error, $file=NULL)
74 {
75  global $mailTo;
76 
77  if(is_file($file))
78  {
79  if(is_readable($file))
80  {
81  $longMsg = file_get_contents($file);
82  }
83  else
84  {
85  $longMsg = "$file was not readable\n";
86  }
87  }
88  else if(strlen($file) != 0)
89  {
90  if(is_string($file))
91  {
92  $longMsg = $file;
93  }
94  else
95  {
96  $longMsg = "Could not append a non-string to the message, " .
97  "reportError was passed an invalid 2nd parameter\n";
98  }
99  }
100 
101  $hdr = "There were errors in the nightly test setup." .
102  "The tests were not run due to one or more errors.\n\n";
103 
104  $msg = $hdr . $error . "\n" . $longMsg . "\n";
105 
106  // mailx will not take a string as the message body... save to a tmp
107  // file and give it that.
108 
109  $tmpFile = tempnam('.', 'testError');
110  $F = fopen($tmpFile, 'w') or die("Can not open tmp file $tmpFile\n");
111  fwrite($F, $msg);
112  fclose($F);
113  $last = exec("mailx -s 'test Setup Failed' $mailTo < $tmpFile ",$tossme, $rptGen);
114 }
115 
116 // check if we are running under jenkins, and if so, use that path
117 if(array_key_exists('WORKSPACE', $_ENV))
118 {
119  $JenkinsWkSpace = $_ENV['WORKSPACE'];
120  $path = $JenkinsWkSpace;
121  print "workspaces path is:$JenkinsWkSpace\n";
122 }
123 
124 $tonight = new TestRun($path);
125 
126 // Step 1 update sources
127 
128 /* not sure the code below will be needed with jenkins...
129  print "removing model.dat file so sources will update\n";
130  $modelPath = $WORKSPACE . 'fossology/agents/copyright_analysis/model.dat';
131  //$last = exec("rm $modelPath 2>&1", $output, $rtn);
132  $last = exec("rm -f $modelPath ", $output, $rtn);
133 
134  // if the file doesn't exist, that's OK
135  if((preg_match('/No such file or directory/',$last, $matches)) != 1)
136  {
137  if($rtn != 0)
138  {
139  $error = "Error, could not remove $modelPath, sources will not update, exiting\n";
140  print $error;
141  reportError($error,NULL);
142  exit(1);
143  }
144  }
145  print "Updating sources with svn update\n";
146  if($tonight->svnUpdate() !== TRUE)
147  {
148  $error = "Error, could not svn Update the sources, aborting test\n";
149  print $error;
150  reportError($error,NULL);
151  exit(1);
152  }
153  */
154 //TODO: remove all log files as sudo
155 
156 // Step 2 make clean and make sources
157 print "Making sources\n";
158 if($tonight->makeSrcs() !== TRUE)
159 {
160  $error = "There were Errors in the make of the sources examine make.out\n";
161  print $error;
162  reportError($error,'make.out');
163  exit(1);
164 }
165 //try to stop the scheduler before the make install step.
166 print "Stopping Scheduler before install\n";
167 if($tonight->stopScheduler() !== TRUE)
168 {
169  $error = "Could not stop fossology-scheduler, maybe it wasn't running?\n";
170  print $error;
171  reportError($error, NULL);
172 }
173 
174 // Step 4 install fossology
175 print "Installing fossology\n";
176 if($tonight->makeInstall() !== TRUE)
177 {
178  $error = "There were Errors in the Installation examine make-install.out\n";
179  print $error;
180  reportError($error, 'mi.out');
181  exit(1);
182 }
183 
184 // Step 5 run the post install process
185 /*
186  for most updates you don't have to remake the db and license cache. Need to
187  add a -d for turning it off.
188  */
189 
190 print "Running fo-postinstall\n";
191 $iRes = $tonight->foPostinstall();
192 print "install results are:$iRes\n";
193 
194 if($iRes !== TRUE)
195 {
196 
197  $error = "There were errors in the postinstall process check fop.out\n";
198  print $error;
199  print "calling reportError\n";
200  reportError($error, 'fop.out');
201  exit(1);
202 }
203 
204 // Step 6 run the scheduler test to make sure everything is clean
205 print "Starting Scheduler Test\n";
206 if($tonight->schedulerTest() !== TRUE)
207 {
208  $error = "Error! in scheduler test examine ST.out\n";
209  print $error;
210  reportError($error, 'ST.out');
211  exit(1);
212 }
213 
214 print "Starting Scheduler\n";
215 if($tonight->startScheduler() !== TRUE)
216 {
217  $error = "Error! Could not start fossology-scheduler\n";
218  print $error;
219  reportError($error, NULL);
220  exit(1);
221 }
222 ?>
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:48
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:44