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