CVS tagging now defaults to "no" and added koha-tmpl directory
[koha.git] / buildrelease
blobabd982f29ca65f624b1e5f939fa219f513b3b8b6
1 #!/usr/bin/perl
3 sub guess_kohahtmldir ($;$);
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;
11 my $has_kohaautobuild_conf = 0;
13 if (-e "$roothomedir/.kohaautobuild.conf") {
14 open C, "<$roothomedir/.kohaautobuild.conf";
15 while (<C>) {
16 chomp;
17 if (/kohadir=(.*)/) {
18 $kohadir=$1;
20 if (/kohahtmldir=(.*)/) {
21 $kohahtmldir=$1;
24 $has_kohaautobuild_conf = 1;
27 my $input;
29 print qq |
30 ***************************************
31 * Welcome to the Koha Release Builder *
32 ***************************************
34 This script will automatically build a release tarball.
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.
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;
49 print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
50 chomp($input = <STDIN>);
51 if ($input) {
52 $kohahtmldir=$input;
55 open (C, ">$roothomedir/.kohaautobuild.conf");
56 print C qq|
57 kohadir=$kohadir
58 kohahtmldir=$kohahtmldir
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;
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;
88 } else {
89 $version=$id;
90 if (versioncompare($version, $highestversion)) {
91 $highestversion=$version;
92 $released=1;
93 $highestrc=0;
96 $symbolicnames->{$version}->{$rc}=1;
102 my $releaseversion='';
103 my $currentversion='';
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";
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;
135 } else {
136 print "What should the new version be? [$releaseversion]: ";
137 chomp ($input=<STDIN>);
138 if ($input) {
139 $releaseversion=$input;
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=0;
147 # FIXME: This means anything other than n will tag; too dangerous?
148 if ($input=~/^y/i) {
149 $cvstag=1;
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;
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;
177 $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
179 my $tagname=$releaseversion;
180 $tagname=~s/\./-/g;
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.
187 chdir($kohadir);
188 system("cvs update");
189 if ($cvstag) {
190 print qq|
191 Tagging koha with tag R_$tagname
193 system("cvs tag -F R_$tagname");
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.
200 chdir($kohahtmldir) || die "$kohahtmldir: $!\n";
201 system("cvs update");
203 if ($cvstag) {
204 print qq|
205 Tagging koha-html with tag R_$tagname
207 system("cvs tag -F R_$tagname");
213 my $rootdir="/tmp/koha-".$releaseversion;
214 system("rm -rf $rootdir");
215 mkdir ($rootdir, 0700);
216 chdir($rootdir) || die "$rootdir: $!\n";
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);
227 # Create koha.versin file
229 open (KV, ">$rootdir/koha.version");
230 print KV "$releaseversion\n";
231 close KV;
233 # Copy all CVS files to intranet-cgi
234 system("cp -a $kohadir/* $rootdir/intranet-cgi");
236 # Move C4 to modules directory
237 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
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");
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");
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/");
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");
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");
298 # Move koha-tmpl files
299 system("mv $rootdir/intranet-cgi/koha-tmpl/opac-tmpl/* $rootdir/opac-html");
300 system("mv $rootdir/intranet-cgi/koha-tmpl/intranet-tmpl/* $rootdir/intranet-html");
301 system("rm -rf $rootdir/intranet-cgi/koha-tmpl");
303 # Remove extraneous files from opac-html
304 system("rm -f $rootdir/opac-html/koha.mo");
305 system("rm -f $rootdir/opac-html/koha.pot");
306 system("rm -f $rootdir/opac-html/test");
308 # Remove extraneous files from intranet-html
309 system("rm -f $rootdir/intranet-html/koha.pot");
310 system("rm -f $rootdir/intranet-html/results.html");
311 system("rm -f $rootdir/intranet-html/test");
313 # Remove junk from directory
314 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
315 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
316 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
319 if (-e "$roothomedir/docs") {
320 print "Copying docs folder from $roothomedir/docs...";
321 system("cp -r $roothomedir/docs/* $rootdir/docs/");
322 } else {
323 print "I would have copied the docs from from $roothomedir/docs, but I couldn't find it.\n";
324 print "Press <ENTER> to continue...\n";
325 <STDIN>;
328 chdir("/tmp");
329 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
330 system("rm -rf $rootdir");
332 print qq|
333 ============
334 = ALL DONE =
335 ============
337 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
342 sub versioncompare {
343 my $v1=shift;
344 my $v2=shift;
345 my @v1=split(/\./, $v1);
346 my @v2=split(/\./, $v2);
347 my $count=$#v1;
348 ($#v2>$count) && ($count=$#v2);
349 for (my $index=0; $index<$count; $index++) {
350 if ($v1[$index]>$v2[$index]) {
351 return 1;
354 return 0;
357 sub guess_kohahtmldir ($;$) {
358 my($kohadir, $default) = @_;
359 my $kohahtmldir;
360 # It probably makes sense to assume that the 'koha' and 'koha-html'
361 # modules are checked out within the same parent directory
362 if (-d $kohadir && $kohadir =~ /^(.*)\/[^\/]+$/) {
363 $kohahtmldir = "$1/koha-html"
364 } else {
365 $kohahtmldir = $default;
367 return $kohahtmldir;