33 require_once
'../lib/TestRun.php';
62 $euid = posix_getuid();
64 print
"Error, this script must be run as root\n";
71 echo
"fossVersion: $Migrate\n";
75 $f = exec(
'cat /etc/issue', $dist, $dRtn);
76 $distros = explode(
' ', $dist[0]);
83 switch ($distros[0]) {
86 $debianVersion = $distros[2];
87 echo
"debian version is:$debianVersion\n";
90 $Debian =
new ConfigSys($distros[0], $debianVersion,$Migrate);
94 echo
"FATAL! could not process ini file for Debian $debianVersion system\n";
100 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
103 echo
"*** Installing fossology ***\n";
106 echo
"FATAL! Could not install fossology on {$distros[0]} version $debianVersion\n";
112 $rhVersion = $distros[6];
116 $RedHat =
new ConfigSys($redHat, $rhVersion,$Migrate);
120 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
126 echo
"FATAL! could not install fossology.conf yum configuration file\n";
129 echo
"*** Installing fossology ***\n";
132 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
135 echo
"*** stopping scheduler ***\n";
137 if(!
stop(
'iptables'))
139 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
148 echo
"rh version is:$rhVersion\n";
151 $RedHat =
new ConfigSys($redHat, $rhVersion,$Migrate);
155 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
161 echo
"FATAL! could not install fossology.conf yum configuration file\n";
164 echo
"*** Installing fossology ***\n";
167 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
170 echo
"*** stopping scheduler ***\n";
172 if(!
stop(
'iptables'))
174 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
180 $fedVersion = $distros[2];
183 $Fedora =
new ConfigSys($fedora, $fedVersion, $Migrate);
187 echo
"FATAL! could not process ini file for Fedora $fedVersion system\n";
193 echo
"FATAL! could not install fossology.repo yum configuration file\n";
197 echo
"*** Installing fossology ***\n";
200 echo
"FATAL! Could not install fossology on $fedora version $fedVersion\n";
203 echo
"*** stopping scheduler ***\n";
205 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
208 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
214 $ubunVersion = $distros[1];
215 echo
"Ubuntu version is:$ubunVersion\n";
218 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion, $Migrate);
222 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
228 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
231 echo
"*** Installing fossology ***\n";
234 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
237 echo
"*** stopping scheduler ***\n";
241 echo
"*** Setting up config files ***\n";
244 echo
"FATAL! could not configure postgres or php config files\n";
249 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
256 public $osVersion = 0;
257 private $fossVersion;
260 public $comment =
'';
263 function __construct($osFlavor, $osVersion, $migrate)
267 throw new Exception(
"No Os Flavor supplied\n");
269 if(empty($osVersion))
271 throw new Exception(
"No Os Version Supplied\n");
276 $dataFile =
'../dataFiles/miginstall/' . strtolower($osFlavor) .
'.ini';
279 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
282 $releases = parse_ini_file($dataFile, 1);
285 foreach($releases as $release => $values)
287 if($values[
'osversion'] == $osVersion)
290 $this->osFlavor = $values[
'osflavor'];
291 $this->osVersion = $values[
'osversion'];
292 $this->fossVersion = $values[
'fossversion'];
293 $this->osCodeName = $values[
'codename'];
295 switch (strtolower($this->osFlavor)) {
298 $this->deb = $values[
'deb'];
302 $this->yum = $values[
'yum'];
308 $this->comment = $values[
'comment'];
311 if($this->osVersion == 0)
313 throw new Exception(
"FATAL! no matching os flavor or version found\n");
326 echo
"Attributes of ConfigSys:\n";
327 echo
"\tosFlavor:$this->osFlavor\n";
328 echo
"\tosVersion:$this->osVersion\n";
329 echo
"\tfossVersion:$this->fossVersion\n";
330 echo
"\tosCodeName:$this->osCodeName\n";
331 echo
"\tdeb:$this->deb\n";
332 echo
"\tcomment:$this->comment\n";
333 echo
"\tyum:$this->yum\n";
349 if(!is_object($objRef))
354 $APT = fopen(
'/etc/apt/sources.list',
'a+');
355 if(!is_resource($APT))
357 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
360 $written = fwrite($APT,
"\n");
363 if(empty($objRef->comment))
365 $comment =
'# Automatically inserted by pkgConfig.php';
368 $com = fwrite($APT, $objRef->comment .
"\n");
369 if(!$written = fwrite($APT, $objRef->deb))
371 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
390 if(!is_object($objRef))
394 $aptUpdate =
'apt-get update 2>&1';
395 $aptInstall =
'apt-get -y --force-yes install fossology 2>&1';
396 $yumClean =
'yum clean all';
397 $yumUpdate =
'yum -y update 2>&1';
398 $yumInstall =
'yum -y install fossology > fossinstall.log 2>&1';
400 $aptUpgrade =
'apt-get -y --force-yes dist-upgrade 2>&1';
401 $yumUpgrade =
'yum -y upgrade fossology* > fossinstall.log 2>&1';
407 switch ($objRef->osFlavor) {
410 $last = exec($aptUpdate, $out, $rtn);
413 $last = exec($aptInstall, $iOut, $iRtn);
415 $last = exec($aptUpgrade, $iOut, $iRtn);
418 echo
"Failed to install fossology!\nTranscript is:\n";
419 echo implode(
"\n",$iOut) .
"\n";
423 echo
"DB: in ubun/deb case, before installLog implode\n";
424 $debLog = implode(
"\n",$iOut);
427 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
428 "Could not connect to FOSSology database:\n" .
429 "Unable to connect to PostgreSQL server:\n" .
430 "Was found in the install output. This install is suspect and is considered FAILED.\n";
437 echo
"** Running yum clean **\n";
438 $last = exec($yumClean, $out, $rtn);
441 echo
"Failed to clean all cache data!\nTranscript is:\n";
442 echo implode(
"\n",$out) .
"\n";
447 echo
"** Running yum update **\n";
448 $last = exec($yumUpdate, $out, $rtn);
451 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
452 echo implode(
"\n",$out) .
"\n";
459 echo
"** Running yum install fossology **\n";
460 $last = exec($yumInstall, $yumOut, $yumRtn);
464 echo
"** Running yum upgrade fossology **\n";
465 $last = exec($yumUpgrade, $yumOut, $yumRtn);
471 echo
"Failed to install fossology!\nTranscript is:\n";
472 system(
'cat fossinstall.log');
475 if(!($installLog = file_get_contents(
'fossinstall.log')))
477 echo
"FATAL! could not read 'fossinstall.log\n";
482 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
483 "Could not connect to FOSSology database:\n" .
484 "Unable to connect to PostgreSQL server:\n" .
485 "Was found in the install output. This install is suspect and is considered failed.\n";
491 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
514 $traces = $fates = $connects = $postgresFail = 0;
515 $stack =
'/PHP Stack trace:/';
517 $noConnect =
'/Could not connect to FOSSology database/';
518 $noPG =
'/Unable to connect to PostgreSQL server:/';
520 $traces = preg_match_all($stack, $log, $stackMatches);
521 $fates = preg_match_all($fatal, $log, $fatalMatches);
522 $connects = preg_match_all($noConnect, $log, $noconMatches);
523 $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
524 echo
"Number of PHP stack traces found:$traces\n";
525 echo
"Number of FATAL's found:$fates\n";
526 echo
"Number of 'cannot connect' found:$connects\n";
527 echo
"Number of 'cannot connect to postgres server' found:$postgresFail\n";
528 print
"DB: install log is:\n$log\n";
555 throw new Exception(
'No file to copy', 0);
559 throw new Exception(
'No destination for copy', 0);
562 $login = posix_getlogin();
567 foreach($files as $file)
571 $baseFile = basename($file);
574 $to = $dest .
"/$baseFile";
582 if(!copy($file, $to))
584 throw new Exception(
"Could not copy $file to $to");
594 $baseFile = basename($files);
597 $to = $dest .
"/$baseFile";
605 if(!copy($files,$to))
607 throw new Exception(
"Could not copy $file to $to");
629 if(empty($osVersion))
642 echo
"debianConfig got os version 6.0!\n";
647 echo
"debianConfig got os version $osVersion!\n";
653 echo
"debianConfig got os version $osVersion!\n";
655 echo
"Old PHPunit installation with PEAR is deprecated, it is now done with composer.\n";
656 echo
"To install composer type:\n";
657 echo
"curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer\n ";
662 echo
"debianConfig got os version $osVersion!\n";
683 if(!is_object($objRef))
687 if(empty($objRef->yum))
689 echo
"FATAL, no yum install line to install\n";
693 $RedFedRepo =
'redfed-fossology.repo';
695 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
696 $fcont = file_get_contents($n);
698 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
700 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
702 echo
"FATAL! could not write repo file $RedFedRepo\n";
706 if(is_dir(
'/etc/yum.repos.d'))
708 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
713 if(!mkdir(
'/etc/yum.repos.d'))
715 echo
"FATAL! could not create yum.repos.d\n";
718 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
721 if (($objRef->osFlavor ==
'RedHat') && (empty($migrate)))
723 $last = exec(
"yum -y install wget", $out, $rtn);
726 echo
"FATAL! install EPEL repo fail\n";
727 echo
"transcript is:\n";print_r($out) .
"\n";
730 $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);
733 echo
"FATAL! install EPEL repo fail\n";
734 echo
"transcript is:\n";print_r($out) .
"\n";
737 $last = exec(
"rpm -ivh epel-release-6-8.noarch.rpm", $out, $rtn);
740 echo
"FATAL! install EPEL repo fail\n";
741 echo
"transcript is:\n";print_r($out) .
"\n";
744 $last = exec(
"yum -y install php-phpunit-PHPUnit", $out, $rtn);
747 echo
"FATAL! install PHPUnit fail\n";
748 echo
"transcript is:\n";print_r($out) .
"\n";
767 if(empty($application))
772 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
775 echo
"FATAL! could not stop $application\n";
776 echo
"transcript is:\n";print_r($out) .
"\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.
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied...
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...
configYum($objRef, $migrate)
config yum on a redhat based system to install fossology.