FOSSology  4.4.0
Open Source License Compliance by Open Source Software
BuildandInstall.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
29 require_once('TestRun.php');
30 require_once('mailTo.php');
31 
32 global $mailTo;
33 
34 $usage = "$argv[0] [-h] [-p <path>]\n" .
35  "h: help, this message\n" .
36  "p path: the path to the fossology sources to test\n";
37 
38 $path = NULL;
39 
40 $options = getopt('hp:');
41 if(array_key_exists('h', $options))
42 {
43  echo $usage;
44  exit(0);
45 }
46 if(array_key_exists('p', $options))
47 {
48  $path = $options['p'];
49 }
50 
61 function reportError($error, $file=NULL)
62 {
63  global $mailTo;
64 
65  if(is_file($file))
66  {
67  if(is_readable($file))
68  {
69  $longMsg = file_get_contents($file);
70  }
71  else
72  {
73  $longMsg = "$file was not readable\n";
74  }
75  }
76  else if(strlen($file) != 0)
77  {
78  if(is_string($file))
79  {
80  $longMsg = $file;
81  }
82  else
83  {
84  $longMsg = "Could not append a non-string to the message, " .
85  "reportError was passed an invalid 2nd parameter\n";
86  }
87  }
88 
89  $hdr = "There were errors in the nightly test setup." .
90  "The tests were not run due to one or more errors.\n\n";
91 
92  $msg = $hdr . $error . "\n" . $longMsg . "\n";
93 
94  // mailx will not take a string as the message body... save to a tmp
95  // file and give it that.
96 
97  $tmpFile = tempnam('.', 'testError');
98  $F = fopen($tmpFile, 'w') or die("Can not open tmp file $tmpFile\n");
99  fwrite($F, $msg);
100  fclose($F);
101  $last = exec("mailx -s 'test Setup Failed' $mailTo < $tmpFile ",$tossme, $rptGen);
102 }
103 
104 // check if we are running under jenkins, and if so, use that path
105 if(array_key_exists('WORKSPACE', $_ENV))
106 {
107  $JenkinsWkSpace = $_ENV['WORKSPACE'];
108  $path = $JenkinsWkSpace;
109  print "workspaces path is:$JenkinsWkSpace\n";
110 }
111 
112 $tonight = new TestRun($path);
113 
114 // Step 1 update sources
115 
116 /* not sure the code below will be needed with jenkins...
117  print "removing model.dat file so sources will update\n";
118  $modelPath = $WORKSPACE . 'fossology/agents/copyright_analysis/model.dat';
119  //$last = exec("rm $modelPath 2>&1", $output, $rtn);
120  $last = exec("rm -f $modelPath ", $output, $rtn);
121 
122  // if the file doesn't exist, that's OK
123  if((preg_match('/No such file or directory/',$last, $matches)) != 1)
124  {
125  if($rtn != 0)
126  {
127  $error = "Error, could not remove $modelPath, sources will not update, exiting\n";
128  print $error;
129  reportError($error,NULL);
130  exit(1);
131  }
132  }
133  print "Updating sources with svn update\n";
134  if($tonight->svnUpdate() !== TRUE)
135  {
136  $error = "Error, could not svn Update the sources, aborting test\n";
137  print $error;
138  reportError($error,NULL);
139  exit(1);
140  }
141  */
142 //TODO: remove all log files as sudo
143 
144 // Step 2 make clean and make sources
145 print "Making sources\n";
146 if($tonight->makeSrcs() !== TRUE)
147 {
148  $error = "There were Errors in the make of the sources examine make.out\n";
149  print $error;
150  reportError($error,'make.out');
151  exit(1);
152 }
153 //try to stop the scheduler before the make install step.
154 print "Stopping Scheduler before install\n";
155 if($tonight->stopScheduler() !== TRUE)
156 {
157  $error = "Could not stop fossology-scheduler, maybe it wasn't running?\n";
158  print $error;
159  reportError($error, NULL);
160 }
161 
162 // Step 4 install fossology
163 print "Installing fossology\n";
164 if($tonight->makeInstall() !== TRUE)
165 {
166  $error = "There were Errors in the Installation examine make-install.out\n";
167  print $error;
168  reportError($error, 'mi.out');
169  exit(1);
170 }
171 
172 // Step 5 run the post install process
173 /*
174  for most updates you don't have to remake the db and license cache. Need to
175  add a -d for turning it off.
176  */
177 
178 print "Running fo-postinstall\n";
179 $iRes = $tonight->foPostinstall();
180 print "install results are:$iRes\n";
181 
182 if($iRes !== TRUE)
183 {
184 
185  $error = "There were errors in the postinstall process check fop.out\n";
186  print $error;
187  print "calling reportError\n";
188  reportError($error, 'fop.out');
189  exit(1);
190 }
191 
192 // Step 6 run the scheduler test to make sure everything is clean
193 print "Starting Scheduler Test\n";
194 if($tonight->schedulerTest() !== TRUE)
195 {
196  $error = "Error! in scheduler test examine ST.out\n";
197  print $error;
198  reportError($error, 'ST.out');
199  exit(1);
200 }
201 
202 print "Starting Scheduler\n";
203 if($tonight->startScheduler() !== TRUE)
204 {
205  $error = "Error! Could not start fossology-scheduler\n";
206  print $error;
207  reportError($error, NULL);
208  exit(1);
209 }
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
if(!preg_match("/\s$projectGroup\s/", $groups) &&(posix_getgid() !=$gInfo[ 'gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:33