FOSSology  4.4.0
Open Source License Compliance by Open Source Software
pkgConfig.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011-2014 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  /*
111  echo "*** Checking apache config ***\n";
112  if(!configApache2($distros[0]))
113  {
114  echo "Fatal, could not configure apache2 to use fossology\n";
115  }
116 
117  if(!restart('apache2'))
118  {
119  echo "Erorr! Could not restart apache2, please restart by hand\n";
120  exit(1);
121  }
122  */
123  /*
124  echo "*** Starting FOSSology ***\n";
125  if(!start('fossology'))
126  {
127  echo "Erorr! Could not start FOSSology, please restart by hand\n";
128  exit(1);
129  }
130  */
131  break;
132  case 'Red':
133  $redHat = 'RedHat';
134  $rhVersion = $distros[6];
135  //echo "rh version is:$rhVersion\n";
136  try
137  {
138  $RedHat = new ConfigSys($redHat, $rhVersion);
139  }
140  catch (Exception $e)
141  {
142  echo "FATAL! could not process ini file for RedHat $rhVersion system\n";
143  echo $e;
144  exit(1);
145  }
146  if(!configYum($RedHat))
147  {
148  echo "FATAL! could not install fossology.conf yum configuration file\n";
149  exit(1);
150  }
151  /*
152  echo "*** Tuning kernel ***\n";
153  tuneKernel();
154  */
155  echo "*** Installing fossology ***\n";
156  if(!installFossology($RedHat))
157  {
158  echo "FATAL! Could not install fossology on $redHat version $rhVersion\n";
159  exit(1);
160  }
161  echo "*** stopping scheduler ***\n";
162  // Stop scheduler so system files can be configured.
163  //$testUtils->stopScheduler();
164  /*
165  echo "*** Setting up config files ***\n";
166  if(!configRhel($redHat, $rhVersion))
167  {
168  echo "FATAL! could not install php and postgress configuration files\n";
169  exit(1);
170  }
171  */
172  /*
173  echo "*** Checking apache config ***\n";
174  if(!configApache2($distros[0]))
175  {
176  echo "Fatal, could not configure apache2 to use fossology\n";
177  }
178  */
179  /*
180  if(!restart('httpd'))
181  {
182  echo "Erorr! Could not restart httpd, please restart by hand\n";
183  exit(1);
184  }
185  */
186  if(!stop('iptables'))
187  {
188  echo "Erorr! Could not stop Firewall, please stop by hand\n";
189  exit(1);
190  }
191 
192  break;
193  case 'CentOS':
194  $redHat = 'RedHat';
195  $rhVersion = $distros[2];
196  echo "rh version is:$rhVersion\n";
197  try
198  {
199  $RedHat = new ConfigSys($redHat, $rhVersion);
200  }
201  catch (Exception $e)
202  {
203  echo "FATAL! could not process ini file for RedHat $rhVersion system\n";
204  echo $e;
205  exit(1);
206  }
207  if(!configYum($RedHat))
208  {
209  echo "FATAL! could not install fossology.conf yum configuration file\n";
210  exit(1);
211  }
212  /*
213  echo "*** Tuning kernel ***\n";
214  tuneKernel();
215  */
216  echo "*** Installing fossology ***\n";
217  if(!installFossology($RedHat))
218  {
219  echo "FATAL! Could not install fossology on $redHat version $rhVersion\n";
220  exit(1);
221  }
222  echo "*** stopping scheduler ***\n";
223  // Stop scheduler so system files can be configured.
224  //$testUtils->stopScheduler();
225  /*
226  echo "*** Setting up config files ***\n";
227  if(!configRhel($redHat, $rhVersion))
228  {
229  echo "FATAL! could not install php and postgress configuration files\n";
230  exit(1);
231  }
232  */
233  /*
234  echo "*** Checking apache config ***\n";
235  if(!configApache2($distros[0]))
236  {
237  echo "Fatal, could not configure apache2 to use fossology\n";
238  }
239  */
240  /*
241  if(!stop('httpd'))
242  {
243  echo "Erorr! Could not restart httpd, please restart by hand\n";
244  exit(1);
245  }
246  if(!start('httpd'))
247  {
248  echo "Erorr! Could not restart httpd, please restart by hand\n";
249  exit(1);
250  }
251  */
252  if(!stop('iptables'))
253  {
254  echo "Erorr! Could not stop Firewall, please stop by hand\n";
255  exit(1);
256  }
257  /*
258  echo "*** Starting fossology ***\n";
259  if(!start('fossology'))
260  {
261  echo "Erorr! Could not start fossology, please restart by hand\n";
262  exit(1);
263  }
264  */
265  break;
266  case 'Fedora':
267  $fedora = 'Fedora';
268  $fedVersion = $distros[2];
269  try
270  {
271  $Fedora = new ConfigSys($fedora, $fedVersion);
272  }
273  catch (Exception $e)
274  {
275  echo "FATAL! could not process ini file for Fedora $fedVersion system\n";
276  echo $e;
277  exit(1);
278  }
279  if(!configYum($Fedora))
280  {
281  echo "FATAL! could not install fossology.repo yum configuration file\n";
282  exit(1);
283  break;
284  }
285  echo "*** Installing fossology ***\n";
286  if(!installFossology($Fedora))
287  {
288  echo "FATAL! Could not install fossology on $fedora version $fedVersion\n";
289  exit(1);
290  }
291  echo "*** stopping scheduler ***\n";
292  // Stop scheduler so system files can be configured.
293  //$testUtils->stopScheduler();
294  /*
295  echo "*** Tuning kernel ***\n";
296  tuneKernel();
297 
298  echo "*** Setting up config files ***\n";
299  if(!configRhel($fedora, $fedVersion))
300  {
301  echo "FATAL! could not install php and postgress configuration files\n";
302  exit(1);
303  }
304  */
305  /*
306  echo "*** Checking apache config ***\n";
307  if(!configApache2($distros[0]))
308  {
309  echo "Fatal, could not configure apache2 to use fossology\n";
310  }
311  */
312  /*
313  $last = exec("systemctl restart httpd.service", $out, $rtn);
314  if($rtn != 0)
315  {
316  echo "Erorr! Could not restart httpd, please restart by hand\n";
317  exit(1);
318  }
319  */
320  $last = exec("systemctl stop iptables.service", $out, $rtn);
321  if($rtn != 0)
322  {
323  echo "Erorr! Could not stop Firewall, please stop by hand\n";
324  exit(1);
325  }
326  /*
327  echo "*** Starting fossology ***\n";
328  if(!start('fossology'))
329  {
330  echo "Erorr! Could not start fossology, please restart by hand\n";
331  exit(1);
332  }
333  */
334  break;
335  case 'Ubuntu':
336  $distro = 'Ubuntu';
337  $ubunVersion = $distros[1];
338  echo "Ubuntu version is:$ubunVersion\n";
339  try
340  {
341  $Ubuntu = new ConfigSys($distros[0], $ubunVersion);
342  }
343  catch (Exception $e)
344  {
345  echo "FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
346  echo $e . "\n";
347  exit(1);
348  }
349  if(insertDeb($Ubuntu) === FALSE)
350  {
351  echo "FATAL! cannot insert deb line into /etc/apt/sources.list\n";
352  exit(1);
353  }
354  /*
355  echo "*** Tuning kernel ***\n";
356  tuneKernel();
357  */
358  echo "*** Installing fossology ***\n";
359  if(!installFossology($Ubuntu))
360  {
361  echo "FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
362  exit(1);
363  }
364  echo "*** stopping scheduler ***\n";
365  // Stop scheduler so system files can be configured.
366  //$testUtils->stopScheduler();
367 
368  echo "*** Setting up config files ***\n";
369  if(configDebian($distros[0], $ubunVersion) === FALSE)
370  {
371  echo "FATAL! could not configure postgres or php config files\n";
372  exit(1);
373  }
374  /*
375  echo "*** Checking apache config ***\n";
376  if(!configApache2($distros[0]))
377  {
378  echo "Fatal, could not configure apache2 to use fossology\n";
379  }
380 
381  if(!restart('apache2'))
382  {
383  echo "Erorr! Could not restart apache2, please restart by hand\n";
384  exit(1);
385  }
386  */
387  /*
388  echo "*** Starting FOSSology ***\n";
389  if(!start('fossology'))
390  {
391  echo "Erorr! Could not start FOSSology, please restart by hand\n";
392  exit(1);
393  }
394  */
395  break;
396  default:
397  echo "Fatal! unrecognized distribution! {$distros[0]}\n" ;
398  exit(1);
399  break;
400 }
401 class ConfigSys {
402 
403  public $osFlavor;
404  public $osVersion = 0;
405  private $fossVersion;
406  private $osCodeName;
407  public $deb;
408  public $comment = '';
409  public $yum;
410 
411  function __construct($osFlavor, $osVersion)
412  {
413  if(empty($osFlavor))
414  {
415  throw new Exception("No Os Flavor supplied\n");
416  }
417  if(empty($osVersion))
418  {
419  throw new Exception("No Os Version Supplied\n");
420  }
421 
422  $dataFile = '../dataFiles/pkginstall/' . strtolower($osFlavor) . '.ini';
423  $releases = parse_ini_file($dataFile, 1);
424  //echo "DB: the parsed ini file is:\n";
425  //print_r($releases) . "\n";
426  foreach($releases as $release => $values)
427  {
428  if($values['osversion'] == $osVersion)
429  {
430  // found the correct os, gather attributes
431  $this->osFlavor = $values['osflavor'];
432  $this->osVersion = $values['osversion'];
433  $this->fossVersion = $values['fossversion'];
434  $this->osCodeName = $values['codename'];
435  // code below is needed to avoid php notice
436  switch (strtolower($this->osFlavor)) {
437  case 'ubuntu':
438  case 'debian':
439  $this->deb = $values['deb'];
440  break;
441  case 'fedora':
442  case 'redhat':
443  $this->yum = $values['yum'];
444  break;
445  default:
446  ;
447  break;
448  }
449  $this->comment = $values['comment'];
450  }
451  }
452  if($this->osVersion == 0)
453  {
454  throw new Exception("FATAL! no matching os flavor or version found\n");
455  }
456  return;
457  } // __construct
458 
464  public function printAttr()
465  {
466 
467  echo "Attributes of ConfigSys:\n";
468  echo "\tosFlavor:$this->osFlavor\n";
469  echo "\tosVersion:$this->osVersion\n";
470  echo "\tfossVersion:$this->fossVersion\n";
471  echo "\tosCodeName:$this->osCodeName\n";
472  echo "\tdeb:$this->deb\n";
473  echo "\tcomment:$this->comment\n";
474  echo "\tyum:$this->yum\n";
475 
476  return;
477  } //printAttr
478 } // ConfigSys
479 
487 function insertDeb($objRef)
488 {
489 
490  if(!is_object($objRef))
491  {
492  return(FALSE);
493  }
494  // open file for append
495  $APT = fopen('/etc/apt/sources.list', 'a+');
496  if(!is_resource($APT))
497  {
498  echo "FATAL! could not open /etc/apt/sources.list for modification\n";
499  return(FALSE);
500  }
501  $written = fwrite($APT, "\n");
502  fflush($APT);
503 
504  if(empty($objRef->comment))
505  {
506  $comment = '# Automatically inserted by pkgConfig.php';
507  }
508 
509  $com = fwrite($APT, $objRef->comment . "\n");
510  if(!$written = fwrite($APT, $objRef->deb))
511  {
512  echo "FATAL! could not write deb line to /etc/apt/sources.list\n";
513  return(FALSE);
514  }
515  fclose($APT);
516  return(TRUE);
517 } // insertDeb
518 
529 function installFossology($objRef)
530 {
531  if(!is_object($objRef))
532  {
533  return(FALSE);
534  }
535  $aptUpdate = 'apt-get update 2>&1';
536  $aptInstall = 'apt-get -y --force-yes install fossology > fossinstall.log 2>&1';
537  $yumClean = 'yum clean all';
538  $yumUpdate = 'yum -y update 2>&1';
539  $yumInstall = 'yum -y install fossology > fossinstall.log 2>&1';
540  $debLog = NULL;
541  $installLog = NULL;
542 
543  //echo "DB: IFOSS: osFlavor is:$objRef->osFlavor\n";
544  switch ($objRef->osFlavor) {
545  case 'Ubuntu':
546  case 'Debian':
547  $last = exec($aptUpdate, $out, $rtn);
548  //echo "last is:$last\nresults of update are:\n";print_r($out) . "\n";
549  $last = exec($aptInstall, $iOut, $iRtn);
550  if($iRtn != 0)
551  {
552  echo "Failed to install fossology! aptInstall is:$aptInstall, iRtn is:$iRtn, last is:$last \nTranscript is:\n";
553  echo implode("\n",$iOut) . "\n";
554  return(FALSE);
555  }
556  // check for php or other errors that don't make apt return 1
557  echo "DB: in ubun/deb case, before installLog implode\n";
558  $debLog = implode("\n",$iOut);
559  if(!ckInstallLog($debLog))
560  {
561  echo "One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
562  "Could not connect to FOSSology database:\n" .
563  "Unable to connect to PostgreSQL server:\n" .
564  "Was found in the install output. This install is suspect and is considered FAILED.\n";
565  return(FALSE);
566  }
567  // if any of the above are non zero, return false
568  break;
569  case 'Fedora':
570  case 'RedHat':
571  echo "** Running yum clean **\n";
572  $last = exec($yumClean, $out, $rtn);
573  if($rtn != 0)
574  {
575  echo "Failed to clean all cache data!\nTranscript is:\n";
576  echo implode("\n",$out) . "\n";
577  return(FALSE);
578  }
579  echo "** Running yum update **\n";
580  $last = exec($yumUpdate, $out, $rtn);
581  if($rtn != 0)
582  {
583  echo "Failed to update yum repositories with fossology!\nTranscript is:\n";
584  echo implode("\n",$out) . "\n";
585  return(FALSE);
586  }
587  echo "** Running yum install fossology **\n";
588  $last = exec($yumInstall, $yumOut, $yumRtn);
589  //echo "install of fossology finished, yumRtn is:$yumRtn\nlast is:$last\n";
590  //$clast = system('cat fossinstall.log');
591  if($yumRtn != 0)
592  {
593  echo "Failed to install fossology! yumInstall is:$yumInstall, yumRtn is:$yumRtn, last is:$last \nTranscript is:\n";
594  echo implode("\n",$yumOut) . "\n";
595  return(FALSE);
596  }
597  if(!($installLog = file_get_contents('fossinstall.log')))
598  {
599  echo "FATAL! could not read 'fossinstall.log\n";
600  return(FALSE);
601  }
602  if(!ckInstallLog($installLog))
603  {
604  echo "One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
605  "Could not connect to FOSSology database:\n" .
606  "Unable to connect to PostgreSQL server:\n" .
607  "Was found in the install output. This install is suspect and is considered failed.\n";
608  return(FALSE);
609  }
610  break;
611 
612  default:
613  echo "FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
614  " or Fedora\n";
615  return(FALSE);
616  break;
617  }
618  return(TRUE);
619 }
620 
630 function ckInstallLog($log) {
631  if(empty($log))
632  {
633  return(FALSE);
634  }
635  // check for php or other errors that don't make apt return 1
636  $traces = $fates = $connects = $postgresFail = 0;
637  $stack = '/PHP Stack trace:/';
638  $fatal = '/FATAL/';
639  $noConnect = '/Could not connect to FOSSology database/';
640  $noPG = '/Unable to connect to PostgreSQL server:/';
641 
642  $traces = preg_match_all($stack, $log, $stackMatches);
643  $fates = preg_match_all($fatal, $log, $fatalMatches);
644  $connects = preg_match_all($noConnect, $log, $noconMatches);
645  $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
646  echo "Number of PHP stack traces found:$traces\n";
647  echo "Number of FATAL's found:$fates\n";
648  echo "Number of 'cannot connect' found:$connects\n";
649  echo "Number of 'cannot connect to postgres server' found:$postgresFail\n";
650  //print "DB: install log is:\n$log\n";
651  if($traces ||
652  $fates ||
653  $connects ||
654  $postgresFail)
655  {
656  return(FALSE);
657  }
658  return(TRUE);
659 }
673 function copyFiles($files, $dest)
674 {
675  if(empty($files))
676  {
677  throw new Exception('No file to copy', 0);
678  }
679  if(empty($dest))
680  {
681  throw new Exception('No destination for copy', 0);
682  }
683  //echo "DB: copyFiles: we are at:" . getcwd() . "\n";
684  $login = posix_getlogin();
685  //echo "DB: copyFiles: running as:$login\n";
686  //echo "DB: copyFiles: uid is:" . posix_getuid() . "\n";
687  if(is_array($files))
688  {
689  foreach($files as $file)
690  {
691  // Get left name and check if dest is a directory, copy cannot copy to a
692  // dir.
693  $baseFile = basename($file);
694  if(is_dir($dest))
695  {
696  $to = $dest . "/$baseFile";
697  }
698  else
699  {
700  $to = $dest;
701  }
702  //echo "DB: copyfiles: file copied is:$file\n";
703  //echo "DB: copyfiles: to is:$to\n";
704  if(!copy($file, $to))
705  {
706  throw new Exception("Could not copy $file to $to");
707  }
708  //$lastcp = exec("cp -v $file $to", $cpout, $cprtn);
709  //echo "DB: copyfiles: cprtn is:$cprtn\n";
710  //echo "DB: copyfiles: lastcp is:$lastcp\n";
711  //echo "DB: copyfiles: out is:\n";print_r($cpout) . "\n";
712  }
713  }
714  else
715  {
716  $baseFile = basename($files);
717  if(is_dir($dest))
718  {
719  $to = $dest . "/$baseFile";
720  }
721  else
722  {
723  $to = $dest;
724  }
725  //echo "DB: copyfiles-single: file copied is:$files\n";
726  //echo "DB: copyfiles-single: to is:$to\n";
727  if(!copy($files,$to))
728  {
729  throw new Exception("Could not copy $file to $to");
730  }
731  }
732  return(TRUE);
733 } // copyFiles
734 
735 
742 function findVerPsql()
743 {
744  $version = NULL;
745 
746  $last = exec('psql --version', $out, $rtn);
747  if($rtn != 0)
748  {
749  return(FALSE);
750  }
751  else
752  {
753  // isolate the version number and return it
754  list( , ,$ver) = explode(' ', $out[0]);
755  $version = substr($ver, 0, 3);
756  }
757  return($version);
758 }
759 
765 function tuneKernel()
766 {
767  // check to see if we have already done this... so the sysctl.conf file doesn't
768  // end up with dup entries.
769  $grepCmd = 'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
770  $last = exec($grepCmd, $out, $rtn);
771  if($rtn == 0) // kernel already configured
772  {
773  echo "NOTE: kernel already configured.\n";
774  return;
775  }
776  $cmd1 = "echo 512000000 > /proc/sys/kernel/shmmax";
777  $cmd2 = "echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
778  // Tune the kernel
779  $last1 = exec($cmd1, $cmd1Out, $rtn1);
780  if ($rtn1 != 0)
781  {
782  echo "Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
783  }
784  $last2 = exec($cmd2, $cmd2Out, $rtn2);
785  // make it permanent
786  if ($rtn2 != 0)
787  {
788  echo "Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
789  }
790  return;
791 } // tuneKernel
792 
802 function configApache2($osType)
803 {
804  if(empty($osType))
805  {
806  return(FALSE);
807  }
808  switch ($osType) {
809  case 'Ubuntu':
810  case 'Debian':
811  if(is_link('/etc/apache2/conf.d/fossology'))
812  {
813  break;
814  }
815  else
816  {
817  // copy config file, create sym link
818  if(!copy('../dataFiles/pkginstall/fo-apache.conf', '/etc/fossology/fo-apache.conf'))
819  {
820  echo "FATAL!, Cannot configure fossology into apache2\n";
821  return(FALSE);
822  }
823  if(!symlink('/etc/fossology/fo-apache.conf','/etc/apache2/conf.d/fossology'))
824  {
825  echo "FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
826  return(FALSE);
827  }
828  // restart apache so changes take effect
829  if(!restart('apache2'))
830  {
831  echo "Erorr! Could not restart apache2, please restart by hand\n";
832  return(FALSE);
833  }
834  }
835  break;
836  case 'Red':
837  // copy config file, no symlink needed for redhat
838  if(!copy('../dataFiles/pkginstall/fo-apache.conf', '/etc/httpd/conf.d/fossology.conf'))
839  {
840  echo "FATAL!, Cannot configure fossology into apache2\n";
841  return(FALSE);
842  }
843  // restart apapche so changes take effect
844  if(!restart('httpd'))
845  {
846  echo "Erorr! Could not restart httpd, please restart by hand\n";
847  return(FALSE);
848  }
849  break;
850  default:
851  ;
852  break;
853  }
854  return(TRUE);
855 } // configApache2
856 
867 function configDebian($osType, $osVersion)
868 {
869  if(empty($osType))
870  {
871  return(FALSE);
872  }
873  if(empty($osVersion))
874  {
875  return(FALSE);
876  }
877 
878  // based on type read the appropriate ini file.
879 
880  //echo "DB:configD: osType is:$osType\n";
881  //echo "DB:configD: osversion is:$osVersion\n";
882 
883  // can't check in pg_hba.conf as it shows HP's firewall settings, get it
884  // internally
885 
886  // No need to update pg_hba.conf file
887  //getPGhba('../dataFiles/pkginstall/debian/6/pg_hba.conf');
888 
889  //$debPath = '../dataFiles/pkginstall/debian/6/';
890 
891  //$psqlFiles = array(
892  //$debPath . 'pg_hba.conf',
893  //$debPath . 'postgresql.conf');
894 
895  switch ($osVersion)
896  {
897  case '6.0':
898  echo "debianConfig got os version 6.0!\n";
899  // copy config files
900  /*
901  * Change the structure of data files:
902  * e.g. debian/5/pg_hba..., etc, all files that go with this version
903  * debian/6/pg_hba....
904  * and use a symlink for the 'codename' squeeze -> debian/6/
905  */
906  /*
907  try
908  {
909  copyFiles($psqlFiles, "/etc/postgresql/8.4/main");
910  }
911  catch (Exception $e)
912  {
913  echo "Failure: Could not copy postgres 8.4 config file\n";
914  }
915  try
916  {
917  copyFiles($debPath . 'cli-php.ini', '/etc/php5/cli/php.ini');
918  } catch (Exception $e)
919  {
920  echo "Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
921  return(FALSE);
922  }
923  try
924  {
925  copyFiles($debPath . 'apache2-php.ini', '/etc/php5/apache2/php.ini');
926  } catch (Exception $e)
927  {
928  echo "Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
929  return(FALSE);
930  }
931  */
932  break;
933  case '10.04.3':
934  case '11.04':
935  case '11.10':
936  echo "debianConfig got os version $osVersion!\n";
937  /*
938  try
939  {
940  copyFiles($psqlFiles, "/etc/postgresql/8.4/main");
941  }
942  catch (Exception $e)
943  {
944  echo "Failure: Could not copy postgres 8.4 config file\n";
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  */
963  break;
964  case '12.04.1':
965  case '12.04.2':
966  case '12.04.3':
967  case '12.04.4':
968  echo "debianConfig got os version $osVersion!\n";
969  echo "Old PHPunit installation with PEAR is deprecated, it is now done with composer.\n";
970  echo "To install composer type:\n";
971  echo "curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer\n ";
972  break;
973  case '12.10':
974  echo "debianConfig got os version $osVersion!\n";
975  //postgresql-9.1 can't use 8.4 conf file
976  /*
977  try
978  {
979  copyFiles($psqlFiles, "/etc/postgresql/9.1/main");
980  }
981  catch (Exception $e)
982  {
983  echo "Failure: Could not copy postgres 9.1 config file\n";
984  }
985  */
986  /*
987  try
988  {
989  copyFiles($debPath . 'cli-php.ini', '/etc/php5/cli/php.ini');
990  } catch (Exception $e)
991  {
992  echo "Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
993  return(FALSE);
994  }
995  try
996  {
997  copyFiles($debPath . 'apache2-php.ini', '/etc/php5/apache2/php.ini');
998  } catch (Exception $e)
999  {
1000  echo "Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
1001  return(FALSE);
1002  }
1003  */
1004  break;
1005  default:
1006  return(FALSE); // unsupported debian version
1007  break;
1008  }
1009  /*
1010  // restart apache and postgres so changes take effect
1011  if(!restart('apache2'))
1012  {
1013  echo "Erorr! Could not restart apache2, please restart by hand\n";
1014  return(FALSE);
1015  }
1016  // Get the postrgres version so the correct file is used.
1017  $pName = 'postgresql';
1018  if($osVersion == '10.04.3')
1019  {
1020  $ver = findVerPsql();
1021  //echo "DB: returned version is:$ver\n";
1022  $pName = 'postgresql-' . $ver;
1023  }
1024  echo "DB pName is:$pName\n";
1025  if(!restart($pName))
1026  {
1027  echo "Erorr! Could not restart $pName, please restart by hand\n";
1028  return(FALSE);
1029  }
1030  */
1031  return(TRUE);
1032 } // configDebian
1033 
1041 function configRhel($osType, $osVersion)
1042 {
1043  if(empty($osType))
1044  {
1045  return(FALSE);
1046  }
1047  if(empty($osVersion))
1048  {
1049  return(FALSE);
1050  }
1051 
1052  $rpmPath = '../dataFiles/pkginstall/redhat/6.x';
1053  // getPGhba($rpmPath . '/pg_hba.conf');
1054  $psqlFiles = array(
1055  //$rpmPath . '/pg_hba.conf',
1056  $rpmPath . '/postgresql.conf');
1057  // fossology tweaks the postgres files so the packages work.... don't copy
1058  /*
1059  try
1060  {
1061  copyFiles($psqlFiles, "/var/lib/pgsql/data/");
1062  }
1063  catch (Exception $e)
1064  {
1065  echo "Failure: Could not copy postgres 8.4 config files\n";
1066  }
1067  */
1068  try
1069  {
1070  copyFiles($rpmPath . '/php.ini', '/etc/php.ini');
1071  } catch (Exception $e)
1072  {
1073  echo "Failure: Could not copy php.ini to /etc/php.ini\n";
1074  return(FALSE);
1075  }
1076  // restart postgres, postgresql conf didn't change do not restart
1077  /*
1078  $pName = 'postgresql';
1079  if(!restart($pName))
1080  {
1081  echo "Erorr! Could not restart $pName, please restart by hand\n";
1082  return(FALSE);
1083  }
1084  */
1085  return(TRUE);
1086 } // configRhel
1087 
1097 function configYum($objRef)
1098 {
1099  if(!is_object($objRef))
1100  {
1101  return(FALSE);
1102  }
1103  if(empty($objRef->yum))
1104  {
1105  echo "FATAL, no yum install line to install\n";
1106  return(FALSE);
1107  }
1108 
1109  $RedFedRepo = 'redfed-fossology.repo'; // name of generic repo file.
1110  // replace the baseurl line with the current one.
1111  $n = "../dataFiles/pkginstall/" . $RedFedRepo;
1112  $fcont = file_get_contents($n);
1113  //if(!$fcont);
1114  //{
1115  //echo "FATAL! could not read repo file $n\n";
1116  //exit(1);
1117  //}
1118  //echo "DB: contents is:\n$fcont\n";
1119  $newRepo = preg_replace("/baseurl=(.*)?/", 'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1120  // write the file, fix below to copy the correct thing...
1121  if(!($written = file_put_contents("../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1122  {
1123  echo "FATAL! could not write repo file $RedFedRepo\n";
1124  exit(1);
1125  }
1126  // coe plays with yum stuff, check if yum.repos.d exists and if not create it.
1127  if(is_dir('/etc/yum.repos.d'))
1128  {
1129  copyFiles("../dataFiles/pkginstall/" . $RedFedRepo, '/etc/yum.repos.d/fossology.repo');
1130  }
1131  else
1132  {
1133  // create the dir and then copy
1134  if(!mkdir('/etc/yum.repos.d'))
1135  {
1136  echo "FATAL! could not create yum.repos.d\n";
1137  return(FALSE);
1138  }
1139  copyFiles("../dataFiles/pkginstall/" . $RedFedRepo, '/etc/yum.repos.d/fossology.repo');
1140  }
1141  //print_r($objRef);
1142  if ($objRef->osFlavor == 'RedHat')
1143  {
1144  $last = exec("yum -y install wget", $out, $rtn);
1145  if($rtn != 0)
1146  {
1147  echo "FATAL! install EPEL repo fail\n";
1148  echo "transcript is:\n";print_r($out) . "\n";
1149  return(FALSE);
1150  }
1151  /* comment out the epel repo installation
1152  $last = exec("wget -e http_proxy=http://web-proxy.cce.hp.com:8088 http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm", $out, $rtn);
1153  if($rtn != 0)
1154  {
1155  echo "FATAL! install EPEL repo fail\n";
1156  echo "transcript is:\n";print_r($out) . "\n";
1157  return(FALSE);
1158  }
1159  $last = exec("rpm -ivh epel-release-6-8.noarch.rpm", $out, $rtn);
1160  if($rtn != 0)
1161  {
1162  echo "FATAL! install EPEL repo fail\n";
1163  echo "transcript is:\n";print_r($out) . "\n";
1164  return(FALSE);
1165  }*/
1166  $last = exec("yum -y install php-phpunit-PHPUnit", $out, $rtn);
1167  if($rtn != 0)
1168  {
1169  echo "FATAL! install PHPUnit fail\n";
1170  echo "transcript is:\n";print_r($out) . "\n";
1171  return(FALSE);
1172  }
1173  }
1174  return(TRUE);
1175 } // configYum
1176 
1187 function restart($application)
1188 {
1189  if(empty($application))
1190  {
1191  return(FALSE);
1192  }
1193 
1194  $last = exec("/etc/init.d/$application restart 2>&1", $out, $rtn);
1195  if($rtn != 0)
1196  {
1197  echo "FATAL! could not restart $application\n";
1198  echo "transcript is:\n";print_r($out) . "\n";
1199  return(FALSE);
1200  }
1201  return(TRUE);
1202 } // restart
1203 
1214 function start($application)
1215 {
1216  if(empty($application))
1217  {
1218  return(FALSE);
1219  }
1220 
1221  echo "Starting $application ...\n";
1222  $last = exec("/etc/init.d/$application stop 2>&1", $out, $rtn);
1223  if($rtn != 0)
1224  {
1225  echo "FATAL! could not start $application\n";
1226  echo "transcript is:\n";print_r($out) . "\n";
1227  return(FALSE);
1228  }
1229  $last = exec("/etc/init.d/$application start 2>&1", $out, $rtn);
1230  if($rtn != 0)
1231  {
1232  echo "FATAL! could not start $application\n";
1233  echo "transcript is:\n";print_r($out) . "\n";
1234  return(FALSE);
1235  }
1236  return(TRUE);
1237 } // start
1248 function stop($application)
1249 {
1250  if(empty($application))
1251  {
1252  return(FALSE);
1253  }
1254 
1255  $last = exec("/etc/init.d/$application stop 2>&1", $out, $rtn);
1256  if($rtn != 0)
1257  {
1258  echo "FATAL! could not stop $application\n";
1259  echo "transcript is:\n";print_r($out) . "\n";
1260  return(FALSE);
1261  }
1262  return(TRUE);
1263 } // stop
1264 
1272 function getPGhba($destPath)
1273 {
1274  if(empty($destPath))
1275  {
1276  return(FALSE);
1277  }
1278  $wcmd = "wget -q -O $destPath " .
1279  "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1280 
1281  $last = exec($wcmd, $wOut, $wRtn);
1282  if($wRtn != 0)
1283  {
1284  echo "Error, could not download pg_hba.conf file, pleases configure by hand\n";
1285  echo "wget output is:\n" . implode("\n",$wOut) . "\n";
1286  return(FALSE);
1287  }
1288  return(TRUE);
1289 }
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
configYum($objRef)
config yum on a redhat based system to install fossology.
Definition: pkgConfig.php:1097
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
Definition: pkgConfig.php:1272
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
Definition: pkgConfig.php:487
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied.
Definition: pkgConfig.php:673
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
Definition: pkgConfig.php:1187
ckInstallLog($log)
Check the fossology install output for errors in the install.
Definition: pkgConfig.php:630
installFossology($objRef)
Install fossology using either apt or yum.
Definition: pkgConfig.php:529
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
configDebian($osType, $osVersion)
config a debian based system to install fossology.
Definition: pkgConfig.php:867
stop($application)
stop the application Assumes application is restartable via /etc/init.d/<script>. The application pas...
Definition: pkgConfig.php:1248
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308