FOSSology  4.4.0
Open Source License Compliance by Open Source Software
changeENV.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
20 $argv = array();
21 $opts = array();
22 
23 print "changeENV starting....\n";
24 $opts = getopt('hc:');
25 //print "changeENV: opts is:\n";print_r($opts) . "\n";
26 $Usage = "{$argv[0]}: [-h] -c <change-string>\n";
27 
28 if (empty($opts)) {
29  print $Usage;
30  exit(1);
31 }
32 
33 if (array_key_exists("h",$opts)) {
34  print $Usage;
35  exit(0);
36 }
37 /*
38  Only required option, get it and check it
39  */
40 if (array_key_exists("c",$opts)) {
41  $change2 = $opts['c'];
42  if(!strlen($change2)) {
43  print $Usage;
44  exit(1);
45  }
46 }
47 else {
48  print $Usage;
49  exit(1);
50 }
51 
52 $testEnv = '../../../tests/TestEnvironment.php';
53 
54 $sedLine = "sed -e \"1,$ s/USER=.*/USER='$change2';/\" ".
55  "-e \"1,$ s/WORD=.*/WORD='$change2';/\" $testEnv
56  ";
57 $changed = exec($sedLine, $out, $rtn);
58 //print "output is:\n";print_r($out) . "\n";
59 
60 $FH = fopen($testEnv, 'w') or die("Can't open $testEnv\n $phpErrorMsg");
61 foreach ($out as $line) {
62  if(FALSE === fwrite($FH, "$line\n")) {
63  print "FATAL! cannot wite to $testEnv\n";
64  exit(1);
65  }
66 }
67 fclose($FH);
68 exit(0);