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.
107 # Test for Perl and Modules
116 print "\nChecking perl modules ...\n";
117 unless (eval "require 5.004") {
118 die "Sorry, you need at least Perl 5.004\n";
122 unless (eval {require DBI}) { push @missing,"DBI" };
123 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
124 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
125 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
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";
159 my $backupdir='/usr/local/koha/backups';
160 print "Please specify a backup directory [$backupdir]: ";
169 if (! -e $backupdir) {
170 my $result=mkdir ($backupdir, oct(770));
172 my @dirs = split(m#/#, $backupdir);
176 unless (-e "$checkdir") {
177 mkdir($checkdir, 0775);
183 chmod 0770, $backupdir;
185 # Backup MySql database
191 foreach my $mysql (qw(/usr/local/mysql
204 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
207 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
209 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
211 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
215 my $biblioitemcounter=0;
219 (/insert into items /i) && ($itemcounter++);
220 (/insert into biblioitems /i) && ($biblioitemcounter++);
221 (/insert into biblio /i) && ($bibliocounter++);
222 (/insert into borrowers /i) && ($membercounter++);
230 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
237 %6d biblioitems entries
243 Does this look right? ([Y]/N):
244 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
249 if ($answer=~/^n/i) {
252 Aborting. The database dump is located in:
254 $backupdir/Koha.backup_$date
259 print "Great! continuing upgrade... \n";
264 if ($opacdir && $intranetdir) {
267 I believe that your old files are located in:
270 INTRANET: $intranetdir
273 Does this look right? ([Y]/N):
278 if ($answer =~/n/i) {
282 print "Great! continuing upgrade... \n";
287 if (!$opacdir || !$intranetdir) {
290 while (!$intranetdir) {
291 print "Please specify the location of your INTRANET files: ";
297 $intranetdir=$answer;
299 if (! -e "$intranetdir/htdocs") {
300 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
305 print "Please specify the location of your OPAC files: ";
313 if (! -e "$opacdir/htdocs") {
314 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
322 print "\n\nBacking up old Koha scripts...\n";
323 print "===============================\n\n";
325 mkdir "$backupdir/kohafiles-$date", 0770;
326 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
327 mkdir "$backupdir/kohafiles-$date/opac", 0770;
329 my $result=system("cp -R $intranetdir/* $backupdir/kohafiles-$date/intranet/");
331 print "Error encounted when copying $intranetdir to $backupdir/kohafiles-$date/intranet/\n";
334 system("rm -rf $intranetdir/*");
336 $result=system("cp -R $opacdir/* $backupdir/kohafiles-$date/opac/");
338 print "Error encounted when copying $opacdir to $backupdir/kohafiles-$date/opac/\n";
341 system("rm -rf $opacdir/*");
344 print "Creating $intranetdir/htdocs...\n";
345 mkdir ("$intranetdir/htdocs", oct(750));
346 print "Creating $intranetdir/cgi-bin...\n";
347 mkdir ("$intranetdir/cgi-bin", oct(750));
348 print "Creating $intranetdir/modules...\n";
349 mkdir ("$intranetdir/modules", oct(750));
350 print "Creating $intranetdir/scripts...\n";
351 mkdir ("$intranetdir/scripts", oct(750));
352 chmod (oct(770), "$opacdir");
353 print "Creating $opacdir/htdocs...\n";
354 mkdir ("$opacdir/htdocs", oct(750));
355 print "Creating $opacdir/cgi-bin...\n";
356 mkdir ("$opacdir/cgi-bin", oct(750));
361 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
362 /usr/local/etc/apache/httpd.conf
363 /usr/local/etc/apache/apache.conf
364 /var/www/conf/httpd.conf
365 /etc/apache/conf/httpd.conf
366 /etc/apache/conf/apache.conf
367 /etc/apache-ssl/conf/apache.conf
368 /etc/httpd/conf/httpd.conf
369 /etc/httpd/httpd.conf)) {
370 if ( -f $httpdconf ) {
371 $realhttpdconf=$httpdconf;
372 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
373 while (<HTTPDCONF>) {
374 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
382 unless ($httpduser) {
384 I was not able to determine the user that Apache is running as. This
385 information is necessary in order to set the access privileges correctly on
386 /etc/koha.conf. This user should be set in one of the Apache configuration
387 files using the "User" directive.
389 print "What is your Apache user? ";
390 chomp($input = <STDIN>);
395 $httpduser='Undetermined';
399 print "\n\nINSTALLING KOHA...\n";
400 print "\n\n==================\n";
401 print "Copying internet-html files to $intranetdir/htdocs...\n";
402 system("cp -R intranet-html/* $intranetdir/htdocs/");
403 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
404 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
405 print "Copying script files to $intranetdir/scripts...\n";
406 system("cp -R scripts/* $intranetdir/scripts/");
407 print "Copying module files to $intranetdir/modules...\n";
408 system("cp -R modules/* $intranetdir/modules/");
409 print "Copying opac-html files to $opacdir/htdocs...\n";
410 system("cp -R opac-html/* $opacdir/htdocs/");
411 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
412 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
414 system("chown -R root.$httpduser $opacdir");
415 system("chown -R root.$httpduser $intranetdir");
418 print "Modifying Z39.50 daemon launch script...\n";
420 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
423 $newfile.="RunAsUser=$httpduser\n";
424 } elsif (/^KohaZ3950Dir=/) {
425 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
431 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
432 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
436 unless ($kohalogdir && -e $kohalogdir) {
437 $kohalogdir='/var/log/koha';
438 print "\n\nDirectory for logging by Z39.50 daemon [$kohalogdir]: ";
439 chomp($input = <STDIN>);
445 unless (-e "$kohalogdir") {
446 my $result = mkdir 0770, "$kohalogdir";
448 my @dirs = split(m#/#, $kohalogdir);
452 unless (-e "$checkdir") {
453 mkdir($checkdir, 0775);
460 print "Modifying Z39.50 daemon wrapper script...\n";
462 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
464 if (/^KohaModuleDir=/) {
465 $newfile.="KohaModuleDir=$intranetdir/modules\n";
466 } elsif (/^KohaZ3950Dir=/) {
467 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
468 } elsif (/^LogDir=/) {
469 $newfile.="LogDir=$kohalogdir\n";
476 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
477 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
480 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
481 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
482 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
483 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
484 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
487 open (KC, "/etc/koha.conf");
491 if (/^\s*includes\s*=/) {
492 $kccontents.="includes=$intranetdir/htdocs/includes\n";
494 } elsif (/^\s*httpduser\s*=/) {
495 $kccontents.="httpduser=$httpduser\n";
496 $kc->{'httpduser'}=1;
497 } elsif (/^\s*kohaversion\s*=/) {
498 $kccontents.="kohaversion=$newversion\n";
499 $kc->{'kohaversion'}=1;
500 } elsif (/^\s*kohalogdir\s*=/) {
501 $kccontents.="kohalogdir=$kohalogdir\n";
502 $kc->{'kohalogdir'}=1;
503 } elsif (/^\s*intranetdir\s*=/) {
504 $kccontents.="intranetdir=$intranetdir\n";
505 $kc->{'intranetdir'}=1;
506 } elsif (/^\s*opacdir\s*=/) {
507 $kccontents.="opacdir=$opacdir\n";
514 unless (defined($kc->{'kohaversion'})) {
515 $kccontents.="kohaversion=$newversion\n";
517 unless (defined($kc->{'includes'})) {
518 $kccontents.="includes=$intranetdir/htdocs/includes\n";
520 unless (defined($kc->{'httpduser'})) {
521 $kccontents.="httpduser=$httpduser\n";
523 unless (defined($kc->{'intranetdir'})) {
524 $kccontents.="intranetdir=$intranetdir\n";
526 unless (defined($kc->{'opacdir'})) {
527 $kccontents.="opacdir=$opacdir\n";
529 unless (defined($kc->{'kohalogdir'})) {
530 $kccontents.="kohalogdir=$kohalogdir\n";
534 system("mv /etc/koha.conf /etc/koha.conf.backup");
536 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
537 print KC $kccontents;
546 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
555 This release of Koha has a new authentication module. If you are not already
556 using basic authentication on your intranet, you will be required to log in to
557 access some of the features of the intranet. You can log in using the userid
558 and password from the /etc/koha.conf configuration file at any time. Use the
559 "Members" module to add passwords for other accounts and set their permissions.
561 [NOTE PERMISSIONS ARE NOT COMPLETED AS OF 1.2.3RC1. Do not give passwords to
562 any patrons unless you want them to have full access to your intranet.]
564 print "Press the <ENTER> key to continue: ";
571 ==========================
572 = Koha Upgrade Completed =
573 ==========================
574 The Koha Upgrade is finished. If you are upgrading from a version of Koha
575 prior to 1.2.1, it is likely that you will have to modify your Apache
576 configuration to point it to the new files.
578 In your INTRANET VirtualHost section you should have:
579 DocumentRoot $intranetdir/htdocs
580 ScriptAlias /cgi-bin/koha/ $intranetdir/cgi-bin/
581 SetEnv PERL5LIB $intranetdir/modules
583 In the OPAC VirtualHost section you should have:
584 DocumentRoot $opacdir/htdocs
585 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
586 SetEnv PERL5LIB $intranetdir/modules
588 You may also need to uncomment a "LoadModules env_module ... " line and restart
591 Please report any problems you encounter through http://bugs.koha.org/