22 if (!function_exists(
'resolve_config_value')) {
23 function resolve_config_value($value, array $scope)
25 return preg_replace_callback(
'/\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})/',
static function ($matches) use ($scope) {
26 $name = !empty($matches[1]) ? $matches[1] : $matches[2];
27 return array_key_exists($name, $scope) ? $scope[$name] : $matches[0];
35 $rcfile =
"fossology.rc";
36 $varfile = dirname(__DIR__).
'/variable.list';
37 $sysconfdir = getenv(
'SYSCONFDIR');
38 if ((
false===$sysconfdir) && file_exists($rcfile))
40 $sysconfdir = file_get_contents($rcfile);
42 if ((
false===$sysconfdir) && file_exists($varfile))
44 $ini_array = parse_ini_file($varfile);
45 if($ini_array!==
false && array_key_exists(
'SYSCONFDIR', $ini_array))
47 $sysconfdir = $ini_array[
'SYSCONFDIR'];
50 if (
false===$sysconfdir)
52 $text = _(
"FATAL! System Configuration Error, no SYSCONFDIR.");
78 if (empty($sysconfdir))
81 echo
"assuming SYSCONFDIR=$sysconfdir\n";
84 $sysconfdir =
trim($sysconfdir);
85 $GLOBALS[
'SYSCONFDIR'] = $sysconfdir;
88 $ConfFile =
"{$sysconfdir}/fossology.conf";
89 if (!file_exists($ConfFile))
91 $text = _(
"FATAL! Missing configuration file: $ConfFile");
95 $SysConf = parse_ini_file($ConfFile,
true);
96 if ($SysConf ===
false)
98 $text = _(
"FATAL! Invalid configuration file: $ConfFile");
107 $resolvedValues = array();
108 foreach($SysConf[
'DIRECTORIES'] as $var=>$assign)
110 $resolvedValue = resolve_config_value($assign, $resolvedValues);
111 $resolvedValues[$var] = $resolvedValue;
114 $SysConf[
'DIRECTORIES'][$var] = $resolvedValue;
115 ${$var} = $resolvedValue;
116 $GLOBALS[$var] = $resolvedValue;
121 $text = _(
"FATAL! System initialization failure: MODDIR not defined in $SysConf");
127 require_once(
"$MODDIR/lib/php/common.php");
128 require_once(
"$MODDIR/lib/php/Plugin/FO_Plugin.php");
143 return trim(shell_exec(
'bash -c ' .
144 escapeshellarg(
'fossstdin=' . escapeshellarg($default) .
145 ';read -t ' . ((
int)$seconds) .
' fossstdin;echo "$fossstdin"')));
char * trim(char *ptext)
Trimming whitespace.
bootstrap($sysconfdir="")
Determine SYSCONFDIR, parse fossology.conf.
readlineTimeout($seconds, $default)
Using bash's read command, read input from STDIN.
if(!function_exists('resolve_config_value')) guessSysconfdir()