FOSSology  4.4.0
Open Source License Compliance by Open Source Software
checkTestData.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 
21 $home = getcwd();
22 echo "DB: at the start.... home is:$home\n";
23 $dirs = explode('/',$home);
24 $size = count($dirs);
25 // are we being run by jenkins? if we are not in fossology/tests, cd there
26 if($dirs[$size-1] == 'workspace' )
27 {
28  if(chdir('fossology/src/testing') === FALSE)
29  {
30  echo "FATAL! Cannot cd to fossology/src/testing from" . getcwd() . "\n";
31  exit(1);
32  }
33  $home = getcwd(); // home should now be ...workspace/fossology/src/testing
34 }
35 echo "DB: home is:$home\n";
36 
37 $redHatPath = 'nomos/testdata';
38 $unpackTestFile = '../../ununpack/agent_tests/test-data/testdata4unpack/argmatch.c.gz';
39 $unpackTests = '../../ununpack/agent_tests';
40 $redHatDataFile = 'RedHat.tar.gz';
41 $unpackDataFile = 'unpack-test-data.tar.bz2';
42 $wgetOptions = ' -a wget.log --tries=3 ';
43 $proxy = 'export http_proxy=lart.usa.hp.com:3128;';
44 $Url = 'http://fossology.org/testing/testFiles/';
45 
46 $errors = 0;
47 // check/install RedHat.tar.gz
48 
49 /*
50 if(!file_exists($redHatPath . "/" . $redHatDataFile))
51 {
52  if(chdir($redHatPath) === FALSE)
53  {
54  echo "ERROR! could not cd to $redHatPath, cannot download $redHatDataFile\n";
55  $errors++;
56  }
57  $cmd = $proxy . "wget" . $wgetOptions . $Url . $redHatDataFile;
58  $last = exec($cmd, $wgetOut, $wgetRtn);
59  if($wgetRtn != 0)
60  {
61  echo "ERROR! Download of $Url$redHatDataFile failed\n";
62  echo "Errors were:\n$last\n";print_r($wgetOut) . "\n";
63  $errors++;
64  }
65 }
66 else
67 
68 if(chdir($home) === FALSE)
69 {
70  echo "FATAL! could not cd to $home\n";
71  exit(1);
72 }
73 */
74 
75 // check/install ununpack data
76 echo "downloading unpack data.....\n";
77 if(!file_exists($unpackTestFile))
78 {
79  echo "$unpackTestFile DOES NOT EXIST!, need to download data files...\n";
80  if(chdir($unpackTests) === FALSE)
81  {
82  echo "FATAL! cannot cd to $unpackTests\n";
83  exit(1);
84  }
85  $cmd = $proxy . "wget" . $wgetOptions . $Url . '/' . $unpackDataFile;
86  $unpkLast = exec($cmd, $unpkOut, $unpkRtn);
87  if($unpkRtn != 0)
88  {
89  echo "ERROR! Download of $Url$unpackDataFile failed:$unpkRtn\n";
90  echo "Errors were:\n";print_r($unpkOut) . "\n";
91  $errors++;
92  }
93  // unpack the tar file.
94  $cmd = "tar -xf $unpackDataFile";
95  $tarLast = exec($cmd, $tarOut, $tarRtn);
96  if($tarRtn != 0)
97  {
98  echo "ERROR! un tar of $unpackDataFile failed\n";
99  echo "Errors were:\n$tarLast\n";print_r($tarOut) . "\n";
100  $errors++;
101  }
102 }
103 
104 if($errors)
105 {
106  exit(1);
107 }
108 exit(0);