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