forked from fossology/fossology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fo_dbcheck.php
executable file
·186 lines (160 loc) · 5.31 KB
/
fo_dbcheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/php
<?php
/***********************************************************
Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************/
/**
* @file fo_dbcheck.php
* @brief Check that you can connect to the db.
*
* @exit 0 for success, 1 for failure.
**/
/* Initialize the program configuration variables */
$SysConf = array(); // fo system configuration variables
$PG_CONN = 0; // Database connection
$Plugins = array();
/* Note: php 5 getopt() ignores options not specified in the function call, so add
* dummy options in order to catch invalid options.
*/
$AllPossibleOpts = "abc:defghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
/* defaults */
$Verbose = false;
$DatabaseName = "fossology";
$UpdateLiceneseRef = false;
$sysconfdir = '';
/* command-line options */
$Options = getopt($AllPossibleOpts);
foreach($Options as $Option => $OptVal)
{
switch($Option)
{
case 'c': /* set SYSCONFIDR */
$sysconfdir = $OptVal;
break;
default:
echo "Invalid Option \"$Option\".\n";
Usage();
}
}
/* Set SYSCONFDIR and set global (for backward compatibility) */
$SysConf = bootstrap($sysconfdir);
/* Initialize global system configuration variables $SysConfig[] */
ConfigInit($SYSCONFDIR, $SysConf);
$rv = DBconnect($sysconfdir, "", false);
if ($rv === false) exit(1);
exit(0);
/** \brief Print Usage statement.
* \return No return, this calls exit.
**/
function Usage()
{
global $argv;
$usage = "Usage: " . basename($argv[0]) . " [options]
Update FOSSology database. Options are:
-c fossology system configuration directory
-h this help usage";
print "$usage\n";
exit(0);
}
/************************************************/
/****** From src/lib/php/bootstrap.php ********/
/** Included here so that fossinit can run from any directory **/
/**
* \brief Bootstrap the fossology php library.
* - Determine SYSCONFDIR
* - parse fossology.conf
* - source template (require_once template-plugin.php)
* - source common files (require_once common.php)
*
* The following precedence is used to resolve SYSCONFDIR:
* - $SYSCONFDIR path passed in ($sysconfdir)
* - environment variable SYSCONFDIR
* - ./fossology.rc
*
* Any errors are fatal. A text message will be printed followed by an exit(1)
*
* \param $sysconfdir Typically from the caller's -c command line parameter
*
* \return the $SysConf array of values. The first array dimension
* is the group, the second is the variable name.
* For example:
* - $SysConf[DIRECTORIES][MODDIR] => "/mymoduledir/
*
* The global $SYSCONFDIR is also set for backward compatibility.
*
* \Note Since so many files expect directory paths that used to be in pathinclude.php
* to be global, this function will define the same globals (everything in the
* DIRECTORIES section of fossology.conf).
*/
function bootstrap($sysconfdir="")
{
$rcfile = "fossology.rc";
if (empty($sysconfdir))
{
$sysconfdir = getenv('SYSCONFDIR');
if ($sysconfdir === false)
{
if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
if ($sysconfdir === false)
{
/* NO SYSCONFDIR specified */
$text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
echo "$text\n";
exit(1);
}
}
}
$sysconfdir = trim($sysconfdir);
$GLOBALS['SYSCONFDIR'] = $sysconfdir;
/************* Parse fossology.conf *******************/
$ConfFile = "{$sysconfdir}/fossology.conf";
if (!file_exists($ConfFile))
{
$text = _("FATAL! Missing configuration file: $ConfFile");
echo "$text\n";
exit(1);
}
$SysConf = parse_ini_file($ConfFile, true);
if ($SysConf === false)
{
$text = _("FATAL! Invalid configuration file: $ConfFile");
echo "$text\n";
exit(1);
}
/* evaluate all the DIRECTORIES group for variable substitutions.
* For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
* want BINDIR=/usr/local/bin
*/
foreach($SysConf['DIRECTORIES'] as $var=>$assign)
{
/* Evaluate the individual variables because they may be referenced
* in subsequent assignments.
*/
$toeval = "\$$var = \"$assign\";";
eval($toeval);
/* now reassign the array value with the evaluated result */
$SysConf['DIRECTORIES'][$var] = ${$var};
$GLOBALS[$var] = ${$var};
}
if (empty($MODDIR))
{
$text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
echo $text. "\n";
exit(1);
}
//require("i18n.php"); DISABLED until i18n infrastructure is set-up.
//require_once("$MODDIR/www/ui/template/template-plugin.php"); DISABLED as don't needed
require_once("$MODDIR/lib/php/common.php");
return $SysConf;
}
?>