FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
checkConfig.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 
37 $usage = "$argv[0], -h -o -s <srcpath>
38  -h: help
39  -o: overwrite existing config file
40  -s: path to alternate source\n";
41 
42 $configFile = 'TestEnvironment.php';
43 $overWrite = FALSE;
44 
45 $options = getopt('hos:');
46 
47 if (array_key_exists('h', $options)) {
48  print "$usage\n";
49  exit(0);
50 }
51 if (array_key_exists('o', $options)) {
52  $overWrite = TRUE;
53 }
54 if (array_key_exists('s', $options)) {
55  $sourcePath = $options['s'];
56 }
57 
58 // don't bother checking if file exists, just overwrite it.
59 if($overWrite)
60 {
61  echo "overwritting file\n";
62  $cconfig = callConfig();
63  if(!$cconfig)
64  {
65  exit(1); // fatal errors printed by callConfig
66  }
67  exit(0);
68 }
69 if(file_exists($configFile))
70 {
71  echo "file exists, exiting\n";
72  exit(0);
73 }
74 else
75 {
76  echo "file does not exist, creating...\n";
77  $exists = callConfig();
78  if(!$exists)
79  {
80  exit(1); // fatal errors printed by callConfig
81  }
82 }
83 exit(0);
84 
94 function callConfig($sourcePath=NULL)
95 {
96 
97  // default path
98  if(empty($sourcePath))
99  {
100  $sourcePath = '.';
101  }
102  // get fully qualified hostname
103  // assume /repo
104  $last = exec('hostname -f', $out, $rtn);
105  if($rtn != 0)
106  {
107  echo "Fatal, could not get fully qalified hostname, cannot create config file.\n";
108  echo "Error was\n";
109  print_r($out) . "\n";
110  return(FALSE);
111  }
112 
113  $fossology = 'http://' . $last . '/repo/';
114  $user = 'fossy';
115  $pw = 'fossy';
116 
117  $cmd = $sourcePath . "/configTestEnv.php $fossology $user $pw 2>&1";
118  $lastConfig = exec($cmd, $configOut, $rtn);
119  //echo "last is:$lastConfig, out is:\n";print_r($configOut) . "\n";
120  if($rtn != 0)
121  {
122  echo "Fatal, configTestEnv failed!, Error was:\n$lastConfig\n";
123  print_r($configOut) . "\n";
124  return(FALSE);
125  }
126  return(TRUE);
127 }
128 ?>