FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fo_dbcheck.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
16 /* Initialize the program configuration variables */
17 $SysConf = array(); // fo system configuration variables
18 $PG_CONN = 0; // Database connection
19 $Plugins = array();
20 
21 /* Note: php 5 getopt() ignores options not specified in the function call, so add
22  * dummy options in order to catch invalid options.
23  */
24 $AllPossibleOpts = "abc:defghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
25 
26 /* defaults */
27 $Verbose = false;
28 $DatabaseName = "fossology";
29 $UpdateLiceneseRef = false;
30 $sysconfdir = '';
31 
32 /* command-line options */
33 $Options = getopt($AllPossibleOpts);
34 foreach($Options as $Option => $OptVal)
35 {
36  switch($Option)
37  {
38  case 'c': /* set SYSCONFIDR */
39  $sysconfdir = $OptVal;
40  break;
41  default:
42  echo "Invalid Option \"$Option\".\n";
43  Usage();
44  }
45 }
46 
47 /* Set SYSCONFDIR and set global (for backward compatibility) */
48 $SysConf = bootstrap($sysconfdir);
49 
50 /* Initialize global system configuration variables $SysConfig[] */
51 ConfigInit($SYSCONFDIR, $SysConf);
52 
53 $rv = DBconnect($sysconfdir, "", false);
54 
55 if ($rv === false) exit(1);
56 
57 exit(0);
58 
59 
63 function Usage()
64 {
65  global $argv;
66 
67  $usage = "Usage: " . basename($argv[0]) . " [options]
68  Update FOSSology database. Options are:
69  -c fossology system configuration directory
70  -h this help usage";
71  print "$usage\n";
72  exit(0);
73 }
74 
75 
76 /************************************************/
77 /****** From src/lib/php/bootstrap.php ********/
106 function bootstrap($sysconfdir="")
107 {
108  $rcfile = "fossology.rc";
109 
110  if (empty($sysconfdir))
111  {
112  $sysconfdir = getenv('SYSCONFDIR');
113  if ($sysconfdir === false)
114  {
115  if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
116  if ($sysconfdir === false)
117  {
118  /* NO SYSCONFDIR specified */
119  $text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
120  echo "$text\n";
121  exit(1);
122  }
123  }
124  }
125 
126  $sysconfdir = trim($sysconfdir);
127  $GLOBALS['SYSCONFDIR'] = $sysconfdir;
128 
129  /************* Parse fossology.conf *******************/
130  $ConfFile = "{$sysconfdir}/fossology.conf";
131  if (!file_exists($ConfFile))
132  {
133  $text = _("FATAL! Missing configuration file: $ConfFile");
134  echo "$text\n";
135  exit(1);
136  }
137  $SysConf = parse_ini_file($ConfFile, true);
138  if ($SysConf === false)
139  {
140  $text = _("FATAL! Invalid configuration file: $ConfFile");
141  echo "$text\n";
142  exit(1);
143  }
144 
145  /* evaluate all the DIRECTORIES group for variable substitutions.
146  * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
147  * want BINDIR=/usr/local/bin
148  */
149  foreach($SysConf['DIRECTORIES'] as $var=>$assign)
150  {
151  /* Evaluate the individual variables because they may be referenced
152  * in subsequent assignments.
153  */
154  $toeval = "\$$var = \"$assign\";";
155  eval($toeval);
156 
157  /* now reassign the array value with the evaluated result */
158  $SysConf['DIRECTORIES'][$var] = ${$var};
159  $GLOBALS[$var] = ${$var};
160  }
161 
162  if (empty($MODDIR))
163  {
164  $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
165  echo $text. "\n";
166  exit(1);
167  }
168 
169  //require("i18n.php"); DISABLED until i18n infrastructure is set-up.
170  //require_once("$MODDIR/www/ui/template/template-plugin.php"); DISABLED as don't needed
171  require_once("$MODDIR/lib/php/common.php");
172  return $SysConf;
173 }
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
Definition: common-db.php:33
ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: fo_dbcheck.php:106
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:63
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN