*** 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 $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 chdir $kohadir;
70 open (CVSLOG, "cvs log misc/buildrelease|");
71 my $symbolicnamessection=0;
72 my $symbolicnames;
73 my $highestversion;
74 my $highestrc;
75 my $released;
76 my $majorversion;
77 my $majorversionrc;
78 while (<CVSLOG>) {
79     if (/^symbolic names:/) {
80         $symbolicnamessection=1;
81     }
82     if ($symbolicnamessection && (/^\s+([^:]*):/)) {
83         my $tag=$1;
84         if ($tag=~/R_(.*)/) {
85             my $version='';
86             my $rc=0;
87             my $id=$1;
88             $id=~s/-/\./g;
89             if ($id =~/(.*)RC(.*)/) {
90                 $version=$1;
91                 $rc=$2;
92                 $version=~m#(\d+\.\d+)\.#;
93                 if (versioncompare($version, $majorversion->{$1})) {
94                     $majorversion->{$1}=$version;
95                     $majorversionrc->{$1}=$rc;
96                 }
97                 if (versioncompare($version, $highestversion)) {
98                     $highestversion=$version;
99                     $released=0;
100                     $highestrc=$rc;
101                 }
102             } else {
103                 $version=$id;
104                 $version=~m#(\d+\.\d+)\.#;
105                 if (versioncompare($version, $majorversion->{$1})) {
106                     $majorversion->{$1}=$version;
107                     $majorversionrc->{$1}=0;
108                 }
109                 if (versioncompare($version, $highestversion)) {
110                     $highestversion=$version;
111                     $released=1;
112                     $highestrc=0;
113                 }
114             }
115             $symbolicnames->{$version}->{$rc}=1;
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 -P");
222 if ($cvstag) {
223     print qq|
224 Tagging koha with tag R_$tagname
225 |;
226     system("cvs tag -F R_$tagname");
227 }
228
229 #----------------------------------------------------------
230 # MOVE files to /tmp and build tar.gz
231 #----------------------------------------------------------
232
233 my $rootdir="/tmp/koha-".$releaseversion;
234 system("rm -rf $rootdir");
235 mkdir ($rootdir, 0700);
236 chdir($rootdir) || die "$rootdir: $!\n";
237
238 mkdir("intranet-cgi", 0755);
239 mkdir("intranet-html", 0755);
240 mkdir("opac-cgi", 0755);
241 mkdir("opac-html", 0755);
242 mkdir("scripts", 0755);
243 mkdir("scripts/z3950daemon", 0755);
244 mkdir("modules", 0755);
245 mkdir("docs", 0755);
246
247 # Create koha.version file
248 open (KV, ">$rootdir/koha.version");
249 print KV "$releaseversion\n";
250 close KV;
251
252 # Copy all CVS files to intranet-cgi
253 # FIXME: "cp -a" is GNU-ism. It is not portable.
254 system("cp -a $kohadir/* $rootdir/intranet-cgi");
255
256 # Move C4 to modules directory
257 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
258
259 # Move files from intranet-cgi to root of tarball
260 system("mv $rootdir/intranet-cgi/misc/info/* $rootdir");
261 system("mv $rootdir/intranet-cgi/misc/installer.pl $rootdir");
262 system("mv $rootdir/intranet-cgi/misc/koha.upgrade $rootdir");
263 system("mv $rootdir/intranet-cgi/misc/Install.pm $rootdir");
264 #system("mv $rootdir/intranet-cgi/kohareporter $rootdir"); # does not exist ??
265 chmod 0770, "$rootdir/installer.pl";
266 chmod 0770, "$rootdir/koha.upgrade";
267 system("mv $rootdir/intranet-cgi/misc/koha.conf $rootdir");
268 system("mv $rootdir/intranet-cgi/misc/koha.mysql $rootdir");
269 system("mv $rootdir/intranet-cgi/misc/sampledata-1.2 $rootdir");
270 system("gzip -9 $rootdir/sampledata-1.2");
271
272 # Copy files from intranet-cgi to opac-cgi
273 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
274 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
275 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
276 system("cp $rootdir/intranet-cgi/subjectsearch.pl $rootdir/opac-cgi");
277 system("cp $rootdir/intranet-cgi/logout.pl $rootdir/opac-cgi");
278 system("mv $rootdir/intranet-cgi/opac/* $rootdir/opac-cgi");
279 system("rmdir $rootdir/intranet-cgi/opac");
280
281
282 # Move files from intranet-cgi to /scripts/ directory
283 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
284 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
285
286 # move only batch & daemon. pl script stay here
287 system("mv $rootdir/intranet-cgi/z3950/processz3950queue $rootdir/scripts/z3950daemon/");
288 system("mv $rootdir/intranet-cgi/z3950/*.sh $rootdir/scripts/z3950daemon/");
289
290 # Remove extraneous files from intranet-cgi
291 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
292 system("rm -f $rootdir/intranet-cgi/SendMessages");
293 system("rm -f $rootdir/intranet-cgi/buildrelease");
294 system("rm -rf $rootdir/intranet-cgi/t");
295
296 # Set all .pl scripts executable
297 system("find $rootdir/intranet-cgi -name '*.pl' -exec chmod a+x \\{\\} \\;");
298 # Copy all CVS files to intranet-html and opac-html
299 # FIXME: "cp -a" is GNU-ism. It is not portable.
300 #system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
301 #system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
302
303 # Copy koha-tmpl files
304 # FIXME: "cp -a" is GNU-ism. It is not portable.
305 system('cp', '-a', "$rootdir/intranet-cgi/koha-tmpl/opac-tmpl", "$rootdir/opac-html");
306 system('cp', '-a', "$rootdir/intranet-cgi/koha-tmpl/intranet-tmpl", "$rootdir/intranet-html");
307 #copy index files (they are just redirections to main.pl)
308 system("cp $rootdir/intranet-cgi/koha-tmpl/opac.html $rootdir/opac-html/index.html");
309 system("cp $rootdir/intranet-cgi/koha-tmpl/intranet.html $rootdir/intranet-html/index.html");
310 system('rm', '-rf', "$rootdir/intranet-cgi/koha-tmpl");
311
312 # Remove junk from directory
313 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
314 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
315 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
316
317 chdir("/tmp");
318 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
319 system("rm -rf $rootdir");
320
321 print qq|
322 ============
323 = ALL DONE =
324 ============
325
326 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
327
328 |;
329
330
331 sub versioncompare {
332     my $v1=shift;
333     my $v2=shift;
334     my @v1=split(/\./, $v1);
335     my @v2=split(/\./, $v2);
336     my $count=$#v1;
337     ($#v2>$count) && ($count=$#v2);
338     for (my $index=0; $index<$count; $index++) {
339         if ($v1[$index]>$v2[$index]) {
340             return 1;
341         }
342     }
343     return 0;
344 }
345
346 #sub guess_kohahtmldir ($;$) {
347 #    my($kohadir, $default) = @_;
348 #    my $kohahtmldir;
349     # It probably makes sense to assume that the 'koha' and 'koha-html'
350     # modules are checked out within the same parent directory
351 #    if (-d $kohadir && $kohadir =~ /^(.*)\/[^\/]+$/) {
352 #       $kohahtmldir = "$1/koha-html"
353 #    } else {
354 #       $kohahtmldir = $default;
355 #    }
356 #    return $kohahtmldir;
357 #}
358