22 require_once
'../lib/TestRun.php';
51 $euid = posix_getuid();
53 print
"Error, this script must be run as root\n";
60 echo
"fossVersion: $Migrate\n";
64 $f = exec(
'cat /etc/issue', $dist, $dRtn);
65 $distros = explode(
' ', $dist[0]);
72 switch ($distros[0]) {
75 $debianVersion = $distros[2];
76 echo
"debian version is:$debianVersion\n";
79 $Debian =
new ConfigSys($distros[0], $debianVersion,$Migrate);
83 echo
"FATAL! could not process ini file for Debian $debianVersion system\n";
89 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
92 echo
"*** Installing fossology ***\n";
95 echo
"FATAL! Could not install fossology on {$distros[0]} version $debianVersion\n";
101 $rhVersion = $distros[6];
105 $RedHat =
new ConfigSys($redHat, $rhVersion,$Migrate);
109 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
115 echo
"FATAL! could not install fossology.conf yum configuration file\n";
118 echo
"*** Installing fossology ***\n";
121 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
124 echo
"*** stopping scheduler ***\n";
126 if(!
stop(
'iptables'))
128 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
137 echo
"rh version is:$rhVersion\n";
140 $RedHat =
new ConfigSys($redHat, $rhVersion,$Migrate);
144 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
150 echo
"FATAL! could not install fossology.conf yum configuration file\n";
153 echo
"*** Installing fossology ***\n";
156 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
159 echo
"*** stopping scheduler ***\n";
161 if(!
stop(
'iptables'))
163 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
169 $fedVersion = $distros[2];
172 $Fedora =
new ConfigSys($fedora, $fedVersion, $Migrate);
176 echo
"FATAL! could not process ini file for Fedora $fedVersion system\n";
182 echo
"FATAL! could not install fossology.repo yum configuration file\n";
186 echo
"*** Installing fossology ***\n";
189 echo
"FATAL! Could not install fossology on $fedora version $fedVersion\n";
192 echo
"*** stopping scheduler ***\n";
194 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
197 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
203 $ubunVersion = $distros[1];
204 echo
"Ubuntu version is:$ubunVersion\n";
207 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion, $Migrate);
211 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
217 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
220 echo
"*** Installing fossology ***\n";
223 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
226 echo
"*** stopping scheduler ***\n";
230 echo
"*** Setting up config files ***\n";
233 echo
"FATAL! could not configure postgres or php config files\n";
238 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
245 public $osVersion = 0;
246 private $fossVersion;
249 public $comment =
'';
252 function __construct($osFlavor, $osVersion, $migrate)
256 throw new Exception(
"No Os Flavor supplied\n");
258 if(empty($osVersion))
260 throw new Exception(
"No Os Version Supplied\n");
265 $dataFile =
'../dataFiles/miginstall/' . strtolower($osFlavor) .
'.ini';
268 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
271 $releases = parse_ini_file($dataFile, 1);
274 foreach($releases as $release => $values)
276 if($values[
'osversion'] == $osVersion)
279 $this->osFlavor = $values[
'osflavor'];
280 $this->osVersion = $values[
'osversion'];
281 $this->fossVersion = $values[
'fossversion'];
282 $this->osCodeName = $values[
'codename'];
284 switch (strtolower($this->osFlavor)) {
287 $this->deb = $values[
'deb'];
291 $this->yum = $values[
'yum'];
297 $this->comment = $values[
'comment'];
300 if($this->osVersion == 0)
302 throw new Exception(
"FATAL! no matching os flavor or version found\n");
315 echo
"Attributes of ConfigSys:\n";
316 echo
"\tosFlavor:$this->osFlavor\n";
317 echo
"\tosVersion:$this->osVersion\n";
318 echo
"\tfossVersion:$this->fossVersion\n";
319 echo
"\tosCodeName:$this->osCodeName\n";
320 echo
"\tdeb:$this->deb\n";
321 echo
"\tcomment:$this->comment\n";
322 echo
"\tyum:$this->yum\n";
338 if(!is_object($objRef))
343 $APT = fopen(
'/etc/apt/sources.list',
'a+');
344 if(!is_resource($APT))
346 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
349 $written = fwrite($APT,
"\n");
352 if(empty($objRef->comment))
354 $comment =
'# Automatically inserted by pkgConfig.php';
357 $com = fwrite($APT, $objRef->comment .
"\n");
358 if(!$written = fwrite($APT, $objRef->deb))
360 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
379 if(!is_object($objRef))
383 $aptUpdate =
'apt-get update 2>&1';
384 $aptInstall =
'apt-get -y --force-yes install fossology 2>&1';
385 $yumClean =
'yum clean all';
386 $yumUpdate =
'yum -y update 2>&1';
387 $yumInstall =
'yum -y install fossology > fossinstall.log 2>&1';
389 $aptUpgrade =
'apt-get -y --force-yes dist-upgrade 2>&1';
390 $yumUpgrade =
'yum -y upgrade fossology* > fossinstall.log 2>&1';
396 switch ($objRef->osFlavor) {
399 $last = exec($aptUpdate, $out, $rtn);
402 $last = exec($aptInstall, $iOut, $iRtn);
404 $last = exec($aptUpgrade, $iOut, $iRtn);
407 echo
"Failed to install fossology!\nTranscript is:\n";
408 echo implode(
"\n",$iOut) .
"\n";
412 echo
"DB: in ubun/deb case, before installLog implode\n";
413 $debLog = implode(
"\n",$iOut);
416 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
417 "Could not connect to FOSSology database:\n" .
418 "Unable to connect to PostgreSQL server:\n" .
419 "Was found in the install output. This install is suspect and is considered FAILED.\n";
426 echo
"** Running yum clean **\n";
427 $last = exec($yumClean, $out, $rtn);
430 echo
"Failed to clean all cache data!\nTranscript is:\n";
431 echo implode(
"\n",$out) .
"\n";
436 echo
"** Running yum update **\n";
437 $last = exec($yumUpdate, $out, $rtn);
440 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
441 echo implode(
"\n",$out) .
"\n";
448 echo
"** Running yum install fossology **\n";
449 $last = exec($yumInstall, $yumOut, $yumRtn);
453 echo
"** Running yum upgrade fossology **\n";
454 $last = exec($yumUpgrade, $yumOut, $yumRtn);
460 echo
"Failed to install fossology!\nTranscript is:\n";
461 system(
'cat fossinstall.log');
464 if(!($installLog = file_get_contents(
'fossinstall.log')))
466 echo
"FATAL! could not read 'fossinstall.log\n";
471 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
472 "Could not connect to FOSSology database:\n" .
473 "Unable to connect to PostgreSQL server:\n" .
474 "Was found in the install output. This install is suspect and is considered failed.\n";
480 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
503 $traces = $fates = $connects = $postgresFail = 0;
504 $stack =
'/PHP Stack trace:/';
506 $noConnect =
'/Could not connect to FOSSology database/';
507 $noPG =
'/Unable to connect to PostgreSQL server:/';
509 $traces = preg_match_all($stack, $log, $stackMatches);
510 $fates = preg_match_all($fatal, $log, $fatalMatches);
511 $connects = preg_match_all($noConnect, $log, $noconMatches);
512 $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
513 echo
"Number of PHP stack traces found:$traces\n";
514 echo
"Number of FATAL's found:$fates\n";
515 echo
"Number of 'cannot connect' found:$connects\n";
516 echo
"Number of 'cannot connect to postgres server' found:$postgresFail\n";
517 print
"DB: install log is:\n$log\n";
544 throw new Exception(
'No file to copy', 0);
548 throw new Exception(
'No destination for copy', 0);
551 $login = posix_getlogin();
556 foreach($files as $file)
560 $baseFile = basename($file);
563 $to = $dest .
"/$baseFile";
571 if(!copy($file, $to))
573 throw new Exception(
"Could not copy $file to $to");
583 $baseFile = basename($files);
586 $to = $dest .
"/$baseFile";
594 if(!copy($files,$to))
596 throw new Exception(
"Could not copy $file to $to");
618 if(empty($osVersion))
631 echo
"debianConfig got os version 6.0!\n";
636 echo
"debianConfig got os version $osVersion!\n";
642 echo
"debianConfig got os version $osVersion!\n";
644 echo
"Old PHPunit installation with PEAR is deprecated, it is now done with composer.\n";
645 echo
"To install composer type:\n";
646 echo
"curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer\n ";
651 echo
"debianConfig got os version $osVersion!\n";
672 if(!is_object($objRef))
676 if(empty($objRef->yum))
678 echo
"FATAL, no yum install line to install\n";
682 $RedFedRepo =
'redfed-fossology.repo';
684 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
685 $fcont = file_get_contents($n);
687 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
689 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
691 echo
"FATAL! could not write repo file $RedFedRepo\n";
695 if(is_dir(
'/etc/yum.repos.d'))
697 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
702 if(!mkdir(
'/etc/yum.repos.d'))
704 echo
"FATAL! could not create yum.repos.d\n";
707 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
710 if (($objRef->osFlavor ==
'RedHat') && (empty($migrate)))
712 $last = exec(
"yum -y install wget", $out, $rtn);
715 echo
"FATAL! install EPEL repo fail\n";
716 echo
"transcript is:\n";print_r($out) .
"\n";
719 $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);
722 echo
"FATAL! install EPEL repo fail\n";
723 echo
"transcript is:\n";print_r($out) .
"\n";
726 $last = exec(
"rpm -ivh epel-release-6-8.noarch.rpm", $out, $rtn);
729 echo
"FATAL! install EPEL repo fail\n";
730 echo
"transcript is:\n";print_r($out) .
"\n";
733 $last = exec(
"yum -y install php-phpunit-PHPUnit", $out, $rtn);
736 echo
"FATAL! install PHPUnit fail\n";
737 echo
"transcript is:\n";print_r($out) .
"\n";
756 if(empty($application))
761 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
764 echo
"FATAL! could not stop $application\n";
765 echo
"transcript is:\n";print_r($out) .
"\n";
insertDeb($objRef)
insert the fossology debian line in /etc/apt/sources.list
configYum($objRef, $migrate)
config yum on a redhat based system to install fossology.
copyFiles($files, $dest)
copyFiles, copy one or more files to the destination, throws exception if file is not copied.
ckInstallLog($log)
Check the fossology install output for errors in the install.
installFossology($objRef, $migrate)
Install fossology using either apt or yum.
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...