Added check that programs are being run as root.
[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 } else {
134     print "What should the new version be? [$releaseversion]: ";
135     chomp ($input=<STDIN>);
136     if ($input) {
137         $releaseversion=$input;
138     }
139 }
140
141
142 print "\nWould you like to tag the CVS repository?\n(answer yes if releasing tarball)  [Y]/N: ";
143 chomp ($input=<STDIN>);
144 my $cvstag=1;
145 if ($input=~/^n/i) {
146     $cvstag=0;
147 }
148
149
150 my $sfuserid='';
151 if ($cvsroot=$ENV{'CVSROOT'}) {
152     $cvsroot=~m#(.*)\@cvs#;
153     $sfuserid=$1;
154 } else {
155     $ENV{'CVS_RSH'}='ssh';
156     print "\nWhat is your userid at SourceForge: ";
157     chomp($input = <STDIN>);
158     if ($input) {
159         $sfuserid=$input;
160     }
161     $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
162 }
163 my $tagname=$releaseversion;
164 $tagname=~s/\./-/g;
165
166 print qq|
167 Updating the 'koha' CVS files.  You may need to enter your SourceForge password.
168 Using $kohadir.
169 |;
170 chdir($kohadir);
171 system("cvs update");
172 print qq|
173 Tagging koha with tag R_$tagname
174 |;
175 ($cvstag) && (system("cvs tag -F R_$tagname"));
176 print qq|
177 Updating the 'koha-html' CVS files.  You may need to enter your SourceForge password.
178 Using $kohahtmldir.
179 |;
180 chdir($kohahtmldir);
181 system("cvs update");
182 print qq|
183 Tagging koha-html with tag R_$tagname
184 |;
185 ($cvstag) && (system("cvs tag -F R_$tagname"));
186
187
188
189
190 my $rootdir="/tmp/koha-".$releaseversion;
191 system("rm -rf $rootdir");
192 mkdir ($rootdir, 0700);
193 chdir($rootdir);
194
195 mkdir("intranet-cgi", 0755);
196 mkdir("intranet-html", 0755);
197 mkdir("opac-cgi", 0755);
198 mkdir("opac-html", 0755);
199 mkdir("scripts", 0755);
200 mkdir("scripts/z3950daemon", 0755);
201 mkdir("modules", 0755);
202 mkdir("docs", 0755);
203
204 # Create koha.versin file
205
206 open (KV, ">$rootdir/koha.version");
207 print KV "$releaseversion\n";
208 close KV;
209
210 # Copy all CVS files to intranet-cgi
211 system("cp -a $kohadir/* $rootdir/intranet-cgi");
212
213 # Move C4 to modules directory
214 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
215
216 # Move files from intranet-cgi to root of tarball
217 system("mv $rootdir/intranet-cgi/INSTALL $rootdir");
218 system("mv $rootdir/intranet-cgi/ChangeLog* $rootdir");
219 system("mv $rootdir/intranet-cgi/Hints $rootdir");
220 system("mv $rootdir/intranet-cgi/LICENSE $rootdir");
221 system("mv $rootdir/intranet-cgi/News $rootdir");
222 system("mv $rootdir/intranet-cgi/README $rootdir");
223 system("mv $rootdir/intranet-cgi/TODO $rootdir");
224 system("mv $rootdir/intranet-cgi/installer.pl $rootdir"); 
225 system("mv $rootdir/intranet-cgi/koha.upgrade $rootdir"); 
226 chmod 0770, "$rootdir/installer.pl";
227 chmod 0770, "$rootdir/koha.upgrade";
228 system("mv $rootdir/intranet-cgi/koha.conf $rootdir");
229 system("mv $rootdir/intranet-cgi/koha.mysql $rootdir");
230 system("mv $rootdir/intranet-cgi/sampledata-1.2 $rootdir");
231 system("gzip -9 $rootdir/sampledata-1.2");
232
233 # Copy files from intranet-cgi to opac-cgi
234 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
235 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
236 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
237
238
239 # Move files from intranet-cgi to /scripts/ directory
240 system("mv $rootdir/intranet-cgi/telnet $rootdir/scripts");
241 system("mv $rootdir/intranet-cgi/tkperl $rootdir/scripts");
242 system("mv $rootdir/intranet-cgi/translator $rootdir/scripts");
243 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
244 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
245 system("mv $rootdir/intranet-cgi/acqui.simple/processz3950queue $rootdir/scripts/z3950daemon/");
246 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-launch.sh $rootdir/scripts/z3950daemon/");
247 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-shell.sh $rootdir/scripts/z3950daemon/");
248
249
250 # Remove extraneous files from intranet-cgi
251 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
252 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
253 system("rm -f $rootdir/intranet-cgi/SendMessages");
254 system("rm -f $rootdir/intranet-cgi/buildrelease");
255 system("rm -f $rootdir/intranet-cgi/database.mysql");
256 system("rm -f $rootdir/intranet-cgi/installer-lite.pl");
257 system("rm -f $rootdir/intranet-cgi/koha-1.2.0.tar.gz");
258 system("rm -f $rootdir/intranet-cgi/rel-1-2");
259 system("rm -f $rootdir/intranet-cgi/testKoha.pl");
260 system("rm -rf $rootdir/intranet-cgi/html-template");
261 system("rm -rf $rootdir/intranet-cgi/t");
262
263 # Copy all CVS files to intranet-html and opac-html
264 system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
265 system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
266
267 # Remove extraneous files from opac-html
268 system("rm -f $rootdir/opac-html/koha.mo");
269 system("rm -f $rootdir/opac-html/koha.pot");
270 system("rm -f $rootdir/opac-html/test");
271
272 # Remove extraneous files from intranet-html
273 system("rm -f $rootdir/intranet-html/koha.pot");
274 system("rm -f $rootdir/intranet-html/results.html");
275 system("rm -f $rootdir/intranet-html/test");
276
277 # Remove junk from directory
278 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
279 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
280 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
281
282 if (-e "/root/docs") {
283     print "Copying docs folder from /root/docs...";
284     system("cp -r /root/docs/* $rootdir/docs/");
285 } else {
286     print "I would have copied the docs from from /root/docs, but I couldn't find it.\n";
287     print "Press <ENTER> to continue...\n";
288     <STDIN>;
289 }
290
291 chdir("/tmp");
292 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
293 system("rm -rf $rootdir");
294
295 print qq|
296 ============
297 = ALL DONE =
298 ============
299
300 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
301
302 |;
303
304
305 sub versioncompare {
306     my $v1=shift;
307     my $v2=shift;
308     my @v1=split(/\./, $v1);
309     my @v2=split(/\./, $v2);
310     my $count=$#v1;
311     ($#v2>$count) && ($count=$#v2);
312     for (my $index=0; $index<$count; $index++) {
313         if ($v1[$index]>$v2[$index]) {
314             return 1;
315         }
316     }
317     return 0;
318 }