1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
5 # my.cnf, etcdir and prefix code 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
26 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30 Install.pm - Perl module containing the bulk of the installation logic
34 The Install.pm module contains the bulk
35 of the code to do installation;
36 this code is used by installer.pl
37 to perform an actual installation.
39 =head2 Internal functions (not meant to be used outside of Install.pm)
45 # set the version for version checking
49 @EXPORT = qw( &checkperlmodules
53 &releasecandidatewarning
54 &getinstallationdirectories
71 use vars qw( $kohaversion ); # set in installer.pl
72 use vars qw( $language ); # set in installer.pl
73 use vars qw( $domainname ); # set in installer.pl
75 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
76 use vars qw( $intranetdir $opacdir $kohalogdir );
77 use vars qw( $realhttpdconf $httpduser );
78 use vars qw( $servername $svr_admin $opacport $intranetport );
79 use vars qw( $mysqldir );
80 use vars qw( $database $mysqluser );
81 use vars qw( $mysqlpass ); # normally should not be used
82 use vars qw( $dbname $hostname $user $pass ); # virtual hosting
84 use vars qw( $newversion ); # XXX this seems to be unused
88 $messages->{'WelcomeToKohaInstaller'
89 = heading('Welcome to the Koha Installer') . qq|...|;
91 The heading function takes one string, the text to be displayed as
92 the heading, and returns a formatted heading (currently formatted
93 in the "traditional Koha installer" style, i.e., surrounded by a
96 This reduces the likelihood of pod2man(1) etc. misinterpreting
97 a line of equal signs as illegal POD directives.
103 my $n = length($s) + 4;
104 my $line = ('=' x $n) . "\n";
105 "\n$line= $s =\n$line\n";
108 my $mycnf = $ENV{HOME}."/.my.cnf";
109 my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
112 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
113 $messages->{'WelcomeToKohaInstaller'}->{en} =
114 heading('Welcome to the Koha Installer') . qq|
115 Welcome to the Koha install script! This script will prompt you for some
116 basic information about your desired setup, then install Koha for you.
118 If you want to install the Koha configuration file somewhere other than /etc
119 (eg for non-root installation, or multiple Koha versions on one system), you
120 should set the etcdir and prefix environment variables. If this is your
121 only koha installation on this machine and you are running this as root, the
122 default should be OK.
124 To accept the default value for any question, simply hit Enter at the prompt.
126 Please be sure to read the documentation, or visit the Koha website at
127 http://www.koha.org for more information.
129 Are you ready to begin the installation? ([Y]/N): |;
130 $messages->{'ReleaseCandidateWarning'}->{en} =
131 heading('RELEASE CANDIDATE') . qq|
132 WARNING WARNING WARNING WARNING WARNING
134 You are about to install Koha version %s. This version of Koha is a
135 release candidate. It is not intended to be installed on production systems.
136 It is being released so that users can test it before we release a final
139 Are you sure you want to install Koha %s? (Y/[N]): |;
140 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
142 Watch for announcements of Koha releases on the Koha mailing list or the Koha
143 web site (http://www.koha.org/).
147 $messages->{'NETZ3950Missing'}->{en}=qq|
149 The Net::Z3950 module is missing. This module is necessary if you want to use
150 Koha's Z39.50 client to download bibliographic records from other libraries.
152 To install this module, you will need the yaz client installed from
153 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
156 perl -MCPAN -e 'install Net::Z3950'
158 IMPORTANT NOTE : If you use PERL5.8.0 (RedHat 8.0 or Mandrake 9.x), you MUST install
159 manually the Net::Z3950 and edit Makefile.PL and yazwrap/Makefile.PL to include:
160 'DEFINE' => '-D_GNU_SOURCE',
161 Also note that some installations of Perl on Red Hat will generate a lot of
162 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
163 inserting the following line in yazwrap/ywpriv.h :
166 Press the <ENTER> key to continue: |; #'
168 $messages->{'CheckingPerlModules'}->{en} = heading('PERL & MODULES') . qq|
169 Checking perl modules ...
172 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
174 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
175 You are missing some Perl modules which are required by Koha.
176 Once these modules have been installed, rerun this installer.
177 They can be installed by running (as root) the following:
182 $messages->{'AllPerlModulesInstalled'}->{en} =
183 heading('ALL PERL MODULES INSTALLED') . qq|
184 All mandatory perl modules are installed.
186 Press <ENTER> to continue: |;
187 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
188 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
189 $messages->{'KohaAlreadyInstalled'}->{en} =
190 heading('Koha already installed') . qq|
191 It looks like Koha is already installed on your system (%s/koha.conf exists
192 already). If you would like to upgrade your system to %s, please use
193 the koha.upgrade script in this directory.
198 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
199 Please supply the directory you want Koha to store its OPAC files in. This
200 directory will be auto-created for you if it doesn't exist.
202 OPAC Directory [%s]: |; #'
204 $messages->{'GetIntranetDir'}->{en} =
205 heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
206 Please supply the directory you want Koha to store its Intranet/Librarians
207 files in. This directory will be auto-created for you if it doesn't exist.
209 Intranet Directory [%s]: |; #'
211 $messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
212 Specify a log directory where any Koha daemons can create log files.
214 Koha Log Directory [%s]: |;
216 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
217 This release of Koha has a new authentication module. If you are not already
218 using basic authentication on your intranet, you will be required to log in to
219 access some of the features of the intranet. You can log in using the userid
220 and password from the %s/koha.conf configuration file at any time. Use the
221 "Members" module to add passwords for other accounts and set their permissions.
223 Press the <ENTER> key to continue: |;
225 $messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
226 Congratulations ... your Koha installation is complete!
228 You will be able to connect to your Librarian interface at:
231 use mysql login and password to connect to this interface. Then, go to admin page, and create whatever fits your needs.
233 and the OPAC interface at :
237 Be sure to read the Hints file.
239 For more information visit http://www.koha.org
241 Press <ENTER> to exit the installer: |;
243 sub releasecandidatewarning {
244 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
245 my $answer=showmessage($message, 'yn', 'n');
247 if ($answer =~ /y/i) {
248 print getmessage('continuing');
250 my $message=getmessage('WatchForReleaseAnnouncements');
259 =head2 Accessor functions (for installer.pl)
269 Sets the installation language, normally "en" (English).
270 In fact, only "en" is supported.
274 sub setlanguage ($) {
280 setdomainname('example.org');
282 Sets the domain name of the host.
284 The domain name should not contain a leading dot;
285 otherwise, the results are undefined.
289 sub setdomainname ($) {
297 Sets the sysconfdir, normally /etc.
298 This should be an absolute path; a trailing / is not required.
308 setkohaversion('1.3.3RC26');
310 Sets the Koha version as known by the installer.
314 sub setkohaversion ($) {
320 my $servername = getservername;
322 Gets the name of the Koha virtual server as specified by the user.
326 sub getservername () {
334 Gets the port that will run the Koha OPAC virtual server,
335 as specified by the user.
343 =item getintranetport
345 $port = getintranetport;
347 Gets the port that will run the Koha INTRANET virtual server,
348 as specified by the user.
352 sub getintranetport () {
358 =head2 Miscellaneous utility functions
368 Does the equivalent of dirname(1). Given a path $path, return the
369 parent directory of $path (best guess), except when $path seems to
370 be the same as /, in which case $path itself is returned unchanged.
376 if ($path =~ /[^\/]/s) {
378 $path =~ s/\/+[^\/]+\/*$//s;
389 mkdir_parents $path, $mode;
391 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
392 create the directory $path, recursively creating any intermediate
393 directories. If $mode is given, the directory will be created with
396 WARNING: If $path already exists, mkdir_parents will just return
397 successfully (just like mkdir -p), whether the mode of $path conforms
398 to $mode or not. (This is the behaviour of the mkdir -p command.)
402 sub mkdir_parents ($;$) {
403 my($path, $mode) = @_;
404 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
406 if (!$ok && $! == ENOENT) {
407 my $parent = dirname($path);
408 $ok = mkdir_parents($parent, $mode);
410 # retry and at the same time make sure that $! is set correctly
411 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
420 getmessage($msgid, $variables);
422 Gets a localized message (format string) with message id $msgid,
423 and, if an array reference of variables $variables is given,
424 substitutes variables in the format string with @$variables.
425 Returns the found message string, with variable substitutions
428 $msgid must be the message identifier corresponding to a defined
429 message string (a valid key to the $messages hash in the Installer
430 package). getmessage throws an exception if the message cannot be
436 my $messagename=shift;
438 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
439 if (defined($variables)) {
440 $message=sprintf $message, @$variables;
448 showmessage($message, 'none');
449 showmessage($message, 'none', undef, $noclear);
451 $result = showmessage($message, 'yn');
452 $result = showmessage($message, 'yn', $defaultresponse);
453 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
455 $result = showmessage($message, 'restrictchar CHARS');
456 $result = showmessage($message, 'free');
457 $result = showmessage($message, 'numerical');
458 $result = showmessage($message, 'email');
459 $result = showmessage($message, 'PressEnter');
461 Shows a message and optionally gets a response from the user.
463 The first two arguments, the message and the response type,
464 are mandatory. The message must be the actual string to
465 display; the caller is responsible for calling getmessage if
468 The response type must be one of "none", "yn", "free",
469 "numerical", "email", "PressEnter", or a string consisting
470 of "restrictchar " followed by a list of allowed characters
471 (space can be specified). (Case is not significant, but case is
472 significant in the list of allowed characters.) If a response
473 type other than the above-listed is specified, the result is
476 Note that the response type "yn" is equivalent to "restrictchar yn".
477 Because "restrictchar" is case-sensitive, the user is expected
478 to enter "y" or "n" in lowercase only.
480 Note that the response type of "email" does not actually
481 guarantee that the returned value is a well-formed RFC-822
482 email address, nor does it accept all well-formed RFC-822 email
483 addresses. What it does is to restrict the returned value to a
484 string that is looks reasonably likely to be an email address
485 in the "real world", given the premise that the user is trying
486 to enter a real email address.
488 If a response type other than "none" or "PressEnter" is
489 specified, a third argument, specifying the default value, can
490 be specified: If this default response is not specified, the
491 default response is the first allowed character if the response
492 type is "restrictchar", otherwise the default response is the
493 empty string. This default response is used when the user does
494 not specify a value (i.e., presses Enter without typing in
495 anything), showmessage will assume that the default response is
498 Note that because the response type "yn" is equivalent to
499 "restrictchar yn", the default value for response type "yn",
500 if unspecified, is "y".
502 The screen is normally cleared before the message is displayed;
503 if a fourth argument is specified and is nonzero, this
504 screen-clearing is not done.
511 my $responsetype=shift;
512 my $defaultresponse=shift;
514 $noclear = 0 unless defined $noclear; # defaults to "clear"
515 ($noclear) || (system('clear'));
516 if ($responsetype =~ /^yn$/) {
517 $responsetype='restrictchar ynYN';
520 if ($responsetype =~/^restrictchar (.*)/i) {
523 until ($options=~/$response/) {
524 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
527 (length($response)) || ($response=$defaultresponse);
528 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
529 ($noclear) || (system('clear'));
530 print "Response contains invalid characters. Choose from [$options].\n\n";
534 unless ($options=~/$response/) {
535 ($noclear) || (system('clear'));
536 print "Invalid Response. Choose from [$options].\n\n";
542 } elsif ($responsetype =~/^free$/i) {
543 (defined($defaultresponse)) || ($defaultresponse='');
544 my $response=<STDIN>;
546 ($response) || ($response=$defaultresponse);
548 } elsif ($responsetype =~/^numerical$/i) {
549 (defined($defaultresponse)) || ($defaultresponse='');
551 until ($response=~/^\d+$/) {
554 ($response) || ($response=$defaultresponse);
555 unless ($response=~/^\d+$/) {
556 ($noclear) || (system('clear'));
557 print "Invalid Response ($response). Response must be a number.\n\n";
562 } elsif ($responsetype =~/^email$/i) {
563 (defined($defaultresponse)) || ($defaultresponse='');
565 until ($response=~/.*\@.*\..*/) {
568 ($response) || ($response=$defaultresponse);
569 unless ($response=~/.*\@.*\..*/) {
570 ($noclear) || (system('clear'));
571 print "Invalid Response ($response). Response must be a valid email address.\n\n";
576 } elsif ($responsetype =~/^PressEnter$/i) {
579 } elsif ($responsetype =~/^none$/i) {
582 # FIXME: There are a few places where we will get an undef as the
583 # response type. Should we thrown an exception here, or should we
584 # legitimize this usage and say "none" is the default if not specified?
585 #die "Illegal response type \"$responsetype\"";
592 =head2 Subtasks of doing an installation
598 =item checkabortedinstall
602 Checks whether a previous installation process has been abnormally
603 aborted, by checking whether $etcidr/koha.conf is a symlink matching
604 a particular pattern. If an aborted installation is detected, give
605 the user a chance to abort, before trying to recover the aborted
608 FIXME: The recovery is not complete; it only partially rolls back
613 sub checkabortedinstall () {
614 if (-l("$etcdir/koha.conf")
615 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
618 I have detected that you tried to install Koha before, but the installation
619 was aborted. I will try to continue, but there might be problems if the
620 database is already created.
623 print "Please press <ENTER> to continue: ";
626 # Remove the symlink after the <STDIN>, so the user can back out
627 unlink "$etcdir/koha.conf"
628 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
633 =item checkperlmodules
637 Test whether the version of Perl is new enough, whether Perl is
638 found at the expected location, and whether all required modules
643 sub checkperlmodules {
645 # Test for Perl and Modules
648 my $message = getmessage('CheckingPerlModules');
649 showmessage($message, 'none');
651 unless ($] >= 5.006001) { # Bug 179
652 die getmessage('PerlVersionFailure', ['5.6.1']);
656 unless (eval {require DBI}) { push @missing,"DBI" };
657 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
658 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
659 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
660 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
661 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
662 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
663 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
664 unless (eval {require Net::Z3950}) {
665 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
666 if ($#missing>=0) { # XXX why only when $#missing >= 0?
667 push @missing, "Net::Z3950";
672 # Print out a list of any missing modules
677 foreach my $module (@missing) {
678 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
680 my $message=getmessage('MissingPerlModules', [$missing]);
681 showmessage($message, 'none');
684 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
688 unless (-x "/usr/bin/perl") {
689 my $realperl=`which perl`;
691 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
692 until (-x $realperl) {
693 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
695 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
696 unless ($response eq 'n') {
697 system("ln -s $realperl /usr/bin/perl");
704 $messages->{'NoUsrBinPerl'}->{en} =
705 heading('Perl is not located in /usr/bin/perl') . qq|
706 The Koha perl scripts expect to find the perl executable in the /usr/bin
707 directory. It is not there on your system.
711 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
712 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
713 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
715 May I create this symlink? ([Y]/N):
718 $messages->{'DirFailed'}->{en} = qq|
719 We could not create %s, but continuing anyway...
725 =item getinstallationdirectories
727 getinstallationdirectories;
729 Get the various installation directories from the user, and then
730 create those directories (if they do not already exist).
732 These pieces of information are saved to global variables; the
733 function does not return any values.
737 sub getinstallationdirectories {
738 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
739 $opacdir = $ENV{prefix}.'/koha/opac';
740 $intranetdir = $ENV{prefix}.'/koha/intranet';
742 while ($getdirinfo) {
743 # Loop until opac directory and koha directory are different
744 my $message=getmessage('GetOpacDir', [$opacdir]);
745 $opacdir=showmessage($message, 'free', $opacdir);
747 $message=getmessage('GetIntranetDir', [$intranetdir]);
748 $intranetdir=showmessage($message, 'free', $intranetdir);
750 if ($intranetdir eq $opacdir) {
753 You must specify different directories for the OPAC and INTRANET files!
754 :: $intranetdir :: $opacdir ::
761 $kohalogdir=$ENV{prefix}.'/koha/log';
762 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
763 $kohalogdir=showmessage($message, 'free', $kohalogdir);
766 # FIXME: Need better error handling for all mkdir calls here
767 unless ( -d $intranetdir ) {
768 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed','parents of '.$intranetdir);
769 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',$intranetdir);
770 chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir");
771 chmod (oct(770), "$intranetdir");
773 mkdir_parents ("$intranetdir/htdocs", 0750);
774 mkdir_parents ("$intranetdir/cgi-bin", 0750);
775 mkdir_parents ("$intranetdir/modules", 0750);
776 mkdir_parents ("$intranetdir/scripts", 0750);
777 unless ( -d $opacdir ) {
778 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed','parents of '.$opacdir);
779 mkdir ($opacdir, 0770) || print getmessage('DirFailed',$opacdir);
780 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
781 chmod (oct(770), "$opacdir");
783 mkdir_parents ("$opacdir/htdocs", 0750);
784 mkdir_parents ("$opacdir/cgi-bin", 0750);
787 unless ( -d $kohalogdir ) {
788 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed','parents of '.$kohalogdir);
789 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',$kohalogdir);
790 chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir");
791 chmod (oct(770), "$kohalogdir");
797 =item getdatabaseinfo
801 Get various pieces of information related to the Koha database:
802 the name of the database, the host on which the SQL server is
803 running, and the database user name.
805 These pieces of information are saved to global variables; the
806 function does not return any values.
810 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
811 Please provide the name that you wish to give your koha database.
812 It must not exist already on the database server.
814 Database name [%s]: |;
816 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
817 Please provide the hostname for mysql. Unless the database is located on
818 another machine this will be "localhost".
820 Database host [%s]: |;
822 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
823 Please provide the name of the user who will have full administrative rights
824 to the %s database, when authenticating from %s.
826 This user will also be used to access Koha's INTRANET interface.
828 Database user [%s]: |;
830 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
831 Please provide a good password for the user %s.
833 This password will also be used to access Koha's INTRANET interface.
835 Password for database user %s: |;
837 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
838 You must not use a blank password for your MySQL user.
840 Press <ENTER> to try again:
843 sub getdatabaseinfo {
846 $hostname = 'localhost';
850 #Get the database name
852 my $message=getmessage('DatabaseName', [$dbname]);
853 $dbname=showmessage($message, 'free', $dbname);
855 #Get the hostname for the database
857 $message=getmessage('DatabaseHost', [$hostname]);
858 $hostname=showmessage($message, 'free', $hostname);
860 #Get the username for the database
862 $message=getmessage('DatabaseUser', [$dbname, $hostname, $user]);
863 $user=showmessage($message, 'free', $user);
865 #Get the password for the database user
867 while ($pass eq '') {
868 my $message=getmessage('DatabasePassword', [$user, $user]);
869 $pass=showmessage($message, 'free', $pass);
871 my $message=getmessage('BlankPassword');
872 showmessage($message,'PressEnter');
883 Get various pieces of information related to the Apache server:
884 the location of the configuration file and, if needed, the Unix
885 user that the Koha CGI will be run under.
887 These pieces of information are saved to global variables; the
888 function does not return any values.
892 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
893 heading('MULTIPLE APACHE CONFIG FILES') . qq|
894 I found more than one possible Apache configuration file:
898 Choose the correct file [1]: |;
900 $messages->{'NoApacheConfFiles'}->{en} =
901 heading('NO APACHE CONFIG FILE FOUND') . qq|
902 I was not able to find your Apache configuration file.
904 The file is usually called httpd.conf or apache.conf.
906 Please specify the location of your config file: |;
908 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
909 The file %s does not exist.
911 Please press <ENTER> to continue: |;
913 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
914 I was not able to determine the user that Apache is running as. This
915 information is necessary in order to set the access privileges correctly on
916 %s/koha.conf. This user should be set in one of the Apache configuration
917 files using the "User" directive.
919 Enter the Apache userid: |;
921 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
922 The userid %s is not a valid userid on this system.
924 Press <ENTER> to continue: |;
927 my @confpossibilities;
929 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
930 /usr/local/etc/apache/httpd.conf
931 /usr/local/etc/apache/apache.conf
932 /var/www/conf/httpd.conf
933 /etc/apache2/httpd.conf
934 /etc/apache2/apache.conf
935 /etc/apache/conf/httpd.conf
936 /etc/apache/conf/apache.conf
937 /etc/apache-ssl/conf/apache.conf
938 /etc/apache-ssl/httpd.conf
939 /etc/httpd/conf/httpd.conf
940 /etc/httpd/httpd.conf)) {
941 if ( -f $httpdconf ) {
942 push @confpossibilities, $httpdconf;
946 if ($#confpossibilities==-1) {
947 my $message=getmessage('NoApacheConfFiles');
949 until (-f $realhttpdconf) {
950 $choice=showmessage($message, "free", 1);
952 $realhttpdconf=$choice;
954 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
957 } elsif ($#confpossibilities>0) {
961 foreach (@confpossibilities) {
962 $conffiles.=" $counter: $_\n";
963 $options.="$counter";
966 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
967 my $choice=showmessage($message, "restrictchar $options", 1);
968 $realhttpdconf=$confpossibilities[$choice-1];
970 $realhttpdconf=$confpossibilities[0];
972 unless (open (HTTPDCONF, "<$realhttpdconf")) {
973 warn "Insufficient privileges to open $realhttpdconf for reading.\n";
977 while (<HTTPDCONF>) {
978 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
987 unless ($httpduser) {
988 my $message=getmessage('EnterApacheUser', [$etcdir]);
989 until (length($httpduser) && getpwnam($httpduser)) {
990 $httpduser=showmessage($message, "free", '');
991 if (length($httpduser)>0) {
992 unless (getpwnam($httpduser)) {
993 my $message=getmessage('InvalidUserid', [$httpduser]);
994 showmessage($message,'PressEnter');
999 print "AU: $httpduser\n";
1004 =item getapachevhostinfo
1008 Gets various pieces of information related to virtual hosting:
1009 the webmaster email address, virtual hostname, and the ports
1010 that the OPAC and INTRANET modules run on.
1012 These pieces of information are saved to global variables; the
1013 function does not return any values.
1017 $messages->{'ApacheConfigIntroduction'}->{en} =
1018 heading('APACHE CONFIGURATION') . qq|
1019 Koha needs to write an Apache configuration file for the
1020 OPAC and LIBRARIAN virtual hosts. By default this installer
1021 will do this by using one ip address and two different ports
1022 for the virtual hosts. There are other ways to set this up,
1023 and the installer will leave comments in
1024 $etcdir/koha-httpd.conf detailing
1025 what these other options are.
1027 NOTE: You will need to add lines to your main httpd.conf to
1028 Include $etcdir/koha-httpd.conf
1029 and to make sure it is listening on the right ports
1030 (using the Listen directive).
1032 Press <ENTER> to continue: |;
1034 $messages->{'GetVirtualHostEmail'}->{en} =
1035 heading('WEB SERVER E-MAIL CONTACT') . qq|
1036 Enter the e-mail address to be used as a contact for the virtual hosts (this
1037 address is displayed if any errors are encountered).
1039 E-mail contact [%s]: |;
1041 $messages->{'GetServerName'}->{en} =
1042 heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
1043 Please enter the host name or IP address that you wish to use for koha.
1044 Normally, this should be a name or IP that belongs to this machine.
1046 Host name or IP Address [%s]: |;
1048 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
1049 Please enter the port for your OPAC interface. This defaults to port 80, but
1050 if you are already serving web content from this host, you should change it
1051 to a different port (8000 might be a good choice).
1053 Enter the OPAC Port [%s]: |;
1055 $messages->{'GetIntranetPort'}->{en} =
1056 heading('INTRANET VIRTUAL HOST PORT') . qq|
1057 Please enter the port for your Intranet interface. This must be different from
1060 Enter the Intranet Port [%s]: |;
1063 sub getapachevhostinfo {
1065 $svr_admin = "webmaster\@$domainname";
1066 $servername=`hostname`;
1071 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
1073 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1074 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1077 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1078 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1083 =item updateapacheconf
1087 Updates the Apache config file according to parameters previously
1088 specified by the user.
1090 It will append fully-commented directives at the end of the original
1091 Apache config file. The old config file is renamed with an extension
1094 If you need to uninstall Koha for any reason, the lines between
1096 # Ports to listen to for Koha
1098 and the block of comments beginning with
1100 # If you want to use name based Virtual Hosting:
1106 $messages->{'StartUpdateApache'}->{en} =
1107 heading('UPDATING APACHE CONFIGURATION') . qq|
1108 Checking for modules that need to be loaded...
1111 $messages->{'ApacheConfigMissingModules'}->{en} =
1112 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1113 Koha uses the mod_env and mod_include apache features, but the
1114 installer did not find statements for them in your config. Please
1115 make sure that they are enabled for your Koha host.
1117 Press <ENTER> to continue: |;
1120 $messages->{'ApacheAlreadyConfigured'}->{en} =
1121 heading('APACHE ALREADY CONFIGURED') . qq|
1122 %s appears to already have an entry for Koha
1123 Virtual Hosts. You may need to edit %s
1124 if anything has changed since it was last set up. This
1125 script will not attempt to modify an existing Koha apache
1128 Press <ENTER> to continue: |;
1130 sub updateapacheconf {
1131 my $logfiledir=`grep ^ErrorLog "$realhttpdconf"`;
1134 my $httpdconf = $etcdir."/koha-httpd.conf";
1137 $logfiledir=~m#ErrorLog (.*)/[^/]*$#
1138 or die "Can't parse ErrorLog directive\n";
1142 unless ($logfiledir) {
1146 showmessage(getmessage('StartUpdateApache'), 'none');
1147 # to be polite about it: I don't think this should touch the main httpd.conf
1149 # QUESTION: Should we warn for includes_module too?
1151 my $includesmodule=0;
1152 open HC, "<$realhttpdconf";
1154 if (/^\s*#\s*LoadModule env_module /) {
1155 showmessage(getmessage('ApacheConfigMissingModules'));
1158 if (/\s*LoadModule includes_module / ) {
1163 if (`grep 'VirtualHost $servername' "$httpdconf"`) {
1164 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1167 my $includesdirectives='';
1168 if ($includesmodule) {
1169 $includesdirectives.="Options +Includes\n";
1170 $includesdirectives.=" AddHandler server-parsed .html\n";
1172 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1173 my $opaclisten = '';
1174 if ($opacport != 80) {
1175 $opaclisten="Listen $opacport";
1177 my $intranetlisten = '';
1178 if ($intranetport != 80) {
1179 $intranetlisten="Listen $intranetport";
1183 # Ports to listen to for Koha
1187 # NameVirtualHost is used by one of the optional configurations detailed below
1189 #NameVirtualHost 11.22.33.44
1191 # KOHA's OPAC Configuration
1192 <VirtualHost $servername\:$opacport>
1193 ServerAdmin $svr_admin
1194 DocumentRoot $opacdir/htdocs
1195 ServerName $servername
1196 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1197 ErrorLog $logfiledir/opac-error_log
1198 TransferLog $logfiledir/opac-access_log
1199 SetEnv PERL5LIB "$intranetdir/modules"
1203 # KOHA's INTRANET Configuration
1204 <VirtualHost $servername\:$intranetport>
1205 ServerAdmin $svr_admin
1206 DocumentRoot $intranetdir/htdocs
1207 ServerName $servername
1208 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1209 ErrorLog $logfiledir/koha-error_log
1210 TransferLog $logfiledir/koha-access_log
1211 SetEnv PERL5LIB "$intranetdir/modules"
1215 # If you want to use name based Virtual Hosting:
1216 # 1. remove the two Listen lines
1217 # 2. replace $servername\:$opacport wih your.opac.domain.name
1218 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1219 # 4. replace $servername\:$intranetport wih your intranet domain name
1220 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1222 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1223 # 1. Follow steps 1-5 above
1224 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1233 =item basicauthentication
1235 basicauthentication;
1237 Asks the user whether HTTP basic authentication is wanted, and,
1238 if so, the user name and password for the basic authentication.
1240 These pieces of information are saved to global variables; the
1241 function does not return any values.
1245 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1246 heading('INTRANET AUTHENTICATION') . qq|
1247 I can set it up so that the Intranet/Librarian site is password protected using
1248 Apache's Basic Authorization.
1250 This is going to be phased out very soon. However, setting this up can provide
1251 an extra layer of security before the new authentication system is completely
1254 Would you like to do this ([Y]/N): |; #'
1256 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
1257 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1258 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1260 sub basicauthentication {
1261 my $message=getmessage('IntranetAuthenticationQuestion');
1262 my $answer=showmessage($message, 'yn', 'y');
1263 my $httpdconf = $etcdir."/koha-httpd.conf";
1265 my $apacheauthusername='librarian';
1266 my $apacheauthpassword='';
1267 if ($answer=~/^y/i) {
1268 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1269 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1270 while (! $apacheauthpassword) {
1271 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1272 if (!$apacheauthpassword) {
1273 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1276 open AUTH, ">$etcdir/kohaintranet.pass";
1277 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1278 my $salt=substr($chars, int(rand(length($chars))),1);
1279 $salt.=substr($chars, int(rand(length($chars))),1);
1280 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1282 open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1285 <Directory $intranetdir>
1286 AuthUserFile $etcdir/kohaintranet.pass
1288 AuthName "Koha Intranet (for librarians only)"
1301 Install the Koha files to the specified OPAC and INTRANET
1302 directories (usually in /usr/local/koha).
1304 The koha.conf file is created, but as koha.conf.tmp. The
1305 caller is responsible for calling finalizeconfigfile when
1306 installation is completed, to rename it back to koha.conf.
1310 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1311 Copying files to installation directories:
1316 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1323 showmessage(getmessage('InstallFiles'),'none');
1324 print getmessage('CopyingFiles', ['intranet-html', "$intranetdir/htdocs" ]);
1325 system("cp -R intranet-html/* $intranetdir/htdocs/");
1326 print getmessage('CopyingFiles', ['intranet-cgi', "$intranetdir/cgi-bin" ]);
1327 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
1328 print getmessage('CopyingFiles', ['stand-alone scripts', "$intranetdir/scripts" ]);
1329 system("cp -R scripts/* $intranetdir/scripts/");
1330 print getmessage('CopyingFiles', ['perl modules', "$intranetdir/modules" ]);
1331 system("cp -R modules/* $intranetdir/modules/");
1332 print getmessage('CopyingFiles', ['opac-html', "$opacdir/htdocs" ]);
1333 system("cp -R opac-html/* $opacdir/htdocs/");
1334 print getmessage('CopyingFiles', ['opac-cgi', "$opacdir/cgi-bin" ]);
1335 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
1336 system("touch $opacdir/cgi-bin/opac");
1338 system("chown -R $httpduser:$httpduser $opacdir");
1339 system("chown -R $httpduser:$httpduser $intranetdir");
1341 # Create /etc/koha.conf
1343 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1344 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1350 includes=$opacdir/htdocs/includes
1351 intranetdir=$intranetdir
1353 kohalogdir=$kohalogdir
1354 kohaversion=$kohaversion
1355 httpduser=$httpduser
1356 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1357 opachtdocs=$opacdir/htdocs/opac-tmpl
1362 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1363 chmod 0440, "$etcdir/koha.conf.tmp";
1365 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1366 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1367 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
1368 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1369 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1378 Finds out where the MySQL utitlities are located in the system,
1379 then create the Koha database structure and MySQL permissions.
1383 $messages->{'MysqlRootPassword'}->{en} =
1384 heading('MYSQL ROOT USER PASSWORD') . qq|
1385 To allow us to create the koha database please enter your
1386 mysql server's root user password:
1390 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1391 Creating the MySQL database for Koha...
1395 $messages->{'CreatingDatabaseError'}->{en} =
1396 heading('ERROR CREATING DATABASE') . qq|
1397 Couldn't connect to the MySQL server for the reason given above.
1398 This is a serious problem, the database will not get installed.
\a
1400 Press <ENTER> to continue: |; #'
1402 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1403 If you are installing Koha for evaluation purposes, I have a batch of sample
1404 data that you can install now.
1406 If you are installing Koha with the intention of populating it with your own
1407 data, you probably don't want this sample data installed.
1409 Would you like to install the sample data? Y/[N]: |; #'
1411 $messages->{'SampleDataInstalled'}->{en} =
1412 heading('SAMPLE DATA INSTALLED') . qq|
1413 Sample data has been installed. For some suggestions on testing Koha, please
1414 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1415 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1416 question through the koha-devel mailing list, or you can check for a developer
1417 online at +irc.katipo.co.nz:6667 channel #koha.
1419 You can find instructions for subscribing to the Koha mailing lists at:
1424 Press <ENTER> to continue: |;
1426 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1427 Would you like to install an initial branch and printer? [Y]/N: |;
1429 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1430 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1431 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1432 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1435 $mysqluser = 'root';
1438 foreach my $mysql (qw(/usr/local/mysql
1442 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1447 print "I don't see mysql in the usual places.\n";
1449 print "Where have you installed mysql? ";
1450 chomp($mysqldir = <STDIN>);
1451 last if -f "$mysqldir/bin/mysqladmin";
1454 I can't find it there either. If you compiled mysql yourself,
1455 please give the value of --prefix when you ran configure.
1457 The file mysqladmin should be in bin/mysqladmin under the directory that you
1464 # we must not put the mysql root password on the command line
1465 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'free');
1467 showmessage(getmessage('CreatingDatabase'),'none');
1469 setmysqlclipass($mysqlpass);
1470 # Set up permissions
1471 print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
1472 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 ('%','$dbname','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
1473 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1474 # Change to admin user login
1475 setmysqlclipass($pass);
1476 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$dbname");
1478 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1480 # Create the database structure
1481 system("$mysqldir/bin/mysql -u$user $dbname < koha.mysql");
1487 =item updatedatabase
1491 Updates the Koha database structure, including the addition of
1494 The MARC tables are also populated in addition to being created.
1496 Because updatedatabase calls scripts/updater/updatedatabase to
1497 do the actual update, and that script uses C4::Context,
1498 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1499 environment variable to do this.
1501 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1505 $messages->{'UpdateMarcTables'}->{en} =
1506 heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1507 You can import marc parameters for :
1513 Please choose which parameter you want to install. Note if you choose N,
1514 nothing will be added, and it can be a BIG job to manually create those tables
1516 Choose MARC definition [1]: |;
1518 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1519 This version of koha supports a few languages.
1520 Enter your language preference : either en, fr, es, pl or zh_TW
1522 Note that the en is always choosen when the system does not finds the
1523 language you choose in a specific screen.
1525 fr : all is translated (except pictures)
1526 es : a few intranet is translated (including pictures)
1527 pl : OPAC and a few intranet is translated
1528 zh_TW : partial translation
1530 Whether you specify a language here, you can always go to the
1531 intranet interface and change it from the system preferences.
1533 Which language do you choose? |;
1535 sub updatedatabase {
1536 # At this point, $etcdir/koha.conf must exist, for C4::Context
1537 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp';
1538 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
1541 print "Problem updating database...\n";
1545 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1547 if ($response eq '1') {
1548 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1550 if ($response eq '2') {
1551 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1552 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $dbname");
1555 $result = system ("perl -I $intranetdir/modules scripts/marc/updatedb2marc.pl");
1557 print "Problem updating database to MARC...\n";
1561 delete($ENV{"KOHA_CONF"});
1563 print "\n\nFinished updating of database. Press <ENTER> to continue...";
1568 =item populatedatabase
1572 Populate the non-MARC tables. If the user wants to install the
1573 sample data, install them.
1577 sub populatedatabase {
1578 # my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1579 # if ($response =~/^y/i) {
1581 # FIXME: These calls are now unsafe and should either be removed
1582 # or updated to use -u$user and no mysqlpass_quoted
1584 # system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1585 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1586 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1587 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1588 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1589 # showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1592 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1594 unless ($response =~/^n/i) {
1595 my $branch='Main Library';
1596 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1597 $branch=~s/[^A-Za-z0-9\s]//g;
1599 my $branchcode=$branch;
1600 $branchcode=~s/[^A-Za-z0-9]//g;
1601 $branchcode=uc($branchcode);
1602 $branchcode=substr($branchcode,0,4);
1603 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1604 $branchcode=~s/[^A-Za-z0-9]//g;
1605 $branchcode=uc($branchcode);
1606 $branchcode=substr($branchcode,0,4);
1607 $branchcode or $branchcode='DEF';
1609 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1610 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1611 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1613 my $printername='Library Printer';
1614 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1615 $printername=~s/[^A-Za-z0-9\s]//g;
1617 my $printerqueue='lp';
1618 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1619 $printerqueue=~s/[^A-Za-z0-9]//g;
1620 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1622 my $language=showmessage(getmessage('Language'), 'free', 'en');
1623 system("$mysqldir/bin/mysql -u$user $dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1632 Asks the user whether to restart Apache, and restart it if the user
1635 FIXME: If the installer does not know how to restart the Apache
1636 server (e.g., if the user is not actually using Apache), it still
1641 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1642 Apache needs to be restarted to load the new configuration for Koha.
1643 This requires the root password.
1645 Would you like to try to restart Apache now? [Y]/N: |;
1649 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1653 unless ($response=~/^n/i) {
1654 # Need to support other init structures here?
1655 if (-e "/etc/rc.d/init.d/httpd") {
1656 system('su root -c /etc/rc.d/init.d/httpd restart');
1657 } elsif (-e "/etc/init.d/apache") {
1658 system('su root -c /etc//init.d/apache restart');
1659 } elsif (-e "/etc/init.d/apache-ssl") {
1660 system('su root -c /etc/init.d/apache-ssl restart');
1667 =item finalizeconfigfile
1671 This function must be called when the installation is complete,
1672 to rename the koha.conf.tmp file to koha.conf.
1674 Currently, failure to rename the file results only in a warning.
1678 sub finalizeconfigfile {
1680 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
1681 || showmessage(<<EOF, 'PressEnter', undef, 1);
1682 An unexpected error, $!, occurred
1683 while the Koha config file is being saved to its final location,
1686 Couldn't rename file at $etcdir. Must have write capability.
1688 Press Enter to continue.
1694 =item loadconfigfile
1698 Open the existing koha.conf file and get its values,
1699 saving the values to some global variables.
1701 If the existing koha.conf file cannot be opened for any reason,
1702 the file is silently ignored.
1706 sub loadconfigfile {
1709 open (KC, "<$etcdir/koha.conf");
1712 (next) if (/^\s*#/);
1713 if (/(.*)\s*=\s*(.*)/) {
1716 # Clean up white space at beginning and end
1717 $variable=~s/^\s*//g;
1718 $variable=~s/\s*$//g;
1721 $configfile{$variable}=$value;
1725 $intranetdir=$configfile{'intranetdir'};
1726 $opacdir=$configfile{'opacdir'};
1727 $kohaversion=$configfile{'kohaversion'};
1728 $kohalogdir=$configfile{'kohalogdir'};
1729 $database=$configfile{'database'};
1730 $hostname=$configfile{'hostname'};
1731 $user=$configfile{'user'};
1732 $pass=$configfile{'pass'};
1735 END { } # module clean-up code here (global destructor)
1737 sub setmysqlclipass {
1739 open(MYCNF,">$mycnf");
1741 print MYCNF "[client]\npassword=$pass\n";
1747 rename $mycnf,$mytmpcnf;
1756 rename $mytmpcnf,$mycnf;