FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
createEmptyTestEnvironment.php
1 <?php
2 /*
3  Copyright (C) 2018 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 
28 function setupTestEnv($workingDir, $agent, $agentTable=true)
29 {
30  $SYSCONF_DIR = "$workingDir/testconf";
31  $confFile = "fossology.conf";
32  $agentDir = "$workingDir/../..";
33 
34  exec("rm -rf $SYSCONF_DIR");
35  if(!mkdir($SYSCONF_DIR)) {
36  die("Unable to create $SYSCONF_DIR");
37  }
38  $confFile_fh = fopen("$SYSCONF_DIR/$confFile", 'w')
39  or die("FAIL: Could not open $SYSCONF_DIR/$confFile for writing\n");
40  fwrite($confFile_fh, ";fossology.conf for testing\n");
41  fwrite($confFile_fh, "[FOSSOLOGY]\nport = 24693\n");
42  fwrite($confFile_fh, "address = localhost\n");
43  fwrite($confFile_fh, "depth = 0\n");
44  fwrite($confFile_fh, "path = $SYSCONF_DIR\n");
45  fwrite($confFile_fh, "[HOSTS]\n");
46  fwrite($confFile_fh, "localhost = localhost AGENT_DIR 10\n");
47  fwrite($confFile_fh, "[REPOSITORY]\n");
48  fwrite($confFile_fh, "localhost = * 00 ff\n");
49  fwrite($confFile_fh, "[DIRECTORIES]\n");
50  fwrite($confFile_fh, "PROJECTUSER=fossy\n");
51  fwrite($confFile_fh, "PROJECTGROUP=fossy\n");
52  fwrite($confFile_fh, "MODDIR=$workingDir/../../..\n");
53  fwrite($confFile_fh, 'LIBEXECDIR=$MODDIR/../install/db' . "\n");
54  fwrite($confFile_fh, "LOGDIR=$SYSCONF_DIR\n");
55  fclose($confFile_fh);
56  symlink("$workingDir/../../../../VERSION", "$SYSCONF_DIR/VERSION");
57  mkdir("$SYSCONF_DIR/mods-enabled");
58  symlink($agentDir, "$SYSCONF_DIR/mods-enabled/$agent");
59 
60  $DB_COMMAND = "../../../testing/db/createTestDB.php -c $SYSCONF_DIR -e";
61 
62  exec($DB_COMMAND, $dbout, $rc);
63  if ($rc != 0) {
64  print "Can not create database for this testing sucessfully!\n";
65  exit;
66  }
67  preg_match("/(\d+)/", $dbout[0], $matches);
68  $test_name = $matches[1];
69  $db_conf = $dbout[0];
70  $version_array = parse_ini_file("$db_conf/VERSION");
71  $db_array = parse_ini_file("$db_conf/Db.conf");
72  $DB_NAME = $db_array["dbname"];
73  $db_user = $db_array["user"];
74  $db_pass = $db_array["password"];
75  $db_host = $db_array["host"];
76  $PG_CONN = pg_connect("host=$db_host port=5432 dbname=$DB_NAME user=$db_user password=$db_pass")
77  or die("Could not connect");
78 
79  if($agentTable == true) {
80  $sql = "CREATE TABLE agent (agent_pk serial, agent_name character varying(32), agent_rev character varying(32),"
81  . " agent_desc character varying(255) DEFAULT NULL, agent_enabled boolean DEFAULT true, agent_parms text,"
82  . " agent_ts timestamp with time zone DEFAULT now());";
83  $result = pg_query($PG_CONN, $sql);
84  pg_free_result($result);
85  $sql = "INSERT INTO agent(agent_name, agent_rev) VALUES('$agent','\"" . $version_array["VERSION"]
86  . "\"." . $version_array["COMMIT_HASH"] . "');";
87  $result = pg_query($PG_CONN, $sql);
88  pg_free_result($result);
89  }
90  return array($test_name, $db_conf, $DB_NAME, $PG_CONN);
91 }
92 ?>
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:44
Definition: db.php:41
fo_conf * conf
The loaded configuration data.
Definition: fo_cli.c:50
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN