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