FOSSology  4.4.0
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  SPDX-FileCopyrightText: © 2013 Hewlett-Packard Development Company, L.P.
5  SPDX-FileCopyrightText: © 2015 Siemens AG
6 
7  SPDX-License-Identifier: GPL-2.0-only
8 */
9 
17 /* Initialize the program configuration variables */
18 $PG_CONN = 0; // Database connection
19 $Plugins = array();
20 
21 /* defaults */
22 $Verbose = false;
23 $DatabaseName = "fossology";
24 $UpdateLiceneseRef = false;
25 $sysconfdir = '/usr/local/etc/fossology';
26 
27 /* Set SYSCONFDIR and set global (for backward compatibility) */
28 $SysConf = bootstrap($sysconfdir);
29 $projectGroup = $SysConf['DIRECTORIES']['PROJECTGROUP'] ?: 'fossy';
30 $gInfo = posix_getgrnam($projectGroup);
31 posix_setgid($gInfo['gid']);
32 $groups = `groups`;
33 if (!preg_match("/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo['gid']))
34 {
35  print "FATAL: You must be in group '$projectGroup' to update the FOSSology database.\n";
36  exit(1);
37 }
38 
39 // don't think we want all the other common libs
40 require_once("$MODDIR/lib/php/common.php");
41 /* Initialize global system configuration variables $SysConfig[] */
42 ConfigInit($SYSCONFDIR, $SysConf);
43 
44 /* migration */
45 require_once("./dbmigrate_2.1-2.2.php");
46 print "Migrate data from 2.1 to 2.2 \n";
47 Migrate_21_22($Verbose);
48 
49 exit(0);
50 
51 
52 /************************************************/
53 /****** From src/lib/php/bootstrap.php ********/
82 function bootstrap($sysconfdir="")
83 {
84  $rcfile = "fossology.rc";
85 
86  if (empty($sysconfdir))
87  {
88  $sysconfdir = getenv('SYSCONFDIR');
89  if ($sysconfdir === false)
90  {
91  if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
92  if ($sysconfdir === false)
93  {
94  /* NO SYSCONFDIR specified */
95  $text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
96  echo "$text\n";
97  exit(1);
98  }
99  }
100  }
101 
102  $sysconfdir = trim($sysconfdir);
103  $GLOBALS['SYSCONFDIR'] = $sysconfdir;
104 
105  /************* Parse fossology.conf *******************/
106  $ConfFile = "{$sysconfdir}/fossology.conf";
107  if (!file_exists($ConfFile))
108  {
109  $text = _("FATAL! Missing configuration file: $ConfFile");
110  echo "$text\n";
111  exit(1);
112  }
113  $SysConf = parse_ini_file($ConfFile, true);
114  if ($SysConf === false)
115  {
116  $text = _("FATAL! Invalid configuration file: $ConfFile");
117  echo "$text\n";
118  exit(1);
119  }
120 
121  /* evaluate all the DIRECTORIES group for variable substitutions.
122  * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
123  * want BINDIR=/usr/local/bin
124  */
125  foreach($SysConf['DIRECTORIES'] as $var=>$assign)
126  {
127  /* Evaluate the individual variables because they may be referenced
128  * in subsequent assignments.
129  */
130  $toeval = "\$$var = \"$assign\";";
131  eval($toeval);
132 
133  /* now reassign the array value with the evaluated result */
134  $SysConf['DIRECTORIES'][$var] = ${$var};
135  $GLOBALS[$var] = ${$var};
136  }
137 
138  if (empty($MODDIR))
139  {
140  $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
141  echo $text. "\n";
142  exit(1);
143  }
144 
145  //require("i18n.php"); DISABLED until i18n infrastructure is set-up.
146  require_once("$MODDIR/www/ui/template/template-plugin.php");
147  require_once("$MODDIR/lib/php/common.php");
148  return $SysConf;
149 }
ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().
Migrate_21_22($Verbose)
Create new groups, group_user_member, perm_upload and perm_folder records to support 2....
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:82