1#!/usr/bin/php 2<?php 3/*********************************************************** 4 Copyright (C) 2013 Hewlett-Packard Development Company, L.P. 5 Copyright (C) 2015 Siemens AG 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 version 2 as published by the Free Software Foundation. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License along 17 with this program; if not, write to the Free Software Foundation, Inc., 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 ***********************************************************/ 20 21/** 22 * @file migratetest.php 23 * @brief Test migration function 24 * 25 * @return int 0 for success, 1 for failure. 26 **/ 27 28/* Initialize the program configuration variables */ 29$PG_CONN = 0; // Database connection 30$Plugins = array(); 31 32/* defaults */ 33$Verbose = false; 34$DatabaseName = "fossology"; 35$UpdateLiceneseRef = false; 36$sysconfdir = '/usr/local/etc/fossology'; 37 38/* Set SYSCONFDIR and set global (for backward compatibility) */ 39$SysConf = bootstrap($sysconfdir); 40$projectGroup = $SysConf['DIRECTORIES']['PROJECTGROUP'] ?: 'fossy'; 41$gInfo = posix_getgrnam($projectGroup); 42posix_setgid($gInfo['gid']); 43$groups = `groups`; 44if (!preg_match("/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo['gid'])) 45{ 46 print "FATAL: You must be in group '$projectGroup' to update the FOSSology database.\n"; 47 exit(1); 48} 49 50// don't think we want all the other common libs 51require_once("$MODDIR/lib/php/common.php"); 52/* Initialize global system configuration variables $SysConfig[] */ 53ConfigInit($SYSCONFDIR, $SysConf); 54 55/* migration */ 56require_once("./dbmigrate_2.1-2.2.php"); 57print "Migrate data from 2.1 to 2.2 \n"; 58Migrate_21_22($Verbose); 59 60exit(0); 61 62 63/************************************************/ 64/****** From src/lib/php/bootstrap.php ********/ 65/** Included here so that fossinit can run from any directory **/ 66/** 67 * \brief Bootstrap the fossology php library. 68 * - Determine SYSCONFDIR 69 * - parse fossology.conf 70 * - source template (require_once template-plugin.php) 71 * - source common files (require_once common.php) 72 * 73 * The following precedence is used to resolve SYSCONFDIR: 74 * - $SYSCONFDIR path passed in ($sysconfdir) 75 * - environment variable SYSCONFDIR 76 * - ./fossology.rc 77 * 78 * Any errors are fatal. A text message will be printed followed by an exit(1) 79 * 80 * \param string $sysconfdir Typically from the caller's -c command line parameter 81 * 82 * \return mixed the $SysConf array of values. The first array dimension 83 * is the group, the second is the variable name. 84 * For example: 85 * - $SysConf[DIRECTORIES][MODDIR] => "/mymoduledir/ 86 * 87 * The global $SYSCONFDIR is also set for backward compatibility. 88 * 89 * \Note Since so many files expect directory paths that used to be in pathinclude.php 90 * to be global, this function will define the same globals (everything in the 91 * DIRECTORIES section of fossology.conf). 92 */ 93function bootstrap($sysconfdir="") 94{ 95 $rcfile = "fossology.rc"; 96 97 if (empty($sysconfdir)) 98 { 99 $sysconfdir = getenv('SYSCONFDIR'); 100 if ($sysconfdir === false) 101 { 102 if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile); 103 if ($sysconfdir === false) 104 { 105 /* NO SYSCONFDIR specified */ 106 $text = _("FATAL! System Configuration Error, no SYSCONFDIR."); 107 echo "$text\n"; 108 exit(1); 109 } 110 } 111 } 112 113 $sysconfdir = trim($sysconfdir); 114 $GLOBALS['SYSCONFDIR'] = $sysconfdir; 115 116 /************* Parse fossology.conf *******************/ 117 $ConfFile = "{$sysconfdir}/fossology.conf"; 118 if (!file_exists($ConfFile)) 119 { 120 $text = _("FATAL! Missing configuration file: $ConfFile"); 121 echo "$text\n"; 122 exit(1); 123 } 124 $SysConf = parse_ini_file($ConfFile, true); 125 if ($SysConf === false) 126 { 127 $text = _("FATAL! Invalid configuration file: $ConfFile"); 128 echo "$text\n"; 129 exit(1); 130 } 131 132 /* evaluate all the DIRECTORIES group for variable substitutions. 133 * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we 134 * want BINDIR=/usr/local/bin 135 */ 136 foreach($SysConf['DIRECTORIES'] as $var=>$assign) 137 { 138 /* Evaluate the individual variables because they may be referenced 139 * in subsequent assignments. 140 */ 141 $toeval = "\$$var = \"$assign\";"; 142 eval($toeval); 143 144 /* now reassign the array value with the evaluated result */ 145 $SysConf['DIRECTORIES'][$var] = ${$var}; 146 $GLOBALS[$var] = ${$var}; 147 } 148 149 if (empty($MODDIR)) 150 { 151 $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf"); 152 echo $text. "\n"; 153 exit(1); 154 } 155 156 //require("i18n.php"); DISABLED until i18n infrastructure is set-up. 157 require_once("$MODDIR/www/ui/template/template-plugin.php"); 158 require_once("$MODDIR/lib/php/common.php"); 159 return $SysConf; 160} 161