1<?php 2/*********************************************************** 3 Copyright (C) 2011 Hewlett-Packard Development Company, L.P. 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 version 2 as published by the Free Software Foundation. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17***********************************************************/ 18 19/** 20 * \file bootstrap.php 21 * \brief Fossology system bootstrap 22 * This file may be DUPLICATED in any php utility that needs to 23 * bootstrap itself. 24 * 25 * @version "$Id$" 26 */ 27 28/** 29 * \brief Bootstrap the fossology test system 30 * - Determine SYSCONFDIR 31 * - parse fossology.conf 32 * 33 * The following precedence is used to resolve SYSCONFDIR: 34 * - $SYSCONFDIR path passed in 35 * - environment variable SYSCONFDIR 36 * - ./fossology.rc 37 * 38 * \return the $SysConf array of values. The first array dimension 39 * is the group, the second is the variable name. 40 * For example: 41 * - $SysConf[DIRECTORIES][MODDIR] => "/mymoduledir/ 42 * 43 * The global $SYSCONFDIR is also set for backward compatibility. 44 * 45 * \Note Since so many files expect directory paths that used to be in pathinclude.php 46 * to be global, this function will define the same globals (everything in the 47 * DIRECTORIES section of fossology.conf). 48 */ 49function bootstrap() 50{ 51 $TR = NULL; 52 if(!defined('TESTROOT')) 53 { 54 $TR = getenv('TESTROOT'); 55 if($TR = NULL ) 56 { 57 echo "FATAL! bootstrap cannot determine TESTROOT\n"; 58 } 59 60 } 61 $rcfile = TESTROOT. '/fossologyTest.rc'; 62 63 $sysconfdir = getenv('SYSCONFDIR'); 64 if ($sysconfdir === false) 65 { 66 if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile); 67 if ($sysconfdir === false) 68 { 69 /* NO SYSCONFDIR specified */ 70 $text = _("FATAL: System Configuration Error, no SYSCONFDIR."); 71 echo "<hr><h3>$text</h3><hr>"; 72 exit(1); 73 } 74 } 75 76 $sysconfdir = trim($sysconfdir); 77 $GLOBALS['SYSCONFDIR'] = $sysconfdir; 78 79 /************* Parse fossology.conf *******************/ 80 $ConfFile = "{$sysconfdir}/fossology.conf"; 81 $SysConf = parse_ini_file($ConfFile, true); 82 83 /* evaluate all the DIRECTORIES group for variable substitutions. 84 * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we 85 * want BINDIR=/usr/local/bin 86 */ 87 foreach($SysConf['DIRECTORIES'] as $var=>$assign) 88 { 89 /* Evaluate the individual variables because they may be referenced 90 * in subsequent assignments. 91 */ 92 $toeval = "\$$var = \"$assign\";"; 93 eval($toeval); 94 95 /* now reassign the array value with the evaluated result */ 96 $SysConf['DIRECTORIES'][$var] = ${$var}; 97 $GLOBALS[$var] = ${$var}; 98 } 99 100 if (empty($MODDIR)) 101 { 102 $text = _("FATAL: System initialization failure: MODDIR not defined in fossology.conf"); 103 echo $text. "\n"; 104 exit; 105 } 106 return $SysConf; 107} 108?> 109