1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
5 # Contains parts Copyright 2003 MJ Ray
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
23 # MJR: my.cnf, etcdir, prefix, new display, apache conf, copying fixups
27 #MJR: everyone will have these modules, right?
28 # They look like part of perl core to me
30 use Term::ANSIColor qw(:constants);
34 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38 Install.pm - Perl module containing the bulk of the installation logic
42 The Install.pm module contains the bulk
43 of the code to do installation;
44 this code is used by installer.pl
45 to perform an actual installation.
47 =head2 Internal functions (not meant to be used outside of Install.pm)
53 # set the version for version checking
57 @EXPORT = qw( &checkperlmodules
61 &releasecandidatewarning
62 &getinstallationdirectories
79 use vars qw( $kohaversion ); # set in installer.pl
80 use vars qw( $language ); # set in installer.pl
81 use vars qw( $domainname ); # set in installer.pl
83 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
84 use vars qw( $intranetdir $opacdir $kohalogdir );
85 use vars qw( $realhttpdconf $httpduser );
86 use vars qw( $servername $svr_admin $opacport $intranetport );
87 use vars qw( $mysqldir );
88 use vars qw( $database $mysqluser );
89 use vars qw( $mysqlpass ); # normally should not be used
90 use vars qw( $dbname $hostname $user $pass ); # virtual hosting
92 use vars qw( $newversion ); # XXX this seems to be unused
96 $messages->{'WelcomeToKohaInstaller'
97 = heading('Welcome to the Koha Installer') . qq|...|;
99 The heading function takes one string, the text to be displayed as
100 the heading, and returns a formatted heading (currently formatted
103 This reduces the likelihood of pod2man(1) etc. misinterpreting
104 a line of equal signs as illegal POD directives.
108 my $termios = POSIX::Termios->new();
110 my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
111 my $clear_string = "\n\n"; #MJR: was $terminal->Tputs('cl');
116 return($clear_string.ON_BLUE.WHITE.BOLD." "x$bal.uc($title)." "x$bal.RESET."\n\n");
119 my $mycnf = $ENV{HOME}."/.my.cnf";
120 my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
124 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
125 $messages->{'WelcomeToKohaInstaller'}->{en} =
126 heading('Welcome to the Koha Installer') . qq|
127 Welcome to the Koha install script! This script will prompt you for some
128 basic information about your desired setup, then install Koha for you.
130 If you want to install the Koha configuration file somewhere other than /etc
131 (eg for non-root installation, or multiple Koha versions on one system), you
132 should set the etcdir and prefix environment variables. If this is your
133 only koha installation on this machine and you are running this as root, the
134 default should be OK.
136 To accept the default value for any question, simply hit Enter at the prompt.
138 Please be sure to read the documentation, or visit the Koha website at
139 http://www.koha.org for more information.
141 Are you ready to begin the installation? ([Y]/N): |;
142 $messages->{'ReleaseCandidateWarning'}->{en} =
143 heading('RELEASE CANDIDATE') . qq|
144 WARNING WARNING WARNING WARNING WARNING
146 You are about to install Koha version %s. This version of Koha is a
147 release candidate. It is not intended to be installed on production systems.
148 It is being released so that users can test it before we release a final
151 Are you sure you want to install Koha %s? (Y/[N]): |;
152 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
154 Watch for announcements of Koha releases on the Koha mailing list or the Koha
155 web site (http://www.koha.org/).
159 $messages->{'NETZ3950Missing'}->{en}=qq|
161 The Net::Z3950 module is missing. This module is necessary if you want to use
162 Koha's Z39.50 client to download bibliographic records from other libraries.
164 To install this module, you will need the yaz client installed from
165 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
168 perl -MCPAN -e 'install Net::Z3950'
170 IMPORTANT NOTE : If you use PERL5.8.0 (RedHat 8.0 or Mandrake 9.x), you MUST install
171 manually the Net::Z3950 and edit Makefile.PL and yazwrap/Makefile.PL to include:
172 'DEFINE' => '-D_GNU_SOURCE',
173 Also note that some installations of Perl on Red Hat will generate a lot of
174 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
175 inserting the following line in yazwrap/ywpriv.h :
178 Press the <ENTER> key to continue: |; #'
180 $messages->{'CheckingPerlModules'}->{en} = heading('PERL & MODULES') . qq|
181 Checking perl modules ...
184 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
186 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
187 You are missing some Perl modules which are required by Koha.
188 Once these modules have been installed, rerun this installer.
189 They can be installed by running (as root) the following:
194 $messages->{'AllPerlModulesInstalled'}->{en} =
195 heading('ALL PERL MODULES INSTALLED') . qq|
196 All mandatory perl modules are installed.
198 Press <ENTER> to continue: |;
199 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
200 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
201 $messages->{'KohaAlreadyInstalled'}->{en} =
202 heading('Koha already installed') . qq|
203 It looks like Koha is already installed on your system (%s/koha.conf exists
204 already). If you would like to upgrade your system to %s, please use
205 the koha.upgrade script in this directory.
210 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
211 Please supply the directory you want Koha to store its OPAC files in. This
212 directory will be auto-created for you if it doesn't exist.
214 OPAC Directory [%s]: |; #'
216 $messages->{'GetIntranetDir'}->{en} =
217 heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
218 Please supply the directory you want Koha to store its Intranet/Librarians
219 files in. This directory will be auto-created for you if it doesn't exist.
221 Intranet Directory [%s]: |; #'
223 $messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
224 Specify a log directory where any Koha daemons can create log files.
226 Koha Log Directory [%s]: |;
228 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
229 This release of Koha has a new authentication module. If you are not already
230 using basic authentication on your intranet, you will be required to log in to
231 access some of the features of the intranet.
237 You can log in using the userid and password from the %s/koha.conf configuration file at any time.
238 Use the "Members" module to add passwords for other accounts and set their permissions.
240 Press the <ENTER> key to continue: |;
242 $messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
243 Congratulations ... your Koha installation is complete!
245 You will be able to connect to your Librarian interface at:
248 use mysql login and password to connect to this interface. Then, go to admin page, and create whatever fits your needs.
250 and the OPAC interface at :
254 Be sure to read the Hints file.
256 For more information visit http://www.koha.org
258 Press <ENTER> to exit the installer: |;
260 sub releasecandidatewarning {
261 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
262 my $answer=showmessage($message, 'yn', 'n');
264 if ($answer =~ /y/i) {
265 print getmessage('continuing');
267 my $message=getmessage('WatchForReleaseAnnouncements');
276 =head2 Accessor functions (for installer.pl)
286 Sets the installation language, normally "en" (English).
287 In fact, only "en" is supported.
291 sub setlanguage ($) {
297 setdomainname('example.org');
299 Sets the domain name of the host.
301 The domain name should not contain a leading dot;
302 otherwise, the results are undefined.
306 sub setdomainname ($) {
314 Sets the sysconfdir, normally /etc.
315 This should be an absolute path; a trailing / is not required.
325 setkohaversion('1.3.3RC26');
327 Sets the Koha version as known by the installer.
331 sub setkohaversion ($) {
337 my $servername = getservername;
339 Gets the name of the Koha virtual server as specified by the user.
343 sub getservername () {
351 Gets the port that will run the Koha OPAC virtual server,
352 as specified by the user.
360 =item getintranetport
362 $port = getintranetport;
364 Gets the port that will run the Koha INTRANET virtual server,
365 as specified by the user.
369 sub getintranetport () {
375 =head2 Miscellaneous utility functions
385 Does the equivalent of dirname(1). Given a path $path, return the
386 parent directory of $path (best guess), except when $path seems to
387 be the same as /, in which case $path itself is returned unchanged.
393 if ($path =~ /[^\/]/s) {
395 $path =~ s/\/+[^\/]+\/*$//s;
406 mkdir_parents $path, $mode;
408 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
409 create the directory $path, recursively creating any intermediate
410 directories. If $mode is given, the directory will be created with
413 WARNING: If $path already exists, mkdir_parents will just return
414 successfully (just like mkdir -p), whether the mode of $path conforms
415 to $mode or not. (This is the behaviour of the mkdir -p command.)
420 my($path, $mode) = @_;
421 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
423 if (!$ok && $! == ENOENT) {
424 my $parent = dirname($path);
425 $ok = mkdir_parents($parent, $mode);
427 # retry and at the same time make sure that $! is set correctly
428 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
437 getmessage($msgid, $variables);
439 Gets a localized message (format string) with message id $msgid,
440 and, if an array reference of variables $variables is given,
441 substitutes variables in the format string with @$variables.
442 Returns the found message string, with variable substitutions
445 $msgid must be the message identifier corresponding to a defined
446 message string (a valid key to the $messages hash in the Installer
447 package). getmessage throws an exception if the message cannot be
453 my $messagename=shift;
455 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || RED.BOLD."Error: No message named $messagename in Install.pm\n";
456 if (defined($variables)) {
457 $message=sprintf $message, @$variables;
465 showmessage($message, 'none');
466 showmessage($message, 'none', undef, $noclear);
468 $result = showmessage($message, 'yn');
469 $result = showmessage($message, 'yn', $defaultresponse);
470 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
472 $result = showmessage($message, 'restrictchar CHARS');
473 $result = showmessage($message, 'free');
474 $result = showmessage($message, 'silentfree');
475 $result = showmessage($message, 'numerical');
476 $result = showmessage($message, 'email');
477 $result = showmessage($message, 'PressEnter');
479 Shows a message and optionally gets a response from the user.
481 The first two arguments, the message and the response type,
482 are mandatory. The message must be the actual string to
483 display; the caller is responsible for calling getmessage if
486 The response type must be one of "none", "yn", "free", "silentfree"
487 "numerical", "email", "PressEnter", or a string consisting
488 of "restrictchar " followed by a list of allowed characters
489 (space can be specified). (Case is not significant, but case is
490 significant in the list of allowed characters.) If a response
491 type other than the above-listed is specified, the result is
494 Note that the response type "yn" is equivalent to "restrictchar yn".
495 Because "restrictchar" is case-sensitive, the user is expected
496 to enter "y" or "n" in lowercase only.
498 Note that the response type of "email" does not actually
499 guarantee that the returned value is a well-formed RFC-822
500 email address, nor does it accept all well-formed RFC-822 email
501 addresses. What it does is to restrict the returned value to a
502 string that is looks reasonably likely to be an email address
503 in the "real world", given the premise that the user is trying
504 to enter a real email address.
506 If a response type other than "none" or "PressEnter" is
507 specified, a third argument, specifying the default value, can
508 be specified: If this default response is not specified, the
509 default response is the first allowed character if the response
510 type is "restrictchar", otherwise the default response is the
511 empty string. This default response is used when the user does
512 not specify a value (i.e., presses Enter without typing in
513 anything), showmessage will assume that the default response is
516 Note that because the response type "yn" is equivalent to
517 "restrictchar yn", the default value for response type "yn",
518 if unspecified, is "y".
520 The screen is normally cleared before the message is displayed;
521 if a fourth argument is specified and is nonzero, this
522 screen-clearing is not done.
528 #MJR: Maybe refactor to use anonymous functions that
529 # check the responses instead of RnP branching.
530 my $message=join('',fill('','',(shift)));
531 my $responsetype=shift;
532 my $defaultresponse=shift;
534 $noclear = 0 unless defined $noclear; # defaults to "clear"
535 ($noclear) || (print $clear_string);
536 if ($responsetype =~ /^yn$/) {
537 $responsetype='restrictchar ynYN';
539 print RESET.$message;
540 if ($responsetype =~/^restrictchar (.*)/i) {
543 until ($options=~/$response/) {
544 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
547 (length($response)) || ($response=$defaultresponse);
548 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
549 ($noclear) || (print $clear_string);
550 print RED."Response contains invalid characters. Choose from [$options].\n\n";
551 print RESET.$message;
554 unless ($options=~/$response/) {
555 ($noclear) || (print $clear_string);
556 print RED."Invalid Response. Choose from [$options].\n\n";
557 print RESET.$message;
562 } elsif ($responsetype =~/^(silent)?free$/i) {
563 (defined($defaultresponse)) || ($defaultresponse='');
564 if ($responsetype =~/^(silent)/i) { setecho(0) };
565 my $response=<STDIN>;
566 if ($responsetype =~/^(silent)/i) { setecho(1) };
568 ($response) || ($response=$defaultresponse);
570 } elsif ($responsetype =~/^numerical$/i) {
571 (defined($defaultresponse)) || ($defaultresponse='');
573 until ($response=~/^\d+$/) {
576 ($response) || ($response=$defaultresponse);
577 unless ($response=~/^\d+$/) {
578 ($noclear) || (print $clear_string);
579 print RED."Invalid Response ($response). Response must be a number.\n\n";
580 print RESET.$message;
584 } elsif ($responsetype =~/^email$/i) {
585 (defined($defaultresponse)) || ($defaultresponse='');
587 until ($response=~/.*\@.*\..*/) {
590 ($response) || ($response=$defaultresponse);
591 if ($response!~/.*\@.*\..*/) {
592 ($noclear) || (print $clear_string);
593 print RED."Invalid Response ($response). Response must be a valid email address.\n\n";
594 print RESET.$message;
598 } elsif ($responsetype =~/^PressEnter$/i) {
601 } elsif ($responsetype =~/^none$/i) {
604 # FIXME: There are a few places where we will get an undef as the
605 # response type. Should we thrown an exception here, or should we
606 # legitimize this usage and say "none" is the default if not specified?
607 #die "Illegal response type \"$responsetype\"";
618 Changes the display to show system output until the next showmessage call.
619 At the time of writing, this means using red text.
630 =head2 Subtasks of doing an installation
636 =item checkabortedinstall
640 Checks whether a previous installation process has been abnormally
641 aborted, by checking whether $etcidr/koha.conf is a symlink matching
642 a particular pattern. If an aborted installation is detected, give
643 the user a chance to abort, before trying to recover the aborted
646 FIXME: The recovery is not complete; it only partially rolls back
651 sub checkabortedinstall () {
652 if (-l("$etcdir/koha.conf")
653 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
656 I have detected that you tried to install Koha before, but the installation
657 was aborted. I will try to continue, but there might be problems if the
658 database is already created.
661 print "Please press <ENTER> to continue: ";
664 # Remove the symlink after the <STDIN>, so the user can back out
665 unlink "$etcdir/koha.conf"
666 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
671 =item checkperlmodules
675 Test whether the version of Perl is new enough, whether Perl is
676 found at the expected location, and whether all required modules
681 sub checkperlmodules {
683 # Test for Perl and Modules
686 my $message = getmessage('CheckingPerlModules');
687 showmessage($message, 'none');
689 unless ($] >= 5.006001) { # Bug 179
690 die getmessage('PerlVersionFailure', ['5.6.1']);
695 unless (eval {require DBI}) { push @missing,"DBI" };
696 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
697 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
698 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
699 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
700 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
701 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
702 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
703 unless (eval {require Event}) {
704 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
705 push @missing, "Event";
708 unless (eval {require Net::Z3950}) {
709 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
710 if ($#missing>=0) { # see above note
711 push @missing, "Net::Z3950";
716 # Print out a list of any missing modules
721 foreach my $module (@missing) {
722 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
724 my $message=getmessage('MissingPerlModules', [$missing]);
725 showmessage($message, 'none');
729 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
734 unless (-x "/usr/bin/perl") {
735 my $realperl=`which perl`;
737 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
738 until (-x $realperl) {
739 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
741 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
742 unless ($response eq 'n') {
744 system("ln -s $realperl /usr/bin/perl");
751 $messages->{'NoUsrBinPerl'}->{en} =
752 heading('Perl is not located in /usr/bin/perl') . qq|
753 The Koha perl scripts expect to find the perl executable in the /usr/bin
754 directory. It is not there on your system.
758 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
759 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
760 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
762 May I create this symlink? ([Y]/N):
765 $messages->{'DirFailed'}->{en} = RED.qq|
766 We could not create %s, but continuing anyway...
772 =item getinstallationdirectories
774 getinstallationdirectories;
776 Get the various installation directories from the user, and then
777 create those directories (if they do not already exist).
779 These pieces of information are saved to global variables; the
780 function does not return any values.
784 sub getinstallationdirectories {
785 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
786 $opacdir = $ENV{prefix}.'/koha/opac';
787 $intranetdir = $ENV{prefix}.'/koha/intranet';
789 while ($getdirinfo) {
790 # Loop until opac directory and koha directory are different
791 my $message=getmessage('GetOpacDir', [$opacdir]);
792 $opacdir=showmessage($message, 'free', $opacdir);
794 $message=getmessage('GetIntranetDir', [$intranetdir]);
795 $intranetdir=showmessage($message, 'free', $intranetdir);
797 if ($intranetdir eq $opacdir) {
800 You must specify different directories for the OPAC and INTRANET files!
801 :: $intranetdir :: $opacdir ::
808 $kohalogdir=$ENV{prefix}.'/koha/log';
809 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
810 $kohalogdir=showmessage($message, 'free', $kohalogdir);
813 # FIXME: Need better error handling for all mkdir calls here
814 unless ( -d $intranetdir ) {
815 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed',['parents of '.$intranetdir]);
816 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',[$intranetdir]);
817 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir"); }
818 chmod 0770, "$intranetdir";
820 mkdir_parents ("$intranetdir/htdocs", 0750);
821 mkdir_parents ("$intranetdir/cgi-bin", 0750);
822 mkdir_parents ("$intranetdir/modules", 0750);
823 mkdir_parents ("$intranetdir/scripts", 0750);
824 unless ( -d $opacdir ) {
825 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed',['parents of '.$opacdir]);
826 mkdir ($opacdir, 0770) || print getmessage('DirFailed',[$opacdir]);
827 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$opacdir"); }
828 chmod (oct(770), "$opacdir");
830 mkdir_parents ("$opacdir/htdocs", 0750);
831 mkdir_parents ("$opacdir/cgi-bin", 0750);
834 unless ( -d $kohalogdir ) {
835 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed',['parents of '.$kohalogdir]);
836 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',[$kohalogdir]);
837 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir"); }
838 chmod (oct(770), "$kohalogdir");
844 =item getdatabaseinfo
848 Get various pieces of information related to the Koha database:
849 the name of the database, the host on which the SQL server is
850 running, and the database user name.
852 These pieces of information are saved to global variables; the
853 function does not return any values.
857 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
858 Please provide the name that you wish to give your koha database.
859 It must not exist already on the database server.
861 Database name [%s]: |;
863 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
864 Please provide the hostname for mysql. Unless the database is located on
865 another machine this will be "localhost".
867 Database host [%s]: |;
869 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
870 Please provide the name of the user who will have full administrative rights
871 to the %s database, when authenticating from %s.
873 This user will also be used to access Koha's INTRANET interface.
875 Database user [%s]: |;
877 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
878 Please provide a good password for the user %s.
884 You can log in using this userid and password at any time.
885 Password for database user %s: |;
887 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
888 You must not use a blank password for your MySQL user.
890 Press <ENTER> to try again:
893 sub getdatabaseinfo {
896 $hostname = 'localhost';
900 #Get the database name
902 my $message=getmessage('DatabaseName', [$dbname]);
903 $dbname=showmessage($message, 'free', $dbname);
905 #Get the hostname for the database
907 $message=getmessage('DatabaseHost', [$hostname]);
908 $hostname=showmessage($message, 'free', $hostname);
910 #Get the username for the database
912 $message=getmessage('DatabaseUser', [$dbname, $hostname, $user]);
913 $user=showmessage($message, 'free', $user);
915 #Get the password for the database user
917 while ($pass eq '') {
918 my $message=getmessage('DatabasePassword', [$user, $user]);
919 $pass=showmessage($message, 'free', $pass);
921 my $message=getmessage('BlankPassword');
922 showmessage($message,'PressEnter');
933 Get various pieces of information related to the Apache server:
934 the location of the configuration file and, if needed, the Unix
935 user that the Koha CGI will be run under.
937 These pieces of information are saved to global variables; the
938 function does not return any values.
942 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
943 heading('MULTIPLE APACHE CONFIG FILES') . qq|
944 I found more than one possible Apache configuration file:
948 Choose the correct file [1]: |;
950 $messages->{'NoApacheConfFiles'}->{en} =
951 heading('NO APACHE CONFIG FILE FOUND') . qq|
952 I was not able to find your Apache configuration file.
954 The file is usually called httpd.conf or apache.conf.
956 Please specify the location of your config file: |;
958 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
959 The file %s does not exist.
961 Please press <ENTER> to continue: |;
963 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
964 I was not able to determine the user that Apache is running as. This
965 information is necessary in order to set the access privileges correctly on
966 %s/koha.conf. This user should be set in one of the Apache configuration
967 files using the "User" directive.
969 Enter the Apache userid: |;
971 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
972 The userid %s is not a valid userid on this system.
974 Press <ENTER> to continue: |;
977 my @confpossibilities;
979 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
980 /usr/local/etc/apache/httpd.conf
981 /usr/local/etc/apache/apache.conf
982 /var/www/conf/httpd.conf
983 /etc/apache2/httpd.conf
984 /etc/apache2/apache.conf
985 /etc/apache/conf/httpd.conf
986 /etc/apache/conf/apache.conf
987 /etc/apache-ssl/conf/apache.conf
988 /etc/apache-ssl/httpd.conf
989 /etc/httpd/conf/httpd.conf
990 /etc/httpd/httpd.conf)) {
991 if ( -f $httpdconf ) {
992 push @confpossibilities, $httpdconf;
996 if ($#confpossibilities==-1) {
997 my $message=getmessage('NoApacheConfFiles');
999 until (-f $realhttpdconf) {
1000 $choice=showmessage($message, "free", 1);
1002 $realhttpdconf=$choice;
1004 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
1007 } elsif ($#confpossibilities>0) {
1011 foreach (@confpossibilities) {
1012 $conffiles.=" $counter: $_\n";
1013 $options.="$counter";
1016 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
1017 my $choice=showmessage($message, "restrictchar $options", 1);
1018 $realhttpdconf=$confpossibilities[$choice-1];
1020 $realhttpdconf=$confpossibilities[0];
1022 unless (open (HTTPDCONF, "<$realhttpdconf")) {
1023 warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
1027 while (<HTTPDCONF>) {
1028 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
1034 unless (defined($httpduser)) {
1035 my $message=getmessage('EnterApacheUser', [$etcdir]);
1036 until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
1037 $httpduser=showmessage($message, "free", '');
1038 if (length($httpduser)>0) {
1039 unless (getpwnam($httpduser)) {
1040 my $message=getmessage('InvalidUserid', [$httpduser]);
1041 showmessage($message,'PressEnter');
1050 =item getapachevhostinfo
1054 Gets various pieces of information related to virtual hosting:
1055 the webmaster email address, virtual hostname, and the ports
1056 that the OPAC and INTRANET modules run on.
1058 These pieces of information are saved to global variables; the
1059 function does not return any values.
1063 $messages->{'ApacheConfigIntroduction'}->{en} =
1064 heading('APACHE CONFIGURATION') . qq|
1065 Koha needs to write an Apache configuration file for the
1066 OPAC and LIBRARIAN virtual hosts. By default this installer
1067 will do this by using one ip address and two different ports
1068 for the virtual hosts. There are other ways to set this up,
1069 and the installer will leave comments in
1070 %s/koha-httpd.conf detailing
1071 what these other options are.
1073 NOTE: You will need to add lines to your main httpd.conf to
1074 Include %s/koha-httpd.conf
1075 and to make sure it is listening on the right ports
1076 (using the Listen directive).
1078 Press <ENTER> to continue: |;
1080 $messages->{'GetVirtualHostEmail'}->{en} =
1081 heading('WEB SERVER E-MAIL CONTACT') . qq|
1082 Enter the e-mail address to be used as a contact for the virtual hosts (this
1083 address is displayed if any errors are encountered).
1085 E-mail contact [%s]: |;
1087 $messages->{'GetServerName'}->{en} =
1088 heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
1089 Please enter the host name or IP address that you wish to use for koha.
1090 Normally, this should be a name or IP that belongs to this machine.
1092 Host name or IP Address [%s]: |;
1094 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
1095 Please enter the port for your OPAC interface. This defaults to port 80, but
1096 if you are already serving web content from this host, you should change it
1097 to a different port (8000 might be a good choice).
1099 Enter the OPAC Port [%s]: |;
1101 $messages->{'GetIntranetPort'}->{en} =
1102 heading('INTRANET VIRTUAL HOST PORT') . qq|
1103 Please enter the port for your Intranet interface. This must be different from
1106 Enter the Intranet Port [%s]: |;
1109 sub getapachevhostinfo {
1111 $svr_admin = "webmaster\@$domainname";
1112 $servername=`hostname`;
1117 showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
1119 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1120 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1123 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1124 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1129 =item updateapacheconf
1133 Updates the Apache config file according to parameters previously
1134 specified by the user.
1136 It will append fully-commented directives at the end of the original
1137 Apache config file. The old config file is renamed with an extension
1140 If you need to uninstall Koha for any reason, the lines between
1142 # Ports to listen to for Koha
1144 and the block of comments beginning with
1146 # If you want to use name based Virtual Hosting:
1152 $messages->{'StartUpdateApache'}->{en} =
1153 heading('UPDATING APACHE CONFIGURATION') . qq|
1154 Checking for modules that need to be loaded...
1157 $messages->{'ApacheConfigMissingModules'}->{en} =
1158 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1159 Koha uses the mod_env and mod_include apache features, but the
1160 installer did not find statements for them in your config. Please
1161 make sure that they are enabled for your Koha host.
1163 Press <ENTER> to continue: |;
1166 $messages->{'ApacheAlreadyConfigured'}->{en} =
1167 heading('APACHE ALREADY CONFIGURED') . qq|
1168 %s appears to already have an entry for Koha
1169 Virtual Hosts. You may need to edit %s
1170 if anything has changed since it was last set up. This
1171 script will not attempt to modify an existing Koha apache
1174 Press <ENTER> to continue: |;
1176 sub updateapacheconf {
1177 my $logfiledir=$kohalogdir;
1178 my $httpdconf = $etcdir."/koha-httpd.conf";
1180 showmessage(getmessage('StartUpdateApache'), 'none');
1181 # to be polite about it: I don't think this should touch the main httpd.conf
1183 # QUESTION: Should we warn for includes_module too?
1185 my $includesmodule=0;
1186 open HC, "<$realhttpdconf";
1188 if (/^\s*#\s*LoadModule env_module /) {
1189 showmessage(getmessage('ApacheConfigMissingModules'));
1192 if (/\s*LoadModule includes_module / ) {
1198 if (`grep -q 'VirtualHost $servername' "$httpdconf"`) {
1199 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1202 my $includesdirectives='';
1203 if ($includesmodule) {
1204 $includesdirectives.="Options +Includes\n";
1205 $includesdirectives.=" AddHandler server-parsed .html\n";
1207 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1208 my $opaclisten = '';
1209 if ($opacport != 80) {
1210 $opaclisten="Listen $opacport";
1212 my $intranetlisten = '';
1213 if ($intranetport != 80) {
1214 $intranetlisten="Listen $intranetport";
1218 # Ports to listen to for Koha
1219 # uncomment these if they aren't already in main httpd.conf
1223 # NameVirtualHost is used by one of the optional configurations detailed below
1225 #NameVirtualHost 11.22.33.44
1227 # KOHA's OPAC Configuration
1228 <VirtualHost $servername\:$opacport>
1229 ServerAdmin $svr_admin
1230 DocumentRoot $opacdir/htdocs
1231 ServerName $servername
1232 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1233 ErrorLog $logfiledir/opac-error_log
1234 TransferLog $logfiledir/opac-access_log
1235 SetEnv PERL5LIB "$intranetdir/modules"
1236 SetEnv KOHA_CONF "$etcdir/koha.conf"
1240 # KOHA's INTRANET Configuration
1241 <VirtualHost $servername\:$intranetport>
1242 ServerAdmin $svr_admin
1243 DocumentRoot $intranetdir/htdocs
1244 ServerName $servername
1245 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1246 ErrorLog $logfiledir/koha-error_log
1247 TransferLog $logfiledir/koha-access_log
1248 SetEnv PERL5LIB "$intranetdir/modules"
1249 SetEnv KOHA_CONF "$etcdir/koha.conf"
1253 # If you want to use name based Virtual Hosting:
1254 # 1. remove the two Listen lines
1255 # 2. replace $servername\:$opacport wih your.opac.domain.name
1256 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1257 # 4. replace $servername\:$intranetport wih your intranet domain name
1258 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1260 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1261 # 1. Follow steps 1-5 above
1262 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1271 =item basicauthentication
1273 basicauthentication;
1275 Asks the user whether HTTP basic authentication is wanted, and,
1276 if so, the user name and password for the basic authentication.
1278 These pieces of information are saved to global variables; the
1279 function does not return any values.
1283 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1284 heading('INTRANET AUTHENTICATION') . qq|
1285 I can set it up so that the Intranet/Librarian site is password protected using
1286 Apache's Basic Authorization.
1288 This is going to be phased out very soon. However, setting this up can provide
1289 an extra layer of security before the new authentication system is completely
1292 Would you like to do this ([Y]/N): |; #'
1294 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
1295 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1296 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1298 sub basicauthentication {
1299 my $message=getmessage('IntranetAuthenticationQuestion');
1300 my $answer=showmessage($message, 'yn', 'y');
1301 my $httpdconf = $etcdir."/koha-httpd.conf";
1303 my $apacheauthusername='librarian';
1304 my $apacheauthpassword='';
1305 if ($answer=~/^y/i) {
1306 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1307 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1308 while (! $apacheauthpassword) {
1309 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1310 if (!$apacheauthpassword) {
1311 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1314 open AUTH, ">$etcdir/kohaintranet.pass";
1315 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1316 my $salt=substr($chars, int(rand(length($chars))),1);
1317 $salt.=substr($chars, int(rand(length($chars))),1);
1318 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1320 open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1323 <Directory $intranetdir>
1324 AuthUserFile $etcdir/kohaintranet.pass
1326 AuthName "Koha Intranet (for librarians only)"
1339 Install the Koha files to the specified OPAC and INTRANET
1340 directories (usually in /usr/local/koha).
1342 The koha.conf file is created, but as koha.conf.tmp. The
1343 caller is responsible for calling finalizeconfigfile when
1344 installation is completed, to rename it back to koha.conf.
1348 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1349 Copying files to installation directories:
1354 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1360 #MJR: preserve old files, just in case
1367 print getmessage('CopyingFiles', ["old ".$desc,$tgt.".old"]);
1369 system("mv ".$tgt." ".$tgt.".old");
1372 print getmessage('CopyingFiles', [$desc,$tgt]);
1374 system("cp -R ".$src." ".$tgt);
1377 showmessage(getmessage('InstallFiles'),'none');
1379 neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs");
1380 neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin");
1381 neatcopy("main scripts", 'scripts', "$intranetdir/scripts");
1382 neatcopy("perl modules", 'modules', "$intranetdir/modules");
1383 neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs");
1384 neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin");
1386 system("touch $opacdir/cgi-bin/opac");
1388 #MJR: is this necessary?
1390 system("chown -R $httpduser:$httpduser $opacdir $intranetdir");
1392 system("chmod -R a+rx $opacdir $intranetdir");
1394 # Create /etc/koha.conf
1396 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1397 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1403 includes=$opacdir/htdocs/includes
1404 intranetdir=$intranetdir
1406 kohalogdir=$kohalogdir
1407 kohaversion=$kohaversion
1408 httpduser=$httpduser
1409 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1410 opachtdocs=$opacdir/htdocs/opac-tmpl
1416 #MJR: can't help but this be broken, can we?
1417 chmod 0440, "$etcdir/koha.conf.tmp";
1419 #MJR: does this contain any passwords?
1420 chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
1423 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1424 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1425 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1426 } #MJR: FIXME: Should report that we haven't chown()d.
1434 Finds out where the MySQL utitlities are located in the system,
1435 then create the Koha database structure and MySQL permissions.
1439 $messages->{'MysqlRootPassword'}->{en} =
1440 heading('MYSQL ROOT USER PASSWORD') . qq|
1441 To allow us to create the koha database please enter your
1442 mysql server's root user password:
1446 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1447 Creating the MySQL database for Koha...
1451 $messages->{'CreatingDatabaseError'}->{en} =
1452 heading('ERROR CREATING DATABASE') . qq|
1453 Couldn't connect to the MySQL server for the reason given above.
1454 This is a serious problem, the database will not get installed.
\a
1456 Press <ENTER> to continue: |; #'
1458 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1459 If you are installing Koha for evaluation purposes, I have a batch of sample
1460 data that you can install now.
1462 If you are installing Koha with the intention of populating it with your own
1463 data, you probably don't want this sample data installed.
1465 Would you like to install the sample data? Y/[N]: |; #'
1467 $messages->{'SampleDataInstalled'}->{en} =
1468 heading('SAMPLE DATA INSTALLED') . qq|
1469 Sample data has been installed. For some suggestions on testing Koha, please
1470 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1471 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1472 question through the koha-devel mailing list, or you can check for a developer
1473 online at +irc.katipo.co.nz:6667 channel #koha.
1475 You can find instructions for subscribing to the Koha mailing lists at:
1480 Press <ENTER> to continue: |;
1482 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1483 Would you like to install an initial branch and printer? [Y]/N: |;
1485 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1486 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1487 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1488 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1491 $mysqluser = 'root';
1494 foreach my $mysql (qw(/usr/local/mysql
1498 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1503 print "I don't see mysql in the usual places.\n";
1505 print "Where have you installed mysql? ";
1506 chomp($mysqldir = <STDIN>);
1507 last if -f "$mysqldir/bin/mysqladmin";
1510 I can't find it there either. If you compiled mysql yourself,
1511 please give the value of --prefix when you ran configure.
1513 The file mysqladmin should be in bin/mysqladmin under the directory that you
1520 # we must not put the mysql root password on the command line
1521 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'silentfree');
1523 showmessage(getmessage('CreatingDatabase'),'none');
1525 setmysqlclipass($mysqlpass);
1526 # Set up permissions
1528 print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
1529 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')\"");
1530 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1531 # Change to admin user login
1532 setmysqlclipass($pass);
1533 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$dbname");
1535 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1537 # Create the database structure
1539 system("$mysqldir/bin/mysql -u$user $dbname < koha.mysql");
1545 =item updatedatabase
1549 Updates the Koha database structure, including the addition of
1552 The MARC tables are also populated in addition to being created.
1554 Because updatedatabase calls scripts/updater/updatedatabase to
1555 do the actual update, and that script uses C4::Context,
1556 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1557 environment variable to do this.
1559 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1563 $messages->{'UpdateMarcTables'}->{en} =
1564 heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1565 You can import marc parameters for :
1571 Please choose which parameter you want to install. Note if you choose N,
1572 nothing will be added, and it can be a BIG job to manually create those tables
1574 Choose MARC definition [1]: |;
1576 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1577 This version of koha supports a few languages.
1578 Enter your language preference : either en, fr, es, pl or zh_TW
1580 Note that the en is always choosen when the system does not finds the
1581 language you choose in a specific screen.
1583 fr : all is translated (except pictures)
1584 es : a few intranet is translated (including pictures)
1585 pl : OPAC and a few intranet is translated
1586 zh_TW : partial translation
1588 Whether you specify a language here, you can always go to the
1589 intranet interface and change it from the system preferences.
1591 Which language do you choose? |;
1593 sub updatedatabase {
1594 # At this point, $etcdir/koha.conf must exist, for C4::Context
1595 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp';
1597 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
1600 print "Problem updating database...\n";
1604 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1607 if ($response eq '1') {
1608 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1610 if ($response eq '2') {
1611 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1612 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $dbname");
1615 $result = system ("perl -I $intranetdir/modules scripts/marc/updatedb2marc.pl");
1617 print "Problem updating database to MARC...\n";
1621 delete($ENV{"KOHA_CONF"});
1623 print RESET."\n\nFinished updating of database. Press <ENTER> to continue...";
1628 =item populatedatabase
1632 Populate the non-MARC tables. If the user wants to install the
1633 sample data, install them.
1637 sub populatedatabase {
1638 # my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1639 # if ($response =~/^y/i) {
1641 # FIXME: These calls are now unsafe and should either be removed
1642 # or updated to use -u$user and no mysqlpass_quoted
1644 # system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1645 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1646 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1647 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1648 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1649 # showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1652 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1654 unless ($response =~/^n/i) {
1655 my $branch='Main Library';
1656 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1657 $branch=~s/[^A-Za-z0-9\s]//g;
1659 my $branchcode=$branch;
1660 $branchcode=~s/[^A-Za-z0-9]//g;
1661 $branchcode=uc($branchcode);
1662 $branchcode=substr($branchcode,0,4);
1663 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1664 $branchcode=~s/[^A-Za-z0-9]//g;
1665 $branchcode=uc($branchcode);
1666 $branchcode=substr($branchcode,0,4);
1667 $branchcode or $branchcode='DEF';
1670 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1671 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1672 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1674 my $printername='Library Printer';
1675 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1676 $printername=~s/[^A-Za-z0-9\s]//g;
1678 my $printerqueue='lp';
1679 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1680 $printerqueue=~s/[^A-Za-z0-9]//g;
1682 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1684 my $language=showmessage(getmessage('Language'), 'free', 'en');
1686 system("$mysqldir/bin/mysql -u$user $dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1695 Asks the user whether to restart Apache, and restart it if the user
1698 FIXME: If the installer does not know how to restart the Apache
1699 server (e.g., if the user is not actually using Apache), it still
1704 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1705 Apache needs to be restarted to load the new configuration for Koha.
1706 This requires the root password.
1708 Would you like to try to restart Apache now? [Y]/N: |;
1712 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1716 unless ($response=~/^n/i) {
1718 # Need to support other init structures here?
1719 if (-e "/etc/rc.d/init.d/httpd") {
1720 system('su root -c /etc/rc.d/init.d/httpd restart');
1721 } elsif (-e "/etc/init.d/apache") {
1722 system('su root -c /etc/init.d/apache restart');
1723 } elsif (-e "/etc/init.d/apache-ssl") {
1724 system('su root -c /etc/init.d/apache-ssl restart');
1731 =item finalizeconfigfile
1735 This function must be called when the installation is complete,
1736 to rename the koha.conf.tmp file to koha.conf.
1738 Currently, failure to rename the file results only in a warning.
1742 sub finalizeconfigfile {
1744 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
1745 || showmessage(<<EOF, 'PressEnter', undef, 1);
1746 An unexpected error, $!, occurred
1747 while the Koha config file is being saved to its final location,
1750 Couldn't rename file at $etcdir. Must have write capability.
1752 Press Enter to continue.
1758 =item loadconfigfile
1762 Open the existing koha.conf file and get its values,
1763 saving the values to some global variables.
1765 If the existing koha.conf file cannot be opened for any reason,
1766 the file is silently ignored.
1770 sub loadconfigfile {
1773 open (KC, "<$etcdir/koha.conf");
1776 (next) if (/^\s*#/);
1777 if (/(.*)\s*=\s*(.*)/) {
1780 # Clean up white space at beginning and end
1781 $variable=~s/^\s*//g;
1782 $variable=~s/\s*$//g;
1785 $configfile{$variable}=$value;
1789 $intranetdir=$configfile{'intranetdir'};
1790 $opacdir=$configfile{'opacdir'};
1791 $kohaversion=$configfile{'kohaversion'};
1792 $kohalogdir=$configfile{'kohalogdir'};
1793 $database=$configfile{'database'};
1794 $hostname=$configfile{'hostname'};
1795 $user=$configfile{'user'};
1796 $pass=$configfile{'pass'};
1799 END { } # module clean-up code here (global destructor)
1801 ### These things may move
1805 my $t = POSIX::Termios->new;
1809 $t->setlflag(($t->getlflag) | &POSIX::ECHO);
1812 $t->setlflag(($t->getlflag) & !(&POSIX::ECHO));
1817 sub setmysqlclipass {
1819 open(MYCNF,">$mycnf");
1821 print MYCNF "[client]\npassword=$pass\n";
1827 rename $mycnf,$mytmpcnf;
1836 rename $mytmpcnf,$mycnf;