FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testdata.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011-2012 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
23 require_once '../lib/TestRun.php';
24 
25 global $Debian;
26 global $RedHat;
27 
28 $debian = NULL;
29 $redHat = NULL;
30 $fedora = NULL;
31 $ubuntu = NULL;
32 
33 /*
34  * determine what os and version:
35  * configure yum or apt for fossology
36  * install fossology
37  * stop scheduler (if install is good).
38  * do the steps below.
39  * 1. tune kernel
40  * 2. postgres files
41  * 3. php ini files
42  * 4. fossology.org apache file (No needec)
43  * 5. checkout fossology
44  * 6. run fo-installdeps
45  * 7. for RHEL what else?
46  */
47 
48 // Check for Super User
49 $euid = posix_getuid();
50 if($euid != 0) {
51  print "Error, this script must be run as root\n";
52  exit(1);
53 }
54 
55 // determine os flavor
56 $distros = array();
57 $f = exec('cat /etc/issue', $dist, $dRtn);
58 $distros = explode(' ', $dist[0]);
59 
60 //echo "DB: distros[0] is:{$distros[0]}\n";
61 
62 // configure for fossology and install fossology packages.
63 // Note that after this point, you could just stop if one could rely on the install
64 // process to give a valid exit code... Another script will run the agent unit
65 // and functional tests.
66 
67 // create this class which can be used by any release/os
68 $testUtils = new TestRun();
69 // distro can be Debian, Red, Fedora, Ubuntu
70 switch ($distros[0]) {
71  case 'Debian':
72  $debian = TRUE; // is this needed?
73  $debianVersion = $distros[2];
74  echo "debian version is:$debianVersion\n";
75  try
76  {
77  $Debian = new ConfigSys($distros[0], $debianVersion);
78  }
79  catch (Exception $e)
80  {
81  echo "FATAL! could not process ini file for Debian $debianVersion system\n";
82  exit(1);
83  }
84 
85  if(insertDeb($Debian) === FALSE)
86  {
87  echo "FATAL! cannot insert deb line into /etc/apt/sources.list\n";
88  exit(1);
89  }
90  echo "*** Installing fossology ***\n";
91  if(!installFossology($Debian))
92  {
93  echo "FATAL! Could not install fossology on {$distros[0]} version $debianVersion\n";
94  exit(1);
95  }
96  echo "*** stopping scheduler ***\n";
97  // Stop scheduler so system files can be configured.
98  $testUtils->stopScheduler();
99 
100  echo "*** Tuning kernel ***\n";
101  tuneKernel();
102 
103  echo "*** Setting up config files ***\n";
104  if(configDebian($distros[0], $debianVersion) === FALSE)
105  {
106  echo "FATAL! could not configure postgres or php config files\n";
107  exit(1);
108  }
109  /*
110  echo "*** Checking apache config ***\n";
111  if(!configApache2($distros[0]))
112  {
113  echo "Fatal, could not configure apache2 to use fossology\n";
114  }
115  */
116  if(!restart('apache2'))
117  {
118  echo "Erorr! Could not restart apache2, please restart by hand\n";
119  exit(1);
120  }
121 
122  echo "*** Starting FOSSology ***\n";
123  if(!start('fossology'))
124  {
125  echo "Erorr! Could not start FOSSology, please restart by hand\n";
126  exit(1);
127  }
128  break;
129  case 'Red':
130  $redHat = 'RedHat';
131  $rhVersion = $distros[6];
132  //echo "rh version is:$rhVersion\n";
133  try
134  {
135  $RedHat = new ConfigSys($redHat, $rhVersion);
136  }
137  catch (Exception $e)
138  {
139  echo "FATAL! could not process ini file for RedHat $rhVersion system\n";
140  echo $e;
141  exit(1);
142  }
143  if(!configYum($RedHat))
144  {
145  echo "FATAL! could not install fossology.conf yum configuration file\n";
146  exit(1);
147  }
148  echo "*** Tuning kernel ***\n";
149  tuneKernel();
150 
151  echo "*** Installing fossology ***\n";
152  if(!installFossology($RedHat))
153  {
154  echo "FATAL! Could not install fossology on $redHat version $rhVersion\n";
155  exit(1);
156  }
157  echo "*** stopping scheduler ***\n";
158  // Stop scheduler so system files can be configured.
159  //$testUtils->stopScheduler();
160 
161  echo "*** Setting up config files ***\n";
162  if(!configRhel($redHat, $rhVersion))
163  {
164  echo "FATAL! could not install php and postgress configuration files\n";
165  exit(1);
166  }
167  /*
168  echo "*** Checking apache config ***\n";
169  if(!configApache2($distros[0]))
170  {
171  echo "Fatal, could not configure apache2 to use fossology\n";
172  }
173  */
174  if(!restart('httpd'))
175  {
176  echo "Erorr! Could not restart httpd, please restart by hand\n";
177  exit(1);
178  }
179 
180  if(!stop('iptables'))
181  {
182  echo "Erorr! Could not stop Firewall, please stop by hand\n";
183  exit(1);
184  }
185 
186  break;
187  case 'CentOS':
188  $redHat = 'RedHat';
189  $rhVersion = $distros[2];
190  echo "rh version is:$rhVersion\n";
191  try
192  {
193  $RedHat = new ConfigSys($redHat, $rhVersion);
194  }
195  catch (Exception $e)
196  {
197  echo "FATAL! could not process ini file for RedHat $rhVersion system\n";
198  echo $e;
199  exit(1);
200  }
201  if(!configYum($RedHat))
202  {
203  echo "FATAL! could not install fossology.conf yum configuration file\n";
204  exit(1);
205  }
206  echo "*** Tuning kernel ***\n";
207  tuneKernel();
208 
209  echo "*** Installing fossology ***\n";
210  if(!installFossology($RedHat))
211  {
212  echo "FATAL! Could not install fossology on $redHat version $rhVersion\n";
213  exit(1);
214  }
215  echo "*** stopping scheduler ***\n";
216  // Stop scheduler so system files can be configured.
217  //$testUtils->stopScheduler();
218 
219  echo "*** Setting up config files ***\n";
220  if(!configRhel($redHat, $rhVersion))
221  {
222  echo "FATAL! could not install php and postgress configuration files\n";
223  exit(1);
224  }
225  /*
226  echo "*** Checking apache config ***\n";
227  if(!configApache2($distros[0]))
228  {
229  echo "Fatal, could not configure apache2 to use fossology\n";
230  }
231  */
232  if(!stop('httpd'))
233  {
234  echo "Erorr! Could not restart httpd, please restart by hand\n";
235  exit(1);
236  }
237  if(!start('httpd'))
238  {
239  echo "Erorr! Could not restart httpd, please restart by hand\n";
240  exit(1);
241  }
242  if(!stop('iptables'))
243  {
244  echo "Erorr! Could not stop Firewall, please stop by hand\n";
245  exit(1);
246  }
247  echo "*** Starting fossology ***\n";
248  if(!start('fossology'))
249  {
250  echo "Erorr! Could not start fossology, please restart by hand\n";
251  exit(1);
252  }
253 
254  break;
255  case 'Fedora':
256  $fedora = 'Fedora';
257  $fedVersion = $distros[2];
258  try
259  {
260  $Fedora = new ConfigSys($fedora, $fedVersion);
261  }
262  catch (Exception $e)
263  {
264  echo "FATAL! could not process ini file for Fedora $fedVersion system\n";
265  echo $e;
266  exit(1);
267  }
268  if(!configYum($Fedora))
269  {
270  echo "FATAL! could not install fossology.repo yum configuration file\n";
271  exit(1);
272  break;
273  }
274  echo "*** Installing fossology ***\n";
275  if(!installFossology($Fedora))
276  {
277  echo "FATAL! Could not install fossology on $fedora version $fedVersion\n";
278  exit(1);
279  }
280  echo "*** stopping scheduler ***\n";
281  // Stop scheduler so system files can be configured.
282  //$testUtils->stopScheduler();
283 
284  echo "*** Tuning kernel ***\n";
285  tuneKernel();
286 
287  echo "*** Setting up config files ***\n";
288  if(!configRhel($fedora, $fedVersion))
289  {
290  echo "FATAL! could not install php and postgress configuration files\n";
291  exit(1);
292  }
293  /*
294  echo "*** Checking apache config ***\n";
295  if(!configApache2($distros[0]))
296  {
297  echo "Fatal, could not configure apache2 to use fossology\n";
298  }
299  */
300  $last = exec("systemctl restart httpd.service", $out, $rtn);
301  if($rtn != 0)
302  {
303  echo "Erorr! Could not restart httpd, please restart by hand\n";
304  exit(1);
305  }
306 
307  $last = exec("systemctl stop iptables.service", $out, $rtn);
308  if($rtn != 0)
309  {
310  echo "Erorr! Could not stop Firewall, please stop by hand\n";
311  exit(1);
312  }
313  echo "*** Starting fossology ***\n";
314  $last = exec("systemctl restart fossology.service", $out, $rtn);
315  if($rtn != 0)
316  {
317  echo "Erorr! Could not start FOSSology, please stop by hand\n";
318  exit(1);
319  }
320  break;
321  case 'Ubuntu':
322  $distro = 'Ubuntu';
323  $ubunVersion = $distros[1];
324  echo "Ubuntu version is:$ubunVersion\n";
325  try
326  {
327  $Ubuntu = new ConfigSys($distros[0], $ubunVersion);
328  }
329  catch (Exception $e)
330  {
331  echo "FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
332  echo $e . "\n";
333  exit(1);
334  }
335  if(insertDeb($Ubuntu) === FALSE)
336  {
337  echo "FATAL! cannot insert deb line into /etc/apt/sources.list\n";
338  exit(1);
339  }
340  echo "*** Tuning kernel ***\n";
341  tuneKernel();
342 
343  echo "*** Installing fossology ***\n";
344  if(!installFossology($Ubuntu))
345  {
346  echo "FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
347  exit(1);
348  }
349  echo "*** stopping scheduler ***\n";
350  // Stop scheduler so system files can be configured.
351  $testUtils->stopScheduler();
352 
353  echo "*** Setting up config files ***\n";
354  if(configDebian($distros[0], $ubunVersion) === FALSE)
355  {
356  echo "FATAL! could not configure postgres or php config files\n";
357  exit(1);
358  }
359  /*
360  echo "*** Checking apache config ***\n";
361  if(!configApache2($distros[0]))
362  {
363  echo "Fatal, could not configure apache2 to use fossology\n";
364  }
365  */
366  if(!restart('apache2'))
367  {
368  echo "Erorr! Could not restart apache2, please restart by hand\n";
369  exit(1);
370  }
371 
372  echo "*** Starting FOSSology ***\n";
373  if(!start('fossology'))
374  {
375  echo "Erorr! Could not start FOSSology, please restart by hand\n";
376  exit(1);
377  }
378  break;
379  default:
380  echo "Fatal! unrecognized distribution! {$distros[0]}\n" ;
381  exit(1);
382  break;
383 }
384 class ConfigSys {
385 
386  public $osFlavor;
387  public $osVersion = 0;
388  private $fossVersion;
389  private $osCodeName;
390  public $deb;
391  public $comment = '';
392  public $yum;
393 
394  function __construct($osFlavor, $osVersion)
395  {
396  if(empty($osFlavor))
397  {
398  throw new Exception("No Os Flavor supplied\n");
399  }
400  if(empty($osVersion))
401  {
402  throw new Exception("No Os Version Supplied\n");
403  }
404 
405  $dataFile = '../dataFiles/pkginstall/' . strtolower($osFlavor) . '.ini';
406  $releases = parse_ini_file($dataFile, 1);
407  //echo "DB: the parsed ini file is:\n";
408  //print_r($releases) . "\n";
409  foreach($releases as $release => $values)
410  {
411  if($values['osversion'] == $osVersion)
412  {
413  // found the correct os, gather attributes
414  $this->osFlavor = $values['osflavor'];
415  $this->osVersion = $values['osversion'];
416  $this->fossVersion = $values['fossversion'];
417  $this->osCodeName = $values['codename'];
418  // code below is needed to avoid php notice
419  switch (strtolower($this->osFlavor)) {
420  case 'ubuntu':
421  case 'debian':
422  $this->deb = $values['deb'];
423  break;
424  case 'fedora':
425  case 'redhat':
426  $this->yum = $values['yum'];
427  break;
428  default:
429  ;
430  break;
431  }
432  $this->comment = $values['comment'];
433  }
434  }
435  if($this->osVersion == 0)
436  {
437  throw new Exception("FATAL! no matching os flavor or version found\n");
438  }
439  return;
440  } // __construct
441 
447  public function printAttr()
448  {
449 
450  echo "Attributes of ConfigSys:\n";
451  echo "\tosFlavor:$this->osFlavor\n";
452  echo "\tosVersion:$this->osVersion\n";
453  echo "\tfossVersion:$this->fossVersion\n";
454  echo "\tosCodeName:$this->osCodeName\n";
455  echo "\tdeb:$this->deb\n";
456  echo "\tcomment:$this->comment\n";
457  echo "\tyum:$this->yum\n";
458 
459  return;
460  } //printAttr
461 } // ConfigSys
462 
470 function insertDeb($objRef)
471 {
472 
473  if(!is_object($objRef))
474  {
475  return(FALSE);
476  }
477  // open file for append
478  $APT = fopen('/etc/apt/sources.list', 'a+');
479  if(!is_resource($APT))
480  {
481  echo "FATAL! could not open /etc/apt/sources.list for modification\n";
482  return(FALSE);
483  }
484  $written = fwrite($APT, "\n");
485  fflush($APT);
486 
487  if(empty($objRef->comment))
488  {
489  $comment = '# Automatically inserted by pkgConfig.php';
490  }
491 
492  $com = fwrite($APT, $objRef->comment . "\n");
493  if(!$written = fwrite($APT, $objRef->deb))
494  {
495  echo "FATAL! could not write deb line to /etc/apt/sources.list\n";
496  return(FALSE);
497  }
498  fclose($APT);
499  return(TRUE);
500 } // insertDeb
501 
512 function installFossology($objRef)
513 {
514  if(!is_object($objRef))
515  {
516  return(FALSE);
517  }
518  $aptUpdate = 'apt-get update 2>&1';
519  $aptInstall = 'apt-get -y --force-yes install fossology 2>&1';
520  $yumUpdate = 'yum -y update 2>&1';
521  $yumInstall = 'yum -y install fossology > fossinstall.log 2>&1';
522  $debLog = NULL;
523  $installLog = NULL;
524 
525  //echo "DB: IFOSS: osFlavor is:$objRef->osFlavor\n";
526  switch ($objRef->osFlavor) {
527  case 'Ubuntu':
528  case 'Debian':
529  $last = exec($aptUpdate, $out, $rtn);
530  //echo "last is:$last\nresults of update are:\n";print_r($out) . "\n";
531  $last = exec($aptInstall, $iOut, $iRtn);
532  if($iRtn != 0)
533  {
534  echo "Failed to install fossology!\nTranscript is:\n";
535  echo implode("\n",$iOut) . "\n";
536  return(FALSE);
537  }
538  // check for php or other errors that don't make apt return 1
539  echo "DB: in ubun/deb case, before installLog implode\n";
540  $debLog = implode("\n",$iOut);
541  if(!ckInstallLog($debLog))
542  {
543  echo "One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
544  "Could not connect to FOSSology database:\n" .
545  "Unable to connect to PostgreSQL server:\n" .
546  "Was found in the install output. This install is suspect and is considered FAILED.\n";
547  return(FALSE);
548  }
549  // if any of the above are non zero, return false
550  break;
551  case 'Fedora':
552  case 'RedHat':
553  echo "** Running yum update **\n";
554  $last = exec($yumUpdate, $out, $rtn);
555  if($rtn != 0)
556  {
557  echo "Failed to update yum repositories with fossology!\nTranscript is:\n";
558  echo implode("\n",$out) . "\n";
559  return(FALSE);
560  }
561  echo "** Running yum install fossology **\n";
562  $last = exec($yumInstall, $yumOut, $yumRtn);
563  //echo "install of fossology finished, yumRtn is:$yumRtn\nlast is:$last\n";
564  //$clast = system('cat fossinstall.log');
565  if($yumRtn != 0)
566  {
567  echo "Failed to install fossology!\nTranscript is:\n";
568  system('cat fossinstall.log');
569  return(FALSE);
570  }
571  if(!($installLog = file_get_contents('fossinstall.log')))
572  {
573  echo "FATAL! could not read 'fossinstall.log\n";
574  return(FALSE);
575  }
576  if(!ckInstallLog($installLog))
577  {
578  echo "One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
579  "Could not connect to FOSSology database:\n" .
580  "Unable to connect to PostgreSQL server:\n" .
581  "Was found in the install output. This install is suspect and is considered failed.\n";
582  return(FALSE);
583  }
584  break;
585 
586  default:
587  echo "FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
588  " or Fedora\n";
589  return(FALSE);
590  break;
591  }
592  return(TRUE);
593 }
594 
604 function ckInstallLog($log) {
605  if(empty($log))
606  {
607  return(FALSE);
608  }
609  // check for php or other errors that don't make apt return 1
610  $traces = $fates = $connects = $postgresFail = 0;
611  $stack = '/PHP Stack trace:/';
612  $fatal = '/FATAL/';
613  $noConnect = '/Could not connect to FOSSology database/';
614  $noPG = '/Unable to connect to PostgreSQL server:/';
615 
616  $traces = preg_match_all($stack, $log, $stackMatches);
617  $fates = preg_match_all($fatal, $log, $fatalMatches);
618  $connects = preg_match_all($noConnect, $log, $noconMatches);
619  $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
620  echo "Number of PHP stack traces found:$traces\n";
621  echo "Number of FATAL's found:$fates\n";
622  echo "Number of 'cannot connect' found:$connects\n";
623  echo "Number of 'cannot connect to postgres server' found:$postgresFail\n";
624  //print "DB: install log is:\n$log\n";
625  if($traces ||
626  $fates ||
627  $connects ||
628  $postgresFail)
629  {
630  return(FALSE);
631  }
632  return(TRUE);
633 }
647 function copyFiles($files, $dest)
648 {
649  if(empty($files))
650  {
651  throw new Exception('No file to copy', 0);
652  }
653  if(empty($dest))
654  {
655  throw new Exception('No destination for copy', 0);
656  }
657  //echo "DB: copyFiles: we are at:" . getcwd() . "\n";
658  $login = posix_getlogin();
659  //echo "DB: copyFiles: running as:$login\n";
660  //echo "DB: copyFiles: uid is:" . posix_getuid() . "\n";
661  if(is_array($files))
662  {
663  foreach($files as $file)
664  {
665  // Get left name and check if dest is a directory, copy cannot copy to a
666  // dir.
667  $baseFile = basename($file);
668  if(is_dir($dest))
669  {
670  $to = $dest . "/$baseFile";
671  }
672  else
673  {
674  $to = $dest;
675  }
676  //echo "DB: copyfiles: file copied is:$file\n";
677  //echo "DB: copyfiles: to is:$to\n";
678  if(!copy($file, $to))
679  {
680  throw new Exception("Could not copy $file to $to");
681  }
682  //$lastcp = exec("cp -v $file $to", $cpout, $cprtn);
683  //echo "DB: copyfiles: cprtn is:$cprtn\n";
684  //echo "DB: copyfiles: lastcp is:$lastcp\n";
685  //echo "DB: copyfiles: out is:\n";print_r($cpout) . "\n";
686  }
687  }
688  else
689  {
690  $baseFile = basename($files);
691  if(is_dir($dest))
692  {
693  $to = $dest . "/$baseFile";
694  }
695  else
696  {
697  $to = $dest;
698  }
699  //echo "DB: copyfiles-single: file copied is:$files\n";
700  //echo "DB: copyfiles-single: to is:$to\n";
701  if(!copy($files,$to))
702  {
703  throw new Exception("Could not copy $file to $to");
704  }
705  }
706  return(TRUE);
707 } // copyFiles
708 
709 
716 function findVerPsql()
717 {
718  $version = NULL;
719 
720  $last = exec('psql --version', $out, $rtn);
721  if($rtn != 0)
722  {
723  return(FALSE);
724  }
725  else
726  {
727  // isolate the version number and return it
728  list( , ,$ver) = explode(' ', $out[0]);
729  $version = substr($ver, 0, 3);
730  }
731  return($version);
732 }
733 
739 function tuneKernel()
740 {
741  // check to see if we have already done this... so the sysctl.conf file doesn't
742  // end up with dup entries.
743  $grepCmd = 'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
744  $last = exec($grepCmd, $out, $rtn);
745  if($rtn == 0) // kernel already configured
746  {
747  echo "NOTE: kernel already configured.\n";
748  return;
749  }
750  $cmd1 = "echo 512000000 > /proc/sys/kernel/shmmax";
751  $cmd2 = "echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
752  // Tune the kernel
753  $last1 = exec($cmd1, $cmd1Out, $rtn1);
754  if ($rtn1 != 0)
755  {
756  echo "Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
757  }
758  $last2 = exec($cmd2, $cmd2Out, $rtn2);
759  // make it permanent
760  if ($rtn2 != 0)
761  {
762  echo "Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
763  }
764  return;
765 } // tuneKernel
766 
776 function configApache2($osType)
777 {
778  if(empty($osType))
779  {
780  return(FALSE);
781  }
782  switch ($osType) {
783  case 'Ubuntu':
784  case 'Debian':
785  if(is_link('/etc/apache2/conf.d/fossology'))
786  {
787  break;
788  }
789  else
790  {
791  // copy config file, create sym link
792  if(!copy('../dataFiles/pkginstall/fo-apache.conf', '/etc/fossology/fo-apache.conf'))
793  {
794  echo "FATAL!, Cannot configure fossology into apache2\n";
795  return(FALSE);
796  }
797  if(!symlink('/etc/fossology/fo-apache.conf','/etc/apache2/conf.d/fossology'))
798  {
799  echo "FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
800  return(FALSE);
801  }
802  // restart apache so changes take effect
803  if(!restart('apache2'))
804  {
805  echo "Erorr! Could not restart apache2, please restart by hand\n";
806  return(FALSE);
807  }
808  }
809  break;
810  case 'Red':
811  // copy config file, no symlink needed for redhat
812  if(!copy('../dataFiles/pkginstall/fo-apache.conf', '/etc/httpd/conf.d/fossology.conf'))
813  {
814  echo "FATAL!, Cannot configure fossology into apache2\n";
815  return(FALSE);
816  }
817  // restart apapche so changes take effect
818  if(!restart('httpd'))
819  {
820  echo "Erorr! Could not restart httpd, please restart by hand\n";
821  return(FALSE);
822  }
823  break;
824  default:
825  ;
826  break;
827  }
828  return(TRUE);
829 } // configApache2
830 
841 function configDebian($osType, $osVersion)
842 {
843  if(empty($osType))
844  {
845  return(FALSE);
846  }
847  if(empty($osVersion))
848  {
849  return(FALSE);
850  }
851 
852  // based on type read the appropriate ini file.
853 
854  //echo "DB:configD: osType is:$osType\n";
855  //echo "DB:configD: osversion is:$osVersion\n";
856 
857  // can't check in pg_hba.conf as it shows HP's firewall settings, get it
858  // internally
859 
860  // No need to update pg_hba.conf file
861  //getPGhba('../dataFiles/pkginstall/debian/6/pg_hba.conf');
862 
863  $debPath = '../dataFiles/pkginstall/debian/6/';
864 
865  $psqlFiles = array(
866  //$debPath . 'pg_hba.conf',
867  $debPath . 'postgresql.conf');
868 
869  switch ($osVersion)
870  {
871  case '6.0':
872  echo "debianConfig got os version 6.0!\n";
873  // copy config files
874  /*
875  * Change the structure of data files:
876  * e.g. debian/5/pg_hba..., etc, all files that go with this version
877  * debian/6/pg_hba....
878  * and use a symlink for the 'codename' squeeze -> debian/6/
879  */
880  try
881  {
882  copyFiles($psqlFiles, "/etc/postgresql/8.4/main");
883  }
884  catch (Exception $e)
885  {
886  echo "Failure: Could not copy postgres 8.4 config file\n";
887  }
888  try
889  {
890  copyFiles($debPath . 'cli-php.ini', '/etc/php5/cli/php.ini');
891  } catch (Exception $e)
892  {
893  echo "Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
894  return(FALSE);
895  }
896  try
897  {
898  copyFiles($debPath . 'apache2-php.ini', '/etc/php5/apache2/php.ini');
899  } catch (Exception $e)
900  {
901  echo "Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
902  return(FALSE);
903  }
904  break;
905  case '10.04.3':
906  case '11.04':
907  case '11.10':
908  try
909  {
910  copyFiles($psqlFiles, "/etc/postgresql/8.4/main");
911  }
912  catch (Exception $e)
913  {
914  echo "Failure: Could not copy postgres 8.4 config file\n";
915  }
916  try
917  {
918  copyFiles($debPath . 'cli-php.ini', '/etc/php5/cli/php.ini');
919  } catch (Exception $e)
920  {
921  echo "Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
922  return(FALSE);
923  }
924  try
925  {
926  copyFiles($debPath . 'apache2-php.ini', '/etc/php5/apache2/php.ini');
927  } catch (Exception $e)
928  {
929  echo "Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
930  return(FALSE);
931  }
932  break;
933  case '12.04.1':
934  case '12.10':
935  //postgresql-9.1 can't use 8.4 conf file
936  /*
937  try
938  {
939  copyFiles($psqlFiles, "/etc/postgresql/9.1/main");
940  }
941  catch (Exception $e)
942  {
943  echo "Failure: Could not copy postgres 9.1 config file\n";
944  }
945  */
946  try
947  {
948  copyFiles($debPath . 'cli-php.ini', '/etc/php5/cli/php.ini');
949  } catch (Exception $e)
950  {
951  echo "Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
952  return(FALSE);
953  }
954  try
955  {
956  copyFiles($debPath . 'apache2-php.ini', '/etc/php5/apache2/php.ini');
957  } catch (Exception $e)
958  {
959  echo "Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
960  return(FALSE);
961  }
962  break;
963  default:
964  return(FALSE); // unsupported debian version
965  break;
966  }
967  // restart apache and postgres so changes take effect
968  if(!restart('apache2'))
969  {
970  echo "Erorr! Could not restart apache2, please restart by hand\n";
971  return(FALSE);
972  }
973  // Get the postrgres version so the correct file is used.
974  $pName = 'postgresql';
975  if($osVersion == '10.04.3')
976  {
977  $ver = findVerPsql();
978  //echo "DB: returned version is:$ver\n";
979  $pName = 'postgresql-' . $ver;
980  }
981  echo "DB pName is:$pName\n";
982  if(!restart($pName))
983  {
984  echo "Erorr! Could not restart $pName, please restart by hand\n";
985  return(FALSE);
986  }
987  return(TRUE);
988 } // configDebian
989 
997 function configRhel($osType, $osVersion)
998 {
999  if(empty($osType))
1000  {
1001  return(FALSE);
1002  }
1003  if(empty($osVersion))
1004  {
1005  return(FALSE);
1006  }
1007 
1008  $rpmPath = '../dataFiles/pkginstall/redhat/6.x';
1009  // getPGhba($rpmPath . '/pg_hba.conf');
1010  $psqlFiles = array(
1011  //$rpmPath . '/pg_hba.conf',
1012  $rpmPath . '/postgresql.conf');
1013  // fossology tweaks the postgres files so the packages work.... don't copy
1014  /*
1015  try
1016  {
1017  copyFiles($psqlFiles, "/var/lib/pgsql/data/");
1018  }
1019  catch (Exception $e)
1020  {
1021  echo "Failure: Could not copy postgres 8.4 config files\n";
1022  }
1023  */
1024  try
1025  {
1026  copyFiles($rpmPath . '/php.ini', '/etc/php.ini');
1027  } catch (Exception $e)
1028  {
1029  echo "Failure: Could not copy php.ini to /etc/php.ini\n";
1030  return(FALSE);
1031  }
1032  // restart postgres, postgresql conf didn't change do not restart
1033  /*
1034  $pName = 'postgresql';
1035  if(!restart($pName))
1036  {
1037  echo "Erorr! Could not restart $pName, please restart by hand\n";
1038  return(FALSE);
1039  }
1040  */
1041  return(TRUE);
1042 } // configRhel
1043 
1053 function configYum($objRef)
1054 {
1055  if(!is_object($objRef))
1056  {
1057  return(FALSE);
1058  }
1059  if(empty($objRef->yum))
1060  {
1061  echo "FATAL, no yum install line to install\n";
1062  return(FALSE);
1063  }
1064 
1065  $RedFedRepo = 'redfed-fossology.repo'; // name of generic repo file.
1066  // replace the baseurl line with the current one.
1067  $n = "../dataFiles/pkginstall/" . $RedFedRepo;
1068  $fcont = file_get_contents($n);
1069  //if(!$fcont);
1070  //{
1071  //echo "FATAL! could not read repo file $n\n";
1072  //exit(1);
1073  //}
1074  //echo "DB: contents is:\n$fcont\n";
1075  $newRepo = preg_replace("/baseurl=(.*)?/", 'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1076  // write the file, fix below to copy the correct thing...
1077  if(!($written = file_put_contents("../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1078  {
1079  echo "FATAL! could not write repo file $RedFedRepo\n";
1080  exit(1);
1081  }
1082  // coe plays with yum stuff, check if yum.repos.d exists and if not create it.
1083  if(is_dir('/etc/yum.repos.d'))
1084  {
1085  copyFiles("../dataFiles/pkginstall/" . $RedFedRepo, '/etc/yum.repos.d/fossology.repo');
1086  }
1087  else
1088  {
1089  // create the dir and then copy
1090  if(!mkdir('/etc/yum.repos.d'))
1091  {
1092  echo "FATAL! could not create yum.repos.d\n";
1093  return(FALSE);
1094  }
1095  copyFiles("../dataFiles/pkginstall/" . $RedFedRepo, '/etc/yum.repos.d/fossology.repo');
1096  }
1097  //print_r($objRef);
1098  if ($objRef->osFlavor == 'RedHat')
1099  {
1100  $last = exec("yum -y install wget", $out, $rtn);
1101  if($rtn != 0)
1102  {
1103  echo "FATAL! install EPEL repo fail\n";
1104  echo "transcript is:\n";print_r($out) . "\n";
1105  return(FALSE);
1106  }
1107  $last = exec("wget -e http_proxy=http://lart.usa.hp.com:3128 http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm", $out, $rtn);
1108  if($rtn != 0)
1109  {
1110  echo "FATAL! install EPEL repo fail\n";
1111  echo "transcript is:\n";print_r($out) . "\n";
1112  return(FALSE);
1113  }
1114  $last = exec("rpm -ivh epel-release-6-7.noarch.rpm", $out, $rtn);
1115  if($rtn != 0)
1116  {
1117  echo "FATAL! install EPEL repo fail\n";
1118  echo "transcript is:\n";print_r($out) . "\n";
1119  return(FALSE);
1120  }
1121  }
1122  return(TRUE);
1123 } // configYum
1124 
1135 function restart($application)
1136 {
1137  if(empty($application))
1138  {
1139  return(FALSE);
1140  }
1141 
1142  $last = exec("/etc/init.d/$application restart 2>&1", $out, $rtn);
1143  if($rtn != 0)
1144  {
1145  echo "FATAL! could not restart $application\n";
1146  echo "transcript is:\n";print_r($out) . "\n";
1147  return(FALSE);
1148  }
1149  return(TRUE);
1150 } // restart
1151 
1162 function start($application)
1163 {
1164  if(empty($application))
1165  {
1166  return(FALSE);
1167  }
1168 
1169  echo "Starting $application ...\n";
1170  $last = exec("/etc/init.d/$application restart 2>&1", $out, $rtn);
1171  if($rtn != 0)
1172  {
1173  echo "FATAL! could not start $application\n";
1174  echo "transcript is:\n";print_r($out) . "\n";
1175  return(FALSE);
1176  }
1177  return(TRUE);
1178 } // start
1189 function stop($application)
1190 {
1191  if(empty($application))
1192  {
1193  return(FALSE);
1194  }
1195 
1196  $last = exec("/etc/init.d/$application stop 2>&1", $out, $rtn);
1197  if($rtn != 0)
1198  {
1199  echo "FATAL! could not stop $application\n";
1200  echo "transcript is:\n";print_r($out) . "\n";
1201  return(FALSE);
1202  }
1203  return(TRUE);
1204 } // stop
1205 
1213 function getPGhba($destPath)
1214 {
1215  if(empty($destPath))
1216  {
1217  return(FALSE);
1218  }
1219  $wcmd = "wget -q -O $destPath " .
1220  "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1221 
1222  $last = exec($wcmd, $wOut, $wRtn);
1223  if($wRtn != 0)
1224  {
1225  echo "Error, could not download pg_hba.conf file, pleases configure by hand\n";
1226  echo "wget output is:\n" . implode("\n",$wOut) . "\n";
1227  return(FALSE);
1228  }
1229  return(TRUE);
1230 }
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
configYum($objRef, $migrate)
config yum on a redhat based system to install fossology.
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied.
ckInstallLog($log)
Check the fossology install output for errors in the install.
installFossology($objRef, $migrate)
Install fossology using either apt or yum.
configDebian($osType, $osVersion)
config a debian based system to install fossology.
stop($application)
stop the application Assumes application is restartable via /etc/init.d/<script>. The application pas...
configApache2($osType)
check to see if fossology is configured into apache. If not copy the config file and configure it....
Definition: pkgConfig.php:802
findVerPsql()
find the version of postgres and return major release and sub release. For example,...
Definition: pkgConfig.php:742
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
Definition: pkgConfig.php:1272
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
Definition: pkgConfig.php:1187
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
Definition: pkgConfig.php:1214
tuneKernel()
tune the kernel for this boot and successive boots
Definition: pkgConfig.php:765
configRhel($osType, $osVersion)
copy configuration files and restart apache and postgres
Definition: pkgConfig.php:1041
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308