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