1#!/usr/bin/php
2<?php
3/***********************************************************
4 Copyright (C) 2008 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
20/**
21 * changeENV.php
22 *
23 * change the test environment file.
24 *
25 * @param string -s $subject the subject string to change
26 * @param string -c $change the string to change the subject to.
27 *
28 * @return 0 for OK, 1 for failure
29 */
30
31$argv = array();
32$opts = array();
33
34print "changeENV starting....\n";
35$opts = getopt('hc:');
36//print "changeENV: opts is:\n";print_r($opts) . "\n";
37$Usage = "{$argv[0]}: [-h] -c <change-string>\n";
38
39if (empty($opts)) {
40  print $Usage;
41  exit(1);
42}
43
44if (array_key_exists("h",$opts)) {
45  print $Usage;
46  exit(0);
47}
48/*
49   Only required option, get it and check it
50 */
51if (array_key_exists("c",$opts)) {
52  $change2 = $opts['c'];
53  if(!strlen($change2)) {
54    print $Usage;
55    exit(1);
56  }
57}
58else {
59  print $Usage;
60  exit(1);
61}
62
63$testEnv = '../../../tests/TestEnvironment.php';
64
65$sedLine = "sed -e \"1,$ s/USER=.*/USER='$change2';/\" ".
66               "-e \"1,$ s/WORD=.*/WORD='$change2';/\" $testEnv
67               ";
68$changed = exec($sedLine, $out, $rtn);
69//print "output is:\n";print_r($out) . "\n";
70
71$FH = fopen($testEnv, 'w') or die("Can't open $testEnv\n $phpErrorMsg");
72foreach ($out as $line) {
73  if(FALSE === fwrite($FH, "$line\n")) {
74    print "FATAL! cannot wite to $testEnv\n";
75    exit(1);
76  }
77}
78fclose($FH);
79exit(0);
80?>