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";
98 $testUtils->stopScheduler();
100 echo
"*** Tuning kernel ***\n";
103 echo
"*** Setting up config files ***\n";
106 echo
"FATAL! could not configure postgres or php config files\n";
118 echo
"Erorr! Could not restart apache2, please restart by hand\n";
122 echo
"*** Starting FOSSology ***\n";
123 if(!
start(
'fossology'))
125 echo
"Erorr! Could not start FOSSology, please restart by hand\n";
131 $rhVersion = $distros[6];
135 $RedHat =
new ConfigSys($redHat, $rhVersion);
139 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
145 echo
"FATAL! could not install fossology.conf yum configuration file\n";
148 echo
"*** Tuning kernel ***\n";
151 echo
"*** Installing fossology ***\n";
154 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
157 echo
"*** stopping scheduler ***\n";
161 echo
"*** Setting up config files ***\n";
164 echo
"FATAL! could not install php and postgress configuration files\n";
176 echo
"Erorr! Could not restart httpd, please restart by hand\n";
180 if(!
stop(
'iptables'))
182 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
189 $rhVersion = $distros[2];
190 echo
"rh version is:$rhVersion\n";
193 $RedHat =
new ConfigSys($redHat, $rhVersion);
197 echo
"FATAL! could not process ini file for RedHat $rhVersion system\n";
203 echo
"FATAL! could not install fossology.conf yum configuration file\n";
206 echo
"*** Tuning kernel ***\n";
209 echo
"*** Installing fossology ***\n";
212 echo
"FATAL! Could not install fossology on $redHat version $rhVersion\n";
215 echo
"*** stopping scheduler ***\n";
219 echo
"*** Setting up config files ***\n";
222 echo
"FATAL! could not install php and postgress configuration files\n";
234 echo
"Erorr! Could not restart httpd, please restart by hand\n";
239 echo
"Erorr! Could not restart httpd, please restart by hand\n";
242 if(!
stop(
'iptables'))
244 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
247 echo
"*** Starting fossology ***\n";
248 if(!
start(
'fossology'))
250 echo
"Erorr! Could not start fossology, please restart by hand\n";
257 $fedVersion = $distros[2];
260 $Fedora =
new ConfigSys($fedora, $fedVersion);
264 echo
"FATAL! could not process ini file for Fedora $fedVersion system\n";
270 echo
"FATAL! could not install fossology.repo yum configuration file\n";
274 echo
"*** Installing fossology ***\n";
277 echo
"FATAL! Could not install fossology on $fedora version $fedVersion\n";
280 echo
"*** stopping scheduler ***\n";
284 echo
"*** Tuning kernel ***\n";
287 echo
"*** Setting up config files ***\n";
290 echo
"FATAL! could not install php and postgress configuration files\n";
300 $last = exec(
"systemctl restart httpd.service", $out, $rtn);
303 echo
"Erorr! Could not restart httpd, please restart by hand\n";
307 $last = exec(
"systemctl stop iptables.service", $out, $rtn);
310 echo
"Erorr! Could not stop Firewall, please stop by hand\n";
313 echo
"*** Starting fossology ***\n";
314 $last = exec(
"systemctl restart fossology.service", $out, $rtn);
317 echo
"Erorr! Could not start FOSSology, please stop by hand\n";
323 $ubunVersion = $distros[1];
324 echo
"Ubuntu version is:$ubunVersion\n";
327 $Ubuntu =
new ConfigSys($distros[0], $ubunVersion);
331 echo
"FATAL! could not process ini file for Ubuntu $ubunVersion system\n";
337 echo
"FATAL! cannot insert deb line into /etc/apt/sources.list\n";
340 echo
"*** Tuning kernel ***\n";
343 echo
"*** Installing fossology ***\n";
346 echo
"FATAL! Could not install fossology on {$distros[0]} version $ubunVersion\n";
349 echo
"*** stopping scheduler ***\n";
351 $testUtils->stopScheduler();
353 echo
"*** Setting up config files ***\n";
356 echo
"FATAL! could not configure postgres or php config files\n";
368 echo
"Erorr! Could not restart apache2, please restart by hand\n";
372 echo
"*** Starting FOSSology ***\n";
373 if(!
start(
'fossology'))
375 echo
"Erorr! Could not start FOSSology, please restart by hand\n";
380 echo
"Fatal! unrecognized distribution! {$distros[0]}\n" ;
387 public $osVersion = 0;
388 private $fossVersion;
391 public $comment =
'';
394 function __construct($osFlavor, $osVersion)
398 throw new Exception(
"No Os Flavor supplied\n");
400 if(empty($osVersion))
402 throw new Exception(
"No Os Version Supplied\n");
405 $dataFile =
'../dataFiles/pkginstall/' . strtolower($osFlavor) .
'.ini';
406 $releases = parse_ini_file($dataFile, 1);
409 foreach($releases as $release => $values)
411 if($values[
'osversion'] == $osVersion)
414 $this->osFlavor = $values[
'osflavor'];
415 $this->osVersion = $values[
'osversion'];
416 $this->fossVersion = $values[
'fossversion'];
417 $this->osCodeName = $values[
'codename'];
419 switch (strtolower($this->osFlavor)) {
422 $this->deb = $values[
'deb'];
426 $this->yum = $values[
'yum'];
432 $this->comment = $values[
'comment'];
435 if($this->osVersion == 0)
437 throw new Exception(
"FATAL! no matching os flavor or version found\n");
450 echo
"Attributes of ConfigSys:\n";
451 echo
"\tosFlavor:$this->osFlavor\n";
452 echo
"\tosVersion:$this->osVersion\n";
453 echo
"\tfossVersion:$this->fossVersion\n";
454 echo
"\tosCodeName:$this->osCodeName\n";
455 echo
"\tdeb:$this->deb\n";
456 echo
"\tcomment:$this->comment\n";
457 echo
"\tyum:$this->yum\n";
473 if(!is_object($objRef))
478 $APT = fopen(
'/etc/apt/sources.list',
'a+');
479 if(!is_resource($APT))
481 echo
"FATAL! could not open /etc/apt/sources.list for modification\n";
484 $written = fwrite($APT,
"\n");
487 if(empty($objRef->comment))
489 $comment =
'# Automatically inserted by pkgConfig.php';
492 $com = fwrite($APT, $objRef->comment .
"\n");
493 if(!$written = fwrite($APT, $objRef->deb))
495 echo
"FATAL! could not write deb line to /etc/apt/sources.list\n";
514 if(!is_object($objRef))
518 $aptUpdate =
'apt-get update 2>&1';
519 $aptInstall =
'apt-get -y --force-yes install fossology 2>&1';
520 $yumUpdate =
'yum -y update 2>&1';
521 $yumInstall =
'yum -y install fossology > fossinstall.log 2>&1';
526 switch ($objRef->osFlavor) {
529 $last = exec($aptUpdate, $out, $rtn);
531 $last = exec($aptInstall, $iOut, $iRtn);
534 echo
"Failed to install fossology!\nTranscript is:\n";
535 echo implode(
"\n",$iOut) .
"\n";
539 echo
"DB: in ubun/deb case, before installLog implode\n";
540 $debLog = implode(
"\n",$iOut);
543 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
544 "Could not connect to FOSSology database:\n" .
545 "Unable to connect to PostgreSQL server:\n" .
546 "Was found in the install output. This install is suspect and is considered FAILED.\n";
553 echo
"** Running yum update **\n";
554 $last = exec($yumUpdate, $out, $rtn);
557 echo
"Failed to update yum repositories with fossology!\nTranscript is:\n";
558 echo implode(
"\n",$out) .
"\n";
561 echo
"** Running yum install fossology **\n";
562 $last = exec($yumInstall, $yumOut, $yumRtn);
567 echo
"Failed to install fossology!\nTranscript is:\n";
568 system(
'cat fossinstall.log');
571 if(!($installLog = file_get_contents(
'fossinstall.log')))
573 echo
"FATAL! could not read 'fossinstall.log\n";
578 echo
"One or more of the phrases:\nPHP Stack trace:\nFATAL\n".
579 "Could not connect to FOSSology database:\n" .
580 "Unable to connect to PostgreSQL server:\n" .
581 "Was found in the install output. This install is suspect and is considered failed.\n";
587 echo
"FATAL! Unrecongnized OS/Release, not one of Ubuntu, Debian, RedHat" .
610 $traces = $fates = $connects = $postgresFail = 0;
611 $stack =
'/PHP Stack trace:/';
613 $noConnect =
'/Could not connect to FOSSology database/';
614 $noPG =
'/Unable to connect to PostgreSQL server:/';
616 $traces = preg_match_all($stack, $log, $stackMatches);
617 $fates = preg_match_all($fatal, $log, $fatalMatches);
618 $connects = preg_match_all($noConnect, $log, $noconMatches);
619 $postgresFail = preg_match_all($noPG, $log, $noPGMatches);
620 echo
"Number of PHP stack traces found:$traces\n";
621 echo
"Number of FATAL's found:$fates\n";
622 echo
"Number of 'cannot connect' found:$connects\n";
623 echo
"Number of 'cannot connect to postgres server' found:$postgresFail\n";
651 throw new Exception(
'No file to copy', 0);
655 throw new Exception(
'No destination for copy', 0);
658 $login = posix_getlogin();
663 foreach($files as $file)
667 $baseFile = basename($file);
670 $to = $dest .
"/$baseFile";
678 if(!copy($file, $to))
680 throw new Exception(
"Could not copy $file to $to");
690 $baseFile = basename($files);
693 $to = $dest .
"/$baseFile";
701 if(!copy($files,$to))
703 throw new Exception(
"Could not copy $file to $to");
720 $last = exec(
'psql --version', $out, $rtn);
728 list( , ,$ver) = explode(
' ', $out[0]);
729 $version = substr($ver, 0, 3);
743 $grepCmd =
'grep shmmax=512000000 /etc/sysctl.conf /dev/null 2>&1';
744 $last = exec($grepCmd, $out, $rtn);
747 echo
"NOTE: kernel already configured.\n";
750 $cmd1 =
"echo 512000000 > /proc/sys/kernel/shmmax";
751 $cmd2 =
"echo 'kernel.shmmax=512000000' >> /etc/sysctl.conf";
753 $last1 = exec($cmd1, $cmd1Out, $rtn1);
756 echo
"Fatal! Could not set kernel shmmax in /proc/sys/kernel/shmmax\n";
758 $last2 = exec($cmd2, $cmd2Out, $rtn2);
762 echo
"Fatal! Could not turn kernel.shmmax in /etc/sysctl.conf\n";
785 if(is_link(
'/etc/apache2/conf.d/fossology'))
792 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/fossology/fo-apache.conf'))
794 echo
"FATAL!, Cannot configure fossology into apache2\n";
797 if(!symlink(
'/etc/fossology/fo-apache.conf',
'/etc/apache2/conf.d/fossology'))
799 echo
"FATAL! Could not create symlink in /etc/apache2/conf.d/ for fossology\n";
805 echo
"Erorr! Could not restart apache2, please restart by hand\n";
812 if(!copy(
'../dataFiles/pkginstall/fo-apache.conf',
'/etc/httpd/conf.d/fossology.conf'))
814 echo
"FATAL!, Cannot configure fossology into apache2\n";
820 echo
"Erorr! Could not restart httpd, please restart by hand\n";
847 if(empty($osVersion))
863 $debPath =
'../dataFiles/pkginstall/debian/6/';
867 $debPath .
'postgresql.conf');
872 echo
"debianConfig got os version 6.0!\n";
882 copyFiles($psqlFiles,
"/etc/postgresql/8.4/main");
886 echo
"Failure: Could not copy postgres 8.4 config file\n";
890 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
891 }
catch (Exception $e)
893 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
898 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
899 }
catch (Exception $e)
901 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
910 copyFiles($psqlFiles,
"/etc/postgresql/8.4/main");
914 echo
"Failure: Could not copy postgres 8.4 config file\n";
918 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
919 }
catch (Exception $e)
921 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
926 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
927 }
catch (Exception $e)
929 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
948 copyFiles($debPath .
'cli-php.ini',
'/etc/php5/cli/php.ini');
949 }
catch (Exception $e)
951 echo
"Failure: Could not copy php.ini to /etc/php5/cli/php.ini\n";
956 copyFiles($debPath .
'apache2-php.ini',
'/etc/php5/apache2/php.ini');
957 }
catch (Exception $e)
959 echo
"Failure: Could not copy php.ini to /etc/php5/apache2/php.ini\n";
970 echo
"Erorr! Could not restart apache2, please restart by hand\n";
974 $pName =
'postgresql';
975 if($osVersion ==
'10.04.3')
979 $pName =
'postgresql-' . $ver;
981 echo
"DB pName is:$pName\n";
984 echo
"Erorr! Could not restart $pName, please restart by hand\n";
1003 if(empty($osVersion))
1008 $rpmPath =
'../dataFiles/pkginstall/redhat/6.x';
1012 $rpmPath .
'/postgresql.conf');
1026 copyFiles($rpmPath .
'/php.ini',
'/etc/php.ini');
1027 }
catch (Exception $e)
1029 echo
"Failure: Could not copy php.ini to /etc/php.ini\n";
1055 if(!is_object($objRef))
1059 if(empty($objRef->yum))
1061 echo
"FATAL, no yum install line to install\n";
1065 $RedFedRepo =
'redfed-fossology.repo';
1067 $n =
"../dataFiles/pkginstall/" . $RedFedRepo;
1068 $fcont = file_get_contents($n);
1075 $newRepo = preg_replace(
"/baseurl=(.*)?/",
'baseurl=' . $objRef->yum, $fcont,-1, $cnt);
1077 if(!($written = file_put_contents(
"../dataFiles/pkginstall/" . $RedFedRepo, $newRepo)))
1079 echo
"FATAL! could not write repo file $RedFedRepo\n";
1083 if(is_dir(
'/etc/yum.repos.d'))
1085 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1090 if(!mkdir(
'/etc/yum.repos.d'))
1092 echo
"FATAL! could not create yum.repos.d\n";
1095 copyFiles(
"../dataFiles/pkginstall/" . $RedFedRepo,
'/etc/yum.repos.d/fossology.repo');
1098 if ($objRef->osFlavor ==
'RedHat')
1100 $last = exec(
"yum -y install wget", $out, $rtn);
1103 echo
"FATAL! install EPEL repo fail\n";
1104 echo
"transcript is:\n";print_r($out) .
"\n";
1107 $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);
1110 echo
"FATAL! install EPEL repo fail\n";
1111 echo
"transcript is:\n";print_r($out) .
"\n";
1114 $last = exec(
"rpm -ivh epel-release-6-7.noarch.rpm", $out, $rtn);
1117 echo
"FATAL! install EPEL repo fail\n";
1118 echo
"transcript is:\n";print_r($out) .
"\n";
1135 function restart($application)
1137 if(empty($application))
1142 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1145 echo
"FATAL! could not restart $application\n";
1146 echo
"transcript is:\n";print_r($out) .
"\n";
1162 function start($application)
1164 if(empty($application))
1169 echo
"Starting $application ...\n";
1170 $last = exec(
"/etc/init.d/$application restart 2>&1", $out, $rtn);
1173 echo
"FATAL! could not start $application\n";
1174 echo
"transcript is:\n";print_r($out) .
"\n";
1189 function stop($application)
1191 if(empty($application))
1196 $last = exec(
"/etc/init.d/$application stop 2>&1", $out, $rtn);
1199 echo
"FATAL! could not stop $application\n";
1200 echo
"transcript is:\n";print_r($out) .
"\n";
1215 if(empty($destPath))
1219 $wcmd =
"wget -q -O $destPath " .
1220 "http://fonightly.usa.hp.com/testfiles/pg_hba.conf ";
1222 $last = exec($wcmd, $wOut, $wRtn);
1225 echo
"Error, could not download pg_hba.conf file, pleases configure by hand\n";
1226 echo
"wget output is:\n" . implode(
"\n",$wOut) .
"\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...
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,...
getPGhba($destPath)
wget the pg_hba.conf file and place it in $destPath
restart($application)
restart the application passed in, so any config changes will take affect. Assumes application is res...
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
list_t type structure used to keep various lists. (e.g. there are multiple lists).