FOSSology  4.4.0
Open Source License Compliance by Open Source Software
TestInstaller.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Test;
9 
10 require_once(dirname(dirname(dirname(__DIR__))) . "/vendor/autoload.php");
11 
13 {
15  private $sysConf;
16 
17  function __construct($sysConf)
18  {
19  $this->sysConf = $sysConf;
20  }
21 
22  public function init()
23  {
24  $sysConf = $this->sysConf;
25 
26  $confFile = $sysConf."/fossology.conf";
27  $fakeInstallationDir = "$sysConf/inst";
28 
29  $projectGroup = `id -g -n`;
30  $projectUser = `id -u -n`;
31  $config = "[FOSSOLOGY]\ndepth = 0\npath = $sysConf/repo\n" .
32  "[DIRECTORIES]\nMODDIR = $fakeInstallationDir\n" .
33  "PROJECTGROUP = $projectGroup\n" .
34  "PROJECTUSER = $projectUser\n" .
35  "PREFIX = $fakeInstallationDir\n" .
36  "BINDIR = \$PREFIX/bin\n" .
37  "SBINDIR = \$PREFIX/sbin\n" .
38  "LIBEXECDIR = \$PREFIX/lib\n";
39  file_put_contents($confFile, $config);
40 
41  if (! is_dir($fakeInstallationDir)) {
42  mkdir($fakeInstallationDir, 0777, true);
43 
44  $libDir = dirname(dirname(dirname(__DIR__))) . "/lib";
45  system("ln -sf $libDir $fakeInstallationDir/lib");
46 
47  if (! is_dir("$fakeInstallationDir/www/ui")) {
48  mkdir("$fakeInstallationDir/www/ui/", 0777, true);
49  touch("$fakeInstallationDir/www/ui/ui-menus.php");
50  }
51  }
52 
53  $topDir = dirname(__DIR__,4).'/build/install';
54  system("install -D $topDir/VERSION $sysConf");
55  }
56 
57  public function clear()
58  {
59  system("rm $this->sysConf/inst -rf");
60  $versionFile = $this->sysConf."/VERSION";
61  if (file_exists($versionFile)) {
62  unlink($versionFile);
63  }
64  $confFile = $this->sysConf . "/fossology.conf";
65  if (file_exists($confFile)) {
66  unlink($confFile);
67  }
68  }
69 
70  public function install($srcDir)
71  {
72  $sysConfDir = $this->sysConf;
73  exec("make MODDIR=$sysConfDir DESTDIR= BINDIR=$sysConfDir SYSCONFDIR=$sysConfDir -C $srcDir --file=TestInstall.make install", $unused, $rt);
74  return ($rt != 0);
75  }
76 
77  public function uninstall($srcDir)
78  {
79  $sysConfDir = $this->sysConf;
80  exec("make MODDIR=$sysConfDir DESTDIR= BINDIR=$sysConfDir SYSCONFDIR=$sysConfDir -C $srcDir --file=TestInstall.make uninstall", $unused, $rt);
81  $modEnabled = "$sysConfDir/mods-enabled";
82  if (is_dir($modEnabled)) {
83  rmdir($modEnabled);
84  }
85  return ($rt != 0);
86  }
87 
88  public function cpRepo()
89  {
90  $testRepoDir = __DIR__;
91  system("cp -a $testRepoDir/repo $this->sysConf/");
92  }
93 
94  public function rmRepo()
95  {
96  system("rm $this->sysConf/repo -rf");
97  }
98 }
int Test
Definition: util.c:20