Added support for sampledata files (gzips before tarballing), and modified the
[koha.git] / buildrelease
1 #!/usr/bin/perl
2
3 my $kohadir=`pwd`;
4 chomp $kohadir;
5
6 my $input;
7
8 print qq |
9 ***************************************
10 * Welcome to the Koha Release Builder *
11 ***************************************
12
13 This script will automatically build a release tarball.
14
15 The script assumes that you already have the koha and koha-html modules checked
16 out for the release that you want to build, although it will update the modules
17 before building.
18
19 |;
20 print "\nWhere is the 'koha' cvs module located [$kohadir]: ";
21 chomp($input = <STDIN>);
22 if ($input) {
23     $kohadir=$input;
24 }
25
26
27 my $kohahtmldir="/koha/koha/koha-html/";
28 print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
29 chomp($input = <STDIN>);
30 if ($input) {
31     $kohahtmldir=$input;
32 }
33
34
35 print "\n\nGuessing at next release version.  You may need to enter your SourceForge password...\n";
36 chdir $kohadir;
37 open (CVSLOG, "cvs log buildrelease|");
38 my $symbolicnamessection=0;
39 my $symbolicnames;
40 my $highestversion;
41 my $highestrc;
42 my $released;
43 while (<CVSLOG>) {
44     if (/^symbolic names:/) {
45         $symbolicnamessection=1;
46     }
47     if ($symbolicnamessection && (/^\s+([^:]*):/)) {
48         my $tag=$1;
49         if ($tag=~/R_(.*)/) {
50             my $version='';
51             my $rc=0;
52             my $id=$1;
53             $id=~s/-/\./g;
54             if ($id =~/(.*)RC(.*)/) {
55                 $version=$1;
56                 $rc=$2;
57                 if (versioncompare($version, $highestversion)) {
58                     $highestversion=$version;
59                     $released=0;
60                     $highestrc=$rc;
61                 }
62             } else {
63                 $version=$id;
64                 if (versioncompare($version, $highestversion)) {
65                     $highestversion=$version;
66                     $released=1;
67                     $highestrc=0;
68                 }
69             }
70             $symbolicnames->{$version}->{$rc}=1;
71         }
72     }
73 }
74
75
76 my $releaseversion='';
77 my $currentversion='';
78
79 if ($released) {
80     $releaseversion=($highestversion+1)."RC1";
81     $currentversion=$highestversion;
82 } else {
83     $releaseversion="$highestversion\RC".($highestrc+1);
84     $currentversion="$highestversion\RC$highestrc";
85 }
86
87 print "Current release tag is $currentversion.\n";
88 print "Would you like to bump that up to $releaseversion?  [Y]/N: ";
89 chomp($input = <STDIN>);
90 if ($input =~ /^n/i) {
91     print "Would you like to rebuild the $currentversion tarball?  Y/[N]: ";
92     chomp($input = <STDIN>);
93     if ($input =~ /^y/i) {
94         $releaseversion=$currentversion;
95         print "Do not do this if you have released the tarball to anybody, as it will\n";
96         print "overwrite the tag marking the files that were in the tarball.\n\n";
97         print "Confirm that you want to overwrite the tag for $releaseversion? Y/[N]: ";
98         chomp($input = <STDIN>);
99         if ($input =~ /^n/i || $input eq '') {
100             print "\nStopping.  Please re-run buildrelease now.\n";
101             exit;
102         }
103     } else {
104         print "What should the new version be? [$releaseversion]: ";
105         chomp ($input=<STDIN>);
106         if ($input) {
107             $releaseversion=$input;
108         }
109     }
110 }
111
112
113 my $sfuserid='';
114 if ($cvsroot=$ENV{'CVSROOT'}) {
115     $cvsroot=~m#(.*)\@cvs#;
116     $sfuserid=$1;
117 } else {
118     $ENV{'CVS_RSH'}='ssh';
119     print "\nWhat is your userid at SourceForge: ";
120     chomp($input = <STDIN>);
121     if ($input) {
122         $sfuserid=$input;
123     }
124     $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
125 }
126 my $tagname=$releaseversion;
127 $tagname=~s/\./-/g;
128
129 print qq|
130 Updating the 'koha' CVS files.  You may need to enter your SourceForge password.
131 Using $kohadir.
132 |;
133 chdir($kohadir);
134 system("cvs update");
135 print qq|
136 Tagging koha with tag release-$tagname
137 |;
138 system("cvs tag -F R_$tagname");
139 print qq|
140 Updating the 'koha-html' CVS files.  You may need to enter your SourceForge password.
141 Using $kohahtmldir.
142 |;
143 chdir($kohahtmldir);
144 system("cvs update");
145 print qq|
146 Tagging koha-html with tag release-$tagname
147 |;
148 system("cvs tag -F R_$tagname");
149
150
151
152
153 my $rootdir="/tmp/koha-".$releaseversion;
154 system("rm -rf $rootdir");
155 mkdir ($rootdir, 0700);
156 chdir($rootdir);
157
158 mkdir("intranet-cgi", 0755);
159 mkdir("intranet-html", 0755);
160 mkdir("opac-cgi", 0755);
161 mkdir("opac-html", 0755);
162 mkdir("scripts", 0755);
163 mkdir("modules", 0755);
164 mkdir("docs", 0755);
165
166 # Copy all CVS files to intranet-cgi
167 system("cp -a $kohadir/* $rootdir/intranet-cgi");
168
169 # Move C4 to modules directory
170 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
171
172 # Move files from intranet-cgi to root of tarball
173 system("mv $rootdir/intranet-cgi/INSTALL $rootdir");
174 system("mv $rootdir/intranet-cgi/ChangeLog $rootdir");
175 system("mv $rootdir/intranet-cgi/Hints $rootdir");
176 system("mv $rootdir/intranet-cgi/LICENSE $rootdir");
177 system("mv $rootdir/intranet-cgi/News $rootdir");
178 system("mv $rootdir/intranet-cgi/README $rootdir");
179 system("mv $rootdir/intranet-cgi/TODO $rootdir");
180 system("mv $rootdir/intranet-cgi/databaseinstall.sh $rootdir");
181 system("mv $rootdir/intranet-cgi/installer.pl $rootdir"); 
182 system("mv $rootdir/intranet-cgi/koha.conf $rootdir");
183 system("mv $rootdir/intranet-cgi/koha.mysql $rootdir");
184 system("mv $rootdir/intranet-cgi/sampledata-1.2 $rootdir");
185 system("gzip -9 $rootdir/sampledata-1.2");
186
187 # Copy files from intranet-cgi to opac-cgi
188 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
189 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
190 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
191
192
193 # Move files from intranet-cgi to /scripts/ directory
194 system("mv $rootdir/intranet-cgi/telnet $rootdir/scripts");
195 system("mv $rootdir/intranet-cgi/tkperl $rootdir/scripts");
196 system("mv $rootdir/intranet-cgi/translator $rootdir/scripts");
197 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
198 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
199
200
201 # Remove extraneous files from intranet-cgi
202 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
203 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
204 system("rm -f $rootdir/intranet-cgi/SendMessages");
205 system("rm -f $rootdir/intranet-cgi/buildrelease");
206 system("rm -f $rootdir/intranet-cgi/database.mysql");
207 system("rm -f $rootdir/intranet-cgi/installer-lite.pl");
208 system("rm -f $rootdir/intranet-cgi/koha-1.2.0.tar.gz");
209 system("rm -f $rootdir/intranet-cgi/rel-1-2");
210 system("rm -f $rootdir/intranet-cgi/testKoha.pl");
211 system("rm -rf $rootdir/intranet-cgi/html-template");
212 system("rm -rf $rootdir/intranet-cgi/t");
213
214 # Copy all CVS files to intranet-html and opac-html
215 system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
216 system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
217
218 # Remove extraneous files from opac-html
219 system("rm -f $rootdir/opac-html/koha.mo");
220 system("rm -f $rootdir/opac-html/koha.pot");
221 system("rm -f $rootdir/opac-html/test");
222
223 # Remove extraneous files from intranet-html
224 system("rm -f $rootdir/intranet-html/koha.pot");
225 system("rm -f $rootdir/intranet-html/results.html");
226 system("rm -f $rootdir/intranet-html/test");
227
228 # Remove junk from directory
229 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
230 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
231 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
232
233
234 chdir("/tmp");
235 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
236
237
238 sub versioncompare {
239     my $v1=shift;
240     my $v2=shift;
241     my @v1=split(/\./, $v1);
242     my @v2=split(/\./, $v2);
243     my $count=$#v1;
244     ($#v2>$count) && ($count=$#v2);
245     for (my $index=0; $index<$count; $index++) {
246         if ($v1[$index]>$v2[$index]) {
247             return 1;
248         }
249     }
250     return 0;
251 }