FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
createRC.php
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 // first try the environment
29 // second look for a source install
30 // third look for a package install
31 // give up and error out.
32 
33 // @todo who uses the rc file?
34 
35 $sysconf = NULL;
36 
37 if(!defined('TESTROOT'))
38 {
39  $path = __DIR__;
40  $plenth = strlen($path);
41  // remove /utils from the end.
42  $TESTROOT = substr($path, 0, $plenth-6);
43  $_ENV['TESTROOT'] = $TESTROOT;
44  putenv("TESTROOT=$TESTROOT");
45  define('TESTROOT',$TESTROOT);
46 }
47 
48 $sysconf = getenv('SYSCONFDIR');
49 if($sysconf === FALSE)
50 {
51  if(file_exists('/usr/local/etc/fossology'))
52  {
53  $sysconf = '/usr/local/etc/fossology';
54  }
55  else if(file_exists('/etc/fossology'))
56  {
57  $sysconf = '/etc/fossology';
58  }
59 }
60 if($sysconf === FALSE || $sysconf == NULL)
61 {
62  echo "FATAL! cannot determine where the fossology sysconfigdir is located\n";
63  exit(1);
64 }
65 $RC = fopen("fossology.rc", 'w');
66 if($RC === FALSE)
67 {
68  echo "FATAL! could not open fossology.rc for writting\n";
69  exit(1);
70 }
71 $many = fwrite($RC, $sysconf);
72 fclose($RC);
73 
74 // put in globals and export to environment.
75 echo "DBCRC: sysconf is:$sysconf\n";
76 echo "DBCRC: exporting sysconf to env and globals.\n";
77 $GLOBALS['SYSCONFDIR'] = $sysconf;
78 putenv("SYSCONFDIR={$GLOBALS['SYSCONFDIR']}");
79 $_ENV['SYSCONFDIR'] = $GLOBALS['SYSCONFDIR'];
80 
81 ?>