4 use strict; # please develop with the strict pragma
10 print "\n\nYou must run koha.upgrade as root.\n\n";
21 ($::kohaversion) || ($::kohaversion='unknown version');
22 $::newversion=`cat koha.version`;
24 if ($::newversion =~ /RC/) {
25 releasecandidatewarning();
34 You are attempting to upgrade from Koha $::kohaversion to $::newversion.
36 We recommend that you do a complete backup of all your files before upgrading.
37 This upgrade script will make a backup copy of your files for you.
39 Would you like to proceed? ([Y]/N):
48 Aborting. Please re-run koha.upgrade when you are ready to upgrade Koha.
52 print "Great! continuing upgrade... \n";
61 my $backupdir='/usr/local/koha/backups';
62 print "Please specify a backup directory [$backupdir]: ";
71 if (! -e $backupdir) {
72 my $result=mkdir ($backupdir, oct(770));
74 my @dirs = split(m#/#, $backupdir);
78 unless (-e "$checkdir") {
79 mkdir($checkdir, 0775);
85 chmod 0770, $backupdir;
87 # Backup MySql database
93 foreach my $mysql (qw(/usr/local/mysql
106 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
109 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
111 open (MD, "$mysqldir/bin/mysqldump --user=$::user --password=$::pass --host=$::hostname $::database|");
113 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
117 my $biblioitemcounter=0;
121 (/insert into items /i) && ($itemcounter++);
122 (/insert into biblioitems /i) && ($biblioitemcounter++);
123 (/insert into biblio /i) && ($bibliocounter++);
124 (/insert into borrowers /i) && ($membercounter++);
132 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
139 %6d biblioitems entries
144 ---------------------------------------------------------------------
146 ---------------------------------------------------------------------
148 Does this look right? ([Y]/N):
149 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
154 if ($answer=~/^n/i) {
157 Aborting. The database dump is located in:
159 $backupdir/Koha.backup_$date
164 print "Great! continuing upgrade... \n";
169 if ($::opacdir && $::intranetdir) {
172 I believe that your old files are located in:
175 INTRANET: $::intranetdir
178 Does this look right? ([Y]/N):
183 if ($answer =~/n/i) {
187 print "Great! continuing upgrade... \n";
192 if (!$::opacdir || !$::intranetdir) {
195 while (!$::intranetdir) {
196 print "Please specify the location of your INTRANET files: ";
202 $::intranetdir=$answer;
204 if (! -e "$::intranetdir/htdocs") {
205 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
209 while (!$::opacdir) {
210 print "Please specify the location of your OPAC files: ";
218 if (! -e "$::opacdir/htdocs") {
219 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
227 print "\n\nBacking up old Koha scripts...\n";
228 print "===============================\n\n";
230 mkdir "$backupdir/kohafiles-$date", 0770;
231 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
232 mkdir "$backupdir/kohafiles-$date/opac", 0770;
234 my $result=system("cp -R $::intranetdir/* $backupdir/kohafiles-$date/intranet/");
236 print "Error encounted when copying $::intranetdir to $backupdir/kohafiles-$date/intranet/\n";
239 system("rm -rf $::intranetdir/*");
241 $result=system("cp -R $::opacdir/* $backupdir/kohafiles-$date/opac/");
243 print "Error encounted when copying $::opacdir to $backupdir/kohafiles-$date/opac/\n";
246 system("rm -rf $::opacdir/*");
249 print "Creating $::intranetdir/htdocs...\n";
250 mkdir ("$::intranetdir/htdocs", oct(750));
251 print "Creating $::intranetdir/cgi-bin...\n";
252 mkdir ("$::intranetdir/cgi-bin", oct(750));
253 print "Creating $::intranetdir/modules...\n";
254 mkdir ("$::intranetdir/modules", oct(750));
255 print "Creating $::intranetdir/scripts...\n";
256 mkdir ("$::intranetdir/scripts", oct(750));
257 chmod (oct(770), "$::opacdir");
258 print "Creating $::opacdir/htdocs...\n";
259 mkdir ("$::opacdir/htdocs", oct(750));
260 print "Creating $::opacdir/cgi-bin...\n";
261 mkdir ("$::opacdir/cgi-bin", oct(750));
266 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
267 /usr/local/etc/apache/httpd.conf
268 /usr/local/etc/apache/apache.conf
269 /var/www/conf/httpd.conf
270 /etc/apache/conf/httpd.conf
271 /etc/apache/conf/apache.conf
272 /etc/apache-ssl/conf/apache.conf
273 /etc/httpd/conf/httpd.conf
274 /etc/httpd/httpd.conf)) {
275 if ( -f $httpdconf ) {
276 $realhttpdconf=$httpdconf;
277 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
278 while (<HTTPDCONF>) {
279 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
287 unless ($httpduser) {
289 I was not able to determine the user that Apache is running as. This
290 information is necessary in order to set the access privileges correctly on
291 /etc/koha.conf. This user should be set in one of the Apache configuration
292 files using the "User" directive.
294 print "What is your Apache user? ";
295 chomp($input = <STDIN>);
300 $httpduser='Undetermined';
304 print "\n\nINSTALLING KOHA...\n";
305 print "\n\n==================\n";
306 print "Copying intranet-html files to $::intranetdir/htdocs...\n";
307 system("cp -R intranet-html/* $::intranetdir/htdocs/");
308 print "Copying intranet-cgi files to $::intranetdir/cgi-bin...\n";
309 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
310 print "Copying script files to $::intranetdir/scripts...\n";
311 system("cp -R scripts/* $::intranetdir/scripts/");
312 print "Copying module files to $::intranetdir/modules...\n";
313 system("cp -R modules/* $::intranetdir/modules/");
314 print "Copying opac-html files to $::opacdir/htdocs...\n";
315 system("cp -R opac-html/* $::opacdir/htdocs/");
316 print "Copying opac-cgi files to $::opacdir/cgi-bin...\n";
317 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
318 system("touch $::opacdir/cgi-bin/opac");
320 system("chown -R root.$httpduser $::opacdir");
321 system("chown -R root.$httpduser $::intranetdir");
324 # Copy custom templates and reports back in
326 opendir D, "$backupdir/kohafiles-$date/intranet/htdocs/";
327 my @dirlist=readdir D;
330 (next) if ($_ eq 'default');
331 (next) if ($_ eq 'doc');
332 (next) if ($_=~/^koha-/);
333 (next) if (-e "$::intranetdir/htdocs/$_");
334 print "Restoring custom intranet templates $_...\n";
335 system("cp -a $backupdir/kohafiles-$date/intranet/htdocs/$_ $::intranetdir/htdocs/");
338 opendir D, "$backupdir/kohafiles-$date/opac/htdocs/";
339 my @dirlist=readdir D;
342 (next) if ($_ eq 'default');
343 (next) if ($_ eq 'doc');
344 (next) if ($_=~/^koha-/);
345 (next) if (-e "$::opacdir/htdocs/$_");
346 print "Restoring custom opac template $_...\n";
347 system("cp -a $backupdir/kohafiles-$date/opac/htdocs/$_ $::opacdir/htdocs/");
354 unless ($::kohalogdir && -e $::kohalogdir) {
355 $::kohalogdir='/var/log/koha';
356 print "\n\nDirectory for logging by Z39.50 daemon [$::kohalogdir]: ";
357 chomp($input = <STDIN>);
359 $::kohalogdir=$input;
363 unless (-e "$::kohalogdir") {
364 my $result = mkdir 0770, "$::kohalogdir";
366 my @dirs = split(m#/#, $::kohalogdir);
370 unless (-e "$checkdir") {
371 mkdir($checkdir, 0775);
377 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
378 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
379 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
380 chown(0, (getpwnam($httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
381 chown(0, (getpwnam($httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
384 open (KC, "/etc/koha.conf");
388 if (/^\s*includes\s*=/) {
389 $kccontents.="includes=$::intranetdir/htdocs/includes\n";
391 } elsif (/^\s*httpduser\s*=/) {
392 $kccontents.="httpduser=$httpduser\n";
393 $kc->{'httpduser'}=1;
394 } elsif (/^\s*kohaversion\s*=/) {
395 $kccontents.="kohaversion=$::newversion\n";
396 $kc->{'kohaversion'}=1;
397 } elsif (/^\s*kohalogdir\s*=/) {
398 $kccontents.="kohalogdir=$::kohalogdir\n";
399 $kc->{'kohalogdir'}=1;
400 } elsif (/^\s*intranetdir\s*=/) {
401 $kccontents.="intranetdir=$::intranetdir\n";
402 $kc->{'intranetdir'}=1;
403 } elsif (/^\s*opacdir\s*=/) {
404 $kccontents.="opacdir=$::opacdir\n";
411 unless (defined($kc->{'kohaversion'})) {
412 $kccontents.="kohaversion=$::newversion\n";
414 unless (defined($kc->{'includes'})) {
415 $kccontents.="includes=$::intranetdir/htdocs/includes\n";
417 unless (defined($kc->{'httpduser'})) {
418 $kccontents.="httpduser=$httpduser\n";
420 unless (defined($kc->{'intranetdir'})) {
421 $kccontents.="intranetdir=$::intranetdir\n";
423 unless (defined($kc->{'opacdir'})) {
424 $kccontents.="opacdir=$::opacdir\n";
426 unless (defined($kc->{'kohalogdir'})) {
427 $kccontents.="kohalogdir=$::kohalogdir\n";
431 system("mv /etc/koha.conf /etc/koha.conf.backup");
433 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
434 print KC $kccontents;
443 system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
452 This release of Koha has a new authentication module. If you are not already
453 using basic authentication on your intranet, you will be required to log in to
454 access some of the features of the intranet. You can log in using the userid
455 and password from the /etc/koha.conf configuration file at any time. Use the
456 "Members" module to add passwords for other accounts and set their permissions.
458 [NOTE PERMISSIONS ARE NOT COMPLETED AS OF 1.2.3RC1. Do not give passwords to
459 any patrons unless you want them to have full access to your intranet.]
461 print "Press the <ENTER> key to continue: ";
468 ==========================
469 = Koha Upgrade Completed =
470 ==========================
471 The Koha Upgrade is finished. If you are upgrading from a version of Koha
472 prior to 1.2.1, it is likely that you will have to modify your Apache
473 configuration to point it to the new files.
475 In your INTRANET VirtualHost section you should have:
476 DocumentRoot $::intranetdir/htdocs
477 ScriptAlias /cgi-bin/koha/ $::intranetdir/cgi-bin/
478 SetEnv PERL5LIB $::intranetdir/modules
480 In the OPAC VirtualHost section you should have:
481 DocumentRoot $::opacdir/htdocs
482 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
483 SetEnv PERL5LIB $::intranetdir/modules
485 You may also need to uncomment a "LoadModules env_module ... " line and restart
488 Please report any problems you encounter through http://bugs.koha.org/
492 my $reply=showmessage('Would you like to complete a survey about your library?', 'yn', 'y');
494 system("perl kohareporter");