FOSSology  4.4.0
Open Source License Compliance by Open Source Software
get-fsrc.php
1 #!/usr/bin/php
2 <?php
3 /*
4  get-fsrc.php
5  SPDX-FileCopyrightText: © 2007 Hewlett-Packard Development Company, L.P.
6 
7  SPDX-License-Identifier: GPL-2.0-only
8 */
9 
25 /*
26  * Steps:
27  * 1. establish cvs root in the environment
28  * -> Make sure that set -o noclobber is set in environment.
29  * 2. cd to destination
30  * 3. cvs co
31  * 4. filter for dead packages or packages with no .spec files
32  * - skip processing them, and use a file in the current directory to store them.
33  * 5. make prep for each package.
34  *
35  */
36 
37 // FIXME: $path = '/usr/local/fossology/agents';
38 set_include_path(get_include_path() . PATH_SEPARATOR . $path);
39 
40 require_once("FIXMETOBERELATIVE/pathinclude.php");
41 global $WEBDIR;
42 require_once("$WEBDIR/common/common-cli.php");
43 
44 $usage = "get-fsrc [-h] -s <skip-path> -o <output-path>\n";
45 
46 /*
47  *
48  <<< USAGE
49 
50 Where:
51 -h standard help, usage message.
52 
53 -o output-path path where sources will be checked out, the packages will
54  be checked out into a directory call devel.
55 -s skip-path path were list of dead packages and other skipped packages
56  will be stored.
57  Note is it ALWAYS a good idea to run this script using screen and to
58  capture stdout and stderr into a log file.
59 
60 USAGE;
61 */
62 
63 $options = getopt("ho:s:");
64 //print_r($options);
65 if (empty($options))
66  {
67  echo $usage;
68  exit(1);
69  }
70 if (array_key_exists("h",$options))
71  {
72  echo $usage;
73  exit(0);
74  }
75 if (array_key_exists("o",$options))
76  {
77  $fedora = $options['o'];
78  if (empty($fedora))
79  {
80  echo $usage;
81  exit(1);
82  }
83  }
84  if (array_key_exists("s",$options))
85  {
86  $spath = $options['s'];
87  if (empty($spath))
88  {
89  $spath = '/tmp/skipped.fedora9.pkgs';
90  print "NOTE: setting the path for skipped file to /tmp/skipped.fedora9.pkgs\n";
91  }
92  else
93  {
94  // defect here, should check to see if there is a trailing /....
95  $spath .= '/skipped.fedora9.pkgs';
96  }
97  }
98 
99 
100 chdir($fedora) or die("Can't chdir to $fedora, $php_errormsg\n");
101 
102 $date=`date`;
103 echo "Starting at: $date\n";
104 
105 // checkout and filter
106 $checked_out = cvs_co($fedora);
107 if(!empty($checked_out))
108 {
109  print($checked_out);
110 }
111 // need to check for trailing / and then do the right thing....add
112 // later
113 $devel = "$fedora" . '/devel';
114 chdir($devel) or die("Can't chdir to $fedora, $php_errormsg\n");
115 
116 $list = array();
117 
118 $last = exec('ls', $list, $rtn);
119 if ($rtn != 0)
120 {
121  print "Error, cannot get list of packages with ls\n";
122  exit(1);
123 }
124 
125 // Filter and make
126 foreach($list as $pkg){
127  // wrinkle.... common package does not have a devel, need to special
128  // case it.
129  rtrim($pkg);
130  //cli_PrintDebugMessage("\$pkg is:$pkg");
131  $dir = `pwd`;
132  print "Now at:$dir";
133  if(!(chdir("$pkg"))){
134  echo "ERROR: Can't chdir to $pkg, skipping: $php_errormsg\n";
135  continue;
136  }
137  $plist=`ls`;
138 
139  if (preg_match('/dead.package/', $plist)){
140  echo "$pkg is a dead.package, skipping\n";
141  $saved = save_skipped($spath, "$pkg is a dead package\n");
142  if(!empty($saved))
143  {
144  print "Warning! ";
145  print($saved);
146  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
147  continue;
148  }
149  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
150  }
151  elseif (!(preg_match('/.spec/', $plist)))
152  {
153  echo "$pkg has no spec file, skipping\n";
154  $saved = save_skipped($spath, "$pkg has no spec file\n");
155  if(!empty($saved))
156  {
157  print "Warning! ";
158  print($saved);
159  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
160  continue;
161  }
162  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
163  }
164  else{
165  $dir = `pwd`;
166  $date = `date`;
167  print "Now at:$dir";
168  print "on $date";
169  echo "Making $pkg\n";
170  $mpcmd = "alias rm='rm -f'; make prep > make-prep.out 2>&1";
171  $last = exec("$mpcmd", $mpout, $rtn);
172  if($rtn != 0) {
173  print "ERROR: make prep for $pkg did not exit zero: return was: $rtn\n\n";
174  $saved = save_skipped($spath, "$pkg failed make prep, return code was: $rtn\n");
175  if(!empty($saved))
176  {
177  print "Warning! ";
178  print($saved);
179  }
180  }
181  // put the removeal of the make.out here....as else clause...
182  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
183  }
184  // look for and remove the compressed file... look at older scripts.
185  echo "-----\n\n";
186 }
187 
188 $date=`date`;
189 print "Ending at: $date";
190 
201 function cvs_co($fedora){
202 
203  // make sure cvs root is set
204  $cmd = 'export CVSROOT=:pserver:anonymous@cvs.fedoraproject.org:/cvs/pkgs; '
205  . 'cvs co -r HEAD devel';
206 
207  chdir($fedora) or die("Can't chdir to $fedora, $php_errormsg\n");
208  $last = exec("$cmd", $cvs_co_out, $retval);
209  if ($retval != 0){
210  return("ERROR: cvs co did not return zero status: $retval\n");
211  }
212  return NULL;
213 }
214 
215 function save_skipped ($path, $message)
216 {
217  global $WEBDIR;
218  require_once("$WEBDIR/common/common-cli.php");
219  // save the message containing the package name that failed in a file at $path
220 
221  $logged = cli_logger($path, $message);
222  if(!empty($logged))
223  {
224  return($logged);
225  }
226  return(NULL);
227 }
cli_logger($handle, $message, $mode='a')
Write/append a message to the log handle passed in.
Definition: common-cli.php:63
if(! $Test && $OptionQ) if($stdin_flag) if($Verbose) else
Definition: cp2foss.php:552