FOSSology  4.4.0
Open Source License Compliance by Open Source Software
runBuild_v2.0.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011-2012 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 /**************************************************************
10  runBuild v2.0
11 
12  Script to create packages use Project-Builder.
13 
14  --------------------------------------------------------------------
15  NOTE: This script is _HIGHLY_ customized for the internal fossology
16  team's package build environment. It is _EXTREMELY UNLIKELY_
17  that it will work outside of this environment. If you would
18  like to build packages for FOSSology, it is not hard, and
19  we would greatly welcome your contributions, but this script
20  is probably not the place to start!!!
21  --------------------------------------------------------------------
22 
23  \return 0 for success, 1 for failure.
24  *************************************************************/
25 global $Version;
26 global $Trunk;
27 $VMS = array(
28  'rhel-6-i386',
29  'rhel-6-x86_64',
30 # 'fedora-15-i386',
31 # 'fedora-15-x86_64',
32  'debian-6.0-i386',
33  'debian-6.0-x86_64',
34  'debian-7.0-i386',
35  'debian-7.0-x86_64',
36 # 'ubuntu-11.10-i386',
37 # 'ubuntu-11.10-x86_64',
38 # 'ubuntu-11.04-i386',
39 # 'ubuntu-11.04-x86_64',
40 # 'ubuntu-10.04-i386',
41 # 'ubuntu-10.04-x86_64',
42  'fedora-17-i386',
43  'fedora-17-x86_64',
44  'ubuntu-12.04-i386',
45  'ubuntu-12.04-x86_64',
46  'ubuntu-12.10-i386',
47  'ubuntu-12.10-x86_64',
48  'fedora-18-i386',
49  'fedora-18-x86_64'
50 );
51 //$VMS = NULL;
52 $Usage = "Usage: " . basename($argv[0]) . " [options]
53  Options:
54  -h = this help message
55  -v = enable verbose debugging
56  -V = version to create packages for
57  -t = create packages from trunk
58  ";
59 $Verbose = 0;
60 
61 for ($i = 1;$i < $argc;$i++) {
62  switch ($argv[$i]) {
63  case '-v':
64  $Verbose++;
65  break;
66  case '-h':
67  case '-?':
68  print $Usage . "\n";
69  return (0);
70  case '-V':
71  $i++;
72  $Version = escapeshellarg($argv[$i]);
73  break;
74  case '-t':
75  $Trunk = 1;
76  break;
77  default:
78  if (substr($argv[$i], 0, 1) == '-') {
79  print "Unknown parameter: '" . $argv[$i] . "'\n";
80  print $Usage . "\n";
81  exit(1);
82  }
83  break;
84  } /* switch */
85  } /* for each parameter */
86 
87  if (empty($Version)) {
88  $Version = "2.2.0";
89  }
90 
91  /* Create new version of fossology project */
92  $Cmd = "pb -p fossology -r $Version newproj fossology";
93  if ($Verbose) {
94  print "CMD=$Cmd\n";
95  }
96  system($Cmd);
97 
98  /* Update project-builder conf files */
99  $Cmd = "rm -rf /home/build/pb/projects/fossology/pbconf/$Version/*";
100  if ($Verbose) {
101  print "CMD=$Cmd\n";
102  }
103  system($Cmd);
104  system("rm -rf /home/build/pb/projects/fossology/pbconf/$Version/.svn");
105  system("cd /home/build/pb/projects/fossology/pbconf/$Version/");
106  if ($Trunk) {
107  $Cmd = "svn co http://svn.code.sf.net/p/fossology/code/trunk/fossology/packaging/ /home/build/pb/projects/fossology/pbconf/$Version/";
108  } else {
109  $Cmd = "svn co http://svn.code.sf.net/p/fossology/code/tags/2.2.0/packaging/ /home/build/pb/projects/fossology/pbconf/$Version/";
110  }
111  if ($Verbose) {
112  print "CMD=$Cmd\n";
113  }
114  system($Cmd);
115  system("mkdir /home/build/pb/projects/fossology/pbconf/$Version/fossology");
116  system("mv /home/build/pb/projects/fossology/pbconf/$Version/deb /home/build/pb/projects/fossology/pbconf/$Version/rpm /home/build/pb/projects/fossology/pbconf/$Version/pbcl /home/build/pb/projects/fossology/pbconf/$Version/fossology");
117 
118  /* Checkout source code for build */
119  $Cmd = "pb -p fossology -r $Version sbx2build";
120  if ($Verbose) {
121  print "CMD=$Cmd\n";
122  }
123 
124  /* if exist source code, svn update */
125  if (file_exists("/home/build/pb/projects/fossology/$Version/")){
126  system("rm /home/build/pb/projects/fossology/$Version/Makefile.conf");
127  system("svn update /home/build/pb/projects/fossology/$Version/");
128  }
129  //system("perl -pi -e 's/#pbconfurl/pbconfurl/' /home/build/.pbrc");
130  //system("perl -pi -e 's/1.4.1~rc1\//1.4.1~rc1/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
131  // prevnt annoying warnings from date() by setting the timezone
132  date_default_timezone_set('America/Denver');
133  $showtime = date("Ymd");
134  if ($Trunk){
135  //$showtime = date("Ymd");
136  system("perl -pi -e 's/\/var\/ftp\/pub\/fossology/\/var\/ftp\/pub\/fossology\/$Version\/testing\/$showtime/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
137  system("perl -pi -e 's/code\/trunk\/fossology\//code\/trunk\/fossology/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
138  system("perl -pi -e 's/projver fossology = trunk/projver fossology = $Version/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
139  system("perl -pi -e 's/trunk/$Version~$showtime/' /home/build/pb/projects/fossology/pbconf/$Version/fossology/deb/changelog");
140  } else {
141  system("perl -pi -e 's/$Version\//$Version/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
142  system("perl -pi -e 's/\/var\/ftp\/pub\/fossology/\/var\/ftp\/pub\/fossology\/$Version/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
143  system("perl -pi -e 's/projver fossology = trunk/projver fossology = $Version/' /home/build/pb/projects/fossology/pbconf/$Version/fossology.pb");
144  }
145  system($Cmd);
146  //system("perl -pi -e 's/pbconfurl/#pbconfurl/' /home/build/.pbrc");
147 //exit;
148  /* Build packages from VMs */
149  foreach ($VMS as $VM) {
150  $Cmd = "pb -p fossology -r $Version -m $VM build2vm";
151  if ($Verbose) {
152  print "CMD=$Cmd\n";
153  }
154  system($Cmd);
155  system("sleep 10");
156  }
157 
158  /* update dataFiles */
159  if ($Trunk){
160  system("perl -pi -e 's/^(deb.*debian\/)/deb = \"deb http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/testing\/$showtime\/debian\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/debian.ini");
161  system("perl -pi -e 's/^(deb.*ubuntu\/)/deb = \"deb http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/testing\/$showtime\/ubuntu\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/ubuntu.ini");
162  system("perl -pi -e 's/^(yum.*rhel\/)/yum = \"http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/testing\/$showtime\/rhel\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/redhat.ini");
163  system("perl -pi -e 's/^(yum.*fedora\/15\/)/yum = \"http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/testing\/$showtime\/fedora\/15\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/fedora.ini");
164  } else {
165  system("perl -pi -e 's/^(deb.*debian\/)/deb = \"deb http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/debian\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/debian.ini");
166  system("perl -pi -e 's/^(deb.*ubuntu\/)/deb = \"deb http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/ubuntu\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/ubuntu.ini");
167  system("perl -pi -e 's/^(yum.*rhel\/)/yum = \"http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/rhel\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/redhat.ini");
168  system("perl -pi -e 's/^(yum.*fedora\/15\/)/yum = \"http:\/\/fossbuild.usa.hp.com\/fossology\/$Version\/fedora\/15\//' /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/fedora.ini");
169  }
170 
171  // update a copy of the current packages on the build machine
172  // in /var/ftp/pub/ called 'current', so that it includes the
173  // packages we have just built
174  // Note: A symlink would make more sense here, but the vsftpd
175  // FTP server does not allow symbolic links.
176  $ftp_base = "/var/ftp/pub/fossology/$Version/testing";
177  // first delete any existing directory called 'current'
178  $command = "sudo rm -rf $ftp_base/current";
179  exec($command);
180  // then re-create the 'current' directory with a copy of
181  // the latest package directory
182  $command = "sudo cp -R $ftp_base/$showtime/ $ftp_base/current";
183  exec($command);
184 
185 
186 # temporarily disable this commit since we should really not be
187 # making svn commits from within test code (not a good practice)
188 # but I don't fully grok why it's doing this; might someday be
189 # useful but let's skip it for now
190 # system("svn commit /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/debian.ini /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/ubuntu.ini /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/redhat.ini /home/build/pb/fossology/trunk/fossology/src/testing/dataFiles/pkginstall/fedora.ini -m 'New $Version changes to conf files for package testing'");
191  return (0);