34 require_once
'../lib/TestRun.php';
60 $euid = posix_getuid();
62 print
"Error, this script must be run as root\n";
68 $f = exec(
'cat /etc/issue', $dist, $dRtn);
69 $distros = explode(
' ', $dist[0]);
81 switch ($distros[0]) {
84 $debianVersion = $distros[2];
85 echo
"debian version is:$debianVersion\n";
88 $Debian =
new ConfigSys($distros[0], $debianVersion);
92 echo
"FATAL! could not process ini file for Debian $debianVersion system\n";
98 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
101 echo
"*** Installing fossology ***\n";
104 echo
"FATAL! Could not install fossology on {$distros[0]} version $debianVersion\n";
107 echo
"*** stopping scheduler ***\n";
109 $testUtils->stopScheduler();
111 echo
"*** Tuning kernel ***\n";
114 echo
"*** Setting up config files ***\n";
117 echo
"FATAL! could not configure postgres or php config files\n";
129 echo
"Erorr! Could not restart apache2, please restart by hand\n";
133 echo
"*** Starting FOSSology ***\n";
134 if(!
start(
'fossology'))
136 echo
"Erorr! Could not start FOSSology, please restart by hand\n";
142 $rhVersion = $distros[6];
146 $RedHat =
new ConfigSys($redHat, $rhVersion);
150 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
156 echo
"FATAL! could not install fossology.conf yum configuration file\n";
159 echo
"*** Tuning kernel ***\n";
162 echo
"*** Installing fossology ***\n";
165 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
168 echo
"*** stopping scheduler ***\n";
172 echo
"*** Setting up config files ***\n";
175 echo
"FATAL! could not install php and postgress configuration files\n";
187 echo
"Erorr! Could not restart httpd, please restart by hand\n";
191 if(!
stop(
'iptables'))
193 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
200 $rhVersion = $distros[2];
201 echo
"rh version is:$rhVersion\n";
204 $RedHat =
new ConfigSys($redHat, $rhVersion);
208 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
214 echo
"FATAL! could not install fossology.conf yum configuration file\n";
217 echo
"*** Tuning kernel ***\n";
220 echo
"*** Installing fossology ***\n";
223 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
226 echo
"*** stopping scheduler ***\n";
230 echo
"*** Setting up config files ***\n";
233 echo
"FATAL! could not install php and postgress configuration files\n";
245 echo
"Erorr! Could not restart httpd, please restart by hand\n";
250 echo
"Erorr! Could not restart httpd, please restart by hand\n";
253 if(!
stop(
'iptables'))
255 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
258 echo
"*** Starting fossology ***\n";
259 if(!
start(
'fossology'))
261 echo
"Erorr! Could not start fossology, please restart by hand\n";
268 $fedVersion = $distros[2];
271 $Fedora =
new ConfigSys($fedora, $fedVersion);
275 echo
"FATAL! could not process ini file for Fedora $fedVersion system\n";
281 echo
"FATAL! could not install fossology.repo yum configuration file\n";
285 echo
"*** Installing fossology ***\n";
288 echo
"FATAL! Could not install fossology on $fedora version $fedVersion\n";
291 echo
"*** stopping scheduler ***\n";
295 echo
"*** Tuning kernel ***\n";
298 echo
"*** Setting up config files ***\n";
301 echo
"FATAL! could not install php and postgress configuration files\n";
311 $last = exec(
"systemctl restart httpd.service", $out, $rtn);
314 echo
"Erorr! Could not restart httpd, please restart by hand\n";
318 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
321 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
324 echo
"*** Starting fossology ***\n";
325 $last = exec(
"systemctl restart fossology.service", $out, $rtn);
328 echo
"Erorr! Could not start FOSSology, please stop by hand\n";
334 $ubunVersion = $distros[1];
335 echo
"Ubuntu version is:$ubunVersion\n";
338 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion);
342 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
348 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
351 echo
"*** Tuning kernel ***\n";
354 echo
"*** Installing fossology ***\n";
357 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
360 echo
"*** stopping scheduler ***\n";
362 $testUtils->stopScheduler();
364 echo
"*** Setting up config files ***\n";
367 echo
"FATAL! could not configure postgres or php config files\n";
379 echo
"Erorr! Could not restart apache2, please restart by hand\n";
383 echo
"*** Starting FOSSology ***\n";
384 if(!
start(
'fossology'))
386 echo
"Erorr! Could not start FOSSology, please restart by hand\n";
391 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
398 public $osVersion = 0;
399 private $fossVersion;
402 public $comment =
'';
405 function __construct($osFlavor, $osVersion)
409 throw new Exception(
"No Os Flavor supplied\n");
411 if(empty($osVersion))
413 throw new Exception(
"No Os Version Supplied\n");
416 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
417 $releases = parse_ini_file($dataFile, 1);
420 foreach($releases as $release => $values)
422 if($values[
'osversion'] == $osVersion)
425 $this->osFlavor = $values[
'osflavor'];
426 $this->osVersion = $values[
'osversion'];
427 $this->fossVersion = $values[
'fossversion'];
428 $this->osCodeName = $values[
'codename'];
430 switch (strtolower($this->osFlavor)) {
433 $this->deb = $values[
'deb'];
437 $this->yum = $values[
'yum'];
443 $this->comment = $values[
'comment'];
446 if($this->osVersion == 0)
448 throw new Exception(
"FATAL! no matching os flavor or version found\n");
461 echo
"Attributes of ConfigSys:\n";
462 echo
"\tosFlavor:$this->osFlavor\n";
463 echo
"\tosVersion:$this->osVersion\n";
464 echo
"\tfossVersion:$this->fossVersion\n";
465 echo
"\tosCodeName:$this->osCodeName\n";
466 echo
"\tdeb:$this->deb\n";
467 echo
"\tcomment:$this->comment\n";
468 echo
"\tyum:$this->yum\n";
484 if(!is_object($objRef))
489 $APT = fopen(
'/etc/apt/sources.list',
'a+');
490 if(!is_resource($APT))
492 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
495 $written = fwrite($APT,
"\n");
498 if(empty($objRef->comment))
500 $comment =
'# Automatically inserted by pkgConfig.php';
503 $com = fwrite($APT, $objRef->comment .
"\n");
504 if(!$written = fwrite($APT, $objRef->deb))
506 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
525 if(!is_object($objRef))
529 $aptUpdate =
'apt-get update 2>&1';
530 $aptInstall =
'apt-get -y --force-yes install fossology 2>&1';
531 $yumUpdate =
'yum -y update 2>&1';
532 $yumInstall =
'yum -y install fossology > fossinstall.log 2>&1';
537 switch ($objRef->osFlavor) {
540 $last = exec($aptUpdate, $out, $rtn);
542 $last = exec($aptInstall, $iOut, $iRtn);
545 echo
"Failed to install fossology!\nTranscript is:\n";
546 echo implode(
"\n",$iOut) .
"\n";
550 echo
"DB: in ubun/deb case, before installLog implode\n";
551 $debLog = implode(
"\n",$iOut);
554 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
555 "Could not connect to FOSSology database:\n" .
556 "Unable to connect to PostgreSQL server:\n" .
557 "Was found in the install output. This install is suspect and is considered FAILED.\n";
564 echo
"** Running yum update **\n";
565 $last = exec($yumUpdate, $out, $rtn);
568 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
569 echo implode(
"\n",$out) .
"\n";
572 echo
"** Running yum install fossology **\n";
573 $last = exec($yumInstall, $yumOut, $yumRtn);
578 echo
"Failed to install fossology!\nTranscript is:\n";
579 system(
'cat fossinstall.log');
582 if(!($installLog = file_get_contents(
'fossinstall.log')))
584 echo
"FATAL! could not read 'fossinstall.log\n";
589 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
590 "Could not connect to FOSSology database:\n" .
591 "Unable to connect to PostgreSQL server:\n" .
592 "Was found in the install output. This install is suspect and is considered failed.\n";
598 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
621 $traces = $fates = $connects = $postgresFail = 0;
622 $stack =
'/PHP Stack trace:/';
624 $noConnect =
'/Could not connect to FOSSology database/';
625 $noPG =
'/Unable to connect to PostgreSQL server:/';
627 $traces = preg_match_all($stack, $log, $stackMatches);
628 $fates = preg_match_all($fatal, $log, $fatalMatches);
629 $connects = preg_match_all($noConnect, $log, $noconMatches);
630 $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
631 echo
"Number of PHP stack traces found:$traces\n";
632 echo
"Number of FATAL's found:$fates\n";
633 echo
"Number of 'cannot connect' found:$connects\n";
634 echo
"Number of 'cannot connect to postgres server' found:$postgresFail\n";
662 throw new Exception(
'No file to copy', 0);
666 throw new Exception(
'No destination for copy', 0);
669 $login = posix_getlogin();
674 foreach($files as $file)
678 $baseFile = basename($file);
681 $to = $dest .
"/$baseFile";
689 if(!copy($file, $to))
691 throw new Exception(
"Could not copy $file to $to");
701 $baseFile = basename($files);
704 $to = $dest .
"/$baseFile";
712 if(!copy($files,$to))
714 throw new Exception(
"Could not copy $file to $to");
731 $last = exec(
'psql --version', $out, $rtn);
739 list( , ,$ver) = explode(
' ', $out[0]);
740 $version = substr($ver, 0, 3);
754 $grepCmd =
'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
755 $last = exec($grepCmd, $out, $rtn);
758 echo
"NOTE: kernel already configured.\n";
761 $cmd1 =
"echo 512000000 > /proc/sys/kernel/shmmax";
762 $cmd2 =
"echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
764 $last1 = exec($cmd1, $cmd1Out, $rtn1);
767 echo
"Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
769 $last2 = exec($cmd2, $cmd2Out, $rtn2);
773 echo
"Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
796 if(is_link(
'/etc/apache2/conf.d/fossology'))
803 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/fossology/fo-apache.conf'))
805 echo
"FATAL!, Cannot configure fossology into apache2\n";
808 if(!symlink(
'/etc/fossology/fo-apache.conf',
'/etc/apache2/conf.d/fossology'))
810 echo
"FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
816 echo
"Erorr! Could not restart apache2, please restart by hand\n";
823 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/httpd/conf.d/fossology.conf'))
825 echo
"FATAL!, Cannot configure fossology into apache2\n";
831 echo
"Erorr! Could not restart httpd, please restart by hand\n";
858 if(empty($osVersion))
874 $debPath =
'../dataFiles/pkginstall/debian/6/';
878 $debPath .
'postgresql.conf');
883 echo
"debianConfig got os version 6.0!\n";
893 copyFiles($psqlFiles,
"/etc/postgresql/8.4/main");
897 echo
"Failure: Could not copy postgres 8.4 config file\n";
901 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
902 }
catch (Exception $e)
904 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
909 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
910 }
catch (Exception $e)
912 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
921 copyFiles($psqlFiles,
"/etc/postgresql/8.4/main");
925 echo
"Failure: Could not copy postgres 8.4 config file\n";
929 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
930 }
catch (Exception $e)
932 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
937 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
938 }
catch (Exception $e)
940 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
959 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
960 }
catch (Exception $e)
962 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
967 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
968 }
catch (Exception $e)
970 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
981 echo
"Erorr! Could not restart apache2, please restart by hand\n";
985 $pName =
'postgresql';
986 if($osVersion ==
'10.04.3')
990 $pName =
'postgresql-' . $ver;
992 echo
"DB pName is:$pName\n";
995 echo
"Erorr! Could not restart $pName, please restart by hand\n";
1014 if(empty($osVersion))
1019 $rpmPath =
'../dataFiles/pkginstall/redhat/6.x';
1023 $rpmPath .
'/postgresql.conf');
1037 copyFiles($rpmPath .
'/php.ini',
'/etc/php.ini');
1038 }
catch (Exception $e)
1040 echo
"Failure: Could not copy php.ini to /etc/php.ini\n";
1066 if(!is_object($objRef))
1070 if(empty($objRef->yum))
1072 echo
"FATAL, no yum install line to install\n";
1076 $RedFedRepo =
'redfed-fossology.repo';
1078 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
1079 $fcont = file_get_contents($n);
1086 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1088 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1090 echo
"FATAL! could not write repo file $RedFedRepo\n";
1094 if(is_dir(
'/etc/yum.repos.d'))
1096 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1101 if(!mkdir(
'/etc/yum.repos.d'))
1103 echo
"FATAL! could not create yum.repos.d\n";
1106 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1109 if ($objRef->osFlavor ==
'RedHat')
1111 $last = exec(
"yum -y install wget", $out, $rtn);
1114 echo
"FATAL! install EPEL repo fail\n";
1115 echo
"transcript is:\n";print_r($out) .
"\n";
1118 $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);
1121 echo
"FATAL! install EPEL repo fail\n";
1122 echo
"transcript is:\n";print_r($out) .
"\n";
1125 $last = exec(
"rpm -ivh epel-release-6-7.noarch.rpm", $out, $rtn);
1128 echo
"FATAL! install EPEL repo fail\n";
1129 echo
"transcript is:\n";print_r($out) .
"\n";
1146 function restart($application)
1148 if(empty($application))
1153 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1156 echo
"FATAL! could not restart $application\n";
1157 echo
"transcript is:\n";print_r($out) .
"\n";
1173 function start($application)
1175 if(empty($application))
1180 echo
"Starting $application ...\n";
1181 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1184 echo
"FATAL! could not start $application\n";
1185 echo
"transcript is:\n";print_r($out) .
"\n";
1200 function stop($application)
1202 if(empty($application))
1207 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1210 echo
"FATAL! could not stop $application\n";
1211 echo
"transcript is:\n";print_r($out) .
"\n";
1226 if(empty($destPath))
1230 $wcmd =
"wget -q -O $destPath " .
1231 "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1233 $last = exec($wcmd, $wOut, $wRtn);
1236 echo
"Error, could not download pg_hba.conf file, pleases configure by hand\n";
1237 echo
"wget output is:\n" . implode(
"\n",$wOut) .
"\n";
installFossology($objRef, $migrate)
Install fossology using either apt or yum.
ckInstallLog($log)
Check the fossology install output for errors in the install.
configDebian($osType, $osVersion)
config a debian based system to install fossology.
tuneKernel()
tune the kernel for this boot and successive boots
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied...
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
configRhel($osType, $osVersion)
copy configuration files and restart apache and postgres
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
stop($application)
stop the application Assumes application is restartable via /etc/init.d/<script>. The application pas...
findVerPsql()
find the version of postgres and return major release and sub release. For example, if postgres is at 8.4.8, this function will return 8.4.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
configYum($objRef, $migrate)
config yum on a redhat based system to install fossology.
configApache2($osType)
check to see if fossology is configured into apache. If not copy the config file and configure it...