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";
145 $rhVersion = $distros[6];
149 $RedHat =
new ConfigSys($redHat, $rhVersion);
153 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
159 echo
"FATAL! could not install fossology.conf yum configuration file\n";
166 echo
"*** Installing fossology ***\n";
169 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
172 echo
"*** stopping scheduler ***\n";
197 if(!
stop(
'iptables'))
199 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
206 $rhVersion = $distros[2];
207 echo
"rh version is:$rhVersion\n";
210 $RedHat =
new ConfigSys($redHat, $rhVersion);
214 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
220 echo
"FATAL! could not install fossology.conf yum configuration file\n";
227 echo
"*** Installing fossology ***\n";
230 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
233 echo
"*** stopping scheduler ***\n";
263 if(!
stop(
'iptables'))
265 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
279 $fedVersion = $distros[2];
282 $Fedora =
new ConfigSys($fedora, $fedVersion);
286 echo
"FATAL! could not process ini file for Fedora $fedVersion system\n";
292 echo
"FATAL! could not install fossology.repo yum configuration file\n";
296 echo
"*** Installing fossology ***\n";
299 echo
"FATAL! Could not install fossology on $fedora version $fedVersion\n";
302 echo
"*** stopping scheduler ***\n";
331 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
334 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
348 $ubunVersion = $distros[1];
349 echo
"Ubuntu version is:$ubunVersion\n";
352 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion);
356 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
362 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
369 echo
"*** Installing fossology ***\n";
372 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
375 echo
"*** stopping scheduler ***\n";
379 echo
"*** Setting up config files ***\n";
382 echo
"FATAL! could not configure postgres or php config files\n";
408 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
415 public $osVersion = 0;
416 private $fossVersion;
419 public $comment =
'';
422 function __construct($osFlavor, $osVersion)
426 throw new Exception(
"No Os Flavor supplied\n");
428 if(empty($osVersion))
430 throw new Exception(
"No Os Version Supplied\n");
433 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
434 $releases = parse_ini_file($dataFile, 1);
437 foreach($releases as $release => $values)
439 if($values[
'osversion'] == $osVersion)
442 $this->osFlavor = $values[
'osflavor'];
443 $this->osVersion = $values[
'osversion'];
444 $this->fossVersion = $values[
'fossversion'];
445 $this->osCodeName = $values[
'codename'];
447 switch (strtolower($this->osFlavor)) {
450 $this->deb = $values[
'deb'];
454 $this->yum = $values[
'yum'];
460 $this->comment = $values[
'comment'];
463 if($this->osVersion == 0)
465 throw new Exception(
"FATAL! no matching os flavor or version found\n");
478 echo
"Attributes of ConfigSys:\n";
479 echo
"\tosFlavor:$this->osFlavor\n";
480 echo
"\tosVersion:$this->osVersion\n";
481 echo
"\tfossVersion:$this->fossVersion\n";
482 echo
"\tosCodeName:$this->osCodeName\n";
483 echo
"\tdeb:$this->deb\n";
484 echo
"\tcomment:$this->comment\n";
485 echo
"\tyum:$this->yum\n";
501 if(!is_object($objRef))
506 $APT = fopen(
'/etc/apt/sources.list',
'a+');
507 if(!is_resource($APT))
509 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
512 $written = fwrite($APT,
"\n");
515 if(empty($objRef->comment))
517 $comment =
'# Automatically inserted by pkgConfig.php';
520 $com = fwrite($APT, $objRef->comment .
"\n");
521 if(!$written = fwrite($APT, $objRef->deb))
523 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
542 if(!is_object($objRef))
546 $aptUpdate =
'apt-get update 2>&1';
547 $aptInstall =
'apt-get -y --force-yes install fossology > fossinstall.log 2>&1';
548 $yumClean =
'yum clean all';
549 $yumUpdate =
'yum -y update 2>&1';
550 $yumInstall =
'yum -y install fossology > fossinstall.log 2>&1';
555 switch ($objRef->osFlavor) {
558 $last = exec($aptUpdate, $out, $rtn);
560 $last = exec($aptInstall, $iOut, $iRtn);
563 echo
"Failed to install fossology! aptInstall is:$aptInstall, iRtn is:$iRtn, last is:$last \nTranscript is:\n";
564 echo implode(
"\n",$iOut) .
"\n";
568 echo
"DB: in ubun/deb case, before installLog implode\n";
569 $debLog = implode(
"\n",$iOut);
572 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
573 "Could not connect to FOSSology database:\n" .
574 "Unable to connect to PostgreSQL server:\n" .
575 "Was found in the install output. This install is suspect and is considered FAILED.\n";
582 echo
"** Running yum clean **\n";
583 $last = exec($yumClean, $out, $rtn);
586 echo
"Failed to clean all cache data!\nTranscript is:\n";
587 echo implode(
"\n",$out) .
"\n";
590 echo
"** Running yum update **\n";
591 $last = exec($yumUpdate, $out, $rtn);
594 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
595 echo implode(
"\n",$out) .
"\n";
598 echo
"** Running yum install fossology **\n";
599 $last = exec($yumInstall, $yumOut, $yumRtn);
604 echo
"Failed to install fossology! yumInstall is:$yumInstall, yumRtn is:$yumRtn, last is:$last \nTranscript is:\n";
605 echo implode(
"\n",$yumOut) .
"\n";
608 if(!($installLog = file_get_contents(
'fossinstall.log')))
610 echo
"FATAL! could not read 'fossinstall.log\n";
615 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
616 "Could not connect to FOSSology database:\n" .
617 "Unable to connect to PostgreSQL server:\n" .
618 "Was found in the install output. This install is suspect and is considered failed.\n";
624 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
647 $traces = $fates = $connects = $postgresFail = 0;
648 $stack =
'/PHP Stack trace:/';
650 $noConnect =
'/Could not connect to FOSSology database/';
651 $noPG =
'/Unable to connect to PostgreSQL server:/';
653 $traces = preg_match_all($stack, $log, $stackMatches);
654 $fates = preg_match_all($fatal, $log, $fatalMatches);
655 $connects = preg_match_all($noConnect, $log, $noconMatches);
656 $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
657 echo
"Number of PHP stack traces found:$traces\n";
658 echo
"Number of FATAL's found:$fates\n";
659 echo
"Number of 'cannot connect' found:$connects\n";
660 echo
"Number of 'cannot connect to postgres server' found:$postgresFail\n";
688 throw new Exception(
'No file to copy', 0);
692 throw new Exception(
'No destination for copy', 0);
695 $login = posix_getlogin();
700 foreach($files as $file)
704 $baseFile = basename($file);
707 $to = $dest .
"/$baseFile";
715 if(!copy($file, $to))
717 throw new Exception(
"Could not copy $file to $to");
727 $baseFile = basename($files);
730 $to = $dest .
"/$baseFile";
738 if(!copy($files,$to))
740 throw new Exception(
"Could not copy $file to $to");
757 $last = exec(
'psql --version', $out, $rtn);
765 list( , ,$ver) = explode(
' ', $out[0]);
766 $version = substr($ver, 0, 3);
780 $grepCmd =
'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
781 $last = exec($grepCmd, $out, $rtn);
784 echo
"NOTE: kernel already configured.\n";
787 $cmd1 =
"echo 512000000 > /proc/sys/kernel/shmmax";
788 $cmd2 =
"echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
790 $last1 = exec($cmd1, $cmd1Out, $rtn1);
793 echo
"Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
795 $last2 = exec($cmd2, $cmd2Out, $rtn2);
799 echo
"Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
822 if(is_link(
'/etc/apache2/conf.d/fossology'))
829 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/fossology/fo-apache.conf'))
831 echo
"FATAL!, Cannot configure fossology into apache2\n";
834 if(!symlink(
'/etc/fossology/fo-apache.conf',
'/etc/apache2/conf.d/fossology'))
836 echo
"FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
842 echo
"Erorr! Could not restart apache2, please restart by hand\n";
849 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/httpd/conf.d/fossology.conf'))
851 echo
"FATAL!, Cannot configure fossology into apache2\n";
857 echo
"Erorr! Could not restart httpd, please restart by hand\n";
884 if(empty($osVersion))
909 echo
"debianConfig got os version 6.0!\n";
947 echo
"debianConfig got os version $osVersion!\n";
979 echo
"debianConfig got os version $osVersion!\n";
980 echo
"Old PHPunit installation with PEAR is deprecated, it is now done with composer.\n";
981 echo
"To install composer type:\n";
982 echo
"curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer\n ";
985 echo
"debianConfig got os version $osVersion!\n";
1058 if(empty($osVersion))
1063 $rpmPath =
'../dataFiles/pkginstall/redhat/6.x';
1067 $rpmPath .
'/postgresql.conf');
1081 copyFiles($rpmPath .
'/php.ini',
'/etc/php.ini');
1082 }
catch (Exception $e)
1084 echo
"Failure: Could not copy php.ini to /etc/php.ini\n";
1110 if(!is_object($objRef))
1114 if(empty($objRef->yum))
1116 echo
"FATAL, no yum install line to install\n";
1120 $RedFedRepo =
'redfed-fossology.repo';
1122 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
1123 $fcont = file_get_contents($n);
1130 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1132 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1134 echo
"FATAL! could not write repo file $RedFedRepo\n";
1138 if(is_dir(
'/etc/yum.repos.d'))
1140 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1145 if(!mkdir(
'/etc/yum.repos.d'))
1147 echo
"FATAL! could not create yum.repos.d\n";
1150 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1153 if ($objRef->osFlavor ==
'RedHat')
1155 $last = exec(
"yum -y install wget", $out, $rtn);
1158 echo
"FATAL! install EPEL repo fail\n";
1159 echo
"transcript is:\n";print_r($out) .
"\n";
1177 $last = exec(
"yum -y install php-phpunit-PHPUnit", $out, $rtn);
1180 echo
"FATAL! install PHPUnit fail\n";
1181 echo
"transcript is:\n";print_r($out) .
"\n";
1200 if(empty($application))
1205 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1208 echo
"FATAL! could not restart $application\n";
1209 echo
"transcript is:\n";print_r($out) .
"\n";
1227 if(empty($application))
1232 echo
"Starting $application ...\n";
1233 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1236 echo
"FATAL! could not start $application\n";
1237 echo
"transcript is:\n";print_r($out) .
"\n";
1240 $last = exec(
"/etc/init.d/$application start 2>&1", $out, $rtn);
1243 echo
"FATAL! could not start $application\n";
1244 echo
"transcript is:\n";print_r($out) .
"\n";
1261 if(empty($application))
1266 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1269 echo
"FATAL! could not stop $application\n";
1270 echo
"transcript is:\n";print_r($out) .
"\n";
1285 if(empty($destPath))
1289 $wcmd =
"wget -q -O $destPath " .
1290 "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1292 $last = exec($wcmd, $wOut, $wRtn);
1295 echo
"Error, could not download pg_hba.conf file, pleases configure by hand\n";
1296 echo
"wget output is:\n" . implode(
"\n",$wOut) .
"\n";
tuneKernel()
tune the kernel for this boot and successive boots
stop($application)
stop the application Assumes application is restartable via /etc/init.d/<script>. The application pas...
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied...
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
configDebian($osType, $osVersion)
config a debian based system to install fossology.
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
configYum($objRef)
config yum on a redhat based system to install fossology.
configRhel($osType, $osVersion)
copy configuration files and restart apache and postgres
installFossology($objRef)
Install fossology using either apt or yum.
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).
ckInstallLog($log)
Check the fossology install output for errors in the install.
configApache2($osType)
check to see if fossology is configured into apache. If not copy the config file and configure it...