6 use strict; # please develop with the strict pragma
10 print "\n\nYou must run koha.upgrade as root.\n\n";
18 open (KC, "/etc/koha.conf");
22 if (/(.*)\s*=\s*(.*)/) {
25 # Clean up white space at beginning and end
30 $configfile{$variable}=$value;
34 my $intranetdir=$configfile{'intranetdir'};
35 my $opacdir=$configfile{'opacdir'};
36 my $kohaversion=$configfile{'kohaversion'};
37 my $kohalogdir=$configfile{'kohalogdir'};
38 my $database=$configfile{'database'};
39 my $hostname=$configfile{'hostname'};
40 my $user=$configfile{'user'};
41 my $pass=$configfile{'pass'};
44 ($kohaversion) || ($kohaversion='unknown version');
45 my $newversion=`cat koha.version`;
47 if ($newversion =~ /RC/) {
53 WARNING WARNING WARNING WARNING WARNING
55 You are about to install Koha version $newversion. This version of Koha is a
56 release candidate. It is not intended to be installed on production systems.
57 It is being released so that users can test it before we release a final
61 print "Are you sure you want to install Koha $newversion? (Y/[N]): ";
66 if ($answer eq "Y" || $answer eq "y") {
67 print "Great! continuing setup... \n";
71 Watch for announcements of Koha releases on the Koha mailing list or the Koha
72 web site (http://www.koha.org/).
85 You are attempting to upgrade from Koha $kohaversion to $newversion.
87 We recommend that you do a complete backup of all your files before upgrading.
88 This upgrade script will make a backup copy of your files for you.
90 Would you like to proceed? ([Y]/N):
96 if ($answer eq "Y" || $answer eq "y") {
97 print "Great! continuing upgrade... \n";
101 Aborting. Please re-run koha.upgrade when you are ready to upgrade Koha.
108 # Test for Perl and Modules
117 print "\nChecking perl modules ...\n";
118 unless (eval "require 5.004") {
119 die "Sorry, you need at least Perl 5.004\n";
123 unless (eval {require DBI}) { push @missing,"DBI" };
124 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
125 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
126 unless (eval {require Net::Z3950}) {
129 The Net::Z3950 module is missing. This module is necessary if you want to use
130 Koha's Z39.50 client to download bibliographic records from other libraries.
131 To install this module, you will need the yaz client installed from
132 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
135 perl -MCPAN -e 'install Net::Z3950'
137 Press the <ENTER> key to continue:
143 # Print out a list of any missing modules
147 print "You are missing some Perl modules which are required by Koha.\n";
148 print "Once these modules have been installed, rerun this installer.\n";
149 print "They can be installed by running (as root) the following:\n";
150 foreach my $module (@missing) {
151 print " perl -MCPAN -e 'install \"$module\"'\n";
154 print "All modules appear to be installed, continuing...\n";
158 my $backupdir='/usr/local/koha/backups';
159 print "Please specify a backup directory [$backupdir]: ";
168 if (! -e $backupdir) {
169 my $result=mkdir ($backupdir, oct(770));
171 my @dirs = split(m#/#, $backupdir);
175 unless (-e "$checkdir") {
176 mkdir($checkdir, 0775);
182 chmod 0770, $backupdir;
184 # Backup MySql database
190 foreach my $mysql (qw(/usr/local/mysql
203 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
206 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
208 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
210 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
214 my $biblioitemcounter=0;
218 (/insert into items /i) && ($itemcounter++);
219 (/insert into biblioitems /i) && ($biblioitemcounter++);
220 (/insert into biblio /i) && ($bibliocounter++);
221 (/insert into borrowers /i) && ($membercounter++);
229 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
236 %6d biblioitems entries
242 Does this look right? ([Y]/N):
243 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
248 if ($answer=~/^n/i) {
251 Aborting. The database dump is located in:
253 $backupdir/Koha.backup_$date
258 print "Great! continuing upgrade... \n";
263 if ($opacdir && $intranetdir) {
266 I believe that your old files are located in:
269 INTRANET: $intranetdir
272 Does this look right? ([Y]/N):
277 if ($answer =~/n/i) {
281 print "Great! continuing upgrade... \n";
286 if (!$opacdir || !$intranetdir) {
289 while (!$intranetdir) {
290 print "Please specify the location of your INTRANET files: ";
296 $intranetdir=$answer;
298 if (! -e "$intranetdir/htdocs") {
299 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
304 print "Please specify the location of your OPAC files: ";
312 if (! -e "$opacdir/htdocs") {
313 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
321 print "\n\nBacking up old Koha scripts...\n";
322 print "===============================\n\n";
324 mkdir "$backupdir/kohafiles-$date", 0770;
325 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
326 mkdir "$backupdir/kohafiles-$date/opac", 0770;
328 my $result=system("cp -R $intranetdir/* $backupdir/kohafiles-$date/intranet/");
330 print "Error encounted when copying $intranetdir to $backupdir/kohafiles-$date/intranet/\n";
333 system("rm -rf $intranetdir/*");
335 $result=system("cp -R $opacdir/* $backupdir/kohafiles-$date/opac/");
337 print "Error encounted when copying $opacdir to $backupdir/kohafiles-$date/opac/\n";
340 system("rm -rf $opacdir/*");
343 print "Creating $intranetdir/htdocs...\n";
344 mkdir ("$intranetdir/htdocs", oct(750));
345 print "Creating $intranetdir/cgi-bin...\n";
346 mkdir ("$intranetdir/cgi-bin", oct(750));
347 print "Creating $intranetdir/modules...\n";
348 mkdir ("$intranetdir/modules", oct(750));
349 print "Creating $intranetdir/scripts...\n";
350 mkdir ("$intranetdir/scripts", oct(750));
351 chmod (oct(770), "$opacdir");
352 print "Creating $opacdir/htdocs...\n";
353 mkdir ("$opacdir/htdocs", oct(750));
354 print "Creating $opacdir/cgi-bin...\n";
355 mkdir ("$opacdir/cgi-bin", oct(750));
360 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
361 /usr/local/etc/apache/httpd.conf
362 /usr/local/etc/apache/apache.conf
363 /var/www/conf/httpd.conf
364 /etc/apache/conf/httpd.conf
365 /etc/apache/conf/apache.conf
366 /etc/apache-ssl/conf/apache.conf
367 /etc/httpd/conf/httpd.conf
368 /etc/httpd/httpd.conf)) {
369 if ( -f $httpdconf ) {
370 $realhttpdconf=$httpdconf;
371 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
372 while (<HTTPDCONF>) {
373 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
381 unless ($httpduser) {
383 I was not able to determine the user that Apache is running as. This
384 information is necessary in order to set the access privileges correctly on
385 /etc/koha.conf. This user should be set in one of the Apache configuration
386 files using the "User" directive.
388 print "What is your Apache user? ";
389 chomp($input = <STDIN>);
394 $httpduser='Undetermined';
398 print "\n\nINSTALLING KOHA...\n";
399 print "\n\n==================\n";
400 print "Copying internet-html files to $intranetdir/htdocs...\n";
401 system("cp -R intranet-html/* $intranetdir/htdocs/");
402 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
403 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
404 print "Copying script files to $intranetdir/scripts...\n";
405 system("cp -R scripts/* $intranetdir/scripts/");
406 print "Copying module files to $intranetdir/modules...\n";
407 system("cp -R modules/* $intranetdir/modules/");
408 print "Copying opac-html files to $opacdir/htdocs...\n";
409 system("cp -R opac-html/* $opacdir/htdocs/");
410 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
411 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
413 system("chown -R root.$httpduser $opacdir");
414 system("chown -R root.$httpduser $intranetdir");
417 print "Modifying Z39.50 daemon launch script...\n";
419 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
422 $newfile.="RunAsUser=$httpduser\n";
423 } elsif (/^KohaZ3950Dir=/) {
424 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
430 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
431 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
435 unless ($kohalogdir && -e $kohalogdir) {
436 $kohalogdir='/var/log/koha';
437 print "\n\nDirectory for logging by Z39.50 daemon [$kohalogdir]: ";
438 chomp($input = <STDIN>);
444 unless (-e "$kohalogdir") {
445 my $result = mkdir 0770, "$kohalogdir";
447 my @dirs = split(m#/#, $kohalogdir);
451 unless (-e "$checkdir") {
452 mkdir($checkdir, 0775);
459 print "Modifying Z39.50 daemon wrapper script...\n";
461 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
463 if (/^KohaModuleDir=/) {
464 $newfile.="KohaModuleDir=$intranetdir/modules\n";
465 } elsif (/^KohaZ3950Dir=/) {
466 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
467 } elsif (/^LogDir=/) {
468 $newfile.="LogDir=$kohalogdir\n";
475 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
476 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
479 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
480 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
481 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
482 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
483 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
486 open (KC, "/etc/koha.conf");
490 if (/^\s*includes\s*=/) {
491 $kccontents.="includes=$intranetdir/htdocs/includes\n";
493 } elsif (/^\s*httpduser\s*=/) {
494 $kccontents.="httpduser=$httpduser\n";
495 $kc->{'httpduser'}=1;
496 } elsif (/^\s*kohaversion\s*=/) {
497 $kccontents.="kohaversion=$newversion\n";
498 $kc->{'kohaversion'}=1;
499 } elsif (/^\s*kohalogdir\s*=/) {
500 $kccontents.="kohalogdir=$kohalogdir\n";
501 $kc->{'kohalogdir'}=1;
502 } elsif (/^\s*intranetdir\s*=/) {
503 $kccontents.="intranetdir=$intranetdir\n";
504 $kc->{'intranetdir'}=1;
505 } elsif (/^\s*opacdir\s*=/) {
506 $kccontents.="opacdir=$opacdir\n";
513 unless (defined($kc->{'kohaversion'})) {
514 $kccontents.="kohaversion=$newversion\n";
516 unless (defined($kc->{'includes'})) {
517 $kccontents.="includes=$intranetdir/htdocs/includes\n";
519 unless (defined($kc->{'httpduser'})) {
520 $kccontents.="httpduser=$httpduser\n";
522 unless (defined($kc->{'intranetdir'})) {
523 $kccontents.="intranetdir=$intranetdir\n";
525 unless (defined($kc->{'opacdir'})) {
526 $kccontents.="opacdir=$opacdir\n";
528 unless (defined($kc->{'kohalogdir'})) {
529 $kccontents.="kohalogdir=$kohalogdir\n";
533 system("mv /etc/koha.conf /etc/koha.conf.backup");
535 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
536 print KC $kccontents;
545 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
551 ==========================
552 = Koha Upgrade Completed =
553 ==========================
554 The Koha Upgrade is finished. If you are upgrading from a version of Koha
555 prior to 1.2.1, it is likely that you will have to modify your Apache
556 configuration to point it to the new files.
558 In your INTRANET VirtualHost section you should have:
559 DocumentRoot $intranetdir/htdocs
560 ScriptAlias /cgi-bin/koha/ $intranetdir/cgi-bin/
561 SetEnv PERL5LIB $intranetdir/modules
563 In the OPAC VirtualHost section you should have:
564 DocumentRoot $opacdir/htdocs
565 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
566 SetEnv PERL5LIB $intranetdir/modules
568 You may also need to uncomment a "LoadModules env_module ... " line and restart
571 Please report any problems you encounter through http://bugs.koha.org/