FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
Install.php
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  ***********************************************************/
35 /* Check for Super User */
36 $euid = posix_getuid();
37 if($euid != 0) {
38  print "Error, this script must be run as root\n";
39  exit(1);
40 }
41 
49 function installST() {
50  $here = getcwd();
51  if (is_readable('/etc/fossology/Proxy.conf')) {
52  print "Using proxy found in file /etc/fossology/Proxy.conf\n";
53  $cmd = ". /etc/fossology/Proxy.conf;" .
54  "wget -nv -t 1 'http://downloads.sourceforge.net/simpletest/simpletest_1.0.1.tar.gz'";
55  }
56  else if (is_readable('/usr/local/etc/fossology/Proxy.conf')) {
57  print "Using proxy found in file /usr/local/etc/fossology/Proxy.conf\n";
58  $cmd = ". /usr/local/etc/fossology/Proxy.conf;" .
59  "wget -nv -t 1 'http://downloads.sourceforge.net/simpletest/simpletest_1.0.1.tar.gz'";
60  }
61  else {
62  print "No proxy used when attempting to download simpletest\n";
63  $cmd = "wget -nv -t 1 'http://downloads.sourceforge.net/simpletest/simpletest_1.0.1.tar.gz'";
64  }
65  if(chdir('/usr/local/')) {
66  $wLast = exec($cmd, $wgetOut, $rtn);
67  if($rtn == 0) { // download worked
68  $tar = 'tar -xf simpletest_1.0.1.tar.gz';
69  $tLast = exec($tar, $tout, $rtn);
70  if(is_readable('/usr/local/simpletest')) {
71  /* clean up, try to remove the downloaded archive, */
72  $rl = exec('rm simpletest_1.0.1.tar.gz', $toss, $notchecked);
73  chdir($here);
74  return(TRUE); // un tar worked, installed.
75  }
76  else {
77  print "ERROR! failed to un-tar simpletest into /usr/local\n";
78  print "tar output was:$tLast\n";print_r($tout) . "\n";
79  print "Investigate and install simpletest into /usr/local then rerun this script\n";
80  return(FALSE);
81  }
82  }
83  else {
84  print "ERROR! problem with downloading simpletest with wget, need a proxy?\n";
85  print "wget output was:$wLast\n";print_r($wgetOut) . "\n";
86  print "Investigate and install simpletest into /usr/local then rerun this script\n";
87  return(FALSE);
88  }
89  }
90  else {
91  print "ERROR! cannot cd to /usr/local\n";
92  print "Investigate and install simpletest into /usr/local then rerun this script\n";
93  return(FALSE);
94  }
95  chdir('$here'); // should never get here, but cd back just in case....
96  return(FALSE);
97 }
98 
99 /* Create sym link to fo-runTests, the code below doesn't work well. Just remove
100  * what is found and replace....
101  */
102 $OK = array();
103 print "installing fo-runTests into /usr/local/bin\n";
104 $wd = getcwd();
105 $cmd = "ln -s $wd/fo-runTests.php /usr/local/bin/fo-runTests 2>&1";
106 $last = exec($cmd, $tossme, $rtn);
107 if($rtn != 0) {
108  $OK = preg_grep('/File exists/', $tossme);
109  if(empty($OK)) {
110  print "Error, could not create sym link in /usr/local/bin for fo-runTests\n";
111  exit(1);
112  }
113  else { // link exists, remove and recreate
114  $rm = 'rm /usr/local/bin/fo-runTests';
115  $last = exec($rm, $tossme, $rtn);
116  if($rtn != 0) {
117  print "Error, could not remove /usr/local/bin/fo-runTests\n";
118  print "Remove by hand and remake the symbolic link to the appropriate test source\n";
119  exit(1);
120  }
121  $last = exec($cmd, $tossme, $rtn);
122  if($rtn != 0) {
123  print "Error, could not create sym link in /usr/local/bin for fo-runTests\n";
124  print "Investigate and remake the symbolic link to the appropriate test source\n";
125  exit(1);
126  }
127  }
128 }
129 
130 /* Make sure simpletest is installed, if not, install it. */
131 print "Check to see if simpletest is installed in /usr/local\n";
132 
133 if(!is_readable('/usr/local/simpletest')) {
134  print "Attempting to download and install simpletest into /usr/local\n";
135  $ok = installST();
136  if(!$ok) {
137  print "FATAL ERROR!, install simpletest into /usr/local, then rerun this script\n";
138  exit(1);
139  }
140 }
141 
142 /*
143  * Create the db user and system users,
144  */
145 if(!is_executable("./makeDbUser")) {
146  if(!chmod("./makeDbUser",0755)) {
147  print "FATAL, could not make ./makeDbUser executable\n";
148  exit(1);
149  }
150 }
151 $last = exec("./makeDbUser",$tossme, $rtn);
152 if($rtn != 0) {
153  print "makeDbUser Failed, Investigate, run by hand\n";
154 }
155 
156 print "Creating fosstester and noemail users\n";
157 if(!is_executable("./CreateTestUser.sh")) {
158  if(!chmod("./CreateTestUser.sh",0755)) {
159  print "FATAL, could not make ./CreateTestUser.sh executable\n";
160  exit(1);
161  }
162 }
163 $last = exec("./CreateTestUser.sh",$tossme, $rtn);
164 if($rtn != 0) {
165  print "CreateTestUser.sh Failed, Investigate, run by hand\n";
166 }
167 
168 /* load data into fosstester account */
169 print "loading test data into the fosstester home directory\n";
170 $last = exec("./installTestData.sh",$tossme, $rtn);
171 
172 foreach($tossme as $line){
173  print "$line\n";
174 }
175 
176 $Tconfig = getcwd();
177 print "adjusting servers file in .subversion so checkouts work\n";
178 if(chdir('/home/fosstester/.subversion') === TRUE) {
179  if(!copy('servers.hp', 'servers')) {
180  print "Warning! could not adjust servers file, may not be able to check out sources\n";
181  }
182 }
183 
184 if(chdir($Tconfig) === FALSE){
185  print "Warning! cannot cd to $Tconfig, the next steps may fail\n";
186 }
187 /*
188  * Create the UI users for the tests
189  */
190 print "Creating UI test users fosstester and noemail\n";
191 // fix this... should get the host name and domain and use that....
192 $last = exec("./configTestEnv.php 'http://localhost/repo/' fossy fossy",$tossme, $rtn);
193 if($rtn != 0) {
194  print "./configTestEnv.php Failed for fossy, Investigate\n";
195 }
196 $last = exec("./fo-runTests.php -l 'createUIUsers.php'",$tossme, $rtn);
197 if($rtn != 0) {
198  print "./createUIUsers Failed!, Investigate\n";
199 }
200 $last = exec("./configTestEnv.php 'http://localhost/repo/' fosstester fosstester",$tossme, $rtn);
201 if($rtn != 0) {
202  print "./configTestEnv.php Failed for fosstester, Investigate\n";
203 }
204 /* Remove the symlink in /usr/local/bin for fo-runTests it will get reestablished
205  * when fosstester user configures.
206  */
207 echo "Removing fo-runtests link in /usr/local/bin/\n";
208 $last = exec('sudo rm /usr/local/bin/fo-runTests', $tossme, $rtn);
209 echo "Creating fo-runtests link in /usr/local/bin/\n";
210 $last = exec("ln -s fo-runtests.php /usr/local/bin/fo-runtests",$tossme, $rtn);
211 if($rtn != 0) {
212  print "FATAL! Could create fo-runtests link, Investigate and create by hand\n";
213 }
214 ?>