1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
29 Install.pm - Perl module containing the bulk of the installation logic
33 The Install.pm module contains the bulk
34 of the code to do installation;
35 this code is used by installer.pl
36 to perform an actual installation.
38 =head2 Internal functions (not meant to be used outside of Install.pm)
44 # set the version for version checking
48 @EXPORT = qw( &checkperlmodules
52 &releasecandidatewarning
53 &getinstallationdirectories
68 use vars qw( $kohaversion ); # set in installer.pl
69 use vars qw( $language ); # set in installer.pl
70 use vars qw( $domainname ); # set in installer.pl
72 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
73 use vars qw( $intranetdir $opacdir $kohalogdir );
74 use vars qw( $realhttpdconf $httpduser );
75 use vars qw( $servername $svr_admin $opacport $intranetport );
76 use vars qw( $mysqldir );
77 use vars qw( $database $mysqluser );
78 use vars qw( $mysqlpass ); # normally should not be used
79 use vars qw( $mysqlpass_quoted ); # quoted, contains -p as needed
80 use vars qw( $dbname $hostname $user $pass ); # virtual hosting
82 use vars qw( $newversion ); # XXX this seems to be unused
86 $messages->{'WelcomeToKohaInstaller'
87 = heading('Welcome to the Koha Installer') . qq|...|;
89 The heading function takes one string, the text to be displayed as
90 the heading, and returns a formatted heading (currently formatted
91 in the "traditional Koha installer" style, i.e., surrounded by a
94 This reduces the likelihood of pod2man(1) etc. misinterpreting
95 a line of equal signs as illegal POD directives.
101 my $n = length($s) + 4;
102 my $line = ('=' x $n) . "\n";
103 "\n$line= $s =\n$line\n";
107 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
108 $messages->{'WelcomeToKohaInstaller'}->{en} =
109 heading('Welcome to the Koha Installer') . qq|
110 Welcome to the Koha install script! This script will prompt you for some
111 basic information about your desired setup, then install Koha according to
112 your specifications. To accept the default value for any question, simply hit
115 Please be sure to read the documentation, or visit the Koha website at
116 http://www.koha.org for more information.
118 Are you ready to begin the installation? (Y/[N]): |;
119 $messages->{'ReleaseCandidateWarning'}->{en} =
120 heading('RELEASE CANDIDATE') . qq|
121 WARNING WARNING WARNING WARNING WARNING
123 You are about to install Koha version %s. This version of Koha is a
124 release candidate. It is not intended to be installed on production systems.
125 It is being released so that users can test it before we release a final
128 Are you sure you want to install Koha %s? (Y/[N]): |;
129 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
131 Watch for announcements of Koha releases on the Koha mailing list or the Koha
132 web site (http://www.koha.org/).
136 $messages->{'NETZ3950Missing'}->{en}=qq|
138 The Net::Z3950 module is missing. This module is necessary if you want to use
139 Koha's Z39.50 client to download bibliographic records from other libraries.
141 To install this module, you will need the yaz client installed from
142 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
145 perl -MCPAN -e 'install Net::Z3950'
147 IMPORTANT NOTE : If you use PERL5.8.0 (RedHat 8.0 or Mandrake 9.x), you MUST install
148 manually the Net::Z3950 and edit Makefile.PL and yazwrap/Makefile.PL to include:
149 'DEFINES' => '-D_GNU_SOURCE',
152 Press the <ENTER> key to continue: |; #'
154 $messages->{'CheckingPerlModules'}->{en} = heading('PERL & MODULES') . qq|
155 Checking perl modules ...
158 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
160 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
161 You are missing some Perl modules which are required by Koha.
162 Once these modules have been installed, rerun this installer.
163 They can be installed by running (as root) the following:
168 $messages->{'AllPerlModulesInstalled'}->{en} =
169 heading('ALL PERL MODULES INSTALLED') . qq|
170 All mandatory perl modules are installed.
172 Press <ENTER> to continue: |;
173 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
174 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
175 $messages->{'KohaAlreadyInstalled'}->{en} =
176 heading('Koha already installed') . qq|
177 It looks like Koha is already installed on your system (%s/koha.conf exists
178 already). If you would like to upgrade your system to %s, please use
179 the koha.upgrade script in this directory.
184 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
185 Please supply the directory you want Koha to store its OPAC files in. This
186 directory will be auto-created for you if it doesn't exist.
188 OPAC Directory [%s]: |; #'
190 $messages->{'GetIntranetDir'}->{en} =
191 heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
192 Please supply the directory you want Koha to store its Intranet/Librarians
193 files in. This directory will be auto-created for you if it doesn't exist.
195 Intranet Directory [%s]: |; #'
197 $messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
198 Specify a log directory where any Koha daemons can create log files.
200 Koha Log Directory [%s]: |;
202 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
203 This release of Koha has a new authentication module. If you are not already
204 using basic authentication on your intranet, you will be required to log in to
205 access some of the features of the intranet. You can log in using the userid
206 and password from the %s/koha.conf configuration file at any time. Use the
207 "Members" module to add passwords for other accounts and set their permissions.
209 Press the <ENTER> key to continue: |;
211 $messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
212 Congratulations ... your Koha installation is complete!
214 You will be able to connect to your Librarian interface at:
218 and the OPAC interface at :
222 Be sure to read the Hints file.
224 For more information visit http://www.koha.org
226 Press <ENTER> to exit the installer: |;
228 sub releasecandidatewarning {
229 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
230 my $answer=showmessage($message, 'yn', 'n');
232 if ($answer =~ /y/i) {
233 print getmessage('continuing');
235 my $message=getmessage('WatchForReleaseAnnouncements');
244 =head2 Accessor functions (for installer.pl)
254 Sets the installation language, normally "en" (English).
255 In fact, only "en" is supported.
259 sub setlanguage ($) {
265 setdomainname('example.org');
267 Sets the domain name of the host.
269 The domain name should not contain a leading dot;
270 otherwise, the results are undefined.
274 sub setdomainname ($) {
282 Sets the sysconfdir, normally /etc.
283 This should be an absolute path; a trailing / is not required.
293 setkohaversion('1.3.3RC26');
295 Sets the Koha version as known by the installer.
299 sub setkohaversion ($) {
305 my $servername = getservername;
307 Gets the name of the Koha virtual server as specified by the user.
311 sub getservername () {
319 Gets the port that will run the Koha OPAC virtual server,
320 as specified by the user.
328 =item getintranetport
330 $port = getintranetport;
332 Gets the port that will run the Koha INTRANET virtual server,
333 as specified by the user.
337 sub getintranetport () {
343 =head2 Miscellaneous utility functions
353 Does the equivalent of dirname(1). Given a path $path, return the
354 parent directory of $path (best guess), except when $path seems to
355 be the same as /, in which case $path itself is returned unchanged.
361 if ($path =~ /[^\/]/s) {
363 $path =~ s/\/+[^\/]+\/*$//s;
374 mkdir_parents $path, $mode;
376 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
377 create the directory $path, recursively creating any intermediate
378 directories. If $mode is given, the directory will be created with
381 WARNING: If $path already exists, mkdir_parents will just return
382 successfully (just like mkdir -p), whether the mode of $path conforms
383 to $mode or not. (This is the behaviour of the mkdir -p command.)
387 sub mkdir_parents ($;$) {
388 my($path, $mode) = @_;
389 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
391 if (!$ok && $! == ENOENT) {
392 my $parent = dirname($path);
393 $ok = mkdir_parents($parent, $mode);
395 # retry and at the same time make sure that $! is set correctly
396 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
405 getmessage($msgid, $variables);
407 Gets a localized message (format string) with message id $msgid,
408 and, if an array reference of variables $variables is given,
409 substitutes variables in the format string with @$variables.
410 Returns the found message string, with variable substitutions
413 $msgid must be the message identifier corresponding to a defined
414 message string (a valid key to the $messages hash in the Installer
415 package). getmessage throws an exception if the message cannot be
421 my $messagename=shift;
423 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
424 if (defined($variables)) {
425 $message=sprintf $message, @$variables;
433 showmessage($message, 'none');
434 showmessage($message, 'none', undef, $noclear);
436 $result = showmessage($message, 'yn');
437 $result = showmessage($message, 'yn', $defaultresponse);
438 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
440 $result = showmessage($message, 'restrictchar CHARS');
441 $result = showmessage($message, 'free');
442 $result = showmessage($message, 'numerical');
443 $result = showmessage($message, 'email');
444 $result = showmessage($message, 'PressEnter');
446 Shows a message and optionally gets a response from the user.
448 The first two arguments, the message and the response type,
449 are mandatory. The message must be the actual string to
450 display; the caller is responsible for calling getmessage if
453 The response type must be one of "none", "yn", "free",
454 "numerical", "email", "PressEnter", or a string consisting
455 of "restrictchar " followed by a list of allowed characters
456 (space can be specified). (Case is not significant, but case is
457 significant in the list of allowed characters.) If a response
458 type other than the above-listed is specified, the result is
461 Note that the response type "yn" is equivalent to "restrictchar yn".
462 Because "restrictchar" is case-sensitive, the user is expected
463 to enter "y" or "n" in lowercase only.
465 Note that the response type of "email" does not actually
466 guarantee that the returned value is a well-formed RFC-822
467 email address, nor does it accept all well-formed RFC-822 email
468 addresses. What it does is to restrict the returned value to a
469 string that is looks reasonably likely to be an email address
470 in the "real world", given the premise that the user is trying
471 to enter a real email address.
473 If a response type other than "none" or "PressEnter" is
474 specified, a third argument, specifying the default value, can
475 be specified: If this default response is not specified, the
476 default response is the first allowed character if the response
477 type is "restrictchar", otherwise the default response is the
478 empty string. This default response is used when the user does
479 not specify a value (i.e., presses Enter without typing in
480 anything), showmessage will assume that the default response is
483 Note that because the response type "yn" is equivalent to
484 "restrictchar yn", the default value for response type "yn",
485 if unspecified, is "y".
487 The screen is normally cleared before the message is displayed;
488 if a fourth argument is specified and is nonzero, this
489 screen-clearing is not done.
496 my $responsetype=shift;
497 my $defaultresponse=shift;
499 $noclear = 0 unless defined $noclear; # defaults to "clear"
500 ($noclear) || (system('clear'));
501 if ($responsetype =~ /^yn$/) {
502 $responsetype='restrictchar yn';
505 if ($responsetype =~/^restrictchar (.*)/i) {
508 until ($options=~/$response/) {
509 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
512 (length($response)) || ($response=$defaultresponse);
513 unless ($options=~/$response/) {
514 ($noclear) || (system('clear'));
515 print "Invalid Response. Choose from [$options].\n\n";
520 } elsif ($responsetype =~/^free$/i) {
521 (defined($defaultresponse)) || ($defaultresponse='');
522 my $response=<STDIN>;
524 ($response) || ($response=$defaultresponse);
526 } elsif ($responsetype =~/^numerical$/i) {
527 (defined($defaultresponse)) || ($defaultresponse='');
529 until ($response=~/^\d+$/) {
532 ($response) || ($response=$defaultresponse);
533 unless ($response=~/^\d+$/) {
534 ($noclear) || (system('clear'));
535 print "Invalid Response ($response). Response must be a number.\n\n";
540 } elsif ($responsetype =~/^email$/i) {
541 (defined($defaultresponse)) || ($defaultresponse='');
543 until ($response=~/.*\@.*\..*/) {
546 ($response) || ($response=$defaultresponse);
547 unless ($response=~/.*\@.*\..*/) {
548 ($noclear) || (system('clear'));
549 print "Invalid Response ($response). Response must be a valid email address.\n\n";
554 } elsif ($responsetype =~/^PressEnter$/i) {
557 } elsif ($responsetype =~/^none$/i) {
560 # FIXME: There are a few places where we will get an undef as the
561 # response type. Should we thrown an exception here, or should we
562 # legitimize this usage and say "none" is the default if not specified?
563 #die "Illegal response type \"$responsetype\"";
570 =head2 Subtasks of doing an installation
576 =item checkabortedinstall
580 Checks whether a previous installation process has been abnormally
581 aborted, by checking whether $etcidr/koha.conf is a symlink matching
582 a particular pattern. If an aborted installation is detected, give
583 the user a chance to abort, before trying to recover the aborted
586 FIXME: The recovery is not complete; it only partially rolls back
591 sub checkabortedinstall () {
592 if (-l("$etcdir/koha.conf")
593 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
596 I have detected that you tried to install Koha before, but the installation
597 was aborted. I will try to continue, but there might be problems if the
598 database is already created.
601 print "Please press <ENTER> to continue: ";
604 # Remove the symlink after the <STDIN>, so the user can back out
605 unlink "$etcdir/koha.conf"
606 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
611 =item checkperlmodules
615 Test whether the version of Perl is new enough, whether Perl is
616 found at the expected location, and whether all required modules
621 sub checkperlmodules {
623 # Test for Perl and Modules
626 my $message = getmessage('CheckingPerlModules');
627 showmessage($message, 'none');
629 unless ($] >= 5.006001) { # Bug 179
630 die getmessage('PerlVersionFailure', ['5.6.1']);
634 unless (eval {require DBI}) { push @missing,"DBI" };
635 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
636 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
637 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
638 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
639 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
640 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
641 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
642 unless (eval {require Net::Z3950}) {
643 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
644 if ($#missing>=0) { # XXX why only when $#missing >= 0?
645 push @missing, "Net::Z3950";
650 # Print out a list of any missing modules
655 foreach my $module (@missing) {
656 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
658 my $message=getmessage('MissingPerlModules', [$missing]);
659 showmessage($message, 'none');
662 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
666 unless (-x "/usr/bin/perl") {
667 my $realperl=`which perl`;
669 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
670 until (-x $realperl) {
671 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
673 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
674 unless ($response eq 'n') {
675 system("ln -s $realperl /usr/bin/perl");
682 $messages->{'NoUsrBinPerl'}->{en} =
683 heading('Perl is not located in /usr/bin/perl') . qq|
684 The Koha perl scripts expect to find the perl executable in the /usr/bin
685 directory. It is not there on your system.
689 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
690 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
691 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
693 May I create this symlink? ([Y]/N):
697 =item getinstallationdirectories
699 getinstallationdirectories;
701 Get the various installation directories from the user, and then
702 create those directories (if they do not already exist).
704 These pieces of information are saved to global variables; the
705 function does not return any values.
709 sub getinstallationdirectories {
710 $opacdir = '/usr/local/koha/opac';
711 $intranetdir = '/usr/local/koha/intranet';
713 while ($getdirinfo) {
714 # Loop until opac directory and koha directory are different
715 my $message=getmessage('GetOpacDir', [$opacdir]);
716 $opacdir=showmessage($message, 'free', $opacdir);
718 $message=getmessage('GetIntranetDir', [$intranetdir]);
719 $intranetdir=showmessage($message, 'free', $intranetdir);
721 if ($intranetdir eq $opacdir) {
724 You must specify different directories for the OPAC and INTRANET files!
725 :: $intranetdir :: $opacdir ::
732 $kohalogdir='/var/log/koha';
733 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
734 $kohalogdir=showmessage($message, 'free', $kohalogdir);
737 # FIXME: Missing error handling for all mkdir calls here
738 unless ( -d $intranetdir ) {
739 mkdir_parents (dirname($intranetdir), 0775);
740 mkdir ($intranetdir, 0770);
741 chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir");
742 chmod (oct(770), "$intranetdir");
744 mkdir_parents ("$intranetdir/htdocs", 0750);
745 mkdir_parents ("$intranetdir/cgi-bin", 0750);
746 mkdir_parents ("$intranetdir/modules", 0750);
747 mkdir_parents ("$intranetdir/scripts", 0750);
748 unless ( -d $opacdir ) {
749 mkdir_parents (dirname($opacdir), 0775);
750 mkdir ($opacdir, 0770);
751 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
752 chmod (oct(770), "$opacdir");
754 mkdir_parents ("$opacdir/htdocs", 0750);
755 mkdir_parents ("$opacdir/cgi-bin", 0750);
758 unless ( -d $kohalogdir ) {
759 mkdir_parents (dirname($kohalogdir), 0775);
760 mkdir ($kohalogdir, 0770);
761 chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir");
762 chmod (oct(770), "$kohalogdir");
768 =item getdatabaseinfo
772 Get various pieces of information related to the Koha database:
773 the name of the database, the host on which the SQL server is
774 running, and the database user name.
776 These pieces of information are saved to global variables; the
777 function does not return any values.
781 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
782 Please provide the name of the mysql database for your koha installation.
784 Database name [%s]: |;
786 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
787 Please provide the hostname for mysql. Unless the database is located on
788 another machine this will be "localhost".
790 Database host [%s]: |;
792 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
793 Please provide the name of the user, who will have full administrative rights
794 to the %s database, when authenticating from %s.
796 This user will also be used to access Koha's INTRANET interface.
798 Database user [%s]: |;
800 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
801 Please provide a good password for the user %s.
803 This password will also be used to access Koha's INTRANET interface.
805 Password for database user %s: |;
807 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
808 You must not use a blank password for your MySQL user!
810 Press <ENTER> to try again:
813 sub getdatabaseinfo {
816 $hostname = 'localhost';
820 #Get the database name
822 my $message=getmessage('DatabaseName', [$dbname]);
823 $dbname=showmessage($message, 'free', $dbname);
825 #Get the hostname for the database
827 $message=getmessage('DatabaseHost', [$hostname]);
828 $hostname=showmessage($message, 'free', $hostname);
830 #Get the username for the database
832 $message=getmessage('DatabaseUser', [$dbname, $hostname, $user]);
833 $user=showmessage($message, 'free', $user);
835 #Get the password for the database user
837 while ($pass eq '') {
838 my $message=getmessage('DatabasePassword', [$user, $user]);
839 $pass=showmessage($message, 'free', $pass);
841 my $message=getmessage('BlankPassword');
842 showmessage($message,'PressEnter');
853 Get various pieces of information related to the Apache server:
854 the location of the configuration file and, if needed, the Unix
855 user that the Koha CGI will be run under.
857 These pieces of information are saved to global variables; the
858 function does not return any values.
862 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
863 heading('MULTIPLE APACHE CONFIG FILES') . qq|
864 I found more than one possible Apache configuration file:
868 Choose the correct file [1]: |;
870 $messages->{'NoApacheConfFiles'}->{en} =
871 heading('NO APACHE CONFIG FILE FOUND') . qq|
872 I was not able to find your Apache configuration file.
874 The file is usually called httpd.conf or apache.conf.
876 Please specify the location of your config file: |;
878 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
879 The file %s does not exist.
881 Please press <ENTER> to continue: |;
883 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
884 I was not able to determine the user that Apache is running as. This
885 information is necessary in order to set the access privileges correctly on
886 %s/koha.conf. This user should be set in one of the Apache configuration
887 files using the "User" directive.
889 Enter the Apache userid: |;
891 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
892 The userid %s is not a valid userid on this system.
894 Press <ENTER> to continue: |;
897 my @confpossibilities;
899 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
900 /usr/local/etc/apache/httpd.conf
901 /usr/local/etc/apache/apache.conf
902 /var/www/conf/httpd.conf
903 /etc/apache/conf/httpd.conf
904 /etc/apache/conf/apache.conf
905 /etc/apache-ssl/conf/apache.conf
906 /etc/apache-ssl/httpd.conf
907 /etc/httpd/conf/httpd.conf
908 /etc/httpd/httpd.conf)) {
909 if ( -f $httpdconf ) {
910 push @confpossibilities, $httpdconf;
914 if ($#confpossibilities==-1) {
915 my $message=getmessage('NoApacheConfFiles');
917 until (-f $realhttpdconf) {
918 $choice=showmessage($message, "free", 1);
920 $realhttpdconf=$choice;
922 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
925 } elsif ($#confpossibilities>0) {
929 foreach (@confpossibilities) {
930 $conffiles.=" $counter: $_\n";
931 $options.="$counter";
934 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
935 my $choice=showmessage($message, "restrictchar $options", 1);
936 $realhttpdconf=$confpossibilities[$choice-1];
938 $realhttpdconf=$confpossibilities[0];
940 unless (open (HTTPDCONF, "<$realhttpdconf")) {
941 warn "Insufficient privileges to open $realhttpdconf for reading.\n";
945 while (<HTTPDCONF>) {
946 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
955 unless ($httpduser) {
956 my $message=getmessage('EnterApacheUser', [$etcdir]);
957 until (length($httpduser) && getpwnam($httpduser)) {
958 $httpduser=showmessage($message, "free", '');
959 if (length($httpduser)>0) {
960 unless (getpwnam($httpduser)) {
961 my $message=getmessage('InvalidUserid', [$httpduser]);
962 showmessage($message,'PressEnter');
967 print "AU: $httpduser\n";
972 =item getapachevhostinfo
976 Gets various pieces of information related to virtual hosting:
977 the webmaster email address, virtual hostname, and the ports
978 that the OPAC and INTRANET modules run on.
980 These pieces of information are saved to global variables; the
981 function does not return any values.
985 $messages->{'ApacheConfigIntroduction'}->{en} =
986 heading('APACHE CONFIGURATION') . qq|
987 Koha needs to setup your Apache configuration file for the
988 OPAC and LIBRARIAN virtual hosts. By default this installer
989 will do this by using one ip address and two different ports
990 for the virtual hosts. There are other ways to set this up,
991 and the installer will leave comments in httpd.conf detailing
992 what these other options are.
995 Press <ENTER> to continue: |;
997 $messages->{'GetVirtualHostEmail'}->{en} =
998 heading('WEB SERVER E-MAIL CONTACT') . qq|
999 Enter the e-mail address to be used as a contact for the virtual hosts (this
1000 address is displayed if any errors are encountered).
1002 E-mail contact [%s]: |;
1004 $messages->{'GetServerName'}->{en} =
1005 heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
1006 Please enter the domain name or ip address of your computer.
1008 Host name or IP Address [%s]: |;
1010 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
1011 Please enter the port for your OPAC interface. This defaults to port 80, but
1012 if you are already serving web content from this server, you should change it
1013 to a different port (8000 might be a good choice).
1015 Enter the OPAC Port [%s]: |;
1017 $messages->{'GetIntranetPort'}->{en} =
1018 heading('INTRANET VIRTUAL HOST PORT') . qq|
1019 Please enter the port for your Intranet interface. This must be different from
1022 Enter the Intranet Port [%s]: |;
1025 sub getapachevhostinfo {
1027 $svr_admin = "webmaster\@$domainname";
1028 $servername=`hostname`;
1033 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
1035 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1036 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1039 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1040 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1045 =item updateapacheconf
1049 Updates the Apache config file according to parameters previously
1050 specified by the user.
1052 It will append fully-commented directives at the end of the original
1053 Apache config file. The old config file is renamed with an extension
1056 If you need to uninstall Koha for any reason, the lines between
1058 # Ports to listen to for Koha
1060 and the block of comments beginning with
1062 # If you want to use name based Virtual Hosting:
1068 $messages->{'StartUpdateApache'}->{en} =
1069 heading('UPDATING APACHE CONFIGURATION') . qq|
1070 Checking for modules that need to be loaded...
1073 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
1075 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
1077 $messages->{'ApacheConfigBackupFailed'}->{en} =
1078 heading('APACHE CONFIGURATION BACKUP FAILED') . qq|
1079 An error occurred while trying to make a backup copy of %s.
1083 No changes will be made to the apache configuration file at this time.
1085 Press <ENTER> to continue: |;
1088 $messages->{'ApacheAlreadyConfigured'}->{en} =
1089 heading('APACHE ALREADY CONFIGURED') . qq|
1090 %s appears to already have an entry for Koha
1091 Virtual Hosts. You may need to edit %s
1092 f anything has changed since it was last set up. This
1093 script will not attempt to modify an existing Koha apache
1096 Press <ENTER> to continue: |;
1098 sub updateapacheconf {
1099 my $logfiledir=`grep ^ErrorLog "$realhttpdconf"`;
1103 $logfiledir=~m#ErrorLog (.*)/[^/]*$#
1104 or die "Can't parse ErrorLog directive\n";
1108 unless ($logfiledir) {
1112 showmessage(getmessage('StartUpdateApache'), 'none');
1116 my $includesmodule=0;
1117 open HC, "<$realhttpdconf";
1119 if (/^\s*#\s*LoadModule env_module /) {
1121 showmessage(getmessage('LoadingApacheModuleModEnv'));
1124 if (/^\s*#\s*LoadModule includes_module /) {
1126 showmessage(getmessage('LoadingApacheModuleModInc'));
1128 if (/\s*LoadModule includes_module / ) {
1135 $backupfailed=`cp -f $realhttpdconf $realhttpdconf\.prekoha`;
1136 if ($backupfailed) {
1137 showmessage(getmessage('ApacheConfigBackupFailed', [$realhttpdconf,$backupfailed ]), 'PressEnter');
1141 if ($envmodule || $includesmodule) {
1142 open HC, ">$realhttpdconf";
1143 print HC $httpdconf;
1149 if (`grep 'VirtualHost $servername' "$realhttpdconf"`) {
1150 showmessage(getmessage('ApacheAlreadyConfigured', [$realhttpdconf, $realhttpdconf]), 'PressEnter');
1153 my $includesdirectives='';
1154 if ($includesmodule) {
1155 $includesdirectives.="Options +Includes\n";
1156 $includesdirectives.=" AddHandler server-parsed .html\n";
1158 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1159 my $opaclisten = '';
1160 if ($opacport != 80) {
1161 $opaclisten="Listen $opacport";
1163 my $intranetlisten = '';
1164 if ($intranetport != 80) {
1165 $intranetlisten="Listen $intranetport";
1169 # Ports to listen to for Koha
1173 # NameVirtualHost is used by one of the optional configurations detailed below
1175 #NameVirtualHost 11.22.33.44
1177 # KOHA's OPAC Configuration
1178 <VirtualHost $servername\:$opacport>
1179 ServerAdmin $svr_admin
1180 DocumentRoot $opacdir/htdocs
1181 ServerName $servername
1182 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1183 ErrorLog $logfiledir/opac-error_log
1184 TransferLog $logfiledir/opac-access_log
1185 SetEnv PERL5LIB "$intranetdir/modules"
1189 # KOHA's INTRANET Configuration
1190 <VirtualHost $servername\:$intranetport>
1191 ServerAdmin $svr_admin
1192 DocumentRoot $intranetdir/htdocs
1193 ServerName $servername
1194 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1195 ErrorLog $logfiledir/koha-error_log
1196 TransferLog $logfiledir/koha-access_log
1197 SetEnv PERL5LIB "$intranetdir/modules"
1201 # If you want to use name based Virtual Hosting:
1202 # 1. remove the two Listen lines
1203 # 2. replace $servername\:$opacport wih your.opac.domain.name
1204 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1205 # 4. replace $servername\:$intranetport wih your intranet domain name
1206 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1208 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1209 # 1. Follow steps 1-5 above
1210 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1219 =item basicauthentication
1221 basicauthentication;
1223 Asks the user whether HTTP basic authentication is wanted, and,
1224 if so, the user name and password for the basic authentication.
1226 These pieces of information are saved to global variables; the
1227 function does not return any values.
1231 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1232 heading('INTRANET AUTHENTICATION') . qq|
1233 I can set it up so that the Intranet/Librarian site is password protected using
1234 Apache's Basic Authorization.
1236 This is going to be phased out very soon. However, setting this up can provide
1237 an extra layer of security before the new authentication system is completely
1240 Would you like to do this ([Y]/N): |; #'
1242 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
1243 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1244 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1246 sub basicauthentication {
1247 my $message=getmessage('IntranetAuthenticationQuestion');
1248 my $answer=showmessage($message, 'yn', 'y');
1250 my $apacheauthusername='librarian';
1251 my $apacheauthpassword='';
1252 if ($answer=~/^y/i) {
1253 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1254 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1255 while (! $apacheauthpassword) {
1256 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1257 if (!$apacheauthpassword) {
1258 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1261 open AUTH, ">$etcdir/kohaintranet.pass";
1262 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1263 my $salt=substr($chars, int(rand(length($chars))),1);
1264 $salt.=substr($chars, int(rand(length($chars))),1);
1265 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1267 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1270 <Directory $intranetdir>
1271 AuthUserFile $etcdir/kohaintranet.pass
1273 AuthName "Koha Intranet (for librarians only)"
1286 Install the Koha files to the specified OPAC and INTRANET
1287 directories (usually in /usr/local/koha).
1289 The koha.conf file is created, but as koha.conf.tmp. The
1290 caller is responsible for calling finalizeconfigfile when
1291 installation is completed, to rename it back to koha.conf.
1295 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1296 Copying files to installation directories:
1301 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1308 showmessage(getmessage('InstallFiles'),'none');
1309 print getmessage('CopyingFiles', ['intranet-html', "$intranetdir/htdocs" ]);
1310 system("cp -R intranet-html/* $intranetdir/htdocs/");
1311 print getmessage('CopyingFiles', ['intranet-cgi', "$intranetdir/cgi-bin" ]);
1312 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
1313 print getmessage('CopyingFiles', ['stand-alone scripts', "$intranetdir/scripts" ]);
1314 system("cp -R scripts/* $intranetdir/scripts/");
1315 print getmessage('CopyingFiles', ['perl modules', "$intranetdir/modules" ]);
1316 system("cp -R modules/* $intranetdir/modules/");
1317 print getmessage('CopyingFiles', ['opac-html', "$opacdir/htdocs" ]);
1318 system("cp -R opac-html/* $opacdir/htdocs/");
1319 print getmessage('CopyingFiles', ['opac-cgi', "$opacdir/cgi-bin" ]);
1320 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
1321 system("touch $opacdir/cgi-bin/opac");
1323 system("chown -R $httpduser:$httpduser $opacdir");
1324 system("chown -R $httpduser:$httpduser $intranetdir");
1326 # Create /etc/koha.conf
1328 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1329 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1335 includes=$opacdir/htdocs/includes
1336 intranetdir=$intranetdir
1338 kohalogdir=$kohalogdir
1339 kohaversion=$kohaversion
1340 httpduser=$httpduser
1341 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1342 opachtdocs=$opacdir/htdocs/opac-tmpl
1347 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1348 chmod 0440, "$etcdir/koha.conf.tmp";
1350 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1351 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1352 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
1353 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1354 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1363 Finds out where the MySQL utitlities are located in the system,
1364 then create the Koha database structure and MySQL permissions.
1368 $messages->{'MysqlRootPassword'}->{en} =
1369 heading('MYSQL ROOT USER PASSWORD') . qq|
1370 To allow us to create the koha database please supply your
1371 mysql server's root user password:
1373 Enter MySQL root user password: |; #'
1375 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password. Please try again.";
1377 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1378 Creating the MySQL database for Koha...
1382 $messages->{'CreatingDatabaseError'}->{en} =
1383 heading('ERROR CREATING DATABASE') . qq|
1384 Couldn't connect to the MySQL server for the reason given above.
1385 This is a serious problem, the database will not get installed.
\a
1387 Press <ENTER> to continue: |; #'
1389 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1390 If you are installing Koha for evaluation purposes, I have a batch of sample
1391 data that you can install now.
1393 If you are installing Koha with the intention of populating it with your own
1394 data, you probably don't want this sample data installed.
1396 Would you like to install the sample data? Y/[N]: |; #'
1398 $messages->{'SampleDataInstalled'}->{en} =
1399 heading('SAMPLE DATA INSTALLED') . qq|
1400 Sample data has been installed. For some suggestions on testing Koha, please
1401 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1402 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1403 question through the koha-devel mailing list, or you can check for a developer
1404 online at +irc.katipo.co.nz:6667 channel #koha.
1406 You can find instructions for subscribing to the Koha mailing lists at:
1411 Press <ENTER> to continue: |;
1413 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1414 Would you like to install an initial branch and printer? [Y]/N: |;
1416 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1417 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1418 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1419 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1420 $messages->{'BlankMysqlPassword'}->{en} = heading('Blank MySQL Password') . qq|
1421 Do not leave your MySQL root password blank unless you know exactly what you
1422 are doing. To change your MySQL root password use the mysqladmin command:
1424 mysqladmin password NEWPASSWORDHERE
1426 Press <ENTER> to continue:
1430 $mysqluser = 'root';
1433 foreach my $mysql (qw(/usr/local/mysql
1437 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1442 print "I don't see mysql in the usual places.\n";
1444 print "Where have you installed mysql? ";
1445 chomp($mysqldir = <STDIN>);
1446 last if -f "$mysqldir/bin/mysqladmin";
1449 I can't find it there either. If you compiled mysql yourself,
1450 please give the value of --prefix when you ran configure.
1452 The file mysqladmin should be in bin/mysqladmin under the directory that you
1462 while ($needpassword) {
1463 $mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1464 $mysqlpass_quoted = $mysqlpass;
1465 $mysqlpass_quoted =~ s/"/\\"/g;
1466 $mysqlpass_quoted="-p\"$mysqlpass_quoted\"";
1467 $mysqlpass eq '' and $mysqlpass_quoted='';
1468 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser $mysqlpass_quoted proc > /dev/null 2>&1");
1470 print getmessage('InvalidMysqlRootPassword');
1472 if ($mysqlpass eq '') {
1473 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1479 showmessage(getmessage('CreatingDatabase'),'none');
1481 my $result=system("$mysqldir/bin/mysqladmin", "-u$mysqluser", "-p$mysqlpass", "create", "$dbname");
1483 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1485 # Create the database structure
1486 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname < koha.mysql");
1487 # Set up permissions
1488 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
1489 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted 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')\"");
1490 system("$mysqldir/bin/mysqladmin -u$mysqluser $mysqlpass_quoted reload");
1501 =item updatedatabase
1505 Updates the Koha database structure, including the addition of
1508 The MARC tables are also populated in addition to being created.
1510 Because updatedatabase calls scripts/updater/updatedatabase to
1511 do the actual update, and that script uses C4::Context,
1512 $etcdir/koha.conf must exist at this point. We use a symlink to
1513 do this and to also at the same time faciliate detection of
1514 ahorted installs. (See checkabortedinstall.)
1518 $messages->{'UpdateMarcTables'}->{en} =
1519 heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1520 You can import marc parameters for :
1526 Please choose which parameter you want to install. Note if you choose 3,
1527 nothing will be added, and it can be a BIG job to manually create those tables
1529 Choose MARC definition [1]: |;
1531 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1532 This version of koha supports a few languages.
1533 Enter your language preference : either en, fr, es, pl or zh_TW
1535 Note that the en is always choosen when the system does not finds the
1536 language you choose in a specific screen.
1538 fr : all is translated (except pictures)
1539 es : a few intranet is translated (including pictures)
1540 pl : OPAC and a few intranet is translated
1541 zh_TW : partial translation
1543 Whether you specify a language here, you can always go to the
1544 intranet interface and change it from the system preferences.
1546 Which language do you choose? |;
1548 sub updatedatabase {
1549 # At this point, $etcdir/koha.conf must exist, for C4::Context
1550 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
1552 print "Problem updating database...\n";
1556 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1558 if ($response eq '1') {
1559 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1561 if ($response eq '2') {
1562 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1563 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1566 $result = system ("perl -I $intranetdir/modules scripts/marc/updatedb2marc.pl");
1568 print "Problem updating database to MARC...\n";
1572 print "\n\nFinished updating of database. Press <ENTER> to continue...";
1577 =item populatedatabase
1581 Populate the non-MARC tables. If the user wants to install the
1582 sample data, install them.
1586 sub populatedatabase {
1587 my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1588 if ($response =~/^y/i) {
1589 system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1590 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1591 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1592 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1593 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1594 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1597 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1599 unless ($response =~/^n/i) {
1600 my $branch='Main Library';
1601 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1602 $branch=~s/[^A-Za-z0-9\s]//g;
1604 my $branchcode=$branch;
1605 $branchcode=~s/[^A-Za-z0-9]//g;
1606 $branchcode=uc($branchcode);
1607 $branchcode=substr($branchcode,0,4);
1608 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1609 $branchcode=~s/[^A-Za-z0-9]//g;
1610 $branchcode=uc($branchcode);
1611 $branchcode=substr($branchcode,0,4);
1612 $branchcode or $branchcode='DEF';
1614 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1615 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1616 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1618 my $printername='Library Printer';
1619 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1620 $printername=~s/[^A-Za-z0-9\s]//g;
1622 my $printerqueue='lp';
1623 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1624 $printerqueue=~s/[^A-Za-z0-9]//g;
1625 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1627 my $language=showmessage(getmessage('Language'), 'free', 'en');
1628 system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1637 Asks the user whether to restart Apache, and restart it if the user
1640 FIXME: If the installer does not know how to restart the Apache
1641 server (e.g., if the user is not actually using Apache), it still
1646 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1647 Apache needs to be restarted to load the new configuration for Koha.
1649 Would you like to restart Apache now? [Y]/N: |;
1653 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1657 unless ($response=~/^n/i) {
1658 # Need to support other init structures here?
1659 if (-e "/etc/rc.d/init.d/httpd") {
1660 system('/etc/rc.d/init.d/httpd restart');
1661 } elsif (-e "/etc/init.d/apache") {
1662 system('/etc//init.d/apache restart');
1663 } elsif (-e "/etc/init.d/apache-ssl") {
1664 system('/etc/init.d/apache-ssl restart');
1671 =item finalizeconfigfile
1675 This function must be called when the installation is complete,
1676 to rename the koha.conf.tmp file to koha.conf.
1678 Currently, failure to rename the file results only in a warning.
1682 sub finalizeconfigfile {
1683 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
1684 || showmessage(<<EOF, 'PressEnter', undef, 1);
1685 An unexpected error, $!, occurred
1686 while the Koha config file is being saved to its final location,
1689 Couldn't rename file at $etcdir. Must have write capability.
1691 Press Enter to continue.
1697 =item loadconfigfile
1701 Open the existing koha.conf file and get its values,
1702 saving the values to some global variables.
1704 If the existing koha.conf file cannot be opened for any reason,
1705 the file is silently ignored.
1709 sub loadconfigfile {
1712 open (KC, "<$etcdir/koha.conf");
1715 (next) if (/^\s*#/);
1716 if (/(.*)\s*=\s*(.*)/) {
1719 # Clean up white space at beginning and end
1720 $variable=~s/^\s*//g;
1721 $variable=~s/\s*$//g;
1724 $configfile{$variable}=$value;
1728 $intranetdir=$configfile{'intranetdir'};
1729 $opacdir=$configfile{'opacdir'};
1730 $kohaversion=$configfile{'kohaversion'};
1731 $kohalogdir=$configfile{'kohalogdir'};
1732 $database=$configfile{'database'};
1733 $hostname=$configfile{'hostname'};
1734 $user=$configfile{'user'};
1735 $pass=$configfile{'pass'};
1738 END { } # module clean-up code here (global destructor)