1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
5 # Contains parts Copyright 2003 MJ Ray
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
23 # MJR: my.cnf, etcdir, prefix, new display, apache conf, copying fixups
27 #MJR: everyone will have these modules, right?
28 # They look like part of perl core to me
30 use Term::ANSIColor qw(:constants);
34 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38 Install.pm - Perl module containing the bulk of the installation logic
42 The Install.pm module contains the bulk
43 of the code to do installation;
44 this code is used by installer.pl
45 to perform an actual installation.
47 =head2 Internal functions (not meant to be used outside of Install.pm)
53 # set the version for version checking
57 @EXPORT = qw( &checkperlmodules
61 &releasecandidatewarning
62 &getinstallationdirectories
80 use vars qw( $kohaversion $newversion ); # set in loadconfigfile and installer.pl
81 use vars qw( $language ); # set in installer.pl
82 use vars qw( $domainname ); # set in installer.pl
84 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
85 use vars qw( $intranetdir $opacdir $kohalogdir );
86 use vars qw( $realhttpdconf $httpduser );
87 use vars qw( $servername $svr_admin $opacport $intranetport );
88 use vars qw( $mysqldir );
89 use vars qw( $database $mysqluser );
90 use vars qw( $mysqlpass ); # normally should not be used
91 use vars qw( $hostname $user $pass ); # virtual hosting
95 $messages->{'WelcomeToKohaInstaller'
96 = heading('Welcome to the Koha Installer') . qq|...|;
98 The heading function takes one string, the text to be displayed as
99 the heading, and returns a formatted heading (currently formatted
102 This reduces the likelihood of pod2man(1) etc. misinterpreting
103 a line of equal signs as illegal POD directives.
107 my $termios = POSIX::Termios->new();
109 my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
110 my $clear_string = "\n\n"; #MJR: was $terminal->Tputs('cl');
115 return($clear_string.ON_BLUE.WHITE.BOLD." "x$bal.uc($title)." "x$bal.RESET."\n\n");
118 my $mycnf = $ENV{HOME}."/.my.cnf";
119 my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
123 $messages->{'continuing'}->{en}="Great! Continuing...\n\n";
124 $messages->{'WelcomeToKohaInstaller'}->{en} =
125 heading('Welcome to the Koha Installer') . qq|
126 This program will ask some questions and try to install koha for you.
127 You need to know: where most koha files should be stored (you can set
128 the prefix environment variable for this); the username and password of
129 a mysql superuser; and details of your library setup. You may also need
130 to know details of your Apache setup.
132 If you want to install the Koha configuration files somewhere other than
133 /etc (for multiple Koha versions on one system, for example), you should
134 set the etcdir environment variable. Please look at your manuals for
135 details of how to set that.
137 Recommended answers are given in brackets after each question. To accept
138 the default value for any question (indicated by []), simply hit Enter
141 Are you ready to begin the installation? ([Y]/N): |;
143 $messages->{'WelcomeToUpgrader'}->{en} =
144 heading('Welcome to the Koha Upgrader') . qq|
145 You are attempting to upgrade from Koha %s to %s.
147 We recommend that you do a complete backup of all your files before upgrading.
148 This upgrade script will make a backup copy of your files for you.
150 Would you like to proceed? (Y/[N]):|;
152 $messages->{'AbortingInstall'}->{en} =
153 heading('ABORTING') . qq|
154 Aborting as requested. Please rerun when you are ready.
157 $messages->{'ReleaseCandidateWarning'}->{en} =
158 heading('RELEASE CANDIDATE') . qq|
159 WARNING: You are about to install Koha version %s. This is a
160 release candidate, It is NOT bugfree.
161 However, it works, and has been declared stable enough to
164 Most people should answer Yes here.
166 Are you sure you want to install Koha %s? (Y/[N]): |;
167 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
169 Watch for announcements of Koha releases on the Koha mailing list or the Koha
170 web site (http://www.koha.org/).
174 $messages->{'NETZ3950Missing'}->{en}=qq|
176 The Net::Z3950 module is missing. This module is necessary if you want to use
177 Koha's Z39.50 client to download bibliographic records from other libraries.
179 To install this module, you will need the yaz client installed from
180 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
183 perl -MCPAN -e 'install Net::Z3950'
185 ...or by installing packages for your distribution, if available.
187 IMPORTANT NOTE : If you use Perl 5.8.0, you might need to
188 edit NET::Z3950's Makefile.PL and yazwrap/Makefile.PL to include:
190 'DEFINE' => '-D_GNU_SOURCE',
192 Also note that some installations of Perl on Red Hat will generate a lot of
193 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
194 inserting in yazwrap/ywpriv.h a line saying #include "XSUB.h"
196 Press the <ENTER> key to continue: |; #'
198 $messages->{'CheckingPerlModules'}->{en} = heading('PERL MODULES') . qq|
199 Checking perl modules ...
202 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
204 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
205 You are missing some Perl modules required by Koha.
206 Please run this again after installing them.
207 They may be installed by finding packages from your operating system supplier, or running (as root) the following commands:
212 $messages->{'AllPerlModulesInstalled'}->{en} =
213 heading('PERL MODULES AVAILABLE') . qq|
214 All required perl modules are installed.
216 Press <ENTER> to continue: |;
217 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
218 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
219 $messages->{'KohaAlreadyInstalled'}->{en} =
220 heading('Koha already installed') . qq|
221 It looks like Koha is already installed on your system (%s/koha.conf exists).
222 If you would like to upgrade your system to %s, please use
223 the koha.upgrade script in this directory.
228 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
229 Please supply the directory you want Koha to store its OPAC files in. This
230 directory will be auto-created for you if it doesn't exist.
232 OPAC Directory [%s]: |; #'
234 $messages->{'GetIntranetDir'}->{en} =
235 heading('LIBRARIAN DIRECTORY') . qq|
236 Please supply the directory you want Koha to store its Librarian interface
237 files in. This directory will be auto-created for you if it doesn't exist.
239 Intranet Directory [%s]: |; #'
241 $messages->{'GetKohaLogDir'}->{en} = heading('LOG DIRECTORY') . qq|
242 Specify a directory where log files will be written.
244 Koha Log Directory [%s]: |;
246 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
247 This release of Koha has a new authentication module.
248 You will be required to log in to
249 access some features.
251 IMPORTANT: You can log in using the userid and password from the %s/koha.conf configuration file at any time.
252 Use the "Members" screen to add passwords for other accounts and set their flags.
254 Press the <ENTER> key to continue: |;
256 $messages->{'Completed'}->{en} = heading('INSTALLATION COMPLETE') . qq|
257 Congratulations ... your Koha installation is complete!
259 You will be able to connect to your Librarian interface at:
263 use the koha admin mysql login and password to connect to this interface.
265 and the OPAC interface at:
269 Please read the Hints file and visit http://www.koha.org
271 Press <ENTER> to exit the installer: |;
273 $messages->{'UpgradeCompleted'}->{en} = heading('UPGRADE COMPLETE') . qq|
274 Congratulations ... your Koha upgrade is finished!
276 If you are upgrading from a version of Koha
277 prior to 1.2.1, it is likely that you will have to modify your Apache
278 configuration to point it to the new files.
280 In your INTRANET VirtualHost section you should have:
281 DocumentRoot %s/htdocs
282 ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
283 SetEnv PERL5LIB %s/modules
285 In the OPAC VirtualHost section you should have:
286 DocumentRoot %s/htdocs
287 ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
288 SetEnv PERL5LIB %s/modules
290 You may also need to uncomment a "LoadModules env_module ... " line and restart
292 If you're upgrading from 1.2.x version of Koha note that the MARC DB is NOT populated.
295 * Go to Parameters >> Marc structure option and Koha-MARC links option.
296 * Modify default MARC structure to fit your needs.
299 cd /path/to/koha/misc
300 export PERL5LIB=/path/to/koha
302 the old DB is "copied" in the new MARC one.
303 Koha 2.0.0 is ready :-)
305 Please report any problems you encounter through http://bugs.koha.org/
307 Press <ENTER> to exit the installer: |;
309 sub releasecandidatewarning {
310 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
311 my $answer=showmessage($message, 'yn', 'n');
313 if ($answer =~ /y/i) {
314 print getmessage('continuing');
316 my $message=getmessage('WatchForReleaseAnnouncements');
325 =head2 Accessor functions (for installer.pl)
335 Sets the installation language, normally "en" (English).
336 In fact, only "en" is supported.
340 sub setlanguage ($) {
346 setdomainname('example.org');
348 Sets the domain name of the host.
350 The domain name should not contain a leading dot;
351 otherwise, the results are undefined.
355 sub setdomainname ($) {
363 Sets the sysconfdir, normally /etc.
364 This should be an absolute path; a trailing / is not required.
376 Gets the Koha version as known by the previous config file.
380 sub getkohaversion () {
381 return($kohaversion);
386 setkohaversion('1.3.3RC26');
388 Sets the Koha version as known by the installer.
392 sub setkohaversion ($) {
398 my $servername = getservername;
400 Gets the name of the Koha virtual server as specified by the user.
404 sub getservername () {
412 Gets the port that will run the Koha OPAC virtual server,
413 as specified by the user.
421 =item getintranetport
423 $port = getintranetport;
425 Gets the port that will run the Koha INTRANET virtual server,
426 as specified by the user.
430 sub getintranetport () {
436 =head2 Miscellaneous utility functions
446 Does the equivalent of dirname(1). Given a path $path, return the
447 parent directory of $path (best guess), except when $path seems to
448 be the same as /, in which case $path itself is returned unchanged.
454 if ($path =~ /[^\/]/s) {
456 $path =~ s/\/+[^\/]+\/*$//s;
467 mkdir_parents $path, $mode;
469 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
470 create the directory $path, recursively creating any intermediate
471 directories. If $mode is given, the directory will be created with
474 WARNING: If $path already exists, mkdir_parents will just return
475 successfully (just like mkdir -p), whether the mode of $path conforms
476 to $mode or not. (This is the behaviour of the mkdir -p command.)
481 my($path, $mode) = @_;
482 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
484 if (!$ok && $! == ENOENT) {
485 my $parent = dirname($path);
486 $ok = mkdir_parents($parent, $mode);
488 # retry and at the same time make sure that $! is set correctly
489 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
498 getmessage($msgid, $variables);
500 Gets a localized message (format string) with message id $msgid,
501 and, if an array reference of variables $variables is given,
502 substitutes variables in the format string with @$variables.
503 Returns the found message string, with variable substitutions
506 $msgid must be the message identifier corresponding to a defined
507 message string (a valid key to the $messages hash in the Installer
508 package). getmessage throws an exception if the message cannot be
514 my $messagename=shift;
516 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || RED.BOLD."Error: No message named $messagename in Install.pm\n";
517 if (defined($variables)) {
518 $message=sprintf $message, @$variables;
526 showmessage($message, 'none');
527 showmessage($message, 'none', undef, $noclear);
529 $result = showmessage($message, 'yn');
530 $result = showmessage($message, 'yn', $defaultresponse);
531 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
533 $result = showmessage($message, 'restrictchar CHARS');
534 $result = showmessage($message, 'free');
535 $result = showmessage($message, 'silentfree');
536 $result = showmessage($message, 'numerical');
537 $result = showmessage($message, 'email');
538 $result = showmessage($message, 'PressEnter');
540 Shows a message and optionally gets a response from the user.
542 The first two arguments, the message and the response type,
543 are mandatory. The message must be the actual string to
544 display; the caller is responsible for calling getmessage if
547 The response type must be one of "none", "yn", "free", "silentfree"
548 "numerical", "email", "PressEnter", or a string consisting
549 of "restrictchar " followed by a list of allowed characters
550 (space can be specified). (Case is not significant, but case is
551 significant in the list of allowed characters.) If a response
552 type other than the above-listed is specified, the result is
555 Note that the response type "yn" is equivalent to "restrictchar yn".
556 Because "restrictchar" is case-sensitive, the user is expected
557 to enter "y" or "n" in lowercase only.
559 Note that the response type of "email" does not actually
560 guarantee that the returned value is a well-formed RFC-822
561 email address, nor does it accept all well-formed RFC-822 email
562 addresses. What it does is to restrict the returned value to a
563 string that is looks reasonably likely to be an email address
564 in the "real world", given the premise that the user is trying
565 to enter a real email address.
567 If a response type other than "none" or "PressEnter" is
568 specified, a third argument, specifying the default value, can
569 be specified: If this default response is not specified, the
570 default response is the first allowed character if the response
571 type is "restrictchar", otherwise the default response is the
572 empty string. This default response is used when the user does
573 not specify a value (i.e., presses Enter without typing in
574 anything), showmessage will assume that the default response is
577 Note that because the response type "yn" is equivalent to
578 "restrictchar yn", the default value for response type "yn",
579 if unspecified, is "y".
581 The screen is normally cleared before the message is displayed;
582 if a fourth argument is specified and is nonzero, this
583 screen-clearing is not done.
589 #MJR: Maybe refactor to use anonymous functions that
590 # check the responses instead of RnP branching.
591 my $message=join('',fill('','',(shift)));
592 my $responsetype=shift;
593 my $defaultresponse=shift;
595 $noclear = 0 unless defined $noclear; # defaults to "clear"
596 ($noclear) || (print $clear_string);
597 if ($responsetype =~ /^yn$/) {
598 $responsetype='restrictchar ynYN';
600 print RESET.$message;
601 if ($responsetype =~/^restrictchar (.*)/i) {
604 until ($options=~/$response/) {
605 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
608 (length($response)) || ($response=$defaultresponse);
609 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
610 ($noclear) || (print $clear_string);
611 print RED."Response contains invalid characters. Choose from [$options].\n\n";
612 print RESET.$message;
615 unless ($options=~/$response/) {
616 ($noclear) || (print $clear_string);
617 print RED."Invalid Response. Choose from [$options].\n\n";
618 print RESET.$message;
623 } elsif ($responsetype =~/^(silent)?free$/i) {
624 (defined($defaultresponse)) || ($defaultresponse='');
625 if ($responsetype =~/^(silent)/i) { setecho(0) };
626 my $response=<STDIN>;
627 if ($responsetype =~/^(silent)/i) { setecho(1) };
629 ($response) || ($response=$defaultresponse);
631 } elsif ($responsetype =~/^numerical$/i) {
632 (defined($defaultresponse)) || ($defaultresponse='');
634 until ($response=~/^\d+$/) {
637 ($response) || ($response=$defaultresponse);
638 unless ($response=~/^\d+$/) {
639 ($noclear) || (print $clear_string);
640 print RED."Invalid Response ($response). Response must be a number.\n\n";
641 print RESET.$message;
645 } elsif ($responsetype =~/^email$/i) {
646 (defined($defaultresponse)) || ($defaultresponse='');
648 until ($response=~/.*\@.*\..*/) {
651 ($response) || ($response=$defaultresponse);
652 if ($response!~/.*\@.*\..*/) {
653 ($noclear) || (print $clear_string);
654 print RED."Invalid Response ($response). Response must be a valid email address.\n\n";
655 print RESET.$message;
659 } elsif ($responsetype =~/^PressEnter$/i) {
662 } elsif ($responsetype =~/^none$/i) {
665 # FIXME: There are a few places where we will get an undef as the
666 # response type. Should we thrown an exception here, or should we
667 # legitimize this usage and say "none" is the default if not specified?
668 #die "Illegal response type \"$responsetype\"";
679 Changes the display to show system output until the next showmessage call.
680 At the time of writing, this means using red text.
691 =head2 Subtasks of doing an installation
697 =item checkabortedinstall
701 Checks whether a previous installation process has been abnormally
702 aborted, by checking whether $etcidr/koha.conf is a symlink matching
703 a particular pattern. If an aborted installation is detected, give
704 the user a chance to abort, before trying to recover the aborted
707 FIXME: The recovery is not complete; it only partially rolls back
712 sub checkabortedinstall () {
713 if (-l("$etcdir/koha.conf")
714 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
717 I have detected that you tried to install Koha before, but the installation
718 was aborted. I will try to continue, but there might be problems if the
719 database is already created.
722 print "Please press <ENTER> to continue: ";
725 # Remove the symlink after the <STDIN>, so the user can back out
726 unlink "$etcdir/koha.conf"
727 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
735 Make sure that we loaded the right dirs from an old koha.conf
739 #FIXME: update to use Install.pm
741 if ($opacdir && $intranetdir) {
744 I believe that your old files are located in:
747 LIBRARIAN: $intranetdir
750 Does this look right? ([Y]/N):
752 my $answer = <STDIN>;
755 if ($answer =~/n/i) {
759 print "Great! continuing upgrade... \n";
763 if (!$opacdir || !$intranetdir) {
766 while (!$intranetdir) {
767 print "Please specify the location of your LIBRARIAN files: ";
769 my $answer = <STDIN>;
773 $intranetdir=$answer;
775 if (! -e "$intranetdir/htdocs") {
776 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
781 print "Please specify the location of your OPAC files: ";
783 my $answer = <STDIN>;
789 if (! -e "$opacdir/htdocs") {
790 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
798 =item checkperlmodules
802 Test whether the version of Perl is new enough, whether Perl is
803 found at the expected location, and whether all required modules
808 sub checkperlmodules {
810 # Test for Perl and Modules
813 my $message = getmessage('CheckingPerlModules');
814 showmessage($message, 'none');
816 unless ($] >= 5.006001) { # Bug 179
817 die getmessage('PerlVersionFailure', ['5.6.1']);
822 unless (eval {require DBI}) { push @missing,"DBI" };
823 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
824 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
825 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
826 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
827 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
828 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
829 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
830 unless (eval {require Event}) {
831 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
832 push @missing, "Event";
835 unless (eval {require Net::Z3950}) {
836 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
837 if ($#missing>=0) { # see above note
838 push @missing, "Net::Z3950";
843 # Print out a list of any missing modules
848 if (POSIX::setlocale(LC_ALL) ne "C") {
849 $missing.=" export LC_ALL=C\n";
851 foreach my $module (@missing) {
852 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
854 my $message=getmessage('MissingPerlModules', [$missing]);
855 showmessage($message, 'none');
859 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
864 unless (-x "/usr/bin/perl") {
865 my $realperl=`which perl`;
867 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
868 until (-x $realperl) {
869 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
871 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
872 unless ($response eq 'n') {
874 system("ln -s $realperl /usr/bin/perl");
881 $messages->{'NoUsrBinPerl'}->{en} =
882 heading('No /usr/bin/perl') . qq|
883 Koha expects to find the perl executable in the /usr/bin
884 directory. It is not there on your system.
888 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable [%s]: |;
889 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
890 Some Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
892 Most users should answer Y here.
894 May I try to create this symlink? ([Y]/N):|;
896 $messages->{'DirFailed'}->{en} = RED.qq|
897 We could not create %s, but continuing anyway...
903 =item getinstallationdirectories
905 getinstallationdirectories;
907 Get the various installation directories from the user, and then
908 create those directories (if they do not already exist).
910 These pieces of information are saved to global variables; the
911 function does not return any values.
915 sub getinstallationdirectories {
916 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
917 $opacdir = $ENV{prefix}.'/koha/opac';
918 $intranetdir = $ENV{prefix}.'/koha/intranet';
920 while ($getdirinfo) {
921 # Loop until opac directory and koha directory are different
922 my $message=getmessage('GetOpacDir', [$opacdir]);
923 $opacdir=showmessage($message, 'free', $opacdir);
925 $message=getmessage('GetIntranetDir', [$intranetdir]);
926 $intranetdir=showmessage($message, 'free', $intranetdir);
928 if ($intranetdir eq $opacdir) {
931 You must specify different directories for the OPAC and INTRANET files!
932 :: $intranetdir :: $opacdir ::
939 $kohalogdir=$ENV{prefix}.'/koha/log';
940 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
941 $kohalogdir=showmessage($message, 'free', $kohalogdir);
944 # FIXME: Need better error handling for all mkdir calls here
945 unless ( -d $intranetdir ) {
946 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed',['parents of '.$intranetdir]);
947 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',[$intranetdir]);
948 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir"); }
949 chmod 0770, "$intranetdir";
951 mkdir_parents ("$intranetdir/htdocs", 0750);
952 mkdir_parents ("$intranetdir/cgi-bin", 0750);
953 mkdir_parents ("$intranetdir/modules", 0750);
954 mkdir_parents ("$intranetdir/scripts", 0750);
955 unless ( -d $opacdir ) {
956 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed',['parents of '.$opacdir]);
957 mkdir ($opacdir, 0770) || print getmessage('DirFailed',[$opacdir]);
958 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$opacdir"); }
959 chmod (oct(770), "$opacdir");
961 mkdir_parents ("$opacdir/htdocs", 0750);
962 mkdir_parents ("$opacdir/cgi-bin", 0750);
965 unless ( -d $kohalogdir ) {
966 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed',['parents of '.$kohalogdir]);
967 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',[$kohalogdir]);
968 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir"); }
969 chmod (oct(770), "$kohalogdir");
977 Get the MySQL database server installation directory, automatically if possible.
981 $messages->{'WhereIsMySQL'}->{en} = heading('MYSQL LOCATION').qq|
982 Koha can't find the MySQL command-line tools. If you installed a MySQL package, you may need to install an additional package containing mysqladmin.
983 If you compiled mysql yourself,
984 please give the value of --prefix when you ran configure.
985 The file mysqladmin should be in bin/mysqladmin under the directory that you give here.
987 MySQL installation directory: |;
990 foreach my $mysql (qw(/usr/local/mysql
995 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1001 $mysqldir = showmessage(getmessage('WhereIsMySQL'),'free');
1002 last if -f "$mysqldir/bin/mysqladmin";
1008 =item getdatabaseinfo
1012 Get various pieces of information related to the Koha database:
1013 the name of the database, the host on which the SQL server is
1014 running, and the database user name.
1016 These pieces of information are saved to global variables; the
1017 function does not return any values.
1021 $messages->{'DatabaseName'}->{en} = heading('Database Name') . qq|
1022 Please provide the name that you wish to give your koha database.
1023 It must not exist already on the database server.
1025 Most users give a short single-word name for their library here.
1027 Database name [%s]: |;
1029 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
1030 Please provide the mysql server name. Unless the database is stored on
1031 another machine, this should be "localhost".
1033 Database host [%s]: |;
1035 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
1036 We are going to create a new mysql user for Koha. This user will have full administrative rights
1037 to the database called %s when they connect from %s.
1038 This is also the name of the Koha librarian superuser.
1040 Most users give a single-word name here.
1042 Database user [%s]: |;
1044 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
1045 Please provide a good password for the user %s.
1047 IMPORTANT: You can log in using this user and password at any time.
1049 Password for database user %s: |;
1051 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
1052 You must not use a blank password for your MySQL user.
1054 Press <ENTER> to try again:
1057 sub getdatabaseinfo {
1060 $hostname = 'localhost';
1061 $user = 'kohaadmin';
1064 #Get the database name
1066 my $message=getmessage('DatabaseName', [$database]);
1067 $database=showmessage($message, 'free', $database);
1069 #Get the hostname for the database
1071 $message=getmessage('DatabaseHost', [$hostname]);
1072 $hostname=showmessage($message, 'free', $hostname);
1074 #Get the username for the database
1076 $message=getmessage('DatabaseUser', [$database, $hostname, $user]);
1077 $user=showmessage($message, 'free', $user);
1079 #Get the password for the database user
1081 while ($pass eq '') {
1082 my $message=getmessage('DatabasePassword', [$user, $user]);
1083 $pass=showmessage($message, 'free', $pass);
1085 my $message=getmessage('BlankPassword');
1086 showmessage($message,'PressEnter');
1097 Get various pieces of information related to the Apache server:
1098 the location of the configuration file and, if needed, the Unix
1099 user that the Koha CGI will be run under.
1101 These pieces of information are saved to global variables; the
1102 function does not return any values.
1106 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
1107 heading('MULTIPLE APACHE CONFIG FILES FOUND') . qq|
1108 I found more than one possible Apache configuration file:
1112 Enter number of the file to read [1]: |;
1114 $messages->{'NoApacheConfFiles'}->{en} =
1115 heading('NO APACHE CONFIG FILE FOUND') . qq|
1116 I was not able to find your Apache configuration file.
1118 The file is usually called httpd.conf, apache.conf or similar.
1120 Please enter the full name, starting with /: |;
1122 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
1123 The file %s does not exist.
1125 Please press <ENTER> to continue: |;
1127 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq\
1128 The installer could not find the User setting in the Apache configuration file.
1129 This is used to set up access permissions for
1130 %s/koha.conf. This user should be set in one of the Apache configuration.
1131 Please try to find it and enter the user name below. You might find
1132 that "ps u|grep apache" will tell you. It probably is NOT "root".
1134 Enter the Apache userid: \;
1136 $messages->{'InvalidUserid'}->{en} = heading('INVALID USER') . qq|
1137 The userid %s is not a valid userid on this system.
1139 Press <ENTER> to continue: |;
1142 my @confpossibilities;
1144 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
1145 /usr/local/etc/apache/httpd.conf
1146 /usr/local/etc/apache/apache.conf
1147 /var/www/conf/httpd.conf
1148 /etc/apache2/httpd.conf
1149 /etc/apache2/apache2.conf
1150 /etc/apache/conf/httpd.conf
1151 /etc/apache/conf/apache.conf
1152 /etc/apache/httpd.conf
1153 /etc/apache-ssl/conf/apache.conf
1154 /etc/apache-ssl/httpd.conf
1155 /etc/httpd/conf/httpd.conf
1156 /etc/httpd/httpd.conf
1157 /etc/httpd/2.0/conf/httpd2.conf
1159 if ( -f $httpdconf ) {
1160 push @confpossibilities, $httpdconf;
1164 if ($#confpossibilities==-1) {
1165 my $message=getmessage('NoApacheConfFiles');
1168 until (-f $realhttpdconf) {
1169 $choice=showmessage($message, "free", 1);
1171 $realhttpdconf=$choice;
1173 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
1176 } elsif ($#confpossibilities>0) {
1180 foreach (@confpossibilities) {
1181 $conffiles.=" $counter: $_\n";
1182 $options.="$counter";
1185 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
1186 my $choice=showmessage($message, "restrictchar $options", 1);
1187 $realhttpdconf=$confpossibilities[$choice-1];
1189 $realhttpdconf=$confpossibilities[0];
1191 unless (open (HTTPDCONF, "<$realhttpdconf")) {
1192 warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
1196 while (<HTTPDCONF>) {
1197 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
1203 unless (defined($httpduser)) {
1204 my $message=getmessage('EnterApacheUser', [$etcdir]);
1205 until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
1206 $httpduser=showmessage($message, "free", '');
1207 if (length($httpduser)>0) {
1208 unless (getpwnam($httpduser)) {
1209 my $message=getmessage('InvalidUserid', [$httpduser]);
1210 showmessage($message,'PressEnter');
1219 =item getapachevhostinfo
1223 Gets various pieces of information related to virtual hosting:
1224 the webmaster email address, virtual hostname, and the ports
1225 that the OPAC and INTRANET modules run on.
1227 These pieces of information are saved to global variables; the
1228 function does not return any values.
1232 $messages->{'ApacheConfigIntroduction'}->{en} =
1233 heading('APACHE CONFIGURATION') . qq|
1234 Koha needs to write an Apache configuration file for the
1235 OPAC and Librarian sites. By default this installer
1236 will do this by using one name and two different ports
1237 for the virtual hosts. There are other ways to set this up,
1238 and the installer will leave comments in
1239 %s/koha-httpd.conf about them.
1241 NOTE: You will need to add lines to your main httpd.conf to
1242 include %s/koha-httpd.conf
1243 and to make sure it is listening on the right ports
1244 (using the Listen directive).
1246 Press <ENTER> to continue: |;
1248 $messages->{'GetVirtualHostEmail'}->{en} =
1249 heading('WEB E-MAIL CONTACT') . qq|
1250 Enter the e-mail address to be used as a contact for Koha. This
1251 address is displayed if fatal errors are encountered.
1253 E-mail contact [%s]: |;
1255 $messages->{'GetServerName'}->{en} =
1256 heading('WEB HOST NAME OR IP ADDRESS') . qq|
1257 Please enter the host name or IP address that you wish to use for koha.
1258 Normally, this should be a name or IP that belongs to this machine.
1260 Host name or IP Address [%s]: |;
1262 $messages->{'GetOpacPort'}->{en} = heading('OPAC PORT') . qq|
1263 Please enter the port for your OPAC interface. This defaults to port 80, but
1264 if you are already serving web content with this hostname, you should change it
1265 to a different port (8000 might be a good choice, but check any firewalls).
1267 Enter the OPAC Port [%s]: |;
1269 $messages->{'GetIntranetPort'}->{en} =
1270 heading('LIBRARIAN PORT') . qq|
1271 Please enter the port for your Librarian interface. This must be different from
1274 Enter the Intranet Port [%s]: |;
1277 sub getapachevhostinfo {
1279 $svr_admin = "webmaster\@$domainname";
1280 $servername=`hostname`;
1285 showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
1287 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1288 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1291 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1292 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1297 =item updateapacheconf
1301 Updates the Apache config file according to parameters previously
1302 specified by the user.
1304 It will append fully-commented directives at the end of the original
1305 Apache config file. The old config file is renamed with an extension
1308 If you need to uninstall Koha for any reason, the lines between
1310 # Ports to listen to for Koha
1312 and the block of comments beginning with
1314 # If you want to use name based Virtual Hosting:
1320 $messages->{'StartUpdateApache'}->{en} =
1321 heading('UPDATING APACHE CONFIGURATION') . qq|
1322 Checking for modules that need to be loaded...
1325 $messages->{'ApacheConfigMissingModules'}->{en} =
1326 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1327 Koha uses the mod_env and mod_include apache features, but the
1328 installer did not find them in your config. Please
1329 make sure that they are enabled for your Koha site.
1331 Press <ENTER> to continue: |;
1334 $messages->{'ApacheAlreadyConfigured'}->{en} =
1335 heading('APACHE ALREADY CONFIGURED') . qq|
1336 %s appears to already have an entry for Koha. You may need to edit %s
1337 if anything has changed since it was last set up. This
1338 script will not attempt to modify an existing Koha apache
1341 Press <ENTER> to continue: |;
1343 sub updateapacheconf {
1344 my $logfiledir=$kohalogdir;
1345 my $httpdconf = $etcdir."/koha-httpd.conf";
1347 showmessage(getmessage('StartUpdateApache'), 'none');
1348 # to be polite about it: I don't think this should touch the main httpd.conf
1350 # QUESTION: Should we warn for includes_module too?
1352 my $includesmodule=0;
1353 open HC, "<$realhttpdconf";
1355 if (/^\s*#\s*LoadModule env_module /) {
1356 showmessage(getmessage('ApacheConfigMissingModules'));
1359 if (/\s*LoadModule includes_module / ) {
1365 if (`grep -q 'VirtualHost $servername' "$httpdconf" 2>/dev/null`) {
1366 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1369 my $includesdirectives='';
1370 if ($includesmodule) {
1371 $includesdirectives.="Options +Includes\n";
1372 $includesdirectives.=" AddHandler server-parsed .html\n";
1374 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1375 my $opaclisten = '';
1376 if ($opacport != 80) {
1377 $opaclisten="Listen $opacport";
1379 my $intranetlisten = '';
1380 if ($intranetport != 80) {
1381 $intranetlisten="Listen $intranetport";
1385 # Ports to listen to for Koha
1386 # uncomment these if they aren't already in main httpd.conf
1390 # NameVirtualHost is used by one of the optional configurations detailed below
1392 #NameVirtualHost 11.22.33.44
1394 # KOHA's OPAC Configuration
1395 <VirtualHost $servername\:$opacport>
1396 ServerAdmin $svr_admin
1397 DocumentRoot $opacdir/htdocs
1398 ServerName $servername
1399 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1400 ErrorLog $logfiledir/opac-error_log
1401 TransferLog $logfiledir/opac-access_log
1402 SetEnv PERL5LIB "$intranetdir/modules"
1403 SetEnv KOHA_CONF "$etcdir/koha.conf"
1407 # KOHA's INTRANET Configuration
1408 <VirtualHost $servername\:$intranetport>
1409 ServerAdmin $svr_admin
1410 DocumentRoot $intranetdir/htdocs
1411 ServerName $servername
1412 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1413 ErrorLog $logfiledir/koha-error_log
1414 TransferLog $logfiledir/koha-access_log
1415 SetEnv PERL5LIB "$intranetdir/modules"
1416 SetEnv KOHA_CONF "$etcdir/koha.conf"
1420 # If you want to use name based Virtual Hosting:
1421 # 1. remove the two Listen lines
1422 # 2. replace $servername\:$opacport wih your.opac.domain.name
1423 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1424 # 4. replace $servername\:$intranetport wih your intranet domain name
1425 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1427 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1428 # 1. Follow steps 1-5 above
1429 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1438 =item basicauthentication
1440 basicauthentication;
1442 Asks the user whether HTTP basic authentication is wanted, and,
1443 if so, the user name and password for the basic authentication.
1445 These pieces of information are saved to global variables; the
1446 function does not return any values.
1450 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1451 heading('LIBRARIAN AUTHENTICATION') . qq|
1452 The Librarian site can be password protected using
1453 Apache's Basic Authorization instead of Koha user details.
1455 This method going to be phased out very soon. Most users should answer N here.
1457 Would you like to do this (Y/[N]): |; #'
1459 $messages->{'BasicAuthUsername'}->{en}="Please enter a username for librarian access [%s]: ";
1460 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1461 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1463 sub basicauthentication {
1464 my $message=getmessage('IntranetAuthenticationQuestion');
1465 my $answer=showmessage($message, 'yn', 'n');
1466 my $httpdconf = $etcdir."/koha-httpd.conf";
1468 my $apacheauthusername='librarian';
1469 my $apacheauthpassword='';
1470 if ($answer=~/^y/i) {
1471 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1472 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1473 while (! $apacheauthpassword) {
1474 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1475 if (!$apacheauthpassword) {
1476 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1479 open AUTH, ">$etcdir/kohaintranet.pass";
1480 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1481 my $salt=substr($chars, int(rand(length($chars))),1);
1482 $salt.=substr($chars, int(rand(length($chars))),1);
1483 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1485 open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1488 <Directory $intranetdir>
1489 AuthUserFile $etcdir/kohaintranet.pass
1491 AuthName "Koha Intranet (for librarians only)"
1504 Install the Koha files to the specified OPAC and INTRANET
1505 directories (usually in /usr/local/koha).
1507 The koha.conf file is created, but as koha.conf.tmp. The
1508 caller is responsible for calling finalizeconfigfile when
1509 installation is completed, to rename it back to koha.conf.
1513 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1514 Copying files to installation directories:
1518 $messages->{'OldFiles'}->{en} = heading('OLD FILES') . qq|
1519 Any files from the previous edition of Koha have been
1520 copied to a dated backup directory alongside the new
1521 installation. You should move any custom files that you
1522 want to keep (such as your site templates) into the new
1523 directories and then move the backup off of the live
1526 Press ENTER to continue:|;
1529 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1535 #MJR: preserve old files, just in case
1542 print getmessage('CopyingFiles', ["old ".$desc,$tgt.strftime("%Y%m%d%H%M",localtime())]);
1544 system("mv ".$tgt." ".$tgt.strftime("%Y%m%d%H%M",localtime()));
1547 print getmessage('CopyingFiles', [$desc,$tgt]);
1549 system("cp -R ".$src." ".$tgt);
1552 showmessage(getmessage('InstallFiles'),'none');
1554 neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs");
1555 neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin");
1556 neatcopy("main scripts", 'scripts', "$intranetdir/scripts");
1557 neatcopy("perl modules", 'modules', "$intranetdir/modules");
1558 neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs");
1559 neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin");
1561 system("touch $opacdir/cgi-bin/opac");
1563 #MJR: is this necessary?
1565 system("chown -R $httpduser:$httpduser $opacdir $intranetdir");
1567 system("chmod -R a+rx $opacdir $intranetdir");
1569 # Create /etc/koha.conf
1571 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1572 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1578 intranetdir=$intranetdir
1580 kohalogdir=$kohalogdir
1581 kohaversion=$newversion
1582 httpduser=$httpduser
1583 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1584 opachtdocs=$opacdir/htdocs/opac-tmpl
1590 #MJR: can't help but this be broken, can we?
1591 chmod 0440, "$etcdir/koha.conf.tmp";
1593 #MJR: does this contain any passwords?
1594 chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
1596 #MJR: generate our own settings, to remove the /home/paul hardwired links
1597 open(FILE,">$intranetdir/scripts/z3950daemon/z3950-daemon-options");
1598 print FILE "RunAsUser=$httpduser\nKohaZ3950Dir=$intranetdir/scripts/z3950daemon\nKohaModuleDir=$intranetdir/modules\nLogDir=$kohalogdir\nKohaConf=$etcdir/koha.conf";
1602 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1603 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1604 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1605 } #MJR: report that we haven't chown()d.
1607 print "Please check permissions in $intranetdir/scripts/z3950daemon\n";
1610 showmessage(getmessage('OldFiles'),'PressEnter');
1618 Finds out where the MySQL utitlities are located in the system,
1619 then create the Koha database structure and MySQL permissions.
1623 $messages->{'MysqlRootPassword'}->{en} =
1624 heading('MYSQL ROOT USER PASSWORD') . qq|
1625 To create the koha database, please enter your
1626 mysql server's root user password:
1630 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1631 Creating the MySQL database for Koha...
1635 $messages->{'CreatingDatabaseError'}->{en} =
1636 heading('ERROR CREATING DATABASE') . qq|
1637 Couldn't connect to the MySQL server for the reason given above.
1638 This is a serious problem, the database will not get installed.
1640 Press <ENTER> to continue: |; #'
1642 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1643 If you are installing Koha for evaluation purposes,
1644 you can install some sample data now.
1646 If you are installing Koha to use your own
1647 data, you probably don't want this sample data installed.
1649 Would you like to install the sample data? Y/[N]: |; #'
1651 $messages->{'SampleDataInstalled'}->{en} =
1652 heading('SAMPLE DATA INSTALLED') . qq|
1653 Sample data has been installed. For some suggestions on testing Koha, please
1654 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1655 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1656 question through the koha-devel mailing list, or you can check for a developer
1657 online at irc.katipo.co.nz:6667 channel #koha.
1659 You can find instructions for subscribing to the Koha mailing lists at:
1664 Press <ENTER> to continue: |;
1666 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1667 Would you like to describe an initial branch and printer? [Y]/N: |;
1669 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1670 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1671 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1672 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1675 $mysqluser = 'root';
1677 my $mysqldir = getmysqldir();
1679 # we must not put the mysql root password on the command line
1680 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'silentfree');
1682 showmessage(getmessage('CreatingDatabase'),'none');
1684 setmysqlclipass($mysqlpass);
1685 # Set up permissions
1687 print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
1688 system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$database','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
1689 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1690 # Change to admin user login
1691 setmysqlclipass($pass);
1692 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$database");
1694 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1696 # Create the database structure
1698 system("$mysqldir/bin/mysql -u$user $database < koha.mysql");
1704 =item updatedatabase
1708 Updates the Koha database structure, including the addition of
1711 The MARC tables are also populated in addition to being created.
1713 Because updatedatabase calls scripts/updater/updatedatabase to
1714 do the actual update, and that script uses C4::Context,
1715 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1716 environment variable to do this.
1718 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1722 $messages->{'UpdateMarcTables'}->{en} =
1723 heading('MARC FIELD DEFINITIONS') . qq|
1724 You can import MARC settings for:
1730 NOTE: If you choose N,
1731 nothing will be added, and you must create them all yourself.
1732 Only choose N if you want to use a MARC format not listed here,
1733 such as DANMARC. We would like to hear from you if you do.
1735 Choose MARC definition [1]: |;
1737 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGE') . qq|
1738 This version of koha supports a few languages.
1740 en : default language, all pages available
1741 fr : complete translation (except pictures)
1742 es : partial librarian site translation (including pictures)
1743 pl : complete OPAC and partial librarian translation
1744 zh_TW : partial translation
1746 en is used when a screen is not available in your language
1748 If you specify a language here, you can still
1749 change it from the system preferences screen in the librarian sit.
1751 Which language do you choose? |;
1753 sub updatedatabase {
1754 # At this point, $etcdir/koha.conf must exist, for C4::Context
1755 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf';
1756 if (! -e $ENV{"KOHA_CONF"}) { $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp'; }
1758 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
1761 print "Problem updating database...\n";
1765 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1768 if ($response eq '1') {
1769 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1770 system("cat scripts/misc/lang-datas/en/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
1772 if ($response eq '2') {
1773 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1774 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
1776 delete($ENV{"KOHA_CONF"});
1778 print RESET."\n\nFinished updating of database. Press <ENTER> to continue...";
1783 =item populatedatabase
1787 Populate the non-MARC tables. If the user wants to install the
1788 sample data, install them.
1792 sub populatedatabase {
1793 # my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1794 # if ($response =~/^y/i) {
1796 # FIXME: These calls are now unsafe and should either be removed
1797 # or updated to use -u$user and no mysqlpass_quoted
1799 # system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $database");
1800 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $database -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1801 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1802 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1803 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $database -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1804 # showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1807 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1809 unless ($response =~/^n/i) {
1810 my $branch='Main Library';
1811 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1812 $branch=~s/[^A-Za-z0-9\s]//g;
1814 my $branchcode=$branch;
1815 $branchcode=~s/[^A-Za-z0-9]//g;
1816 $branchcode=uc($branchcode);
1817 $branchcode=substr($branchcode,0,4);
1818 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1819 $branchcode=~s/[^A-Za-z0-9]//g;
1820 $branchcode=uc($branchcode);
1821 $branchcode=substr($branchcode,0,4);
1822 $branchcode or $branchcode='DEF';
1825 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1826 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1827 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1829 my $printername='Library Printer';
1830 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1831 $printername=~s/[^A-Za-z0-9\s]//g;
1833 my $printerqueue='lp';
1834 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1835 $printerqueue=~s/[^A-Za-z0-9]//g;
1837 system("$mysqldir/bin/mysql -u$user $database -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1839 my $language=showmessage(getmessage('Language'), 'free', 'en');
1841 system("$mysqldir/bin/mysql -u$user $database -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1850 Asks the user whether to restart Apache, and restart it if the user
1855 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1856 The web server daemon needs to be restarted to load the new configuration for Koha.
1857 The installer can do this if you are using Apache and give the root password.
1859 Would you like to try to restart Apache now? [Y]/N: |;
1863 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1865 unless ($response=~/^n/i) {
1867 # Need to support other init structures here?
1868 if (-e "/etc/rc.d/init.d/httpd") {
1869 system('su root -c /etc/rc.d/init.d/httpd restart');
1870 } elsif (-e "/etc/init.d/apache") {
1871 system('su root -c /etc/init.d/apache restart');
1872 } elsif (-e "/etc/init.d/apache-ssl") {
1873 system('su root -c /etc/init.d/apache-ssl restart');
1883 This function attempts to back up all koha's details.
1887 $messages->{'BackupDir'}->{en} = heading('BACKUP STORAGE').qq|
1888 The upgrader will now try to backup your old files.
1890 Please specify a directory to store the backup in [%s]: |;
1892 $messages->{'BackupSummary'}->{en} = heading('BACKUP SUMMARY').qq|
1896 %6d biblioitems entries
1901 ---------------------------------------------------------------------
1903 ---------------------------------------------------------------------
1905 Does this look right? ([Y]/N): |;
1907 #FIXME: rewrite to use Install.pm
1909 my $backupdir=$ENV{'prefix'}.'/backups';
1911 my $answer = showmessage(getmessage('BackupDir',[$backupdir]),'free',$backupdir);
1913 if (! -e $backupdir) {
1914 my $result=mkdir ($backupdir, oct(770));
1916 my @dirs = split(m#/#, $backupdir);
1920 unless (-e "$checkdir") {
1921 mkdir($checkdir, 0775);
1927 chmod 0770, $backupdir;
1929 # Backup MySql database
1932 my $mysqldir = getmysqldir();
1934 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
1937 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
1939 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
1941 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
1944 my $bibliocounter=0;
1945 my $biblioitemcounter=0;
1946 my $membercounter=0;
1949 (/insert into items /i) && ($itemcounter++);
1950 (/insert into biblioitems /i) && ($biblioitemcounter++);
1951 (/insert into biblio /i) && ($bibliocounter++);
1952 (/insert into borrowers /i) && ($membercounter++);
1959 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
1961 $answer = showmessage(getmessage('BackupSummary',[$bibliocounter, $biblioitemcounter, $itemcounter, $membercounter, $filels]),'yn');
1963 if ($answer=~/^n/i) {
1966 Aborting. The database dump is located in:
1968 $backupdir/Koha.backup_$date
1973 print "Great! continuing upgrade... \n";
1980 =item finalizeconfigfile
1984 This function must be called when the installation is complete,
1985 to rename the koha.conf.tmp file to koha.conf.
1987 Currently, failure to rename the file results only in a warning.
1991 sub finalizeconfigfile {
1993 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
1994 || showmessage(<<EOF, 'PressEnter', undef, 1);
1995 An unexpected error, $!, occurred
1996 while the Koha config file is being saved to its final location,
1999 Couldn't rename file at $etcdir. Must have write capability.
2001 Press Enter to continue.
2007 =item loadconfigfile
2011 Open the existing koha.conf file and get its values,
2012 saving the values to some global variables.
2014 If the existing koha.conf file cannot be opened for any reason,
2015 the file is silently ignored.
2019 sub loadconfigfile {
2022 #MJR: reverted to r1.53. Please call setetcdir(). Do NOT hardcode this.
2023 #FIXME: make a dated backup
2024 open (KC, "<$etcdir/koha.conf");
2027 (next) if (/^\s*#/);
2028 if (/(.*)\s*=\s*(.*)/) {
2031 # Clean up white space at beginning and end
2032 $variable=~s/^\s*//g;
2033 $variable=~s/\s*$//g;
2036 $configfile{$variable}=$value;
2040 #MJR: Reverted this too. You do not mess with my privates. Please ask for new functions if required.
2041 $intranetdir=$configfile{'intranetdir'};
2042 $opacdir=$configfile{'opacdir'};
2043 $kohaversion=$configfile{'kohaversion'};
2044 $kohalogdir=$configfile{'kohalogdir'};
2045 $database=$configfile{'database'};
2046 $hostname=$configfile{'hostname'};
2047 $user=$configfile{'user'};
2048 $pass=$configfile{'pass'};
2051 END { } # module clean-up code here (global destructor)
2053 ### These things may move
2057 my $t = POSIX::Termios->new;
2061 $t->setlflag(($t->getlflag) | &POSIX::ECHO);
2064 $t->setlflag(($t->getlflag) & !(&POSIX::ECHO));
2069 sub setmysqlclipass {
2071 open(MYCNF,">$mycnf");
2073 print MYCNF "[client]\npassword=$pass\n";
2079 rename $mycnf,$mytmpcnf;
2084 if (defined $mycnf && -e $mycnf) {
2087 if (defined $mytmpcnf && -e $mytmpcnf) {
2088 rename $mytmpcnf,$mycnf;