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