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`;
123 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
124 $messages->{'WelcomeToKohaInstaller'}->{en} =
125 heading('Welcome to the Koha Installer') . qq|
126 Welcome to the Koha install script! This script will prompt you for some
127 basic information about your desired setup, then install Koha for you.
129 If you want to install the Koha configuration file somewhere other than /etc
130 (eg for non-root installation, or multiple Koha versions on one system), you
131 should set the etcdir and prefix environment variables. If this is your
132 only koha installation on this machine and you are running this as root, the
133 default should be OK.
135 To accept the default value for any question, simply hit Enter at the prompt.
137 Please be sure to read the documentation, or visit the Koha website at
138 http://www.koha.org for more information.
140 Are you ready to begin the installation? ([Y]/N): |;
141 $messages->{'ReleaseCandidateWarning'}->{en} =
142 heading('RELEASE CANDIDATE') . qq|
143 WARNING WARNING WARNING WARNING WARNING
145 You are about to install Koha version %s. This version of Koha is a
146 release candidate. It is not intended to be installed on production systems.
147 It is being released so that users can test it before we release a final
150 Are you sure you want to install Koha %s? (Y/[N]): |;
151 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
153 Watch for announcements of Koha releases on the Koha mailing list or the Koha
154 web site (http://www.koha.org/).
158 $messages->{'NETZ3950Missing'}->{en}=qq|
160 The Net::Z3950 module is missing. This module is necessary if you want to use
161 Koha's Z39.50 client to download bibliographic records from other libraries.
163 To install this module, you will need the yaz client installed from
164 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
167 perl -MCPAN -e 'install Net::Z3950'
169 IMPORTANT NOTE : If you use PERL5.8.0 (RedHat 8.0 or Mandrake 9.x), you MUST install
170 manually the Net::Z3950 and edit Makefile.PL and yazwrap/Makefile.PL to include:
171 'DEFINE' => '-D_GNU_SOURCE',
172 Also note that some installations of Perl on Red Hat will generate a lot of
173 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
174 inserting the following line in yazwrap/ywpriv.h :
177 Press the <ENTER> key to continue: |; #'
179 $messages->{'CheckingPerlModules'}->{en} = heading('PERL & MODULES') . qq|
180 Checking perl modules ...
183 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
185 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
186 You are missing some Perl modules which are required by Koha.
187 Once these modules have been installed, rerun this installer.
188 They can be installed by running (as root) the following:
193 $messages->{'AllPerlModulesInstalled'}->{en} =
194 heading('ALL PERL MODULES INSTALLED') . qq|
195 All mandatory perl modules are installed.
197 Press <ENTER> to continue: |;
198 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
199 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
200 $messages->{'KohaAlreadyInstalled'}->{en} =
201 heading('Koha already installed') . qq|
202 It looks like Koha is already installed on your system (%s/koha.conf exists
203 already). If you would like to upgrade your system to %s, please use
204 the koha.upgrade script in this directory.
209 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
210 Please supply the directory you want Koha to store its OPAC files in. This
211 directory will be auto-created for you if it doesn't exist.
213 OPAC Directory [%s]: |; #'
215 $messages->{'GetIntranetDir'}->{en} =
216 heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
217 Please supply the directory you want Koha to store its Intranet/Librarians
218 files in. This directory will be auto-created for you if it doesn't exist.
220 Intranet Directory [%s]: |; #'
222 $messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
223 Specify a log directory where any Koha daemons can create log files.
225 Koha Log Directory [%s]: |;
227 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
228 This release of Koha has a new authentication module. If you are not already
229 using basic authentication on your intranet, you will be required to log in to
230 access some of the features of the intranet. You can log in using the userid
231 and password from the %s/koha.conf configuration file at any time. Use the
232 "Members" module to add passwords for other accounts and set their permissions.
234 Press the <ENTER> key to continue: |;
236 $messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
237 Congratulations ... your Koha installation is complete!
239 You will be able to connect to your Librarian interface at:
242 use mysql login and password to connect to this interface. Then, go to admin page, and create whatever fits your needs.
244 and the OPAC interface at :
248 Be sure to read the Hints file.
250 For more information visit http://www.koha.org
252 Press <ENTER> to exit the installer: |;
254 sub releasecandidatewarning {
255 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
256 my $answer=showmessage($message, 'yn', 'n');
258 if ($answer =~ /y/i) {
259 print getmessage('continuing');
261 my $message=getmessage('WatchForReleaseAnnouncements');
270 =head2 Accessor functions (for installer.pl)
280 Sets the installation language, normally "en" (English).
281 In fact, only "en" is supported.
285 sub setlanguage ($) {
291 setdomainname('example.org');
293 Sets the domain name of the host.
295 The domain name should not contain a leading dot;
296 otherwise, the results are undefined.
300 sub setdomainname ($) {
308 Sets the sysconfdir, normally /etc.
309 This should be an absolute path; a trailing / is not required.
319 setkohaversion('1.3.3RC26');
321 Sets the Koha version as known by the installer.
325 sub setkohaversion ($) {
331 my $servername = getservername;
333 Gets the name of the Koha virtual server as specified by the user.
337 sub getservername () {
345 Gets the port that will run the Koha OPAC virtual server,
346 as specified by the user.
354 =item getintranetport
356 $port = getintranetport;
358 Gets the port that will run the Koha INTRANET virtual server,
359 as specified by the user.
363 sub getintranetport () {
369 =head2 Miscellaneous utility functions
379 Does the equivalent of dirname(1). Given a path $path, return the
380 parent directory of $path (best guess), except when $path seems to
381 be the same as /, in which case $path itself is returned unchanged.
387 if ($path =~ /[^\/]/s) {
389 $path =~ s/\/+[^\/]+\/*$//s;
400 mkdir_parents $path, $mode;
402 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
403 create the directory $path, recursively creating any intermediate
404 directories. If $mode is given, the directory will be created with
407 WARNING: If $path already exists, mkdir_parents will just return
408 successfully (just like mkdir -p), whether the mode of $path conforms
409 to $mode or not. (This is the behaviour of the mkdir -p command.)
413 sub mkdir_parents ($;$) {
414 my($path, $mode) = @_;
415 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
417 if (!$ok && $! == ENOENT) {
418 my $parent = dirname($path);
419 $ok = mkdir_parents($parent, $mode);
421 # retry and at the same time make sure that $! is set correctly
422 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
431 getmessage($msgid, $variables);
433 Gets a localized message (format string) with message id $msgid,
434 and, if an array reference of variables $variables is given,
435 substitutes variables in the format string with @$variables.
436 Returns the found message string, with variable substitutions
439 $msgid must be the message identifier corresponding to a defined
440 message string (a valid key to the $messages hash in the Installer
441 package). getmessage throws an exception if the message cannot be
447 my $messagename=shift;
449 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || RED.BOLD."Error: No message named $messagename in Install.pm\n";
450 if (defined($variables)) {
451 $message=sprintf $message, @$variables;
459 showmessage($message, 'none');
460 showmessage($message, 'none', undef, $noclear);
462 $result = showmessage($message, 'yn');
463 $result = showmessage($message, 'yn', $defaultresponse);
464 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
466 $result = showmessage($message, 'restrictchar CHARS');
467 $result = showmessage($message, 'free');
468 $result = showmessage($message, 'silentfree');
469 $result = showmessage($message, 'numerical');
470 $result = showmessage($message, 'email');
471 $result = showmessage($message, 'PressEnter');
473 Shows a message and optionally gets a response from the user.
475 The first two arguments, the message and the response type,
476 are mandatory. The message must be the actual string to
477 display; the caller is responsible for calling getmessage if
480 The response type must be one of "none", "yn", "free", "silentfree"
481 "numerical", "email", "PressEnter", or a string consisting
482 of "restrictchar " followed by a list of allowed characters
483 (space can be specified). (Case is not significant, but case is
484 significant in the list of allowed characters.) If a response
485 type other than the above-listed is specified, the result is
488 Note that the response type "yn" is equivalent to "restrictchar yn".
489 Because "restrictchar" is case-sensitive, the user is expected
490 to enter "y" or "n" in lowercase only.
492 Note that the response type of "email" does not actually
493 guarantee that the returned value is a well-formed RFC-822
494 email address, nor does it accept all well-formed RFC-822 email
495 addresses. What it does is to restrict the returned value to a
496 string that is looks reasonably likely to be an email address
497 in the "real world", given the premise that the user is trying
498 to enter a real email address.
500 If a response type other than "none" or "PressEnter" is
501 specified, a third argument, specifying the default value, can
502 be specified: If this default response is not specified, the
503 default response is the first allowed character if the response
504 type is "restrictchar", otherwise the default response is the
505 empty string. This default response is used when the user does
506 not specify a value (i.e., presses Enter without typing in
507 anything), showmessage will assume that the default response is
510 Note that because the response type "yn" is equivalent to
511 "restrictchar yn", the default value for response type "yn",
512 if unspecified, is "y".
514 The screen is normally cleared before the message is displayed;
515 if a fourth argument is specified and is nonzero, this
516 screen-clearing is not done.
522 #MJR: Maybe refactor to use anonymous functions that
523 # check the responses instead of RnP branching.
524 my $message=join('',fill('','',(shift)));
525 my $responsetype=shift;
526 my $defaultresponse=shift;
528 $noclear = 0 unless defined $noclear; # defaults to "clear"
529 ($noclear) || (print $clear_string);
530 if ($responsetype =~ /^yn$/) {
531 $responsetype='restrictchar ynYN';
533 print RESET.$message;
534 if ($responsetype =~/^restrictchar (.*)/i) {
537 until ($options=~/$response/) {
538 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
541 (length($response)) || ($response=$defaultresponse);
542 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
543 ($noclear) || (print $clear_string);
544 print RED."Response contains invalid characters. Choose from [$options].\n\n";
545 print RESET.$message;
548 unless ($options=~/$response/) {
549 ($noclear) || (print $clear_string);
550 print RED."Invalid Response. Choose from [$options].\n\n";
551 print RESET.$message;
556 } elsif ($responsetype =~/^(silent)?free$/i) {
557 (defined($defaultresponse)) || ($defaultresponse='');
558 if ($responsetype =~/^(silent)/i) { setecho(0) };
559 my $response=<STDIN>;
560 if ($responsetype =~/^(silent)/i) { setecho(1) };
562 ($response) || ($response=$defaultresponse);
564 } elsif ($responsetype =~/^numerical$/i) {
565 (defined($defaultresponse)) || ($defaultresponse='');
567 until ($response=~/^\d+$/) {
570 ($response) || ($response=$defaultresponse);
571 unless ($response=~/^\d+$/) {
572 ($noclear) || (print $clear_string);
573 print RED."Invalid Response ($response). Response must be a number.\n\n";
574 print RESET.$message;
578 } elsif ($responsetype =~/^email$/i) {
579 (defined($defaultresponse)) || ($defaultresponse='');
581 until ($response=~/.*\@.*\..*/) {
584 ($response) || ($response=$defaultresponse);
585 if ($response!~/.*\@.*\..*/) {
586 ($noclear) || (print $clear_string);
587 print RED."Invalid Response ($response). Response must be a valid email address.\n\n";
588 print RESET.$message;
592 } elsif ($responsetype =~/^PressEnter$/i) {
595 } elsif ($responsetype =~/^none$/i) {
598 # FIXME: There are a few places where we will get an undef as the
599 # response type. Should we thrown an exception here, or should we
600 # legitimize this usage and say "none" is the default if not specified?
601 #die "Illegal response type \"$responsetype\"";
612 Changes the display to show system output until the next showmessage call.
613 At the time of writing, this means using red text.
624 =head2 Subtasks of doing an installation
630 =item checkabortedinstall
634 Checks whether a previous installation process has been abnormally
635 aborted, by checking whether $etcidr/koha.conf is a symlink matching
636 a particular pattern. If an aborted installation is detected, give
637 the user a chance to abort, before trying to recover the aborted
640 FIXME: The recovery is not complete; it only partially rolls back
645 sub checkabortedinstall () {
646 if (-l("$etcdir/koha.conf")
647 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
650 I have detected that you tried to install Koha before, but the installation
651 was aborted. I will try to continue, but there might be problems if the
652 database is already created.
655 print "Please press <ENTER> to continue: ";
658 # Remove the symlink after the <STDIN>, so the user can back out
659 unlink "$etcdir/koha.conf"
660 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
665 =item checkperlmodules
669 Test whether the version of Perl is new enough, whether Perl is
670 found at the expected location, and whether all required modules
675 sub checkperlmodules {
677 # Test for Perl and Modules
680 my $message = getmessage('CheckingPerlModules');
681 showmessage($message, 'none');
683 unless ($] >= 5.006001) { # Bug 179
684 die getmessage('PerlVersionFailure', ['5.6.1']);
689 unless (eval {require DBI}) { push @missing,"DBI" };
690 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
691 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
692 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
693 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
694 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
695 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
696 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
697 unless (eval {require Event}) {
698 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
699 push @missing, "Event";
702 unless (eval {require Net::Z3950}) {
703 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
704 if ($#missing>=0) { # see above note
705 push @missing, "Net::Z3950";
710 # Print out a list of any missing modules
715 foreach my $module (@missing) {
716 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
718 my $message=getmessage('MissingPerlModules', [$missing]);
719 showmessage($message, 'none');
722 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
727 unless (-x "/usr/bin/perl") {
728 my $realperl=`which perl`;
730 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
731 until (-x $realperl) {
732 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
734 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
735 unless ($response eq 'n') {
737 system("ln -s $realperl /usr/bin/perl");
744 $messages->{'NoUsrBinPerl'}->{en} =
745 heading('Perl is not located in /usr/bin/perl') . qq|
746 The Koha perl scripts expect to find the perl executable in the /usr/bin
747 directory. It is not there on your system.
751 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
752 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
753 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
755 May I create this symlink? ([Y]/N):
758 $messages->{'DirFailed'}->{en} = RED.qq|
759 We could not create %s, but continuing anyway...
765 =item getinstallationdirectories
767 getinstallationdirectories;
769 Get the various installation directories from the user, and then
770 create those directories (if they do not already exist).
772 These pieces of information are saved to global variables; the
773 function does not return any values.
777 sub getinstallationdirectories {
778 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
779 $opacdir = $ENV{prefix}.'/koha/opac';
780 $intranetdir = $ENV{prefix}.'/koha/intranet';
782 while ($getdirinfo) {
783 # Loop until opac directory and koha directory are different
784 my $message=getmessage('GetOpacDir', [$opacdir]);
785 $opacdir=showmessage($message, 'free', $opacdir);
787 $message=getmessage('GetIntranetDir', [$intranetdir]);
788 $intranetdir=showmessage($message, 'free', $intranetdir);
790 if ($intranetdir eq $opacdir) {
793 You must specify different directories for the OPAC and INTRANET files!
794 :: $intranetdir :: $opacdir ::
801 $kohalogdir=$ENV{prefix}.'/koha/log';
802 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
803 $kohalogdir=showmessage($message, 'free', $kohalogdir);
806 # FIXME: Need better error handling for all mkdir calls here
807 unless ( -d $intranetdir ) {
808 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed',['parents of '.$intranetdir]);
809 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',[$intranetdir]);
810 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir"); }
811 chmod 0770, "$intranetdir";
813 mkdir_parents ("$intranetdir/htdocs", 0750);
814 mkdir_parents ("$intranetdir/cgi-bin", 0750);
815 mkdir_parents ("$intranetdir/modules", 0750);
816 mkdir_parents ("$intranetdir/scripts", 0750);
817 unless ( -d $opacdir ) {
818 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed',['parents of '.$opacdir]);
819 mkdir ($opacdir, 0770) || print getmessage('DirFailed',[$opacdir]);
820 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$opacdir"); }
821 chmod (oct(770), "$opacdir");
823 mkdir_parents ("$opacdir/htdocs", 0750);
824 mkdir_parents ("$opacdir/cgi-bin", 0750);
827 unless ( -d $kohalogdir ) {
828 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed',['parents of '.$kohalogdir]);
829 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',[$kohalogdir]);
830 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir"); }
831 chmod (oct(770), "$kohalogdir");
837 =item getdatabaseinfo
841 Get various pieces of information related to the Koha database:
842 the name of the database, the host on which the SQL server is
843 running, and the database user name.
845 These pieces of information are saved to global variables; the
846 function does not return any values.
850 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
851 Please provide the name that you wish to give your koha database.
852 It must not exist already on the database server.
854 Database name [%s]: |;
856 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
857 Please provide the hostname for mysql. Unless the database is located on
858 another machine this will be "localhost".
860 Database host [%s]: |;
862 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
863 Please provide the name of the user who will have full administrative rights
864 to the %s database, when authenticating from %s.
866 This user will also be used to access Koha's INTRANET interface.
868 Database user [%s]: |;
870 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
871 Please provide a good password for the user %s.
873 This password will also be used to access Koha's INTRANET interface.
875 Password for database user %s: |;
877 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
878 You must not use a blank password for your MySQL user.
880 Press <ENTER> to try again:
883 sub getdatabaseinfo {
886 $hostname = 'localhost';
890 #Get the database name
892 my $message=getmessage('DatabaseName', [$dbname]);
893 $dbname=showmessage($message, 'free', $dbname);
895 #Get the hostname for the database
897 $message=getmessage('DatabaseHost', [$hostname]);
898 $hostname=showmessage($message, 'free', $hostname);
900 #Get the username for the database
902 $message=getmessage('DatabaseUser', [$dbname, $hostname, $user]);
903 $user=showmessage($message, 'free', $user);
905 #Get the password for the database user
907 while ($pass eq '') {
908 my $message=getmessage('DatabasePassword', [$user, $user]);
909 $pass=showmessage($message, 'free', $pass);
911 my $message=getmessage('BlankPassword');
912 showmessage($message,'PressEnter');
923 Get various pieces of information related to the Apache server:
924 the location of the configuration file and, if needed, the Unix
925 user that the Koha CGI will be run under.
927 These pieces of information are saved to global variables; the
928 function does not return any values.
932 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
933 heading('MULTIPLE APACHE CONFIG FILES') . qq|
934 I found more than one possible Apache configuration file:
938 Choose the correct file [1]: |;
940 $messages->{'NoApacheConfFiles'}->{en} =
941 heading('NO APACHE CONFIG FILE FOUND') . qq|
942 I was not able to find your Apache configuration file.
944 The file is usually called httpd.conf or apache.conf.
946 Please specify the location of your config file: |;
948 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
949 The file %s does not exist.
951 Please press <ENTER> to continue: |;
953 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
954 I was not able to determine the user that Apache is running as. This
955 information is necessary in order to set the access privileges correctly on
956 %s/koha.conf. This user should be set in one of the Apache configuration
957 files using the "User" directive.
959 Enter the Apache userid: |;
961 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
962 The userid %s is not a valid userid on this system.
964 Press <ENTER> to continue: |;
967 my @confpossibilities;
969 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
970 /usr/local/etc/apache/httpd.conf
971 /usr/local/etc/apache/apache.conf
972 /var/www/conf/httpd.conf
973 /etc/apache2/httpd.conf
974 /etc/apache2/apache.conf
975 /etc/apache/conf/httpd.conf
976 /etc/apache/conf/apache.conf
977 /etc/apache-ssl/conf/apache.conf
978 /etc/apache-ssl/httpd.conf
979 /etc/httpd/conf/httpd.conf
980 /etc/httpd/httpd.conf)) {
981 if ( -f $httpdconf ) {
982 push @confpossibilities, $httpdconf;
986 if ($#confpossibilities==-1) {
987 my $message=getmessage('NoApacheConfFiles');
989 until (-f $realhttpdconf) {
990 $choice=showmessage($message, "free", 1);
992 $realhttpdconf=$choice;
994 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
997 } elsif ($#confpossibilities>0) {
1001 foreach (@confpossibilities) {
1002 $conffiles.=" $counter: $_\n";
1003 $options.="$counter";
1006 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
1007 my $choice=showmessage($message, "restrictchar $options", 1);
1008 $realhttpdconf=$confpossibilities[$choice-1];
1010 $realhttpdconf=$confpossibilities[0];
1012 unless (open (HTTPDCONF, "<$realhttpdconf")) {
1013 warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
1017 while (<HTTPDCONF>) {
1018 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
1024 unless (defined($httpduser)) {
1025 my $message=getmessage('EnterApacheUser', [$etcdir]);
1026 until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
1027 $httpduser=showmessage($message, "free", '');
1028 if (length($httpduser)>0) {
1029 unless (getpwnam($httpduser)) {
1030 my $message=getmessage('InvalidUserid', [$httpduser]);
1031 showmessage($message,'PressEnter');
1040 =item getapachevhostinfo
1044 Gets various pieces of information related to virtual hosting:
1045 the webmaster email address, virtual hostname, and the ports
1046 that the OPAC and INTRANET modules run on.
1048 These pieces of information are saved to global variables; the
1049 function does not return any values.
1053 $messages->{'ApacheConfigIntroduction'}->{en} =
1054 heading('APACHE CONFIGURATION') . qq|
1055 Koha needs to write an Apache configuration file for the
1056 OPAC and LIBRARIAN virtual hosts. By default this installer
1057 will do this by using one ip address and two different ports
1058 for the virtual hosts. There are other ways to set this up,
1059 and the installer will leave comments in
1060 %s/koha-httpd.conf detailing
1061 what these other options are.
1063 NOTE: You will need to add lines to your main httpd.conf to
1064 Include %s/koha-httpd.conf
1065 and to make sure it is listening on the right ports
1066 (using the Listen directive).
1068 Press <ENTER> to continue: |;
1070 $messages->{'GetVirtualHostEmail'}->{en} =
1071 heading('WEB SERVER E-MAIL CONTACT') . qq|
1072 Enter the e-mail address to be used as a contact for the virtual hosts (this
1073 address is displayed if any errors are encountered).
1075 E-mail contact [%s]: |;
1077 $messages->{'GetServerName'}->{en} =
1078 heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
1079 Please enter the host name or IP address that you wish to use for koha.
1080 Normally, this should be a name or IP that belongs to this machine.
1082 Host name or IP Address [%s]: |;
1084 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
1085 Please enter the port for your OPAC interface. This defaults to port 80, but
1086 if you are already serving web content from this host, you should change it
1087 to a different port (8000 might be a good choice).
1089 Enter the OPAC Port [%s]: |;
1091 $messages->{'GetIntranetPort'}->{en} =
1092 heading('INTRANET VIRTUAL HOST PORT') . qq|
1093 Please enter the port for your Intranet interface. This must be different from
1096 Enter the Intranet Port [%s]: |;
1099 sub getapachevhostinfo {
1101 $svr_admin = "webmaster\@$domainname";
1102 $servername=`hostname`;
1107 showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
1109 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1110 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1113 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1114 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1119 =item updateapacheconf
1123 Updates the Apache config file according to parameters previously
1124 specified by the user.
1126 It will append fully-commented directives at the end of the original
1127 Apache config file. The old config file is renamed with an extension
1130 If you need to uninstall Koha for any reason, the lines between
1132 # Ports to listen to for Koha
1134 and the block of comments beginning with
1136 # If you want to use name based Virtual Hosting:
1142 $messages->{'StartUpdateApache'}->{en} =
1143 heading('UPDATING APACHE CONFIGURATION') . qq|
1144 Checking for modules that need to be loaded...
1147 $messages->{'ApacheConfigMissingModules'}->{en} =
1148 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1149 Koha uses the mod_env and mod_include apache features, but the
1150 installer did not find statements for them in your config. Please
1151 make sure that they are enabled for your Koha host.
1153 Press <ENTER> to continue: |;
1156 $messages->{'ApacheAlreadyConfigured'}->{en} =
1157 heading('APACHE ALREADY CONFIGURED') . qq|
1158 %s appears to already have an entry for Koha
1159 Virtual Hosts. You may need to edit %s
1160 if anything has changed since it was last set up. This
1161 script will not attempt to modify an existing Koha apache
1164 Press <ENTER> to continue: |;
1166 sub updateapacheconf {
1167 my $logfiledir=$kohalogdir;
1168 my $httpdconf = $etcdir."/koha-httpd.conf";
1170 showmessage(getmessage('StartUpdateApache'), 'none');
1171 # to be polite about it: I don't think this should touch the main httpd.conf
1173 # QUESTION: Should we warn for includes_module too?
1175 my $includesmodule=0;
1176 open HC, "<$realhttpdconf";
1178 if (/^\s*#\s*LoadModule env_module /) {
1179 showmessage(getmessage('ApacheConfigMissingModules'));
1182 if (/\s*LoadModule includes_module / ) {
1188 if (`grep 'VirtualHost $servername' "$httpdconf"`) {
1189 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1192 my $includesdirectives='';
1193 if ($includesmodule) {
1194 $includesdirectives.="Options +Includes\n";
1195 $includesdirectives.=" AddHandler server-parsed .html\n";
1197 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1198 my $opaclisten = '';
1199 if ($opacport != 80) {
1200 $opaclisten="Listen $opacport";
1202 my $intranetlisten = '';
1203 if ($intranetport != 80) {
1204 $intranetlisten="Listen $intranetport";
1208 # Ports to listen to for Koha
1209 # uncomment these if they aren't already in main httpd.conf
1213 # NameVirtualHost is used by one of the optional configurations detailed below
1215 #NameVirtualHost 11.22.33.44
1217 # KOHA's OPAC Configuration
1218 <VirtualHost $servername\:$opacport>
1219 ServerAdmin $svr_admin
1220 DocumentRoot $opacdir/htdocs
1221 ServerName $servername
1222 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1223 ErrorLog $logfiledir/opac-error_log
1224 TransferLog $logfiledir/opac-access_log
1225 SetEnv PERL5LIB "$intranetdir/modules"
1226 SetEnv KOHA_CONF "$etcdir/koha.conf"
1230 # KOHA's INTRANET Configuration
1231 <VirtualHost $servername\:$intranetport>
1232 ServerAdmin $svr_admin
1233 DocumentRoot $intranetdir/htdocs
1234 ServerName $servername
1235 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1236 ErrorLog $logfiledir/koha-error_log
1237 TransferLog $logfiledir/koha-access_log
1238 SetEnv PERL5LIB "$intranetdir/modules"
1239 SetEnv KOHA_CONF "$etcdir/koha.conf"
1243 # If you want to use name based Virtual Hosting:
1244 # 1. remove the two Listen lines
1245 # 2. replace $servername\:$opacport wih your.opac.domain.name
1246 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1247 # 4. replace $servername\:$intranetport wih your intranet domain name
1248 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1250 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1251 # 1. Follow steps 1-5 above
1252 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1261 =item basicauthentication
1263 basicauthentication;
1265 Asks the user whether HTTP basic authentication is wanted, and,
1266 if so, the user name and password for the basic authentication.
1268 These pieces of information are saved to global variables; the
1269 function does not return any values.
1273 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1274 heading('INTRANET AUTHENTICATION') . qq|
1275 I can set it up so that the Intranet/Librarian site is password protected using
1276 Apache's Basic Authorization.
1278 This is going to be phased out very soon. However, setting this up can provide
1279 an extra layer of security before the new authentication system is completely
1282 Would you like to do this ([Y]/N): |; #'
1284 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
1285 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1286 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1288 sub basicauthentication {
1289 my $message=getmessage('IntranetAuthenticationQuestion');
1290 my $answer=showmessage($message, 'yn', 'y');
1291 my $httpdconf = $etcdir."/koha-httpd.conf";
1293 my $apacheauthusername='librarian';
1294 my $apacheauthpassword='';
1295 if ($answer=~/^y/i) {
1296 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1297 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1298 while (! $apacheauthpassword) {
1299 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1300 if (!$apacheauthpassword) {
1301 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1304 open AUTH, ">$etcdir/kohaintranet.pass";
1305 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1306 my $salt=substr($chars, int(rand(length($chars))),1);
1307 $salt.=substr($chars, int(rand(length($chars))),1);
1308 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1310 open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1313 <Directory $intranetdir>
1314 AuthUserFile $etcdir/kohaintranet.pass
1316 AuthName "Koha Intranet (for librarians only)"
1329 Install the Koha files to the specified OPAC and INTRANET
1330 directories (usually in /usr/local/koha).
1332 The koha.conf file is created, but as koha.conf.tmp. The
1333 caller is responsible for calling finalizeconfigfile when
1334 installation is completed, to rename it back to koha.conf.
1338 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1339 Copying files to installation directories:
1344 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1350 #MJR: preserve old files, just in case
1357 print getmessage('CopyingFiles', ["old ".$desc,$tgt.".old"]);
1359 system("mv ".$tgt." ".$tgt.".old");
1362 print getmessage('CopyingFiles', [$desc,$tgt]);
1364 system("cp -R ".$src." ".$tgt);
1367 showmessage(getmessage('InstallFiles'),'none');
1369 neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs");
1370 neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin");
1371 neatcopy("main scripts", 'scripts', "$intranetdir/scripts");
1372 neatcopy("perl modules", 'modules', "$intranetdir/modules");
1373 neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs");
1374 neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin");
1376 system("touch $opacdir/cgi-bin/opac");
1378 #MJR: is this necessary?
1380 system("chown -R $httpduser:$httpduser $opacdir $intranetdir");
1382 system("chmod -R a+rx $opacdir $intranetdir");
1384 # Create /etc/koha.conf
1386 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1387 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1393 includes=$opacdir/htdocs/includes
1394 intranetdir=$intranetdir
1396 kohalogdir=$kohalogdir
1397 kohaversion=$kohaversion
1398 httpduser=$httpduser
1399 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1400 opachtdocs=$opacdir/htdocs/opac-tmpl
1406 #MJR: can't help but this be broken, can we?
1407 chmod 0440, "$etcdir/koha.conf.tmp";
1409 #MJR: does this contain any passwords?
1410 chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
1413 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1414 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1415 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1416 } #MJR: FIXME: Should report that we haven't chown()d.
1424 Finds out where the MySQL utitlities are located in the system,
1425 then create the Koha database structure and MySQL permissions.
1429 $messages->{'MysqlRootPassword'}->{en} =
1430 heading('MYSQL ROOT USER PASSWORD') . qq|
1431 To allow us to create the koha database please enter your
1432 mysql server's root user password:
1436 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1437 Creating the MySQL database for Koha...
1441 $messages->{'CreatingDatabaseError'}->{en} =
1442 heading('ERROR CREATING DATABASE') . qq|
1443 Couldn't connect to the MySQL server for the reason given above.
1444 This is a serious problem, the database will not get installed.
\a
1446 Press <ENTER> to continue: |; #'
1448 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1449 If you are installing Koha for evaluation purposes, I have a batch of sample
1450 data that you can install now.
1452 If you are installing Koha with the intention of populating it with your own
1453 data, you probably don't want this sample data installed.
1455 Would you like to install the sample data? Y/[N]: |; #'
1457 $messages->{'SampleDataInstalled'}->{en} =
1458 heading('SAMPLE DATA INSTALLED') . qq|
1459 Sample data has been installed. For some suggestions on testing Koha, please
1460 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1461 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1462 question through the koha-devel mailing list, or you can check for a developer
1463 online at +irc.katipo.co.nz:6667 channel #koha.
1465 You can find instructions for subscribing to the Koha mailing lists at:
1470 Press <ENTER> to continue: |;
1472 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1473 Would you like to install an initial branch and printer? [Y]/N: |;
1475 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1476 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1477 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1478 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1481 $mysqluser = 'root';
1484 foreach my $mysql (qw(/usr/local/mysql
1488 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1493 print "I don't see mysql in the usual places.\n";
1495 print "Where have you installed mysql? ";
1496 chomp($mysqldir = <STDIN>);
1497 last if -f "$mysqldir/bin/mysqladmin";
1500 I can't find it there either. If you compiled mysql yourself,
1501 please give the value of --prefix when you ran configure.
1503 The file mysqladmin should be in bin/mysqladmin under the directory that you
1510 # we must not put the mysql root password on the command line
1511 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'silentfree');
1513 showmessage(getmessage('CreatingDatabase'),'none');
1515 setmysqlclipass($mysqlpass);
1516 # Set up permissions
1518 print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
1519 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')\"");
1520 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1521 # Change to admin user login
1522 setmysqlclipass($pass);
1523 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$dbname");
1525 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1527 # Create the database structure
1529 system("$mysqldir/bin/mysql -u$user $dbname < koha.mysql");
1535 =item updatedatabase
1539 Updates the Koha database structure, including the addition of
1542 The MARC tables are also populated in addition to being created.
1544 Because updatedatabase calls scripts/updater/updatedatabase to
1545 do the actual update, and that script uses C4::Context,
1546 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1547 environment variable to do this.
1549 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1553 $messages->{'UpdateMarcTables'}->{en} =
1554 heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1555 You can import marc parameters for :
1561 Please choose which parameter you want to install. Note if you choose N,
1562 nothing will be added, and it can be a BIG job to manually create those tables
1564 Choose MARC definition [1]: |;
1566 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1567 This version of koha supports a few languages.
1568 Enter your language preference : either en, fr, es, pl or zh_TW
1570 Note that the en is always choosen when the system does not finds the
1571 language you choose in a specific screen.
1573 fr : all is translated (except pictures)
1574 es : a few intranet is translated (including pictures)
1575 pl : OPAC and a few intranet is translated
1576 zh_TW : partial translation
1578 Whether you specify a language here, you can always go to the
1579 intranet interface and change it from the system preferences.
1581 Which language do you choose? |;
1583 sub updatedatabase {
1584 # At this point, $etcdir/koha.conf must exist, for C4::Context
1585 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp';
1587 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
1590 print "Problem updating database...\n";
1594 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1597 if ($response eq '1') {
1598 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1600 if ($response eq '2') {
1601 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
1602 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $dbname");
1605 $result = system ("perl -I $intranetdir/modules scripts/marc/updatedb2marc.pl");
1607 print "Problem updating database to MARC...\n";
1611 delete($ENV{"KOHA_CONF"});
1613 print RESET."\n\nFinished updating of database. Press <ENTER> to continue...";
1618 =item populatedatabase
1622 Populate the non-MARC tables. If the user wants to install the
1623 sample data, install them.
1627 sub populatedatabase {
1628 # my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1629 # if ($response =~/^y/i) {
1631 # FIXME: These calls are now unsafe and should either be removed
1632 # or updated to use -u$user and no mysqlpass_quoted
1634 # system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
1635 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1636 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1637 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1638 # system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1639 # showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1642 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1644 unless ($response =~/^n/i) {
1645 my $branch='Main Library';
1646 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1647 $branch=~s/[^A-Za-z0-9\s]//g;
1649 my $branchcode=$branch;
1650 $branchcode=~s/[^A-Za-z0-9]//g;
1651 $branchcode=uc($branchcode);
1652 $branchcode=substr($branchcode,0,4);
1653 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1654 $branchcode=~s/[^A-Za-z0-9]//g;
1655 $branchcode=uc($branchcode);
1656 $branchcode=substr($branchcode,0,4);
1657 $branchcode or $branchcode='DEF';
1660 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1661 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1662 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1664 my $printername='Library Printer';
1665 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1666 $printername=~s/[^A-Za-z0-9\s]//g;
1668 my $printerqueue='lp';
1669 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1670 $printerqueue=~s/[^A-Za-z0-9]//g;
1672 system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1674 my $language=showmessage(getmessage('Language'), 'free', 'en');
1676 system("$mysqldir/bin/mysql -u$user $dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1685 Asks the user whether to restart Apache, and restart it if the user
1688 FIXME: If the installer does not know how to restart the Apache
1689 server (e.g., if the user is not actually using Apache), it still
1694 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1695 Apache needs to be restarted to load the new configuration for Koha.
1696 This requires the root password.
1698 Would you like to try to restart Apache now? [Y]/N: |;
1702 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1706 unless ($response=~/^n/i) {
1708 # Need to support other init structures here?
1709 if (-e "/etc/rc.d/init.d/httpd") {
1710 system('su root -c /etc/rc.d/init.d/httpd restart');
1711 } elsif (-e "/etc/init.d/apache") {
1712 system('su root -c /etc/init.d/apache restart');
1713 } elsif (-e "/etc/init.d/apache-ssl") {
1714 system('su root -c /etc/init.d/apache-ssl restart');
1721 =item finalizeconfigfile
1725 This function must be called when the installation is complete,
1726 to rename the koha.conf.tmp file to koha.conf.
1728 Currently, failure to rename the file results only in a warning.
1732 sub finalizeconfigfile {
1734 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
1735 || showmessage(<<EOF, 'PressEnter', undef, 1);
1736 An unexpected error, $!, occurred
1737 while the Koha config file is being saved to its final location,
1740 Couldn't rename file at $etcdir. Must have write capability.
1742 Press Enter to continue.
1748 =item loadconfigfile
1752 Open the existing koha.conf file and get its values,
1753 saving the values to some global variables.
1755 If the existing koha.conf file cannot be opened for any reason,
1756 the file is silently ignored.
1760 sub loadconfigfile {
1763 open (KC, "<$etcdir/koha.conf");
1766 (next) if (/^\s*#/);
1767 if (/(.*)\s*=\s*(.*)/) {
1770 # Clean up white space at beginning and end
1771 $variable=~s/^\s*//g;
1772 $variable=~s/\s*$//g;
1775 $configfile{$variable}=$value;
1779 $intranetdir=$configfile{'intranetdir'};
1780 $opacdir=$configfile{'opacdir'};
1781 $kohaversion=$configfile{'kohaversion'};
1782 $kohalogdir=$configfile{'kohalogdir'};
1783 $database=$configfile{'database'};
1784 $hostname=$configfile{'hostname'};
1785 $user=$configfile{'user'};
1786 $pass=$configfile{'pass'};
1789 END { } # module clean-up code here (global destructor)
1791 ### These things may move
1795 my $t = POSIX::Termios->new;
1799 $t->setlflag(($t->getlflag) | &POSIX::ECHO);
1802 $t->setlflag(($t->getlflag) & !(&POSIX::ECHO));
1807 sub setmysqlclipass {
1809 open(MYCNF,">$mycnf");
1811 print MYCNF "[client]\npassword=$pass\n";
1817 rename $mycnf,$mytmpcnf;
1826 rename $mytmpcnf,$mycnf;