23 require_once
'../lib/TestRun.php';
49 $euid = posix_getuid();
51 print
"Error, this script must be run as root\n";
57 $f = exec(
'cat /etc/issue', $dist, $dRtn);
58 $distros = explode(
' ', $dist[0]);
70 switch ($distros[0]) {
73 $debianVersion = $distros[2];
74 echo
"debian version is:$debianVersion\n";
77 $Debian =
new ConfigSys($distros[0], $debianVersion);
81 echo
"FATAL! could not process ini file for Debian $debianVersion system\n";
87 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
90 echo
"*** Installing fossology ***\n";
93 echo
"FATAL! Could not install fossology on {$distros[0]} version $debianVersion\n";
96 echo
"*** stopping scheduler ***\n";
134 $rhVersion = $distros[6];
138 $RedHat =
new ConfigSys($redHat, $rhVersion);
142 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
148 echo
"FATAL! could not install fossology.conf yum configuration file\n";
155 echo
"*** Installing fossology ***\n";
158 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
161 echo
"*** stopping scheduler ***\n";
186 if(!
stop(
'iptables'))
188 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
195 $rhVersion = $distros[2];
196 echo
"rh version is:$rhVersion\n";
199 $RedHat =
new ConfigSys($redHat, $rhVersion);
203 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
209 echo
"FATAL! could not install fossology.conf yum configuration file\n";
216 echo
"*** Installing fossology ***\n";
219 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
222 echo
"*** stopping scheduler ***\n";
252 if(!
stop(
'iptables'))
254 echo
"Erorr! Could not stop Firewall, please stop 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";
320 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
323 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
337 $ubunVersion = $distros[1];
338 echo
"Ubuntu version is:$ubunVersion\n";
341 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion);
345 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
351 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
358 echo
"*** Installing fossology ***\n";
361 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
364 echo
"*** stopping scheduler ***\n";
368 echo
"*** Setting up config files ***\n";
371 echo
"FATAL! could not configure postgres or php config files\n";
397 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
404 public $osVersion = 0;
405 private $fossVersion;
408 public $comment =
'';
411 function __construct($osFlavor, $osVersion)
415 throw new Exception(
"No Os Flavor supplied\n");
417 if(empty($osVersion))
419 throw new Exception(
"No Os Version Supplied\n");
422 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
423 $releases = parse_ini_file($dataFile, 1);
426 foreach($releases as $release => $values)
428 if($values[
'osversion'] == $osVersion)
431 $this->osFlavor = $values[
'osflavor'];
432 $this->osVersion = $values[
'osversion'];
433 $this->fossVersion = $values[
'fossversion'];
434 $this->osCodeName = $values[
'codename'];
436 switch (strtolower($this->osFlavor)) {
439 $this->deb = $values[
'deb'];
443 $this->yum = $values[
'yum'];
449 $this->comment = $values[
'comment'];
452 if($this->osVersion == 0)
454 throw new Exception(
"FATAL! no matching os flavor or version found\n");
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";
490 if(!is_object($objRef))
495 $APT = fopen(
'/etc/apt/sources.list',
'a+');
496 if(!is_resource($APT))
498 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
501 $written = fwrite($APT,
"\n");
504 if(empty($objRef->comment))
506 $comment =
'# Automatically inserted by pkgConfig.php';
509 $com = fwrite($APT, $objRef->comment .
"\n");
510 if(!$written = fwrite($APT, $objRef->deb))
512 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
531 if(!is_object($objRef))
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';
544 switch ($objRef->osFlavor) {
547 $last = exec($aptUpdate, $out, $rtn);
549 $last = exec($aptInstall, $iOut, $iRtn);
552 echo
"Failed to install fossology! aptInstall is:$aptInstall, iRtn is:$iRtn, last is:$last \nTranscript is:\n";
553 echo implode(
"\n",$iOut) .
"\n";
557 echo
"DB: in ubun/deb case, before installLog implode\n";
558 $debLog = implode(
"\n",$iOut);
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";
571 echo
"** Running yum clean **\n";
572 $last = exec($yumClean, $out, $rtn);
575 echo
"Failed to clean all cache data!\nTranscript is:\n";
576 echo implode(
"\n",$out) .
"\n";
579 echo
"** Running yum update **\n";
580 $last = exec($yumUpdate, $out, $rtn);
583 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
584 echo implode(
"\n",$out) .
"\n";
587 echo
"** Running yum install fossology **\n";
588 $last = exec($yumInstall, $yumOut, $yumRtn);
593 echo
"Failed to install fossology! yumInstall is:$yumInstall, yumRtn is:$yumRtn, last is:$last \nTranscript is:\n";
594 echo implode(
"\n",$yumOut) .
"\n";
597 if(!($installLog = file_get_contents(
'fossinstall.log')))
599 echo
"FATAL! could not read 'fossinstall.log\n";
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";
613 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
636 $traces = $fates = $connects = $postgresFail = 0;
637 $stack =
'/PHP Stack trace:/';
639 $noConnect =
'/Could not connect to FOSSology database/';
640 $noPG =
'/Unable to connect to PostgreSQL server:/';
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";
677 throw new Exception(
'No file to copy', 0);
681 throw new Exception(
'No destination for copy', 0);
684 $login = posix_getlogin();
689 foreach($files as $file)
693 $baseFile = basename($file);
696 $to = $dest .
"/$baseFile";
704 if(!copy($file, $to))
706 throw new Exception(
"Could not copy $file to $to");
716 $baseFile = basename($files);
719 $to = $dest .
"/$baseFile";
727 if(!copy($files,$to))
729 throw new Exception(
"Could not copy $file to $to");
746 $last = exec(
'psql --version', $out, $rtn);
754 list( , ,$ver) = explode(
' ', $out[0]);
755 $version = substr($ver, 0, 3);
769 $grepCmd =
'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
770 $last = exec($grepCmd, $out, $rtn);
773 echo
"NOTE: kernel already configured.\n";
776 $cmd1 =
"echo 512000000 > /proc/sys/kernel/shmmax";
777 $cmd2 =
"echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
779 $last1 = exec($cmd1, $cmd1Out, $rtn1);
782 echo
"Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
784 $last2 = exec($cmd2, $cmd2Out, $rtn2);
788 echo
"Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
811 if(is_link(
'/etc/apache2/conf.d/fossology'))
818 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/fossology/fo-apache.conf'))
820 echo
"FATAL!, Cannot configure fossology into apache2\n";
823 if(!symlink(
'/etc/fossology/fo-apache.conf',
'/etc/apache2/conf.d/fossology'))
825 echo
"FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
831 echo
"Erorr! Could not restart apache2, please restart by hand\n";
838 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/httpd/conf.d/fossology.conf'))
840 echo
"FATAL!, Cannot configure fossology into apache2\n";
846 echo
"Erorr! Could not restart httpd, please restart by hand\n";
873 if(empty($osVersion))
898 echo
"debianConfig got os version 6.0!\n";
936 echo
"debianConfig got os version $osVersion!\n";
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 ";
974 echo
"debianConfig got os version $osVersion!\n";
1047 if(empty($osVersion))
1052 $rpmPath =
'../dataFiles/pkginstall/redhat/6.x';
1056 $rpmPath .
'/postgresql.conf');
1070 copyFiles($rpmPath .
'/php.ini',
'/etc/php.ini');
1071 }
catch (Exception $e)
1073 echo
"Failure: Could not copy php.ini to /etc/php.ini\n";
1099 if(!is_object($objRef))
1103 if(empty($objRef->yum))
1105 echo
"FATAL, no yum install line to install\n";
1109 $RedFedRepo =
'redfed-fossology.repo';
1111 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
1112 $fcont = file_get_contents($n);
1119 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1121 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1123 echo
"FATAL! could not write repo file $RedFedRepo\n";
1127 if(is_dir(
'/etc/yum.repos.d'))
1129 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1134 if(!mkdir(
'/etc/yum.repos.d'))
1136 echo
"FATAL! could not create yum.repos.d\n";
1139 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1142 if ($objRef->osFlavor ==
'RedHat')
1144 $last = exec(
"yum -y install wget", $out, $rtn);
1147 echo
"FATAL! install EPEL repo fail\n";
1148 echo
"transcript is:\n";print_r($out) .
"\n";
1166 $last = exec(
"yum -y install php-phpunit-PHPUnit", $out, $rtn);
1169 echo
"FATAL! install PHPUnit fail\n";
1170 echo
"transcript is:\n";print_r($out) .
"\n";
1189 if(empty($application))
1194 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1197 echo
"FATAL! could not restart $application\n";
1198 echo
"transcript is:\n";print_r($out) .
"\n";
1216 if(empty($application))
1221 echo
"Starting $application ...\n";
1222 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1225 echo
"FATAL! could not start $application\n";
1226 echo
"transcript is:\n";print_r($out) .
"\n";
1229 $last = exec(
"/etc/init.d/$application start 2>&1", $out, $rtn);
1232 echo
"FATAL! could not start $application\n";
1233 echo
"transcript is:\n";print_r($out) .
"\n";
1250 if(empty($application))
1255 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1258 echo
"FATAL! could not stop $application\n";
1259 echo
"transcript is:\n";print_r($out) .
"\n";
1274 if(empty($destPath))
1278 $wcmd =
"wget -q -O $destPath " .
1279 "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1281 $last = exec($wcmd, $wOut, $wRtn);
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";
configApache2($osType)
check to see if fossology is configured into apache. If not copy the config file and configure it....
findVerPsql()
find the version of postgres and return major release and sub release. For example,...
configYum($objRef)
config yum on a redhat based system to install fossology.
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied.
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
ckInstallLog($log)
Check the fossology install output for errors in the install.
installFossology($objRef)
Install fossology using either apt or yum.
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
tuneKernel()
tune the kernel for this boot and successive boots
configRhel($osType, $osVersion)
copy configuration files and restart apache and postgres
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...
list_t type structure used to keep various lists. (e.g. there are multiple lists).