2 # This script uses standard 8-space tabs with 4-space indents
3 # vi users can :set sw=4 ai sm
6 use vars qw( $verbose_p );
9 'verbose|v' => \$verbose_p,
13 ***************************************
14 * Welcome to the Koha Release Builder *
15 ***************************************
18 #----------------------------------------------------------
19 # To guess the version, we need to first guess where this
20 # script itself is Otherwise we will have different results
21 # depending on whether the script is called as ./buildrelease
22 # or misc/buildrelease. If we run the script from misc, we
23 # will also get errors from "cvs update" later, so this is
24 # rather important information
25 #----------------------------------------------------------
26 print STDERR "Perl reports that buildrelease is $0\n" if $verbose_p;
28 if ($0 =~ /^(\.\/)*buildrelease$/) {
29 $self_path = 'buildrelease';
30 } elsif ($0 =~ /^(?:(\.\/)*\/)?misc\/buildrelease$/) {
31 $self_path = 'misc/buildrelease';
35 WARNING: Unable to determine where the buildrelease script is located.
36 The version number guessed by the next step might be wrong.
38 $self_path = (-f 'buildrelease')? 'buildrelease': 'misc/buildrelease';
40 print STDERR "Assuming buildrelease is $self_path\n" if $verbose_p;
42 #----------------------------------------------------------
43 # Fixup the current directory
44 #----------------------------------------------------------
45 if ($self_path eq 'buildrelease') {
48 WARNING: You should run the buildrelease script from the top of the koha
49 CVS module. I will try to change to the correct directory, but
50 it is better if you had ran this script there in the first place.
52 chdir ".." || die "..: chdir: $!\n";
53 $self_path = 'misc/buildrelease';
56 #----------------------------------------------------------
57 # Start the release builder
58 #----------------------------------------------------------
59 #sub guess_kohahtmldir ($;$);
60 #----------------------------------------------------------
61 # DIRECTORIES where source code is located
62 #----------------------------------------------------------
65 #my $kohahtmldir=guess_kohahtmldir($kohadir, "/koha/koha/koha-html/");
66 my $roothomedir=(getpwuid(0))[7]; # ~root is traditionally just /
67 $roothomedir='/root' unless defined $roothomedir;
69 my $has_kohaautobuild_conf = 0;
71 if (-e "$roothomedir/.kohaautobuild.conf") {
72 print STDERR "$roothomedir/.kohaautobuild.conf found\n" if $verbose_p;
73 open C, "<$roothomedir/.kohaautobuild.conf";
79 # if (/kohahtmldir=(.*)/) {
83 $has_kohaautobuild_conf = 1;
89 This script will automatically build a release tarball.
91 The script assumes that you already have the koha and koha-html modules checked
92 out for the release that you want to build, although it will update the modules
95 print "\nWhere is the 'koha' cvs module located? [$kohadir]: ";
96 chomp($input = <STDIN>);
99 # unless ($has_kohaautobuild_conf) {
100 # $kohahtmldir=guess_kohahtmldir($kohadir, $kohahtmldir);
105 #print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
106 #chomp($input = <STDIN>);
108 # $kohahtmldir=$input;
111 open (C, ">$roothomedir/.kohaautobuild.conf");
114 #kohahtmldir=$kohahtmldir
116 print STDERR "$roothomedir/.kohaautobuild.conf written\n" if $verbose_p;
118 #----------------------------------------------------------
119 # which VERSION are we building ?
120 #----------------------------------------------------------
123 Guessing the next release version. You may need to enter your SourceForge password.
126 open (CVSLOG, "cvs log $self_path|");
127 my $symbolicnamessection=0;
135 if (/^symbolic names:/) {
136 $symbolicnamessection=1;
137 print STDERR "Scanning symbolic names from cvs output\n" if $verbose_p;
139 if ($symbolicnamessection && (/^\s+([^:]*):/)) {
141 if ($tag=~/(?:R|rel)_(.*)/) {
146 print STDERR "Found a tag for release $id\n" if $verbose_p;
147 if ($id =~/(.*)RC(.*)/) {
150 $version =~ /^(\d+\.\d+)(?:\.|[RC]|$)/;
151 if (versioncompare($version, $majorversion->{$1})) {
152 $majorversion->{$1}=$version;
153 $majorversionrc->{$1}=$rc;
154 print STDERR "Setting major version for $1 to $version $rc\n" if $verbose_p;
156 if (versioncompare($version, $highestversion)) {
157 $highestversion=$version;
160 print STDERR "Setting highest version to $highestversion $highestrc\n" if $verbose_p;
164 $version =~ /^(\d+\.\d+)(?:\.|[RC]|$)/;
165 if (versioncompare($version, $majorversion->{$1})) {
166 $majorversion->{$1}=$version;
167 $majorversionrc->{$1}=0;
168 print STDERR "Setting major version for $1 to $version $rc\n" if $verbose_p;
170 if (versioncompare($version, $highestversion)) {
171 $highestversion=$version;
174 print STDERR "Setting highest version to $highestversion $highestrc\n" if $verbose_p;
177 $symbolicnames->{$version}->{$rc}=1;
178 print STDERR "Setting symbolic name mapping for version $version $rc to 1\n" if $verbose_p;
183 my $releaseversion='';
184 my $currentversion='';
186 my $cvs_entries_path = $self_path;
187 $cvs_entries_path =~ s/[^\/]+$/CVS\/Entries/;
188 print STDERR "Assuming CVS/Entries is $cvs_entries_path\n" if $verbose_p;
190 my $branchdata=`grep buildrelease $cvs_entries_path`;
192 my $branch=(split(m#/#, $branchdata))[5];
194 $branch =~ s/^(?:R|rel)_//;
195 $branch =~ s/[-_]/./g;
196 print STDERR "Detected branch $branch\n" if $verbose_p;
198 if ($branch =~ /\S/ && defined $majorversion->{$branch}) {
199 $highestversion=$majorversion->{$branch};
200 $highestrc=$majorversionrc->{$branch};
201 ($highestrc) ? ($released=0) : ($released=1);
202 print STDERR "Using highest version for branch $branch\n" if $verbose_p;
206 my @components=split(/\./, $highestversion);
207 if (@components < 3) { # if it's something like just 2.2 or 2.4
208 $releaseversion = $highestversion.".1RC1";
210 $components[$#components]++;
211 $nexthighestversion=join '.', @components;
212 my $minornumber=(split(/\./, $highestversion))[1];
213 if ($minornumber/2 == int($minornumber/2)) {
214 $releaseversion=$nexthighestversion."RC1";
216 $releaseversion=$nexthighestversion;
219 $currentversion=$highestversion;
221 $releaseversion=$highestversion."RC".($highestrc+1);
222 $currentversion=$highestversion."RC$highestrc";
226 print "Current release tag is $currentversion.\n";
227 print "\nWould you like to bump that up to $releaseversion (or manually enter version)? [Y]/N: ";
228 chomp($input = <STDIN>);
229 my $tagging_needs_confirmation = 0;
230 if ($input =~ /^n/i) {
231 print "\nWould you like to rebuild the $currentversion tarball? Y/[N]: ";
232 chomp($input = <STDIN>);
233 if ($input =~ /^y/i) {
234 $releaseversion=$currentversion;
235 $tagging_needs_confirmation = 1;
237 print "What should the new version be? [$releaseversion]: ";
238 chomp ($input=<STDIN>);
240 $releaseversion=$input;
244 print "What should the new version be? [$releaseversion]: ";
245 chomp ($input=<STDIN>);
247 $releaseversion=$input;
252 print "\nWould you like to tag the CVS repository?\n(answer yes if releasing tarball) Y/[N]: ";
253 chomp ($input=<STDIN>);
258 print "The CVS repository ",($cvstag?"WILL BE TAGGED\n":"will not be tagged\n");
261 if ($cvstag && $tagging_needs_confirmation) {
263 print "Do not do this if you have released the tarball to anybody, as it will\n";
264 print "overwrite the tag marking the files that were in the tarball:\n\n";
265 print "Confirm that you want to overwrite the tag for $releaseversion? Y/[N]: ";
266 chomp($input = <STDIN>);
267 if ($input =~ /^n/i || $input !~ /\S/) {
268 print "\nStopping. Please re-run buildrelease now.\n";
275 if ($cvsroot=$ENV{'CVSROOT'}) {
276 $cvsroot=~m#(.*)\@cvs#;
279 $ENV{'CVS_RSH'}='ssh';
280 print "\nWhat is your userid at SourceForge: ";
281 chomp($input = <STDIN>);
285 $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
287 my $tagname=$releaseversion;
291 Updating your checked-out copy of the 'koha' CVS files.
292 You may need to enter your SourceForge password.
295 chdir($kohadir) || die "$kohadir: $!\n";
296 # system("cvs update -P");
299 Tagging koha with tag R_$tagname
301 system("cvs tag -F R_$tagname");
304 #----------------------------------------------------------
305 # MOVE files to /tmp and build tar.gz
306 #----------------------------------------------------------
308 my $rootdir="/tmp/koha-".$releaseversion;
309 system("rm -rf $rootdir");
310 mkdir ($rootdir, 0700);
311 chdir($rootdir) || die "$rootdir: $!\n";
313 mkdir("intranet-cgi", 0755);
314 mkdir("intranet-html", 0755);
315 mkdir("opac-cgi", 0755);
316 mkdir("opac-html", 0755);
317 mkdir("scripts", 0755);
318 mkdir("scripts/z3950daemon", 0755);
319 mkdir("modules", 0755);
322 # Create koha.version file
323 open (KV, ">$rootdir/koha.version");
324 print KV "$releaseversion\n";
327 # Copy all CVS files to intranet-cgi
328 # FIXME: "cp -a" is GNU-ism. It is not portable.
329 system("cp -a $kohadir/* $rootdir/intranet-cgi");
331 # Move C4 to modules directory
332 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
334 # Move files from intranet-cgi to root of tarball
335 system("mv $rootdir/intranet-cgi/misc/info/* $rootdir");
336 system("mv $rootdir/intranet-cgi/misc/installer.pl $rootdir");
337 system("mv $rootdir/intranet-cgi/misc/koha.upgrade $rootdir");
338 system("mv $rootdir/intranet-cgi/misc/Install.pm $rootdir");
339 #system("mv $rootdir/intranet-cgi/kohareporter $rootdir"); # does not exist ??
340 chmod 0770, "$rootdir/installer.pl";
341 chmod 0770, "$rootdir/koha.upgrade";
342 system("mv $rootdir/intranet-cgi/misc/koha.conf $rootdir");
343 system("mv $rootdir/intranet-cgi/misc/koha.mysql $rootdir");
344 system("mv $rootdir/intranet-cgi/misc/sampledata-1.2 $rootdir");
345 system("gzip -9 $rootdir/sampledata-1.2");
347 # Copy files from intranet-cgi to opac-cgi
348 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
349 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
350 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
351 system("cp $rootdir/intranet-cgi/subjectsearch.pl $rootdir/opac-cgi");
352 system("cp $rootdir/intranet-cgi/logout.pl $rootdir/opac-cgi");
353 system("mv $rootdir/intranet-cgi/opac/* $rootdir/opac-cgi");
354 system("rmdir $rootdir/intranet-cgi/opac");
357 # Move files from intranet-cgi to /scripts/ directory
358 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
359 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
361 # move only batch & daemon. pl script stay here
362 system("mv $rootdir/intranet-cgi/z3950/processz3950queue $rootdir/scripts/z3950daemon/");
363 system("mv $rootdir/intranet-cgi/z3950/*.sh $rootdir/scripts/z3950daemon/");
365 # Remove extraneous files from intranet-cgi
366 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
367 system("rm -f $rootdir/intranet-cgi/SendMessages");
368 system("rm -f $rootdir/intranet-cgi/buildrelease");
369 system("rm -rf $rootdir/intranet-cgi/t");
371 # Set all .pl scripts executable
372 system("find $rootdir/intranet-cgi -name '*.pl' -exec chmod a+x \\{\\} \\;");
373 # Copy all CVS files to intranet-html and opac-html
374 # FIXME: "cp -a" is GNU-ism. It is not portable.
375 #system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
376 #system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
378 # Copy koha-tmpl files
379 # FIXME: "cp -a" is GNU-ism. It is not portable.
380 system('cp', '-a', "$rootdir/intranet-cgi/koha-tmpl/opac-tmpl", "$rootdir/opac-html");
381 system('cp', '-a', "$rootdir/intranet-cgi/koha-tmpl/intranet-tmpl", "$rootdir/intranet-html");
382 #copy index files (they are just redirections to main.pl)
383 system("cp $rootdir/intranet-cgi/koha-tmpl/opac.html $rootdir/opac-html/index.html");
384 system("cp $rootdir/intranet-cgi/koha-tmpl/intranet.html $rootdir/intranet-html/index.html");
385 system('rm', '-rf', "$rootdir/intranet-cgi/koha-tmpl");
387 # Remove junk from directory
388 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
389 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
390 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
393 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
394 system("rm -rf $rootdir");
401 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
406 # Given two version numbers (v1, v2), returns 0 if v1 <= v2, or 1 if v1 > v2
410 my @v1=split(/\./, $v1);
411 my @v2=split(/\./, $v2);
413 ($#v2>$count) && ($count=$#v2);
414 for (my $index=0; $index<$count; $index++) {
415 if ($v1[$index]>$v2[$index]) {
422 #sub guess_kohahtmldir ($;$) {
423 # my($kohadir, $default) = @_;
425 # It probably makes sense to assume that the 'koha' and 'koha-html'
426 # modules are checked out within the same parent directory
427 # if (-d $kohadir && $kohadir =~ /^(.*)\/[^\/]+$/) {
428 # $kohahtmldir = "$1/koha-html"
430 # $kohahtmldir = $default;
432 # return $kohahtmldir;