last modif for 1.3.2 release
[koha.git] / misc / buildrelease
1 #!/usr/bin/perl
2
3 sub guess_kohahtmldir ($;$);
4 #----------------------------------------------------------
5 # DIRECTORIES where source code is located
6 #----------------------------------------------------------
7 my $kohadir=`pwd`;
8 chomp $kohadir;
9 my $kohahtmldir=guess_kohahtmldir($kohadir, "/koha/koha/koha-html/");
10 my $roothomedir=(getpwuid(0))[7];       # ~root is traditionally just /
11 $roothomedir='/root' unless defined $roothomedir;
12
13 my $has_kohaautobuild_conf = 0;
14
15 if (-e "$roothomedir/.kohaautobuild.conf") {
16     open C, "<$roothomedir/.kohaautobuild.conf";
17     while (<C>) {
18         chomp;
19         if (/kohadir=(.*)/) {
20             $kohadir=$1;
21         }
22         if (/kohahtmldir=(.*)/) {
23             $kohahtmldir=$1;
24         }
25     }
26     $has_kohaautobuild_conf = 1;
27 }
28
29 my $input;
30
31 print qq |
32 ***************************************
33 * Welcome to the Koha Release Builder *
34 ***************************************
35
36 This script will automatically build a release tarball.
37
38 The script assumes that you already have the koha and koha-html modules checked
39 out for the release that you want to build, although it will update the modules
40 before building.
41
42 |;
43 print "\nWhere is the 'koha' cvs module located [$kohadir]: ";
44 chomp($input = <STDIN>);
45 if ($input) {
46     $kohadir=$input;
47     $kohahtmldir=guess_kohahtmldir($kohadir, $kohahtmldir) unless $has_kohaautobuild_conf;
48 }
49
50
51 print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
52 chomp($input = <STDIN>);
53 if ($input) {
54     $kohahtmldir=$input;
55 }
56
57 open (C, ">$roothomedir/.kohaautobuild.conf");
58 print C qq|
59 kohadir=$kohadir
60 kohahtmldir=$kohahtmldir
61 |;
62
63 #----------------------------------------------------------
64 # which VERSION are we building ?
65 #----------------------------------------------------------
66 print "\n\nGuessing at next release version.  You may need to enter your SourceForge password...\n";
67 open (CVSLOG, "cvs log buildrelease|");
68 my $symbolicnamessection=0;
69 my $symbolicnames;
70 my $highestversion;
71 my $highestrc;
72 my $released;
73 my $majorversion;
74 my $majorversionrc;
75 while (<CVSLOG>) {
76     if (/^symbolic names:/) {
77         $symbolicnamessection=1;
78     }
79     if ($symbolicnamessection && (/^\s+([^:]*):/)) {
80         my $tag=$1;
81         if ($tag=~/R_(.*)/) {
82             my $version='';
83             my $rc=0;
84             my $id=$1;
85             $id=~s/-/\./g;
86             if ($id =~/(.*)RC(.*)/) {
87                 $version=$1;
88                 $rc=$2;
89                 $version=~m#(\d+\.\d+)\.#;
90                 if (versioncompare($version, $majorversion->{$1})) {
91                     $majorversion->{$1}=$version;
92                     $majorversionrc->{$1}=$rc;
93                 }
94                 if (versioncompare($version, $highestversion)) {
95                     $highestversion=$version;
96                     $released=0;
97                     $highestrc=$rc;
98                 }
99             } else {
100                 $version=$id;
101                 $version=~m#(\d+\.\d+)\.#;
102                 if (versioncompare($version, $majorversion->{$1})) {
103                     $majorversion->{$1}=$version;
104                     $majorversionrc->{$1}=0;
105                 }
106                 if (versioncompare($version, $highestversion)) {
107                     $highestversion=$version;
108                     $released=1;
109                     $highestrc=0;
110                 }
111             }
112             $symbolicnames->{$version}->{$rc}=1;
113         }
114     }
115 }
116
117
118 my $releaseversion='';
119 my $currentversion='';
120
121 my $branchdata=`grep buildrelease CVS/Entries`;
122 chomp $branchdata;
123 my $branch=(split(m#/#, $branchdata))[5];
124
125 if ($branch eq 'Trel-1-2') {
126     $highestversion=$majorversion->{'1.2'};
127     $highestrc=$majorversionrc->{'1.2'};
128     ($highestrc) ? ($released=0) : ($released=1);
129 }
130
131 if ($released) {
132     my @components=split(/\./, $highestversion);
133     $components[$#components]++;
134     $nexthighestversion=join '.', @components;
135     my $minornumber=(split(/\./, $highestversion))[1];
136     if ($minornumber/2 == int($minornumber/2)) {
137         $releaseversion=$nexthighestversion."RC1";
138     } else {
139         $releaseversion=$nexthighestversion;
140     }
141     $currentversion=$highestversion;
142 } else {
143     $releaseversion=$highestversion."RC".($highestrc+1);
144     $currentversion=$highestversion."RC$highestrc";
145 }
146
147
148 print "Current release tag is $currentversion.\n";
149 print "\nWould you like to bump that up to $releaseversion (or manually enter version)?  [Y]/N: ";
150 chomp($input = <STDIN>);
151 my $tagging_needs_confirmation = 0;
152 if ($input =~ /^n/i) {
153     print "\nWould you like to rebuild the $currentversion tarball?  Y/[N]: ";
154     chomp($input = <STDIN>);
155     print STDERR "releaseversion=($releaseversion), currentversion=($currentversion)\n";#XXXZZZ
156     if ($input =~ /^y/i) {
157         $releaseversion=$currentversion;
158         $tagging_needs_confirmation = 1;
159     } else {
160         print "What should the new version be? [$releaseversion]: ";
161         chomp ($input=<STDIN>);
162         if ($input) {
163             $releaseversion=$input;
164         }
165     }
166 } else {
167     print "What should the new version be? [$releaseversion]: ";
168     chomp ($input=<STDIN>);
169     if ($input) {
170         $releaseversion=$input;
171     }
172 }
173
174
175 print "\nWould you like to tag the CVS repository?\n(answer yes if releasing tarball)  Y/[N]: ";
176 chomp ($input=<STDIN>);
177 my $cvstag=0;
178 # FIXME: This means anything other than n will tag; too dangerous?
179 if ($input=~/^y/i) {
180     $cvstag=1;
181 }
182
183
184 if ($cvstag && $tagging_needs_confirmation) {
185         print "\n\n";
186         print "Do not do this if you have released the tarball to anybody, as it will\n";
187         print "overwrite the tag marking the files that were in the tarball:\n\n";
188         print "Confirm that you want to overwrite the tag for $releaseversion? Y/[N]: ";
189         chomp($input = <STDIN>);
190         if ($input =~ /^n/i || $input !~ /\S/) {
191             print "\nStopping.  Please re-run buildrelease now.\n";
192             exit;
193         }
194 }
195
196
197 my $sfuserid='';
198 if ($cvsroot=$ENV{'CVSROOT'}) {
199     $cvsroot=~m#(.*)\@cvs#;
200     $sfuserid=$1;
201 } else {
202     $ENV{'CVS_RSH'}='ssh';
203     print "\nWhat is your userid at SourceForge: ";
204     chomp($input = <STDIN>);
205     if ($input) {
206         $sfuserid=$input;
207     }
208     $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
209 }
210 my $tagname=$releaseversion;
211 $tagname=~s/\./-/g;
212
213 print qq|
214 Updating your checked-out copy of the 'koha' CVS files.
215 You may need to enter your SourceForge password.
216 Using $kohadir.
217 |;
218 chdir($kohadir);
219 system("cvs update");
220 if ($cvstag) {
221     print qq|
222 Tagging koha with tag R_$tagname
223 |;
224     system("cvs tag -F R_$tagname");
225 }
226 print qq|
227 Updating your checked-out copy of the 'koha-html' CVS files.
228 You may need to enter your SourceForge password.
229 Using $kohahtmldir.
230 |;
231 chdir($kohahtmldir) || die "$kohahtmldir: $!\n";
232 system("cvs update");
233
234 if ($cvstag) {
235     print qq|
236 Tagging koha-html with tag R_$tagname
237 |;
238     system("cvs tag -F R_$tagname");
239 }
240
241 #----------------------------------------------------------
242 # MOVE files to /tmp and build tar.gz
243 #----------------------------------------------------------
244 my $rootdir="/tmp/koha-".$releaseversion;
245 system("rm -rf $rootdir");
246 mkdir ($rootdir, 0700);
247 chdir($rootdir) || die "$rootdir: $!\n";
248
249 mkdir("intranet-cgi", 0755);
250 mkdir("intranet-html", 0755);
251 mkdir("opac-cgi", 0755);
252 mkdir("opac-html", 0755);
253 mkdir("scripts", 0755);
254 mkdir("scripts/z3950daemon", 0755);
255 mkdir("modules", 0755);
256 mkdir("docs", 0755);
257
258 # Create koha.version file
259 open (KV, ">$rootdir/koha.version");
260 print KV "$releaseversion\n";
261 close KV;
262
263 # Copy all CVS files to intranet-cgi
264 system("cp -a $kohadir/* $rootdir/intranet-cgi");
265
266 # Move C4 to modules directory
267 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
268
269 # Move files from intranet-cgi to root of tarball
270 system("mv $rootdir/intranet-cgi/misc/info/* $rootdir");
271 system("mv $rootdir/intranet-cgi/misc/installer.pl $rootdir");
272 system("mv $rootdir/intranet-cgi/misc/koha.upgrade $rootdir");
273 #system("mv $rootdir/intranet-cgi/Install.pm $rootdir"); #does not exist ??
274 #system("mv $rootdir/intranet-cgi/kohareporter $rootdir"); # does not exist ??
275 chmod 0770, "$rootdir/installer.pl";
276 chmod 0770, "$rootdir/koha.upgrade";
277 system("mv $rootdir/intranet-cgi/misc/koha.conf $rootdir");
278 system("mv $rootdir/intranet-cgi/misc/koha.mysql $rootdir");
279 system("mv $rootdir/intranet-cgi/misc/sampledata-1.2 $rootdir");
280 system("gzip -9 $rootdir/sampledata-1.2");
281
282 # Copy files from intranet-cgi to opac-cgi
283 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
284 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
285 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
286 system("cp $rootdir/intranet-cgi/subjectsearch.pl $rootdir/opac-cgi");
287 system("cp $rootdir/intranet-cgi/logout.pl $rootdir/opac-cgi");
288 system("mv $rootdir/intranet-cgi/opac/* $rootdir/opac-cgi");
289 system("rmdir $rootdir/intranet-cgi/opac");
290
291
292 # Move files from intranet-cgi to /scripts/ directory
293 system("mv $rootdir/intranet-cgi/telnet $rootdir/scripts");
294 system("mv $rootdir/intranet-cgi/tkperl $rootdir/scripts");
295 system("mv $rootdir/intranet-cgi/translator $rootdir/scripts");
296 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
297 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
298 system("mv $rootdir/intranet-cgi/marc $rootdir/scripts");
299 system("mv $rootdir/intranet-cgi/misc/bulkmarcimport.pl $rootdir/scripts/z3950daemon/");
300 system("mv $rootdir/intranet-cgi/z3950/* $rootdir/scripts/z3950daemon/");
301
302
303 # Remove extraneous files from intranet-cgi
304 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
305 system("rm -f $rootdir/intranet-cgi/SendMessages");
306 system("rm -f $rootdir/intranet-cgi/buildrelease");
307 #system("rm -f $rootdir/intranet-cgi/database.mysql");
308 #system("rm -f $rootdir/intranet-cgi/installer-lite.pl");
309 # FIXME: The following two lines look suspicious
310 #system("rm -f $rootdir/intranet-cgi/koha-1.2.0.tar.gz");
311 #system("rm -f $rootdir/intranet-cgi/rel-1-2");
312 #system("rm -f $rootdir/intranet-cgi/testKoha.pl");
313 #system("rm -rf $rootdir/intranet-cgi/html-template");
314 system("rm -rf $rootdir/intranet-cgi/t");
315
316 # Set all .pl scripts executable
317 system("find $rootdir/intranet-cgi -name '*.pl' -exec chmod a+x \\{\\} \\;");
318 # Copy all CVS files to intranet-html and opac-html
319 system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
320 system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
321
322 # Move koha-tmpl files
323 #system("mv $rootdir/intranet-cgi/koha-tmpl/opac-tmpl/* $rootdir/opac-html");
324 #system("mv $rootdir/intranet-cgi/koha-tmpl/intranet-tmpl/* $rootdir/intranet-html");
325 #system("rm -rf $rootdir/intranet-cgi/koha-tmpl");
326
327 # Remove extraneous files from opac-html
328 system("rm -f $rootdir/opac-html/koha.mo");
329 system("rm -f $rootdir/opac-html/koha.pot");
330 system("rm -f $rootdir/opac-html/test");
331
332 # Remove extraneous files from intranet-html
333 system("rm -f $rootdir/intranet-html/koha.pot");
334 system("rm -f $rootdir/intranet-html/results.html");
335 system("rm -f $rootdir/intranet-html/test");
336
337 # Remove junk from directory
338 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
339 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
340 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
341
342
343 if (-e "$roothomedir/docs") {
344     print "Copying docs folder from $roothomedir/docs...";
345     system("cp -r $roothomedir/docs/* $rootdir/docs/");
346 } else {
347     print "I would have copied the docs from from $roothomedir/docs, but I couldn't find it.\n";
348     print "Press <ENTER> to continue...\n";
349     <STDIN>;
350 }
351
352 chdir("/tmp");
353 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
354 system("rm -rf $rootdir");
355
356 print qq|
357 ============
358 = ALL DONE =
359 ============
360
361 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
362
363 |;
364
365
366 sub versioncompare {
367     my $v1=shift;
368     my $v2=shift;
369     my @v1=split(/\./, $v1);
370     my @v2=split(/\./, $v2);
371     my $count=$#v1;
372     ($#v2>$count) && ($count=$#v2);
373     for (my $index=0; $index<$count; $index++) {
374         if ($v1[$index]>$v2[$index]) {
375             return 1;
376         }
377     }
378     return 0;
379 }
380
381 sub guess_kohahtmldir ($;$) {
382     my($kohadir, $default) = @_;
383     my $kohahtmldir;
384     # It probably makes sense to assume that the 'koha' and 'koha-html'
385     # modules are checked out within the same parent directory
386     if (-d $kohadir && $kohadir =~ /^(.*)\/[^\/]+$/) {
387         $kohahtmldir = "$1/koha-html"
388     } else {
389         $kohahtmldir = $default;
390     }
391     return $kohahtmldir;
392 }