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 Net::Z3950}) {
127 The Net::Z3950 module is missing. This module is necessary if you want to use
128 Koha's Z39.50 client to download bibliographic records from other libraries.
129 To install this module, you will need the yaz client installed from
130 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
133 perl -MCPAN -e 'install Net::Z3950'
135 Press the <ENTER> key to continue:
141 # Print out a list of any missing modules
145 print "You are missing some Perl modules which are required by Koha.\n";
146 print "Once these modules have been installed, rerun this installer.\n";
147 print "They can be installed by running (as root) the following:\n";
148 foreach my $module (@missing) {
149 print " perl -MCPAN -e 'install \"$module\"'\n";
152 print "All modules appear to be installed, continuing...\n";
156 my $backupdir='/usr/local/koha/backups';
157 print "Please specify a backup directory [$backupdir]: ";
166 if (! -e $backupdir) {
167 my $result=mkdir ($backupdir, oct(770));
169 my @dirs = split(m#/#, $backupdir);
173 unless (-e "$checkdir") {
174 mkdir($checkdir, 0775);
180 chmod 0770, $backupdir;
182 # Backup MySql database
188 foreach my $mysql (qw(/usr/local/mysql
201 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
204 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
206 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
208 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
212 my $biblioitemcounter=0;
216 (/insert into items /i) && ($itemcounter++);
217 (/insert into biblioitems /i) && ($biblioitemcounter++);
218 (/insert into biblio /i) && ($bibliocounter++);
219 (/insert into borrowers /i) && ($membercounter++);
227 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
234 %6d biblioitems entries
240 Does this look right? ([Y]/N):
241 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
246 if ($answer=~/^n/i) {
249 Aborting. The database dump is located in:
251 $backupdir/Koha.backup_$date
256 print "Great! continuing upgrade... \n";
261 if ($opacdir && $intranetdir) {
264 I believe that your old files are located in:
267 INTRANET: $intranetdir
270 Does this look right? ([Y]/N):
275 if ($answer =~/n/i) {
279 print "Great! continuing upgrade... \n";
284 if (!$opacdir || !$intranetdir) {
287 while (!$intranetdir) {
288 print "Please specify the location of your INTRANET files: ";
294 $intranetdir=$answer;
296 if (! -e "$intranetdir/htdocs") {
297 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
302 print "Please specify the location of your OPAC files: ";
310 if (! -e "$opacdir/htdocs") {
311 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
319 print "\n\nBacking up old Koha scripts...\n";
320 print "===============================\n\n";
322 mkdir "$backupdir/kohafiles-$date", 0770;
323 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
324 mkdir "$backupdir/kohafiles-$date/opac", 0770;
326 my $result=system("cp -R $intranetdir/* $backupdir/kohafiles-$date/intranet/");
328 print "Error encounted when copying $intranetdir to $backupdir/kohafiles-$date/intranet/\n";
331 system("rm -rf $intranetdir/*");
333 $result=system("cp -R $opacdir/* $backupdir/kohafiles-$date/opac/");
335 print "Error encounted when copying $opacdir to $backupdir/kohafiles-$date/opac/\n";
338 system("rm -rf $opacdir/*");
341 print "Creating $intranetdir/htdocs...\n";
342 mkdir ("$intranetdir/htdocs", oct(750));
343 print "Creating $intranetdir/cgi-bin...\n";
344 mkdir ("$intranetdir/cgi-bin", oct(750));
345 print "Creating $intranetdir/modules...\n";
346 mkdir ("$intranetdir/modules", oct(750));
347 print "Creating $intranetdir/scripts...\n";
348 mkdir ("$intranetdir/scripts", oct(750));
349 chmod (oct(770), "$opacdir");
350 print "Creating $opacdir/htdocs...\n";
351 mkdir ("$opacdir/htdocs", oct(750));
352 print "Creating $opacdir/cgi-bin...\n";
353 mkdir ("$opacdir/cgi-bin", oct(750));
358 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
359 /usr/local/etc/apache/httpd.conf
360 /usr/local/etc/apache/apache.conf
361 /var/www/conf/httpd.conf
362 /etc/apache/conf/httpd.conf
363 /etc/apache/conf/apache.conf
364 /etc/apache-ssl/conf/apache.conf
365 /etc/httpd/conf/httpd.conf
366 /etc/httpd/httpd.conf)) {
367 if ( -f $httpdconf ) {
368 $realhttpdconf=$httpdconf;
369 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
370 while (<HTTPDCONF>) {
371 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
379 unless ($httpduser) {
381 I was not able to determine the user that Apache is running as. This
382 information is necessary in order to set the access privileges correctly on
383 /etc/koha.conf. This user should be set in one of the Apache configuration
384 files using the "User" directive.
386 print "What is your Apache user? ";
387 chomp($input = <STDIN>);
392 $httpduser='Undetermined';
396 print "\n\nINSTALLING KOHA...\n";
397 print "\n\n==================\n";
398 print "Copying internet-html files to $intranetdir/htdocs...\n";
399 system("cp -R intranet-html/* $intranetdir/htdocs/");
400 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
401 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
402 print "Copying script files to $intranetdir/scripts...\n";
403 system("cp -R scripts/* $intranetdir/scripts/");
404 print "Copying module files to $intranetdir/modules...\n";
405 system("cp -R modules/* $intranetdir/modules/");
406 print "Copying opac-html files to $opacdir/htdocs...\n";
407 system("cp -R opac-html/* $opacdir/htdocs/");
408 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
409 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
411 system("chown -R root.$httpduser $opacdir");
412 system("chown -R root.$httpduser $intranetdir");
415 print "Modifying Z39.50 daemon launch script...\n";
417 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
420 $newfile.="RunAsUser=$httpduser\n";
421 } elsif (/^KohaZ3950Dir=/) {
422 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
428 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
429 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
433 unless ($kohalogdir && -e $kohalogdir) {
434 $kohalogdir='/var/log/koha';
435 print "\n\nDirectory for logging by Z39.50 daemon [$kohalogdir]: ";
436 chomp($input = <STDIN>);
442 unless (-e "$kohalogdir") {
443 my $result = mkdir 0770, "$kohalogdir";
445 my @dirs = split(m#/#, $kohalogdir);
449 unless (-e "$checkdir") {
450 mkdir($checkdir, 0775);
457 print "Modifying Z39.50 daemon wrapper script...\n";
459 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
461 if (/^KohaModuleDir=/) {
462 $newfile.="KohaModuleDir=$intranetdir/modules\n";
463 } elsif (/^KohaZ3950Dir=/) {
464 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
465 } elsif (/^LogDir=/) {
466 $newfile.="LogDir=$kohalogdir\n";
473 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
474 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
477 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
478 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
479 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
480 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
481 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
484 open (KC, "/etc/koha.conf");
488 if (/^\s*includes\s*=/) {
489 $kccontents.="includes=$intranetdir/htdocs/includes\n";
491 } elsif (/^\s*httpduser\s*=/) {
492 $kccontents.="httpduser=$httpduser\n";
493 $kc->{'httpduser'}=1;
494 } elsif (/^\s*kohaversion\s*=/) {
495 $kccontents.="kohaversion=$newversion\n";
496 $kc->{'kohaversion'}=1;
497 } elsif (/^\s*kohalogdir\s*=/) {
498 $kccontents.="kohalogdir=$kohalogdir\n";
499 $kc->{'kohalogdir'}=1;
500 } elsif (/^\s*intranetdir\s*=/) {
501 $kccontents.="intranetdir=$intranetdir\n";
502 $kc->{'intranetdir'}=1;
503 } elsif (/^\s*opacdir\s*=/) {
504 $kccontents.="opacdir=$opacdir\n";
511 unless (defined($kc->{'kohaversion'})) {
512 $kccontents.="kohaversion=$newversion\n";
514 unless (defined($kc->{'includes'})) {
515 $kccontents.="includes=$intranetdir/htdocs/includes\n";
517 unless (defined($kc->{'httpduser'})) {
518 $kccontents.="httpduser=$httpduser\n";
520 unless (defined($kc->{'intranetdir'})) {
521 $kccontents.="intranetdir=$intranetdir\n";
523 unless (defined($kc->{'opacdir'})) {
524 $kccontents.="opacdir=$opacdir\n";
526 unless (defined($kc->{'kohalogdir'})) {
527 $kccontents.="kohalogdir=$kohalogdir\n";
531 system("mv /etc/koha.conf /etc/koha.conf.backup");
533 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
534 print KC $kccontents;
543 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
549 ==========================
550 = Koha Upgrade Completed =
551 ==========================
552 The Koha Upgrade is finished. If you are upgrading from a version of Koha
553 prior to 1.2.1, it is likely that you will have to modify your Apache
554 configuration to point it to the new files.
556 In your INTRANET VirtualHost section you should have:
557 DocumentRoot $intranetdir/htdocs
558 ScriptAlias /cgi-bin/koha/ $intranetdir/cgi-bin/
559 SetEnv PERL5LIB $intranetdir/modules
561 In the OPAC VirtualHost section you should have:
562 DocumentRoot $opacdir/htdocs
563 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
564 SetEnv PERL5LIB $intranetdir/modules
566 You may also need to uncomment a "LoadModules env_module ... " line and restart
569 Please report any problems you encounter through http://bugs.koha.org/