FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
migratetest.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 /***********************************************************
4  Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
5  Copyright (C) 2015 Siemens AG
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  version 2 as published by the Free Software Foundation.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  ***********************************************************/
20 
28 /* Initialize the program configuration variables */
29 $PG_CONN = 0; // Database connection
30 $Plugins = array();
31 
32 /* defaults */
33 $Verbose = false;
34 $DatabaseName = "fossology";
35 $UpdateLiceneseRef = false;
36 $sysconfdir = '/usr/local/etc/fossology';
37 
38 /* Set SYSCONFDIR and set global (for backward compatibility) */
39 $SysConf = bootstrap($sysconfdir);
40 $projectGroup = $SysConf['DIRECTORIES']['PROJECTGROUP'] ?: 'fossy';
41 $gInfo = posix_getgrnam($projectGroup);
42 posix_setgid($gInfo['gid']);
43 $groups = `groups`;
44 if (!preg_match("/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo['gid']))
45 {
46  print "FATAL: You must be in group '$projectGroup' to update the FOSSology database.\n";
47  exit(1);
48 }
49 
50 // don't think we want all the other common libs
51 require_once("$MODDIR/lib/php/common.php");
52 /* Initialize global system configuration variables $SysConfig[] */
53 ConfigInit($SYSCONFDIR, $SysConf);
54 
55 /* migration */
56 require_once("./dbmigrate_2.1-2.2.php");
57 print "Migrate data from 2.1 to 2.2 \n";
58 Migrate_21_22($Verbose);
59 
60 exit(0);
61 
62 
63 /************************************************/
64 /****** From src/lib/php/bootstrap.php ********/
93 function bootstrap($sysconfdir="")
94 {
95  $rcfile = "fossology.rc";
96 
97  if (empty($sysconfdir))
98  {
99  $sysconfdir = getenv('SYSCONFDIR');
100  if ($sysconfdir === false)
101  {
102  if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
103  if ($sysconfdir === false)
104  {
105  /* NO SYSCONFDIR specified */
106  $text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
107  echo "$text\n";
108  exit(1);
109  }
110  }
111  }
112 
113  $sysconfdir = trim($sysconfdir);
114  $GLOBALS['SYSCONFDIR'] = $sysconfdir;
115 
116  /************* Parse fossology.conf *******************/
117  $ConfFile = "{$sysconfdir}/fossology.conf";
118  if (!file_exists($ConfFile))
119  {
120  $text = _("FATAL! Missing configuration file: $ConfFile");
121  echo "$text\n";
122  exit(1);
123  }
124  $SysConf = parse_ini_file($ConfFile, true);
125  if ($SysConf === false)
126  {
127  $text = _("FATAL! Invalid configuration file: $ConfFile");
128  echo "$text\n";
129  exit(1);
130  }
131 
132  /* evaluate all the DIRECTORIES group for variable substitutions.
133  * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
134  * want BINDIR=/usr/local/bin
135  */
136  foreach($SysConf['DIRECTORIES'] as $var=>$assign)
137  {
138  /* Evaluate the individual variables because they may be referenced
139  * in subsequent assignments.
140  */
141  $toeval = "\$$var = \"$assign\";";
142  eval($toeval);
143 
144  /* now reassign the array value with the evaluated result */
145  $SysConf['DIRECTORIES'][$var] = ${$var};
146  $GLOBALS[$var] = ${$var};
147  }
148 
149  if (empty($MODDIR))
150  {
151  $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
152  echo $text. "\n";
153  exit(1);
154  }
155 
156  //require("i18n.php"); DISABLED until i18n infrastructure is set-up.
157  require_once("$MODDIR/www/ui/template/template-plugin.php");
158  require_once("$MODDIR/lib/php/common.php");
159  return $SysConf;
160 }
Migrate_21_22($Verbose)
Create new groups, group_user_member, perm_upload and perm_folder records to support 2...
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:93
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695