4 use strict; # please develop with the strict pragma
10 print "\n\nYou must run koha.upgrade as root.\n\n";
18 ($::kohaversion) || ($::kohaversion='unknown version');
19 $::newversion=`cat koha.version`;
21 if ($::newversion =~ /RC/) {
22 releasecandidatewarning();
31 You are attempting to upgrade from Koha $::kohaversion to $::newversion.
33 We recommend that you do a complete backup of all your files before upgrading.
34 This upgrade script will make a backup copy of your files for you.
36 Would you like to proceed? (Y/[N]):
42 unless ($answer =~/y/i) {
45 Aborting. Please re-run koha.upgrade when you are ready to upgrade Koha.
49 print "Great! continuing upgrade... \n";
54 my $backupdir='/usr/local/koha/backups';
55 print "Please specify a backup directory [$backupdir]: ";
64 if (! -e $backupdir) {
65 my $result=mkdir ($backupdir, oct(770));
67 my @dirs = split(m#/#, $backupdir);
71 unless (-e "$checkdir") {
72 mkdir($checkdir, 0775);
78 chmod 0770, $backupdir;
80 # Backup MySql database
86 foreach my $mysql (qw(/usr/local/mysql
90 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
95 print "I don't see mysql in the usual places.\n";
97 print "Where have you installed mysql? ";
98 chomp($mysqldir = <STDIN>);
99 last if -f "$mysqldir/bin/mysqladmin";
102 I can't find it there either. If you compiled mysql yourself,
103 please give the value of --prefix when you ran configure.
105 The file mysqladmin should be in bin/mysqladmin under the directory that you
112 print "Doing backup\n";
115 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
118 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
120 open (MD, "$mysqldir/bin/mysqldump --user=$::user --password=$::pass --host=$::hostname $::database|");
122 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
126 my $biblioitemcounter=0;
130 (/insert into items /i) && ($itemcounter++);
131 (/insert into biblioitems /i) && ($biblioitemcounter++);
132 (/insert into biblio /i) && ($bibliocounter++);
133 (/insert into borrowers /i) && ($membercounter++);
140 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
147 %6d biblioitems entries
152 ---------------------------------------------------------------------
154 ---------------------------------------------------------------------
156 Does this look right? ([Y]/N):
157 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
162 if ($answer=~/^n/i) {
165 Aborting. The database dump is located in:
167 $backupdir/Koha.backup_$date
172 print "Great! continuing upgrade... \n";
177 if ($::opacdir && $::intranetdir) {
180 I believe that your old files are located in:
183 INTRANET: $::intranetdir
186 Does this look right? ([Y]/N):
191 if ($answer =~/n/i) {
195 print "Great! continuing upgrade... \n";
200 if (!$::opacdir || !$::intranetdir) {
203 while (!$::intranetdir) {
204 print "Please specify the location of your INTRANET files: ";
210 $::intranetdir=$answer;
212 if (! -e "$::intranetdir/htdocs") {
213 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
217 while (!$::opacdir) {
218 print "Please specify the location of your OPAC files: ";
226 if (! -e "$::opacdir/htdocs") {
227 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
235 print "\n\nBacking up old Koha scripts...\n";
236 print "===============================\n\n";
238 mkdir "$backupdir/kohafiles-$date", 0770;
239 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
240 mkdir "$backupdir/kohafiles-$date/opac", 0770;
242 my $result=system("cp -R $::intranetdir/* $backupdir/kohafiles-$date/intranet/");
244 print "Error encounted when copying $::intranetdir to $backupdir/kohafiles-$date/intranet/\n";
247 system("rm -rf $::intranetdir/*");
249 $result=system("cp -R $::opacdir/* $backupdir/kohafiles-$date/opac/");
251 print "Error encounted when copying $::opacdir to $backupdir/kohafiles-$date/opac/\n";
254 system("rm -rf $::opacdir/*");
257 print "Creating $::intranetdir/htdocs...\n";
258 mkdir ("$::intranetdir/htdocs", oct(750));
259 print "Creating $::intranetdir/cgi-bin...\n";
260 mkdir ("$::intranetdir/cgi-bin", oct(750));
261 print "Creating $::intranetdir/modules...\n";
262 mkdir ("$::intranetdir/modules", oct(750));
263 print "Creating $::intranetdir/scripts...\n";
264 mkdir ("$::intranetdir/scripts", oct(750));
265 chmod (oct(770), "$::opacdir");
266 print "Creating $::opacdir/htdocs...\n";
267 mkdir ("$::opacdir/htdocs", oct(750));
268 print "Creating $::opacdir/cgi-bin...\n";
269 mkdir ("$::opacdir/cgi-bin", oct(750));
274 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
275 /usr/local/etc/apache/httpd.conf
276 /usr/local/etc/apache/apache.conf
277 /var/www/conf/httpd.conf
278 /etc/apache/conf/httpd.conf
279 /etc/apache/conf/apache.conf
280 /etc/apache-ssl/conf/apache.conf
281 /etc/httpd/conf/httpd.conf
282 /etc/httpd/conf/commonhttpd.conf
283 /etc/httpd/httpd.conf)) {
284 if ( -f $httpdconf ) {
285 $realhttpdconf=$httpdconf;
286 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
287 while (<HTTPDCONF>) {
288 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
296 unless ($httpduser) {
298 I was not able to determine the user that Apache is running as. This
299 information is necessary in order to set the access privileges correctly on
300 /etc/koha.conf. This user should be set in one of the Apache configuration
301 files using the "User" directive.
303 print "What is your Apache user? ";
304 chomp($input = <STDIN>);
309 $httpduser='Undetermined';
313 print "\n\nINSTALLING KOHA...\n";
314 print "\n\n==================\n";
315 print "Copying intranet-html files to $::intranetdir/htdocs...\n";
316 system("cp -R intranet-html/* $::intranetdir/htdocs/");
317 print "Copying intranet-cgi files to $::intranetdir/cgi-bin...\n";
318 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
319 print "Copying script files to $::intranetdir/scripts...\n";
320 system("cp -R scripts/* $::intranetdir/scripts/");
321 print "Copying module files to $::intranetdir/modules...\n";
322 system("cp -R modules/* $::intranetdir/modules/");
323 print "Copying opac-html files to $::opacdir/htdocs...\n";
324 system("cp -R opac-html/* $::opacdir/htdocs/");
325 print "Copying opac-cgi files to $::opacdir/cgi-bin...\n";
326 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
327 system("touch $::opacdir/cgi-bin/opac");
329 system("chown -R root:$httpduser $::opacdir");
330 system("chown -R root:$httpduser $::intranetdir");
333 # Copy custom templates and reports back in
335 opendir D, "$backupdir/kohafiles-$date/intranet/htdocs/";
336 my @dirlist=readdir D;
339 (next) if ($_ eq 'default');
340 (next) if ($_ eq 'doc');
341 (next) if ($_=~/^koha-/);
342 (next) if (-e "$::intranetdir/htdocs/$_");
343 print "Restoring custom intranet templates $_...\n";
344 system("cp -a $backupdir/kohafiles-$date/intranet/htdocs/$_ $::intranetdir/htdocs/");
347 opendir D, "$backupdir/kohafiles-$date/opac/htdocs/";
351 (next) if ($_ eq 'default');
352 (next) if ($_ eq 'doc');
353 (next) if ($_=~/^koha-/);
354 (next) if (-e "$::opacdir/htdocs/$_");
355 print "Restoring custom opac template $_...\n";
356 system("cp -a $backupdir/kohafiles-$date/opac/htdocs/$_ $::opacdir/htdocs/");
363 unless ($::kohalogdir && -e $::kohalogdir) {
364 $::kohalogdir='/var/log/koha';
365 print "\n\nDirectory for logging by Z39.50 daemon [$::kohalogdir]: ";
366 chomp($input = <STDIN>);
368 $::kohalogdir=$input;
372 unless (-e "$::kohalogdir") {
373 my $result = mkdir 0770, "$::kohalogdir";
375 my @dirs = split(m#/#, $::kohalogdir);
379 unless (-e "$checkdir") {
380 mkdir($checkdir, 0775);
386 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
387 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
388 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
389 chown(0, (getpwnam($httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
390 chown(0, (getpwnam($httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
394 my $kccontents='';open (KC, "/etc/koha.conf");
397 if (/^\s*includes\s*=/) {
398 $kccontents.="includes=$::intranetdir/htdocs/includes\n";
400 } elsif (/^\s*httpduser\s*=/) {
401 $kccontents.="httpduser=$httpduser\n";
402 $kc->{'httpduser'}=1;
403 } elsif (/^\s*kohaversion\s*=/) {
404 $kccontents.="kohaversion=$::newversion\n";
405 $kc->{'kohaversion'}=1;
406 } elsif (/^\s*kohalogdir\s*=/) {
407 $kccontents.="kohalogdir=$::kohalogdir\n";
408 $kc->{'kohalogdir'}=1;
409 } elsif (/^\s*intranetdir\s*=/) {
410 $kccontents.="intranetdir=$::intranetdir\n";
411 $kc->{'intranetdir'}=1;
412 } elsif (/^\s*opacdir\s*=/) {
413 $kccontents.="opacdir=$::opacdir\n";
420 unless (defined($kc->{'kohaversion'})) {
421 $kccontents.="kohaversion=$::newversion\n";
423 unless (defined($kc->{'includes'})) {
424 $kccontents.="includes=$::intranetdir/htdocs/includes\n";
426 unless (defined($kc->{'httpduser'})) {
427 $kccontents.="httpduser=$httpduser\n";
429 unless (defined($kc->{'intranetdir'})) {
430 $kccontents.="intranetdir=$::intranetdir\n";
432 unless (defined($kc->{'opacdir'})) {
433 $kccontents.="opacdir=$::opacdir\n";
435 unless (defined($kc->{'kohalogdir'})) {
436 $kccontents.="kohalogdir=$::kohalogdir\n";
440 system("mv /etc/koha.conf /etc/koha.conf.backup");
442 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
443 print KC $kccontents;
452 system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
461 This release of Koha has a new authentication module. If you are not already
462 using basic authentication on your intranet, you will be required to log in to
463 access some of the features of the intranet. You can log in using the userid
464 and password from the /etc/koha.conf configuration file at any time. Use the
465 "Members" module to add passwords for other accounts and set their permissions.
467 print "Press the <ENTER> key to continue: ";
474 ==========================
475 = Koha Upgrade Completed =
476 ==========================
477 The Koha Upgrade is finished.
478 If you are upgrading from a version of Koha
479 prior to 1.2.1, it is likely that you will have to modify your Apache
480 configuration to point it to the new files.
482 In your INTRANET VirtualHost section you should have:
483 DocumentRoot $::intranetdir/htdocs
484 ScriptAlias /cgi-bin/koha/ $::intranetdir/cgi-bin/
485 SetEnv PERL5LIB $::intranetdir/modules
487 In the OPAC VirtualHost section you should have:
488 DocumentRoot $::opacdir/htdocs
489 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
490 SetEnv PERL5LIB $::intranetdir/modules
492 You may also need to uncomment a "LoadModules env_module ... " line and restart
495 Please report any problems you encounter through http://bugs.koha.org/
499 my $reply=showmessage('Would you like to complete a survey about your library?', 'yn', 'y');
501 system("perl kohareporter");