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