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