FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
TestInstaller.php
1 <?php
2 /*
3 Copyright (C) 2015, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Test;
20 
21 require_once(dirname(dirname(dirname(__DIR__))) . "/vendor/autoload.php");
22 
24 {
26  private $sysConf;
27 
28  function __construct($sysConf)
29  {
30  $this->sysConf = $sysConf;
31  }
32 
33  public function init()
34  {
35  $sysConf = $this->sysConf;
36 
37  $confFile = $sysConf."/fossology.conf";
38  $fakeInstallationDir = "$sysConf/inst";
39 
40  $projectGroup = `id -g -n`;
41  $config = "[FOSSOLOGY]\ndepth = 0\npath = $sysConf/repo\n"
42  . "[DIRECTORIES]\nMODDIR = $fakeInstallationDir\nPROJECTGROUP = $projectGroup";
43  file_put_contents($confFile, $config);
44 
45  if (! is_dir($fakeInstallationDir)) {
46  mkdir($fakeInstallationDir, 0777, true);
47 
48  $libDir = dirname(dirname(dirname(__DIR__))) . "/lib";
49  system("ln -sf $libDir $fakeInstallationDir/lib");
50 
51  if (! is_dir("$fakeInstallationDir/www/ui")) {
52  mkdir("$fakeInstallationDir/www/ui/", 0777, true);
53  touch("$fakeInstallationDir/www/ui/ui-menus.php");
54  }
55  }
56 
57  $topDir = dirname(dirname(dirname(dirname(__DIR__))));
58  system("install -D $topDir/VERSION $sysConf");
59  }
60 
61  public function clear()
62  {
63  system("rm $this->sysConf/inst -rf");
64  $versionFile = $this->sysConf."/VERSION";
65  if (file_exists($versionFile)) {
66  unlink($versionFile);
67  }
68  $confFile = $this->sysConf . "/fossology.conf";
69  if (file_exists($confFile)) {
70  unlink($confFile);
71  }
72  }
73 
74  public function install($srcDir)
75  {
76  $sysConfDir = $this->sysConf;
77  exec("make MODDIR=$sysConfDir DESTDIR= BINDIR=$sysConfDir SYSCONFDIR=$sysConfDir -C $srcDir install", $unused, $rt);
78  return ($rt != 0);
79  }
80 
81  public function uninstall($srcDir)
82  {
83  $sysConfDir = $this->sysConf;
84  exec("make MODDIR=$sysConfDir DESTDIR= BINDIR=$sysConfDir SYSCONFDIR=$sysConfDir -C $srcDir uninstall", $unused, $rt);
85  $modEnabled = "$sysConfDir/mods-enabled";
86  if (is_dir($modEnabled)) {
87  rmdir($modEnabled);
88  }
89  return ($rt != 0);
90  }
91 
92  public function cpRepo()
93  {
94  $testRepoDir = __DIR__;
95  system("cp -a $testRepoDir/repo $this->sysConf/");
96  }
97 
98  public function rmRepo()
99  {
100  system("rm $this->sysConf/repo -rf");
101  }
102 }