FOSSology  3.2.0rc1
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  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
28 /* Initialize the program configuration variables */
29 $SysConf = array(); // fo system configuration variables
30 $PG_CONN = 0; // Database connection
31 $Plugins = array();
32 
33 /* Note: php 5 getopt() ignores options not specified in the function call, so add
34  * dummy options in order to catch invalid options.
35  */
36 $AllPossibleOpts = "abc:defghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
37 
38 /* defaults */
39 $Verbose = false;
40 $DatabaseName = "fossology";
41 $UpdateLiceneseRef = false;
42 $sysconfdir = '';
43 
44 /* command-line options */
45 $Options = getopt($AllPossibleOpts);
46 foreach($Options as $Option => $OptVal)
47 {
48  switch($Option)
49  {
50  case 'c': /* set SYSCONFIDR */
51  $sysconfdir = $OptVal;
52  break;
53  default:
54  echo "Invalid Option \"$Option\".\n";
55  Usage();
56  }
57 }
58 
59 /* Set SYSCONFDIR and set global (for backward compatibility) */
60 $SysConf = bootstrap($sysconfdir);
61 
62 /* Initialize global system configuration variables $SysConfig[] */
63 ConfigInit($SYSCONFDIR, $SysConf);
64 
65 $rv = DBconnect($sysconfdir, "", false);
66 
67 if ($rv === false) exit(1);
68 
69 exit(0);
70 
71 
75 function Usage()
76 {
77  global $argv;
78 
79  $usage = "Usage: " . basename($argv[0]) . " [options]
80  Update FOSSology database. Options are:
81  -c fossology system configuration directory
82  -h this help usage";
83  print "$usage\n";
84  exit(0);
85 }
86 
87 
88 /************************************************/
89 /****** From src/lib/php/bootstrap.php ********/
118 function bootstrap($sysconfdir="")
119 {
120  $rcfile = "fossology.rc";
121 
122  if (empty($sysconfdir))
123  {
124  $sysconfdir = getenv('SYSCONFDIR');
125  if ($sysconfdir === false)
126  {
127  if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
128  if ($sysconfdir === false)
129  {
130  /* NO SYSCONFDIR specified */
131  $text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
132  echo "$text\n";
133  exit(1);
134  }
135  }
136  }
137 
138  $sysconfdir = trim($sysconfdir);
139  $GLOBALS['SYSCONFDIR'] = $sysconfdir;
140 
141  /************* Parse fossology.conf *******************/
142  $ConfFile = "{$sysconfdir}/fossology.conf";
143  if (!file_exists($ConfFile))
144  {
145  $text = _("FATAL! Missing configuration file: $ConfFile");
146  echo "$text\n";
147  exit(1);
148  }
149  $SysConf = parse_ini_file($ConfFile, true);
150  if ($SysConf === false)
151  {
152  $text = _("FATAL! Invalid configuration file: $ConfFile");
153  echo "$text\n";
154  exit(1);
155  }
156 
157  /* evaluate all the DIRECTORIES group for variable substitutions.
158  * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
159  * want BINDIR=/usr/local/bin
160  */
161  foreach($SysConf['DIRECTORIES'] as $var=>$assign)
162  {
163  /* Evaluate the individual variables because they may be referenced
164  * in subsequent assignments.
165  */
166  $toeval = "\$$var = \"$assign\";";
167  eval($toeval);
168 
169  /* now reassign the array value with the evaluated result */
170  $SysConf['DIRECTORIES'][$var] = ${$var};
171  $GLOBALS[$var] = ${$var};
172  }
173 
174  if (empty($MODDIR))
175  {
176  $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
177  echo $text. "\n";
178  exit(1);
179  }
180 
181  //require("i18n.php"); DISABLED until i18n infrastructure is set-up.
182  //require_once("$MODDIR/www/ui/template/template-plugin.php"); DISABLED as don't needed
183  require_once("$MODDIR/lib/php/common.php");
184  return $SysConf;
185 }
186 ?>
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:44
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: fo_dbcheck.php:118
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:75
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695