FOSSology  4.4.0
Open Source License Compliance by Open Source Software
checkConfig.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
26 $usage = "$argv[0], -h -o -s <srcpath>
27  -h: help
28  -o: overwrite existing config file
29  -s: path to alternate source\n";
30 
31 $configFile = 'TestEnvironment.php';
32 $overWrite = FALSE;
33 
34 $options = getopt('hos:');
35 
36 if (array_key_exists('h', $options)) {
37  print "$usage\n";
38  exit(0);
39 }
40 if (array_key_exists('o', $options)) {
41  $overWrite = TRUE;
42 }
43 if (array_key_exists('s', $options)) {
44  $sourcePath = $options['s'];
45 }
46 
47 // don't bother checking if file exists, just overwrite it.
48 if($overWrite)
49 {
50  echo "overwritting file\n";
51  $cconfig = callConfig();
52  if(!$cconfig)
53  {
54  exit(1); // fatal errors printed by callConfig
55  }
56  exit(0);
57 }
58 if(file_exists($configFile))
59 {
60  echo "file exists, exiting\n";
61  exit(0);
62 }
63 else
64 {
65  echo "file does not exist, creating...\n";
66  $exists = callConfig();
67  if(!$exists)
68  {
69  exit(1); // fatal errors printed by callConfig
70  }
71 }
72 exit(0);
73 
83 function callConfig($sourcePath=NULL)
84 {
85 
86  // default path
87  if(empty($sourcePath))
88  {
89  $sourcePath = '.';
90  }
91  // get fully qualified hostname
92  // assume /repo
93  $last = exec('hostname -f', $out, $rtn);
94  if($rtn != 0)
95  {
96  echo "Fatal, could not get fully qalified hostname, cannot create config file.\n";
97  echo "Error was\n";
98  print_r($out) . "\n";
99  return(FALSE);
100  }
101 
102  $fossology = 'http://' . $last . '/repo/';
103  $user = 'fossy';
104  $pw = 'fossy';
105 
106  $cmd = $sourcePath . "/configTestEnv.php $fossology $user $pw 2>&1";
107  $lastConfig = exec($cmd, $configOut, $rtn);
108  //echo "last is:$lastConfig, out is:\n";print_r($configOut) . "\n";
109  if($rtn != 0)
110  {
111  echo "Fatal, configTestEnv failed!, Error was:\n$lastConfig\n";
112  print_r($configOut) . "\n";
113  return(FALSE);
114  }
115  return(TRUE);
116 }