4 use strict; # please develop with the strict pragma
8 print "\n\nYou must run koha.upgrade as root.\n\n";
16 open (KC, "/etc/koha.conf");
20 if (/(.*)\s*=\s*(.*)/) {
23 # Clean up white space at beginning and end
28 $configfile{$variable}=$value;
32 my $intranetdir=$configfile{'intranetdir'};
33 my $opacdir=$configfile{'opacdir'};
34 my $kohaversion=$configfile{'kohaversion'};
35 my $kohalogdir=$configfile{'kohalogdir'};
36 my $database=$configfile{'database'};
37 my $hostname=$configfile{'hostname'};
38 my $user=$configfile{'user'};
39 my $pass=$configfile{'pass'};
42 ($kohaversion) || ($kohaversion='unknown version');
43 my $newversion=`cat koha.version`;
45 if ($newversion =~ /RC/) {
51 WARNING WARNING WARNING WARNING WARNING
53 You are about to install Koha version $newversion. This version of Koha is a
54 release candidate. It is not intended to be installed on production systems.
55 It is being released so that users can test it before we release a final
59 print "Are you sure you want to install Koha $newversion? (Y/[N]): ";
64 if ($answer eq "Y" || $answer eq "y") {
65 print "Great! continuing setup... \n";
69 Watch for announcements of Koha releases on the Koha mailing list or the Koha
70 web site (http://www.koha.org/).
83 You are attempting to upgrade from Koha $kohaversion to $newversion.
85 We recommend that you do a complete backup of all your files before upgrading.
86 This upgrade script will make a backup copy of your files for you.
88 Would you like to proceed? ([Y]/N):
94 if ($answer eq "Y" || $answer eq "y") {
95 print "Great! continuing upgrade... \n";
99 Aborting. Please re-run koha.upgrade when you are ready to upgrade Koha.
106 # Test for Perl and Modules
115 print "\nChecking perl modules ...\n";
116 unless (eval "require 5.004") {
117 die "Sorry, you need at least Perl 5.004\n";
121 unless (eval {require DBI}) { push @missing,"DBI" };
122 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
123 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
124 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
125 unless (eval {require Net::Z3950}) {
128 The Net::Z3950 module is missing. This module is necessary if you want to use
129 Koha's Z39.50 client to download bibliographic records from other libraries.
130 To install this module, you will need the yaz client installed from
131 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
134 perl -MCPAN -e 'install Net::Z3950'
136 Press the <ENTER> key to continue:
142 # Print out a list of any missing modules
146 print "You are missing some Perl modules which are required by Koha.\n";
147 print "Once these modules have been installed, rerun this installer.\n";
148 print "They can be installed by running (as root) the following:\n";
149 foreach my $module (@missing) {
150 print " perl -MCPAN -e 'install \"$module\"'\n";
153 print "All modules appear to be installed, continuing...\n";
157 my $backupdir='/usr/local/koha/backups';
158 print "Please specify a backup directory [$backupdir]: ";
167 if (! -e $backupdir) {
168 my $result=mkdir ($backupdir, oct(770));
170 my @dirs = split(m#/#, $backupdir);
174 unless (-e "$checkdir") {
175 mkdir($checkdir, 0775);
181 chmod 0770, $backupdir;
183 # Backup MySql database
189 foreach my $mysql (qw(/usr/local/mysql
202 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
205 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
207 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
209 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
213 my $biblioitemcounter=0;
217 (/insert into items /i) && ($itemcounter++);
218 (/insert into biblioitems /i) && ($biblioitemcounter++);
219 (/insert into biblio /i) && ($bibliocounter++);
220 (/insert into borrowers /i) && ($membercounter++);
228 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
235 %6d biblioitems entries
241 Does this look right? ([Y]/N):
242 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
247 if ($answer=~/^n/i) {
250 Aborting. The database dump is located in:
252 $backupdir/Koha.backup_$date
257 print "Great! continuing upgrade... \n";
262 if ($opacdir && $intranetdir) {
265 I believe that your old files are located in:
268 INTRANET: $intranetdir
271 Does this look right? ([Y]/N):
276 if ($answer =~/n/i) {
280 print "Great! continuing upgrade... \n";
285 if (!$opacdir || !$intranetdir) {
288 while (!$intranetdir) {
289 print "Please specify the location of your INTRANET files: ";
295 $intranetdir=$answer;
297 if (! -e "$intranetdir/htdocs") {
298 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
303 print "Please specify the location of your OPAC files: ";
311 if (! -e "$opacdir/htdocs") {
312 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
320 print "\n\nBacking up old Koha scripts...\n";
321 print "===============================\n\n";
323 mkdir "$backupdir/kohafiles-$date", 0770;
324 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
325 mkdir "$backupdir/kohafiles-$date/opac", 0770;
327 my $result=system("cp -R $intranetdir/* $backupdir/kohafiles-$date/intranet/");
329 print "Error encounted when copying $intranetdir to $backupdir/kohafiles-$date/intranet/\n";
332 system("rm -rf $intranetdir/*");
334 $result=system("cp -R $opacdir/* $backupdir/kohafiles-$date/opac/");
336 print "Error encounted when copying $opacdir to $backupdir/kohafiles-$date/opac/\n";
339 system("rm -rf $opacdir/*");
342 print "Creating $intranetdir/htdocs...\n";
343 mkdir ("$intranetdir/htdocs", oct(750));
344 print "Creating $intranetdir/cgi-bin...\n";
345 mkdir ("$intranetdir/cgi-bin", oct(750));
346 print "Creating $intranetdir/modules...\n";
347 mkdir ("$intranetdir/modules", oct(750));
348 print "Creating $intranetdir/scripts...\n";
349 mkdir ("$intranetdir/scripts", oct(750));
350 chmod (oct(770), "$opacdir");
351 print "Creating $opacdir/htdocs...\n";
352 mkdir ("$opacdir/htdocs", oct(750));
353 print "Creating $opacdir/cgi-bin...\n";
354 mkdir ("$opacdir/cgi-bin", oct(750));
359 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
360 /usr/local/etc/apache/httpd.conf
361 /usr/local/etc/apache/apache.conf
362 /var/www/conf/httpd.conf
363 /etc/apache/conf/httpd.conf
364 /etc/apache/conf/apache.conf
365 /etc/apache-ssl/conf/apache.conf
366 /etc/httpd/conf/httpd.conf
367 /etc/httpd/httpd.conf)) {
368 if ( -f $httpdconf ) {
369 $realhttpdconf=$httpdconf;
370 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
371 while (<HTTPDCONF>) {
372 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
380 unless ($httpduser) {
382 I was not able to determine the user that Apache is running as. This
383 information is necessary in order to set the access privileges correctly on
384 /etc/koha.conf. This user should be set in one of the Apache configuration
385 files using the "User" directive.
387 print "What is your Apache user? ";
388 chomp($input = <STDIN>);
393 $httpduser='Undetermined';
397 print "\n\nINSTALLING KOHA...\n";
398 print "\n\n==================\n";
399 print "Copying internet-html files to $intranetdir/htdocs...\n";
400 system("cp -R intranet-html/* $intranetdir/htdocs/");
401 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
402 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
403 print "Copying script files to $intranetdir/scripts...\n";
404 system("cp -R scripts/* $intranetdir/scripts/");
405 print "Copying module files to $intranetdir/modules...\n";
406 system("cp -R modules/* $intranetdir/modules/");
407 print "Copying opac-html files to $opacdir/htdocs...\n";
408 system("cp -R opac-html/* $opacdir/htdocs/");
409 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
410 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
412 system("chown -R root.$httpduser $opacdir");
413 system("chown -R root.$httpduser $intranetdir");
416 print "Modifying Z39.50 daemon launch script...\n";
418 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
421 $newfile.="RunAsUser=$httpduser\n";
422 } elsif (/^KohaZ3950Dir=/) {
423 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
429 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
430 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
434 unless ($kohalogdir && -e $kohalogdir) {
435 $kohalogdir='/var/log/koha';
436 print "\n\nDirectory for logging by Z39.50 daemon [$kohalogdir]: ";
437 chomp($input = <STDIN>);
443 unless (-e "$kohalogdir") {
444 my $result = mkdir 0770, "$kohalogdir";
446 my @dirs = split(m#/#, $kohalogdir);
450 unless (-e "$checkdir") {
451 mkdir($checkdir, 0775);
458 print "Modifying Z39.50 daemon wrapper script...\n";
460 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
462 if (/^KohaModuleDir=/) {
463 $newfile.="KohaModuleDir=$intranetdir/modules\n";
464 } elsif (/^KohaZ3950Dir=/) {
465 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
466 } elsif (/^LogDir=/) {
467 $newfile.="LogDir=$kohalogdir\n";
474 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
475 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
478 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
479 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
480 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
481 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
482 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
485 open (KC, "/etc/koha.conf");
489 if (/^\s*includes\s*=/) {
490 $kccontents.="includes=$intranetdir/htdocs/includes\n";
492 } elsif (/^\s*httpduser\s*=/) {
493 $kccontents.="httpduser=$httpduser\n";
494 $kc->{'httpduser'}=1;
495 } elsif (/^\s*kohaversion\s*=/) {
496 $kccontents.="kohaversion=$newversion\n";
497 $kc->{'kohaversion'}=1;
498 } elsif (/^\s*kohalogdir\s*=/) {
499 $kccontents.="kohalogdir=$kohalogdir\n";
500 $kc->{'kohalogdir'}=1;
501 } elsif (/^\s*intranetdir\s*=/) {
502 $kccontents.="intranetdir=$intranetdir\n";
503 $kc->{'intranetdir'}=1;
504 } elsif (/^\s*opacdir\s*=/) {
505 $kccontents.="opacdir=$opacdir\n";
512 unless (defined($kc->{'kohaversion'})) {
513 $kccontents.="kohaversion=$newversion\n";
515 unless (defined($kc->{'includes'})) {
516 $kccontents.="includes=$intranetdir/htdocs/includes\n";
518 unless (defined($kc->{'httpduser'})) {
519 $kccontents.="httpduser=$httpduser\n";
521 unless (defined($kc->{'intranetdir'})) {
522 $kccontents.="intranetdir=$intranetdir\n";
524 unless (defined($kc->{'opacdir'})) {
525 $kccontents.="opacdir=$opacdir\n";
527 unless (defined($kc->{'kohalogdir'})) {
528 $kccontents.="kohalogdir=$kohalogdir\n";
532 system("mv /etc/koha.conf /etc/koha.conf.backup");
534 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
535 print KC $kccontents;
544 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
550 ==========================
551 = Koha Upgrade Completed =
552 ==========================
553 The Koha Upgrade is finished. If you are upgrading from a version of Koha
554 prior to 1.2.1, it is likely that you will have to modify your Apache
555 configuration to point it to the new files.
557 In your INTRANET VirtualHost section you should have:
558 DocumentRoot $intranetdir/htdocs
559 ScriptAlias /cgi-bin/koha/ $intranetdir/cgi-bin/
560 SetEnv PERL5LIB $intranetdir/modules
562 In the OPAC VirtualHost section you should have:
563 DocumentRoot $opacdir/htdocs
564 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
565 SetEnv PERL5LIB $intranetdir/modules
567 You may also need to uncomment a "LoadModules env_module ... " line and restart
570 Please report any problems you encounter through http://bugs.koha.org/