1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
5 # Contains parts Copyright 2003-4 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);
32 use File::Temp qw/ :mktemp /;
35 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
39 Install.pm - Perl module containing the bulk of the installation logic
43 The Install.pm module contains the bulk
44 of the code to do installation;
45 this code is used by installer.pl
46 to perform an actual installation.
48 =head2 Internal functions (not meant to be used outside of Install.pm)
54 # set the version for version checking
59 &read_autoinstall_file
65 &releasecandidatewarning
66 &getinstallationdirectories
84 use vars qw( $kohaversion $newversion ); # set in loadconfigfile and installer.pl
85 use vars qw( $language ); # set in installer.pl
86 use vars qw( $domainname ); # set in installer.pl
88 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
89 use vars qw( $intranetdir $opacdir $kohalogdir );
90 use vars qw( $realhttpdconf $httpduser $httpdgroup );
91 use vars qw( $servername $svr_admin $opacport $intranetport );
92 use vars qw( $mysqldir );
93 use vars qw( $database $mysqluser );
94 use vars qw( $mysqlpass ); # normally should not be used
95 use vars qw( $hostname $user $pass ); # virtual hosting
99 $messages->{'WelcomeToKohaInstaller'
100 = heading('Welcome to the Koha Installer') . qq|...|;
102 The heading function takes one string, the text to be displayed as
103 the heading, and returns a formatted heading (currently formatted
106 This reduces the likelihood of pod2man(1) etc. misinterpreting
107 a line of equal signs as illegal POD directives.
111 #my $termios = POSIX::Termios->new();
112 #$termios->getattr();
113 #my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
114 my $clear_string = "\n\n"; #MJR: was $terminal->Tputs('cl');
119 return($clear_string.ON_BLUE.WHITE.BOLD." "x$bal.uc($title)." "x$bal.RESET."\n\n");
122 my $mycnf = $ENV{HOME}."/.my.cnf";
123 my $mytmpcnf = mktemp("my.cnf.koha.XXXXXX");
127 $messages->{'continuing'}->{en}="Great! Continuing...\n\n";
128 $messages->{'WelcomeToKohaInstaller'}->{en} =
129 heading('Welcome to the Koha Installer') . qq|
130 This program will ask some questions and try to install koha for you.
131 You need to know: where most koha files should be stored (you can set
132 the prefix environment variable for this); the username and password of
133 a mysql superuser; and details of your library setup. You may also need
134 to know details of your Apache setup.
136 If you want to install the Koha configuration files somewhere other than
137 /etc (for installing not as root, or to have many Kohas on one system, for example), you should
138 set the etcdir environment variable. Please look at your manuals for
139 details of how to set that.
141 Recommended answers are given in brackets after each question. To accept
142 the default value for any question (indicated by []), simply hit Enter
145 Note that you also can define an auto_install_file, that will answer every question automatically.
146 To use this feature, run ./installer.pl -i /path/to/auto_install_file
148 Are you ready to begin the installation? ([Y]/N): |;
150 $messages->{'WelcomeToUpgrader'}->{en} =
151 heading('Welcome to the Koha Upgrader') . qq|
152 You are attempting to upgrade from Koha %s to Koha %s.
154 We recommend that you do a complete backup of all your files before upgrading.
155 This upgrade script will make a backup copy of your files for you.
157 Would you like to proceed? (Y/[N]):|;
159 $messages->{'AbortingInstall'}->{en} =
160 heading('ABORTING') . qq|
161 Aborting as requested. Please rerun when you are ready.
164 $messages->{'ReleaseCandidateWarning'}->{en} =
165 heading('RELEASE CANDIDATE') . qq|
166 WARNING: You are about to install Koha version %s. This is a
167 release candidate, It is NOT bugfree.
168 However, it works, and has been declared stable enough to
171 Most people should answer Yes here.
173 Are you sure you want to install Koha %s? (Y/[N]): |;
174 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
176 Watch for announcements of Koha releases on the Koha mailing list or the Koha
177 web site (http://www.koha.org/).
181 $messages->{'NETZ3950Missing'}->{en}=qq|
183 The Net::Z3950 module is missing. This module is necessary if you want to use
184 Koha's Z39.50 client to download bibliographic records from other libraries.
186 To install this module, you will need the yaz client installed from
187 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
190 perl -MCPAN -e 'install Net::Z3950'
192 ...or by installing packages for your distribution, if available.
194 IMPORTANT NOTE : If you use Perl 5.8.0, you might need to
195 edit NET::Z3950's Makefile.PL and yazwrap/Makefile.PL to include:
197 'DEFINE' => '-D_GNU_SOURCE',
199 Also note that some installations of Perl on Red Hat will generate a lot of
200 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
201 inserting in yazwrap/ywpriv.h a line saying #include "XSUB.h"
203 Press the <ENTER> key to continue: |; #'
205 $messages->{'CheckingPerlModules'}->{en} = heading('PERL MODULES') . qq|
206 Checking perl modules ...
209 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
211 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
212 You are missing some Perl modules required by Koha.
213 Please run this again after installing them.
214 They may be installed by finding packages from your operating system supplier, or running (as root) the following commands:
219 $messages->{'AllPerlModulesInstalled'}->{en} =
220 heading('PERL MODULES AVAILABLE') . qq|
221 All required perl modules are installed.
223 Press <ENTER> to continue: |;
224 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
225 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
226 $messages->{'KohaAlreadyInstalled'}->{en} =
227 heading('Koha already installed') . qq|
228 It looks like Koha is already installed on your system (%s/koha.conf exists).
229 If you would like to upgrade your system to %s, please use
230 the koha.upgrade script in this directory.
235 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
236 Please supply the directory you want Koha to store its OPAC files in. This
237 directory will be auto-created for you if it doesn't exist.
239 OPAC Directory [%s]: |; #'
241 $messages->{'GetIntranetDir'}->{en} =
242 heading('LIBRARIAN DIRECTORY') . qq|
243 Please supply the directory you want Koha to store its Librarian interface
244 files in. This directory will be auto-created for you if it doesn't exist.
246 Intranet Directory [%s]: |; #'
248 $messages->{'GetKohaLogDir'}->{en} = heading('LOG DIRECTORY') . qq|
249 Specify a directory where log files will be written.
251 Koha Log Directory [%s]: |;
253 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
254 This release of Koha has a new authentication module.
255 You will be required to log in to
256 access some features.
258 IMPORTANT: You can log in using the userid and password from the %s/koha.conf configuration file at any time.
259 Use the "Members" screen to add passwords for other accounts and set their flags.
261 Press the <ENTER> key to continue: |;
263 $messages->{'Completed'}->{en} = heading('INSTALLATION COMPLETE') . qq|
264 Congratulations ... your Koha installation is complete!
266 You will be able to connect to your Librarian interface at:
270 use the koha admin mysql login and password to connect to this interface.
271 and the OPAC interface at:
275 NOTE: You need to add lines to your main httpd.conf to include
276 /etc/koha-httpd.conf and to make sure it is listening on the right ports
277 (using the Listen directive). Then, restart Apache.
279 Please read the Hints file and visit http://www.koha.org (in english) or www.koha-fr.org (in french)
280 Press <ENTER> to exit the installer: |;
282 $messages->{'UpgradeCompleted'}->{en} = heading('UPGRADE COMPLETE') . qq|
283 Congratulations ... your Koha upgrade is finished!
285 Please report any problems you encounter through http://bugs.koha.org/
287 Press <ENTER> to exit the installer: |;
291 =item completeupgrade
295 Display a message describing what may need changing in httpd.conf
296 and any other instructions
300 sub completeupgrade {
301 showmessage(getmessage('UpgradeCompleted',[$intranetdir,$intranetdir,$intranetdir,$opacdir,$opacdir,$intranetdir]),'PressEnter');
304 sub releasecandidatewarning {
305 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
306 my $answer=showmessage($message, 'yn', 'n');
308 if ($answer =~ /y/i) {
309 print getmessage('continuing');
311 my $message=getmessage('WatchForReleaseAnnouncements');
317 sub read_autoinstall_file
319 my $fname = shift; # Config file to read
320 my $retval = {}; # Return value: ref-to-hash holding the
323 open (CONF, $fname) or return undef;
327 my $var; # Variable name
328 my $value; # Variable value
331 s/#.*//; # Strip comments
332 next if /^\s*$/; # Ignore blank lines
334 # Look for a line of the form
336 if (!/^\s*(\w+)\s*=\s*(.*?)\s*$/)
341 # Found a variable assignment
342 # variable that was already set.
345 $retval->{$var} = $value;
348 if ($retval->{MysqlRootPassword} eq "XXX") {
349 print "ERROR : the root password is XXX. It is NOT valid. Edit your auto_install_file\n";
356 =head2 Accessor functions (for installer.pl)
366 Sets the installation language, normally "en" (English).
367 In fact, only "en" is supported.
371 sub setlanguage ($) {
377 setdomainname('example.org');
379 Sets the domain name of the host.
381 The domain name should not contain a leading dot;
382 otherwise, the results are undefined.
386 sub setdomainname ($) {
394 Sets the sysconfdir, normally /etc.
395 This should be an absolute path; a trailing / is not required.
396 Must be writeable, else we die.
402 if (! ((-d $etcdir) && (-w $etcdir))) { die("Cannot write to $etcdir! Please set the etcdir environment variable to a writeable directory.\nFailed"); }
409 Gets the Koha version as known by the previous config file.
413 sub getkohaversion () {
414 return($kohaversion);
419 setkohaversion('1.3.3RC26');
421 Sets the Koha version as known by the installer.
425 sub setkohaversion ($) {
431 my $servername = getservername;
433 Gets the name of the Koha virtual server as specified by the user.
437 sub getservername () {
445 Gets the port that will run the Koha OPAC virtual server,
446 as specified by the user.
454 =item getintranetport
456 $port = getintranetport;
458 Gets the port that will run the Koha INTRANET virtual server,
459 as specified by the user.
463 sub getintranetport () {
469 =head2 Miscellaneous utility functions
479 Does the equivalent of dirname(1). Given a path $path, return the
480 parent directory of $path (best guess), except when $path seems to
481 be the same as /, in which case $path itself is returned unchanged.
487 if ($path =~ /[^\/]/s) {
489 $path =~ s/\/+[^\/]+\/*$//s;
500 mkdir_parents $path, $mode;
502 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
503 create the directory $path, recursively creating any intermediate
504 directories. If $mode is given, the directory will be created with
507 WARNING: If $path already exists, mkdir_parents will just return
508 successfully (just like mkdir -p), whether the mode of $path conforms
509 to $mode or not. (This is the behaviour of the mkdir -p command.)
514 my($path, $mode) = @_;
515 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
517 if (!$ok && $! == ENOENT) {
518 my $parent = dirname($path);
519 $ok = mkdir_parents($parent, $mode);
521 # retry and at the same time make sure that $! is set correctly
522 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
531 getmessage($msgid, $variables);
533 Gets a localized message (format string) with message id $msgid,
534 and, if an array reference of variables $variables is given,
535 substitutes variables in the format string with @$variables.
536 Returns the found message string, with variable substitutions
539 $msgid must be the message identifier corresponding to a defined
540 message string (a valid key to the $messages hash in the Installer
541 package). getmessage throws an exception if the message cannot be
547 my $messagename=shift;
549 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || RED.BOLD."Error: No message named $messagename in Install.pm\n";
550 if (defined($variables)) {
551 $message=sprintf $message, @$variables;
559 showmessage($message, 'none');
560 showmessage($message, 'none', undef, $noclear);
562 $result = showmessage($message, 'yn');
563 $result = showmessage($message, 'yn', $defaultresponse);
564 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
566 $result = showmessage($message, 'restrictchar CHARS');
567 $result = showmessage($message, 'free');
568 $result = showmessage($message, 'silentfree');
569 $result = showmessage($message, 'numerical');
570 $result = showmessage($message, 'email');
571 $result = showmessage($message, 'PressEnter');
573 Shows a message and optionally gets a response from the user.
575 The first two arguments, the message and the response type,
576 are mandatory. The message must be the actual string to
577 display; the caller is responsible for calling getmessage if
580 The response type must be one of "none", "yn", "free", "silentfree"
581 "numerical", "email", "PressEnter", or a string consisting
582 of "restrictchar " followed by a list of allowed characters
583 (space can be specified). (Case is not significant, but case is
584 significant in the list of allowed characters.) If a response
585 type other than the above-listed is specified, the result is
588 Note that the response type "yn" is equivalent to "restrictchar yn".
589 Because "restrictchar" is case-sensitive, the user is expected
590 to enter "y" or "n" in lowercase only.
592 Note that the response type of "email" does not actually
593 guarantee that the returned value is a well-formed RFC-822
594 email address, nor does it accept all well-formed RFC-822 email
595 addresses. What it does is to restrict the returned value to a
596 string that is looks reasonably likely to be an email address
597 in the "real world", given the premise that the user is trying
598 to enter a real email address.
600 If a response type other than "none" or "PressEnter" is
601 specified, a third argument, specifying the default value, can
602 be specified: If this default response is not specified, the
603 default response is the first allowed character if the response
604 type is "restrictchar", otherwise the default response is the
605 empty string. This default response is used when the user does
606 not specify a value (i.e., presses Enter without typing in
607 anything), showmessage will assume that the default response is
610 Note that because the response type "yn" is equivalent to
611 "restrictchar yn", the default value for response type "yn",
612 if unspecified, is "y".
614 The screen is normally cleared before the message is displayed;
615 if a fourth argument is specified and is nonzero, this
616 screen-clearing is not done.
622 #MJR: Maybe refactor to use anonymous functions that
623 # check the responses instead of RnP branching.
624 my $message=join('',fill('','',(shift)));
625 my $responsetype=shift;
626 my $defaultresponse=shift;
628 $noclear = 0 unless defined $noclear; # defaults to "clear"
629 ($noclear) || (print $clear_string);
630 if ($responsetype =~ /^yn$/) {
631 $responsetype='restrictchar ynYN';
633 print RESET.$message;
634 if ($responsetype =~/^restrictchar (.*)/i) {
637 until ($options=~/$response/) {
638 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
641 (length($response)) || ($response=$defaultresponse);
642 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
643 ($noclear) || (print $clear_string);
644 print RED."Response contains invalid characters. Choose from [$options].\n\n";
645 print RESET.$message;
648 unless ($options=~/$response/) {
649 ($noclear) || (print $clear_string);
650 print RED."Invalid Response. Choose from [$options].\n\n";
651 print RESET.$message;
656 } elsif ($responsetype =~/^(silent)?free$/i) {
657 (defined($defaultresponse)) || ($defaultresponse='');
658 if ($responsetype =~/^(silent)/i) { setecho(0) };
659 my $response=<STDIN>;
660 if ($responsetype =~/^(silent)/i) { setecho(1) };
662 ($response) || ($response=$defaultresponse);
664 } elsif ($responsetype =~/^numerical$/i) {
665 (defined($defaultresponse)) || ($defaultresponse='');
667 until ($response=~/^\d+$/) {
670 ($response) || ($response=$defaultresponse);
671 unless ($response=~/^\d+$/) {
672 ($noclear) || (print $clear_string);
673 print RED."Invalid Response ($response). Response must be a number.\n\n";
674 print RESET.$message;
678 } elsif ($responsetype =~/^email$/i) {
679 (defined($defaultresponse)) || ($defaultresponse='');
681 until ($response=~/.*\@.*\..*/) {
684 ($response) || ($response=$defaultresponse);
685 if ($response!~/.*\@.*\..*/) {
686 ($noclear) || (print $clear_string);
687 print RED."Invalid Response ($response). Response must be a valid email address.\n\n";
688 print RESET.$message;
692 } elsif ($responsetype =~/^PressEnter$/i) {
695 } elsif ($responsetype =~/^none$/i) {
698 # FIXME: There are a few places where we will get an undef as the
699 # response type. Should we thrown an exception here, or should we
700 # legitimize this usage and say "none" is the default if not specified?
701 #die "Illegal response type \"$responsetype\"";
712 Changes the display to show system output until the next showmessage call.
713 At the time of writing, this means using red text.
724 =head2 Subtasks of doing an installation
730 =item checkabortedinstall
734 Checks whether a previous installation process has been abnormally
735 aborted, by checking whether $etcidr/koha.conf is a symlink matching
736 a particular pattern. If an aborted installation is detected, give
737 the user a chance to abort, before trying to recover the aborted
740 FIXME: The recovery is not complete; it only partially rolls back
745 sub checkabortedinstall () {
746 if (-l("$etcdir/koha.conf")
747 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
750 I have detected that you tried to install Koha before, but the installation
751 was aborted. I will try to continue, but there might be problems if the
752 database is already created.
755 print "Please press <ENTER> to continue: ";
758 # Remove the symlink after the <STDIN>, so the user can back out
759 unlink "$etcdir/koha.conf"
760 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
768 Make sure that we loaded the right dirs from an old koha.conf
772 #FIXME: update to use Install.pm
774 if ($opacdir && $intranetdir) {
777 I believe that your old files are located in:
780 LIBRARIAN: $intranetdir
783 Does this look right? ([Y]/N):
785 my $answer = <STDIN>;
788 if ($answer =~/n/i) {
792 print "Great! continuing upgrade... \n";
796 if (!$opacdir || !$intranetdir) {
799 while (!$intranetdir) {
800 print "Please specify the location of your LIBRARIAN files: ";
802 my $answer = <STDIN>;
806 $intranetdir=$answer;
808 if (! -e "$intranetdir/htdocs") {
809 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
814 print "Please specify the location of your OPAC files: ";
816 my $answer = <STDIN>;
822 if (! -e "$opacdir/htdocs") {
823 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
831 =item checkperlmodules
835 Test whether the version of Perl is new enough, whether Perl is
836 found at the expected location, and whether all required modules
841 sub checkperlmodules {
843 # Test for Perl and Modules
845 my ($auto_install) = @_;
846 my $message = getmessage('CheckingPerlModules');
847 showmessage($message, 'none');
849 unless ($] >= 5.006001) { # Bug 179
850 die getmessage('PerlVersionFailure', ['5.6.1']);
855 unless (eval {require DBI}) { push @missing,"DBI" };
856 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
857 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
858 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
859 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
860 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
861 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
862 unless (eval {require PDF::API2}) { push @missing,"PDF::API2" };
863 # The following modules are not mandatory, depends on how the library want to use Koha
864 unless (eval {require Net::LDAP}) {
865 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
866 push @missing, "Net::LDAP";
869 unless (eval {require Event}) {
870 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
871 push @missing, "Event";
874 unless (eval {require Net::Z3950}) {
875 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
876 if ($#missing>=0) { # see above note
877 push @missing, "Net::Z3950";
882 # Print out a list of any missing modules
887 if (POSIX::setlocale(LC_ALL) ne "C") {
888 $missing.=" export LC_ALL=C\n";
890 foreach my $module (@missing) {
891 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
893 my $message=getmessage('MissingPerlModules', [$missing]);
894 showmessage($message, 'none');
898 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1) unless $auto_install->{NoPressEnter};
903 unless (-x "/usr/bin/perl") {
904 my $realperl=`which perl`;
906 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
907 until (-x $realperl) {
908 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
910 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
911 unless ($response eq 'n') {
913 system("ln -s $realperl /usr/bin/perl");
920 $messages->{'NoUsrBinPerl'}->{en} =
921 heading('No /usr/bin/perl') . qq|
922 Koha expects to find the perl executable in the /usr/bin
923 directory. It is not there on your system.
927 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable [%s]: |;
928 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
929 Some Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
931 Most users should answer Y here.
933 May I try to create this symlink? ([Y]/N):|;
935 $messages->{'DirFailed'}->{en} = RED.qq|
936 We could not create %s, but continuing anyway...
942 =item getinstallationdirectories
944 getinstallationdirectories;
946 Get the various installation directories from the user, and then
947 create those directories (if they do not already exist).
949 These pieces of information are saved to global variables; the
950 function does not return any values.
954 sub getinstallationdirectories {
955 my ($auto_install) = @_;
956 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
957 $opacdir = $ENV{prefix}.'/koha/opac';
958 $intranetdir = $ENV{prefix}.'/koha/intranet';
960 while ($getdirinfo) {
961 # Loop until opac directory and koha directory are different
963 if ($auto_install->{GetOpacDir}) {
964 $opacdir=$auto_install->{GetOpacDir};
965 print ON_YELLOW.BLACK."auto-setting OpacDir to : $opacdir".RESET."\n";
967 $message=getmessage('GetOpacDir', [$opacdir]);
968 $opacdir=showmessage($message, 'free', $opacdir);
970 if ($auto_install->{GetIntranetDir}) {
971 $intranetdir=$auto_install->{GetIntranetDir};
972 print ON_YELLOW.BLACK."auto-setting IntranetDir to : $intranetdir".RESET."\n";
974 $message=getmessage('GetIntranetDir', [$intranetdir]);
975 $intranetdir=showmessage($message, 'free', $intranetdir);
977 if ($intranetdir eq $opacdir) {
980 You must specify different directories for the OPAC and INTRANET files!
981 :: $intranetdir :: $opacdir ::
988 $kohalogdir=$ENV{prefix}.'/koha/log';
989 if ($auto_install->{GetOpacDir}) {
990 $kohalogdir=$auto_install->{KohaLogDir};
991 print ON_YELLOW.BLACK."auto-setting log dir to : $kohalogdir".RESET."\n";
993 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
994 $kohalogdir=showmessage($message, 'free', $kohalogdir);
998 # FIXME: Need better error handling for all mkdir calls here
999 unless ( -d $intranetdir ) {
1000 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed',['parents of '.$intranetdir]);
1001 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',[$intranetdir]);
1002 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir"); }
1003 chmod 0770, "$intranetdir";
1005 mkdir_parents ("$intranetdir/htdocs", 0750);
1006 mkdir_parents ("$intranetdir/cgi-bin", 0750);
1007 mkdir_parents ("$intranetdir/modules", 0750);
1008 mkdir_parents ("$intranetdir/scripts", 0750);
1009 unless ( -d $opacdir ) {
1010 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed',['parents of '.$opacdir]);
1011 mkdir ($opacdir, 0770) || print getmessage('DirFailed',[$opacdir]);
1012 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$opacdir"); }
1013 chmod (oct(770), "$opacdir");
1015 mkdir_parents ("$opacdir/htdocs", 0750);
1016 mkdir_parents ("$opacdir/cgi-bin", 0750);
1019 unless ( -d $kohalogdir ) {
1020 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed',['parents of '.$kohalogdir]);
1021 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',[$kohalogdir]);
1022 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir"); }
1023 chmod (oct(770), "$kohalogdir");
1031 Get the MySQL database server installation directory, automatically if possible.
1035 $messages->{'WhereIsMySQL'}->{en} = heading('MYSQL LOCATION').qq|
1036 Koha can't find the MySQL command-line tools. If you installed a MySQL package, you may need to install an additional package containing mysqladmin.
1037 If you compiled mysql yourself,
1038 please give the value of --prefix when you ran configure.
1039 The file mysqladmin should be in bin/mysqladmin under the directory that you give here.
1041 MySQL installation directory: |;
1044 foreach my $mysql (qw(/usr/local/mysql
1049 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1055 $mysqldir = showmessage(getmessage('WhereIsMySQL'),'free');
1056 last if -f "$mysqldir/bin/mysqladmin";
1062 =item getdatabaseinfo
1066 Get various pieces of information related to the Koha database:
1067 the name of the database, the host on which the SQL server is
1068 running, and the database user name.
1070 These pieces of information are saved to global variables; the
1071 function does not return any values.
1075 $messages->{'DatabaseName'}->{en} = heading('Database Name') . qq|
1076 Please provide the name that you wish to give your koha database.
1077 It must not exist already on the database server.
1079 Most users give a short single-word name for their library here.
1081 Database name [%s]: |;
1083 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
1084 Please provide the mysql server name. Unless the database is stored on
1085 another machine, this should be "localhost".
1087 Database host [%s]: |;
1089 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
1090 We are going to create a new mysql user for Koha. This user will have full administrative rights
1091 to the database called %s when they connect from %s.
1092 This is also the name of the Koha librarian superuser.
1094 Most users give a single-word name here.
1096 Database user [%s]: |;
1098 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
1099 Please provide a good password for the user %s.
1101 IMPORTANT: You can log in using this user and password at any time.
1103 Password for database user %s: |;
1105 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
1106 You must not use a blank password for your MySQL user.
1108 Press <ENTER> to try again:
1111 sub getdatabaseinfo {
1112 my ($auto_install) = @_;
1114 $hostname = 'localhost';
1115 $user = 'kohaadmin';
1118 #Get the database name
1121 if ($auto_install->{database}) {
1122 $database=$auto_install->{database};
1123 print ON_YELLOW.BLACK."auto-setting database to : $database".RESET."\n";
1125 $message=getmessage('DatabaseName', [$database]);
1126 $database=showmessage($message, 'free', $database);
1128 #Get the hostname for the database
1130 if ($auto_install->{DatabaseHost}) {
1131 $hostname=$auto_install->{DatabaseHost};
1132 print ON_YELLOW.BLACK."auto-setting database host to : $hostname".RESET."\n";
1134 $message=getmessage('DatabaseHost', [$hostname]);
1135 $hostname=showmessage($message, 'free', $hostname);
1137 #Get the username for the database
1139 if ($auto_install->{DatabaseUser}) {
1140 $user=$auto_install->{DatabaseUser};
1141 print ON_YELLOW.BLACK."auto-setting DB user to : $user".RESET."\n";
1143 $message=getmessage('DatabaseUser', [$database, $hostname, $user]);
1144 $user=showmessage($message, 'free', $user);
1146 #Get the password for the database user
1148 while ($pass eq '') {
1149 my $message=getmessage('DatabasePassword', [$user, $user]);
1150 if ($auto_install->{DatabasePassword}) {
1151 $pass=$auto_install->{DatabasePassword};
1152 print ON_YELLOW.BLACK."auto-setting database password to : $pass".RESET."\n";
1154 $pass=showmessage($message, 'free', $pass);
1157 my $message=getmessage('BlankPassword');
1158 showmessage($message,'PressEnter');
1169 Get various pieces of information related to the Apache server:
1170 the location of the configuration file and, if needed, the Unix
1171 user that the Koha CGI will be run under.
1173 These pieces of information are saved to global variables; the
1174 function does not return any values.
1178 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
1179 heading('MULTIPLE APACHE CONFIG FILES FOUND') . qq|
1180 I found more than one possible Apache configuration file:
1184 Enter number of the file to read [1]: |;
1186 $messages->{'NoApacheConfFiles'}->{en} =
1187 heading('NO APACHE CONFIG FILE FOUND') . qq|
1188 I was not able to find your Apache configuration file.
1190 The file is usually called httpd.conf, apache.conf or similar.
1192 Please enter the full name, starting with /: |;
1194 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
1195 The file %s does not exist.
1197 Please press <ENTER> to continue: |;
1199 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq\
1200 The installer could not find the User setting in the Apache configuration file.
1201 This is used to set up access permissions for
1202 %s/koha.conf. This user should be set in one of the Apache configuration.
1203 Please try to find it and enter the user name below. You might find
1204 that "ps u|grep apache" will tell you. It probably is NOT "root".
1206 Enter the Apache userid: \;
1208 $messages->{'InvalidUserid'}->{en} = heading('INVALID USER') . qq|
1209 The userid %s is not a valid userid on this system.
1211 Press <ENTER> to continue: |;
1214 my ($auto_install) = @_;
1215 my @confpossibilities;
1217 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
1218 /usr/local/etc/apache/httpd.conf
1219 /usr/local/etc/apache/apache.conf
1220 /var/www/conf/httpd.conf
1221 /etc/apache2/httpd.conf
1222 /etc/apache2/apache2.conf
1223 /etc/apache/conf/httpd.conf
1224 /etc/apache/conf/apache.conf
1225 /etc/apache/httpd.conf
1226 /etc/apache-ssl/conf/apache.conf
1227 /etc/apache-ssl/httpd.conf
1228 /etc/httpd/conf/httpd.conf
1229 /etc/httpd/httpd.conf
1230 /etc/httpd/2.0/conf/httpd2.conf
1232 if ( -f $httpdconf ) {
1233 push @confpossibilities, $httpdconf;
1237 if ($#confpossibilities==-1) {
1238 my $message=getmessage('NoApacheConfFiles');
1241 until (-f $realhttpdconf) {
1242 $choice=showmessage($message, "free", 1);
1244 $realhttpdconf=$choice;
1246 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
1249 } elsif ($#confpossibilities>0) {
1253 foreach (@confpossibilities) {
1254 $conffiles.=" $counter: $_\n";
1255 $options.="$counter";
1258 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
1259 my $choice=showmessage($message, "restrictchar $options", 1);
1260 $realhttpdconf=$confpossibilities[$choice-1];
1262 $realhttpdconf=$confpossibilities[0];
1264 unless (open (HTTPDCONF, "<$realhttpdconf")) {
1265 warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
1269 while (<HTTPDCONF>) {
1270 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
1276 unless (defined($httpduser)) {
1278 if ($auto_install->{EnterApacheUser}) {
1279 $message = $auto_install->{EnterApacheUser};
1280 print ON_YELLOW.BLACK."auto-setting Apache User to : $message".RESET."\n";
1282 $message=getmessage('EnterApacheUser', [$etcdir]);
1284 until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
1285 if ($auto_install->{EnterApacheUser}) {
1286 $httpduser = $auto_install->{EnterApacheUser};
1288 $httpduser=showmessage($message, "free", '');
1290 if (length($httpduser)>0) {
1291 unless (getpwnam($httpduser)) {
1292 my $message=getmessage('InvalidUserid', [$httpduser]);
1293 showmessage($message,'PressEnter');
1302 =item getapachevhostinfo
1306 Gets various pieces of information related to virtual hosting:
1307 the webmaster email address, virtual hostname, and the ports
1308 that the OPAC and INTRANET modules run on.
1310 These pieces of information are saved to global variables; the
1311 function does not return any values.
1315 $messages->{'ApacheConfigIntroduction'}->{en} =
1316 heading('APACHE CONFIGURATION') . qq|
1317 Koha needs to write an Apache configuration file for the
1318 OPAC and Librarian sites. By default this installer
1319 will do this by using one name and two different ports
1320 for the virtual hosts. There are other ways to set this up,
1321 and the installer will leave comments in
1322 %s/koha-httpd.conf about them.
1324 NOTE: You will need to add lines to your main httpd.conf to
1325 include %s/koha-httpd.conf
1326 (using the Include directive)
1327 and to make sure it is listening on the right ports
1329 (using the Listen directive).
1331 Press <ENTER> to continue: |;
1333 $messages->{'GetVirtualHostEmail'}->{en} =
1334 heading('WEB E-MAIL CONTACT') . qq|
1335 Enter the e-mail address to be used as a contact for Koha. This
1336 address is displayed if fatal errors are encountered.
1338 E-mail contact [%s]: |;
1340 $messages->{'GetServerName'}->{en} =
1341 heading('WEB HOST NAME OR IP ADDRESS') . qq|
1342 Please enter the host name or IP address that you wish to use for koha.
1343 Normally, this should be a name or IP that belongs to this machine.
1345 Host name or IP Address [%s]: |;
1347 $messages->{'GetOpacPort'}->{en} = heading('OPAC PORT') . qq|
1348 Please enter the port for your OPAC interface. This defaults to port 80, but
1349 if you are already serving web content with this hostname, you should change it
1350 to a different port (8000 might be a good choice, but check any firewalls).
1352 Enter the OPAC Port [%s]: |;
1354 $messages->{'GetIntranetPort'}->{en} =
1355 heading('LIBRARIAN PORT') . qq|
1356 Please enter the port for your Librarian interface. This must be different from
1359 Enter the Intranet Port [%s]: |;
1362 sub getapachevhostinfo {
1363 my ($auto_install) = @_;
1364 $svr_admin = "webmaster\@$domainname";
1365 $servername=`hostname`;
1370 if ($auto_install->{GetVirtualHostEmail}) {
1371 $svr_admin=$auto_install->{GetVirtualHostEmail};
1372 print ON_YELLOW.BLACK."auto-setting VirtualHostEmail to : $svr_admin".RESET."\n";
1374 showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
1375 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1377 if ($auto_install->{servername}) {
1378 $servername=$auto_install->{servername};
1379 print ON_YELLOW.BLACK."auto-setting server name to : $servername".RESET."\n";
1381 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1383 if ($auto_install->{opacport}) {
1384 $opacport=$auto_install->{opacport};
1385 print ON_YELLOW.BLACK."auto-setting opac port to : $opacport".RESET."\n";
1387 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1389 if ($auto_install->{intranetport}) {
1390 $intranetport=$auto_install->{intranetport};
1391 print ON_YELLOW.BLACK."auto-setting intranet port to : $intranetport".RESET."\n";
1393 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1399 =item updateapacheconf
1403 Updates the Apache config file according to parameters previously
1404 specified by the user.
1406 It will append fully-commented directives at the end of the original
1407 Apache config file. The old config file is renamed with an extension
1410 If you need to uninstall Koha for any reason, the lines between
1412 # Ports to listen to for Koha
1414 and the block of comments beginning with
1416 # If you want to use name based Virtual Hosting:
1422 $messages->{'StartUpdateApache'}->{en} =
1423 heading('UPDATING APACHE CONFIGURATION') . qq|
1424 Checking for modules that need to be loaded...
1427 $messages->{'ApacheConfigMissingModules'}->{en} =
1428 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1429 Koha uses the mod_env and mod_include apache features, but the
1430 installer did not find them in your config. Please
1431 make sure that they are enabled for your Koha site.
1433 Press <ENTER> to continue: |;
1436 $messages->{'ApacheAlreadyConfigured'}->{en} =
1437 heading('APACHE ALREADY CONFIGURED') . qq|
1438 %s appears to already have an entry for Koha. You may need to edit %s
1439 if anything has changed since it was last set up. This
1440 script will not attempt to modify an existing Koha apache
1443 Press <ENTER> to continue: |;
1445 sub updateapacheconf {
1446 my ($auto_install)=@_;
1447 my $logfiledir=$kohalogdir;
1448 my $httpdconf = $etcdir."/koha-httpd.conf";
1450 showmessage(getmessage('StartUpdateApache'), 'none') unless $auto_install->{NoPressEnter};
1451 # to be polite about it: I don't think this should touch the main httpd.conf
1453 # QUESTION: Should we warn for includes_module too?
1455 my $includesmodule=0;
1456 open HC, "<$realhttpdconf";
1458 if (/^\s*#\s*LoadModule env_module /) {
1459 showmessage(getmessage('ApacheConfigMissingModules'));
1462 if (/\s*LoadModule includes_module / ) {
1468 if (`grep -q 'VirtualHost $servername' "$httpdconf" 2>/dev/null`) {
1469 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1472 my $includesdirectives='';
1473 if ($includesmodule) {
1474 $includesdirectives.="Options +Includes\n";
1475 $includesdirectives.=" AddHandler server-parsed .html\n";
1477 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1478 my $opaclisten = '';
1479 if ($opacport != 80) {
1480 $opaclisten="Listen $opacport";
1482 my $intranetlisten = '';
1483 if ($intranetport != 80) {
1484 $intranetlisten="Listen $intranetport";
1488 # Koha 2.2 Apache Virtual Host Config File
1490 # Please include this file in your apache configuration.
1491 # The best way to do that depends on your site setup.
1492 # Some like an Include adding to /etc/apache/httpd.conf
1493 # and some prefer a symlink to this file from some dir.
1494 # Please refer to your system manuals.
1496 # Ports to listen to for Koha
1497 # uncomment these if they aren't already in main httpd.conf
1501 # NameVirtualHost is used by one of the optional configurations detailed below
1502 # Please make sure this line is correct before uncommenting.
1503 # See http://httpd.apache.org/docs/vhosts/ for some guides.
1505 #NameVirtualHost 11.22.33.44
1507 # KOHA's OPAC Configuration
1508 <VirtualHost $servername\:$opacport>
1509 ServerAdmin $svr_admin
1510 DocumentRoot $opacdir/htdocs
1511 ServerName $servername
1512 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1513 Redirect permanent index.html http://$servername\:$opacport/cgi-bin/koha/opac-main.pl
1514 ErrorLog $logfiledir/opac-error_log
1515 TransferLog $logfiledir/opac-access_log
1516 SetEnv PERL5LIB "$intranetdir/modules"
1517 SetEnv KOHA_CONF "$etcdir/koha.conf"
1521 # KOHA's INTRANET Configuration
1522 <VirtualHost $servername\:$intranetport>
1523 ServerAdmin $svr_admin
1524 DocumentRoot $intranetdir/htdocs
1525 ServerName $servername
1526 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1527 Redirect permanent index.html http://$servername\:$intranetport/cgi-bin/koha/mainpage.pl
1528 ErrorLog $logfiledir/koha-error_log
1529 TransferLog $logfiledir/koha-access_log
1530 SetEnv PERL5LIB "$intranetdir/modules"
1531 SetEnv KOHA_CONF "$etcdir/koha.conf"
1535 # If you want to use name based Virtual Hosting:
1536 # 1. remove the two Listen lines
1537 # 2. replace $servername\:$opacport wih your.opac.domain.name
1538 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1539 # 4. replace $servername\:$intranetport wih your intranet domain name
1540 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1542 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1543 # 1. Follow steps 1-5 above
1544 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1553 =item basicauthentication
1555 basicauthentication;
1557 Asks the user whether HTTP basic authentication is wanted, and,
1558 if so, the user name and password for the basic authentication.
1560 These pieces of information are saved to global variables; the
1561 function does not return any values.
1565 # $messages->{'IntranetAuthenticationQuestion'}->{en} =
1566 # heading('LIBRARIAN AUTHENTICATION') . qq|
1567 # The Librarian site can be password protected using
1568 # Apache's Basic Authorization instead of Koha user details.
1570 # This method going to be phased out very soon. Most users should answer N here.
1572 # Would you like to do this (Y/[N]): |; #'
1574 # $messages->{'BasicAuthUsername'}->{en}="Please enter a username for librarian access [%s]: ";
1575 # $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1576 # $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1578 # sub basicauthentication {
1579 # my $message=getmessage('IntranetAuthenticationQuestion');
1580 # my $answer=showmessage($message, 'yn', 'n');
1581 # my $httpdconf = $etcdir."/koha-httpd.conf";
1583 # my $apacheauthusername='librarian';
1584 # my $apacheauthpassword='';
1585 # if ($answer=~/^y/i) {
1586 # ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1587 # $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1588 # while (! $apacheauthpassword) {
1589 # ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1590 # if (!$apacheauthpassword) {
1591 # ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1594 # open AUTH, ">$etcdir/kohaintranet.pass";
1595 # my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1596 # my $salt=substr($chars, int(rand(length($chars))),1);
1597 # $salt.=substr($chars, int(rand(length($chars))),1);
1598 # print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1600 # open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1603 # <Directory $intranetdir>
1604 # AuthUserFile $etcdir/kohaintranet.pass
1606 # AuthName "Koha Intranet (for librarians only)"
1607 # Require valid-user
1619 Install the Koha files to the specified OPAC and INTRANET
1620 directories (usually in /usr/local/koha).
1622 The koha.conf file is created, but as koha.conf.tmp. The
1623 caller is responsible for calling finalizeconfigfile when
1624 installation is completed, to rename it back to koha.conf.
1628 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1629 Copying files to installation directories:
1633 $messages->{'OldFiles'}->{en} = heading('OLD FILES') . qq|
1634 Any files from the previous edition of Koha have been
1635 copied to a dated backup directory alongside the new
1636 installation. You should move any custom files that you
1637 want to keep (such as your site templates) into the new
1638 directories and then move the backup off of the live
1641 Press ENTER to continue:|;
1644 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1650 my ($is_first_install,$auto_install) = @_;
1651 # $is_install is set if it's a fresh install and not an upgrade. If it's an upgrade, copy old files.
1657 my $auto_install = shift;
1658 my $is_first_install = shift;
1659 if (!$is_first_install && -e $tgt) {
1660 print getmessage('CopyingFiles', ["old ".$desc,$tgt.strftime("%Y%m%d%H%M",localtime())]) unless ($auto_install->{NoPressEnter});
1661 system("mv ".$tgt." ".$tgt.strftime("%Y%m%d%H%M",localtime()));
1662 system("mkdir ".$tgt); ##New line
1664 print getmessage('CopyingFiles', [$desc,$tgt]) unless ($auto_install->{NoPressEnter});
1665 system("cp -R ".$src."/* ".$tgt);
1668 # my ($auto_install) = @_;
1669 showmessage(getmessage('InstallFiles'),'none') unless ($auto_install->{NoPressEnter});
1671 neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs",$auto_install,$is_first_install);
1672 neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin",$auto_install,$is_first_install);
1673 neatcopy("main scripts", 'scripts', "$intranetdir/scripts",$auto_install,$is_first_install);
1674 neatcopy("perl modules", 'modules', "$intranetdir/modules",$auto_install,$is_first_install);
1675 neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs",$auto_install,$is_first_install);
1676 neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin",$auto_install,$is_first_install);
1678 system("touch $opacdir/cgi-bin/opac");
1680 #MJR: is this necessary?
1682 my $httpdgrp = getgrnam($httpduser);
1683 system("chown -R $httpduser:$httpdgrp $opacdir $intranetdir");
1685 system("chmod -R a+rx $opacdir $intranetdir");
1687 # Create /etc/koha.conf
1689 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1690 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1696 intranetdir=$intranetdir
1698 kohalogdir=$kohalogdir
1699 kohaversion=$newversion
1700 httpduser=$httpduser
1701 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1702 opachtdocs=$opacdir/htdocs/opac-tmpl
1708 #MJR: can't help but this be broken, can we?
1709 chmod 0440, "$etcdir/koha.conf.tmp";
1711 #MJR: does this contain any passwords?
1712 chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
1714 open(FILE,">$intranetdir/scripts/z3950daemon/z3950-daemon-options");
1715 print FILE "RunAsUser=$httpduser\nKohaZ3950Dir=$intranetdir/scripts/z3950daemon\nKohaModuleDir=$intranetdir/modules\nLogDir=$kohalogdir\nKohaConf=$etcdir/koha.conf";
1719 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1720 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1721 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1722 } #MJR: report that we haven't chown()d.
1724 print "Please check permissions in $intranetdir/scripts/z3950daemon\n";
1726 showmessage(getmessage('OldFiles'),'PressEnter') unless ($auto_install->{NoPressEnter} or $is_first_install);
1734 Finds out where the MySQL utitlities are located in the system,
1735 then create the Koha database structure and MySQL permissions.
1739 $messages->{'MysqlRootPassword'}->{en} =
1740 heading('MYSQL ROOT USER PASSWORD') . qq|
1741 To create the koha database, please enter your
1742 mysql server's root user password:
1746 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1747 Creating the MySQL database for Koha...
1751 $messages->{'CreatingDatabaseError'}->{en} =
1752 heading('ERROR CREATING DATABASE') . qq|
1753 Couldn't connect to the MySQL server for the reason given above.
1754 This is a serious problem, the database will not get installed.
1756 Press <ENTER> to continue: |; #'
1758 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1759 If you are installing Koha for evaluation purposes,
1760 you can install some sample data now.
1762 If you are installing Koha to use your own
1763 data, you probably don't want this sample data installed.
1765 Would you like to install the sample data? Y/[N]: |; #'
1767 $messages->{'SampleDataInstalled'}->{en} =
1768 heading('SAMPLE DATA INSTALLED') . qq|
1769 Sample data has been installed. For some suggestions on testing Koha, please
1770 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1771 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1772 question through the koha-devel mailing list, or you can check for a developer
1773 online at irc.katipo.co.nz:6667 channel #koha.
1775 You can find instructions for subscribing to the Koha mailing lists at:
1780 Press <ENTER> to continue: |;
1782 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1783 Would you like to describe an initial branch and printer? [Y]/N: |;
1785 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1786 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1787 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1788 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1791 my ($auto_install) = @_;
1792 $mysqluser = 'root';
1794 my $mysqldir = getmysqldir();
1796 if ($auto_install->{MysqlRootPassword}) {
1797 $mysqlpass=$auto_install->{MysqlRootPassword};
1799 # we must not put the mysql root password on the command line
1800 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'silentfree');
1803 showmessage(getmessage('CreatingDatabase'),'none') unless ($auto_install->{NoPressEnter});
1805 setmysqlclipass($mysqlpass);
1806 # Set up permissions
1808 print system("$mysqldir/bin/mysql -u$mysqluser -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\" mysql\;");
1809 system("$mysqldir/bin/mysql -u$mysqluser -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$database','$user','Y','Y','Y','Y','Y','Y','Y','Y')\" mysql");
1810 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1811 # Change to admin user login
1812 setmysqlclipass($pass);
1813 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$database");
1815 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1817 # Create the database structure
1819 system("$mysqldir/bin/mysql -u$user $database < koha.mysql");
1825 =item updatedatabase
1829 Updates the Koha database structure, including the addition of
1832 The MARC tables are also populated in addition to being created.
1834 Because updatedatabase calls scripts/updater/updatedatabase to
1835 do the actual update, and that script uses C4::Context,
1836 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1837 environment variable to do this.
1839 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1843 $messages->{'UpdateMarcTables'}->{en} =
1844 heading('MARC FIELD DEFINITIONS') . qq|
1845 You can import MARC settings for:
1851 NOTE: If you choose N,
1852 nothing will be added, and you must create them all yourself.
1853 Only choose N if you want to use a MARC format not listed here,
1854 such as DANMARC. We would like to hear from you if you do.
1857 If you UPGRADE your version from a previous 2.x.x, the right choice here is N (None) to preserve your local MARC setup.
1859 Choose MARC definition [1]: |;
1861 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGE') . qq|
1862 This version of koha supports a few languages.
1864 en : default language, all pages available
1865 fr : complete translation
1866 es : partial librarian site translation
1867 zh_TW : partial translation
1869 en is used when a screen is not available in your language
1871 If you specify a language here, you can still
1872 change it from the system preferences screen in the librarian sit.
1874 Which language do you choose? |;
1876 sub updatedatabase {
1877 my ($auto_install) = @_;
1878 # At this point, $etcdir/koha.conf must exist, for C4::Context
1879 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf';
1880 if (! -e $ENV{"KOHA_CONF"}) { $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp'; }
1882 setmysqlclipass($pass);
1883 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase -s");
1886 print "Problem updating database...\n";
1890 if ($auto_install->{UpdateMarcTables}) {
1891 $response=$auto_install->{UpdateMarcTables};
1892 print ON_YELLOW.BLACK."auto-setting UpdateMarcTable to : $response".RESET."\n";
1894 $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12Nn', '1');
1897 if ($response eq '1') {
1898 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1900 if ($response eq '2') {
1901 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1903 delete($ENV{"KOHA_CONF"});
1905 print RESET."\nFinished updating of database. Press <ENTER> to continue..." unless ($auto_install->{NoPressEnter});
1906 <STDIN> unless ($auto_install->{NoPressEnter});
1910 =item populatedatabase
1914 Populate the non-MARC tables. If the user wants to install the
1915 sample data, install them.
1919 $messages->{'ConfirmFileUpload'}->{en} = qq|
1920 Confirm loading of this file into Koha [Y]/N: |;
1922 sub populatedatabase {
1923 my ($auto_install) = @_;
1927 if ($auto_install->{BranchName}) {
1928 $branch=$auto_install->{BranchName};
1929 print ON_YELLOW.BLACK."auto-setting a branch : $branch".RESET."\n";
1931 $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1932 unless ($response =~/^n/i) {
1933 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1934 $branch=~s/[^A-Za-z0-9\s]//g;
1938 my $branchcode=$branch;
1939 $branchcode=~s/[^A-Za-z0-9]//g;
1940 $branchcode=uc($branchcode);
1941 $branchcode=substr($branchcode,0,4);
1942 if ($auto_install->{BranchCode}) {
1943 $branchcode=$auto_install->{BranchCode};
1944 print ON_YELLOW.BLACK."auto-setting branch code : $branchcode".RESET."\n";
1946 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1948 $branchcode=~s/[^A-Za-z0-9]//g;
1949 $branchcode=uc($branchcode);
1950 $branchcode=substr($branchcode,0,4);
1951 $branchcode or $branchcode='DEF';
1954 system("$mysqldir/bin/mysql -u$user -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\" $database");
1955 system("$mysqldir/bin/mysql -u$user -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\" $database");
1956 system("$mysqldir/bin/mysql -u$user -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\" $database");
1958 my $printername='lp';
1959 my $printerqueue='/dev/lp0';
1960 if ($auto_install->{PrinterName}) {
1961 $printername=$auto_install->{PrinterName};
1962 print ON_YELLOW.BLACK."auto-setting a printer : $printername".RESET."\n";
1964 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1965 $printername=~s/[^A-Za-z0-9\s]//g;
1967 if ($auto_install->{PrinterQueue}) {
1968 $printerqueue=$auto_install->{PrinterQueue};
1969 print ON_YELLOW.BLACK."auto-setting printer queue to : $printerqueue".RESET."\n";
1971 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1972 $printerqueue=~s/[^A-Za-z0-9]//g;
1975 system("$mysqldir/bin/mysql -u$user -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\" $database");
1978 if ($auto_install->{Language}) {
1979 $language=$auto_install->{Language};
1980 print ON_YELLOW.BLACK."auto-setting language to : $language".RESET."\n";
1982 $language=showmessage(getmessage('Language'), 'free', 'en');
1985 system("$mysqldir/bin/mysql -u$user -e \"update systempreferences set value='$language' where variable='opaclanguages'\" $database");
1987 if (-d "scripts/misc/sql-datas") {
1988 # ask for directory to look for files to append
1990 push @directories,"FINISHED";
1991 if (-d "scripts/misc/sql-datas") {
1992 opendir D, "scripts/misc/sql-datas";
1993 foreach my $dir (readdir D) {
1994 next if ($dir =~ /^\./);
1995 push @directories, $dir;
1999 while (not $loopend) {
2000 print heading("SELECT SQL DIRECTORY");
2002 Select a directory. You will see every file included in this directory and be able to choose file(s) to import into Koha
2003 This is a VERY important feature. By selecting the proper options, you can get a pre-setup Koha, almost ready to be put in production.
2006 for (my $i=0;$i<=$#directories;$i++) {
2007 print "$i => ".$directories[$i]."\n";
2009 my $sqluploaddir =<STDIN>;
2010 if ($sqluploaddir==0) {
2013 $sqluploaddir = $directories[$sqluploaddir];
2014 # CHECK for any other file to append...
2016 push @sql,"FINISHED";
2017 if (-d "scripts/misc/sql-datas/$sqluploaddir") {
2018 opendir D, "scripts/misc/sql-datas/$sqluploaddir";
2019 foreach my $sql (readdir D) {
2020 next unless ($sql =~ /.txt$/);
2025 while (not $loopend) {
2026 print heading("SELECT SQL FILE");
2028 Select a file to append to the Koha DB.
2029 enter a number. A detailled explanation of the file will be given
2030 if you confirm, the file will be added to the DB
2032 for (my $i=0;$i<=$#sql;$i++) {
2033 print "$i => ".$sql[$i]."\n";
2035 my $response =<STDIN>;
2039 # show the content of the file
2040 my $FileToUpload = $sql[$response];
2041 open FILE,"scripts/misc/sql-datas/$sqluploaddir/$FileToUpload";
2042 my $content = <FILE>;
2043 print heading("INSERT $sqluploaddir/$FileToUpload ?")."$content\n";
2045 $response=showmessage(getmessage('ConfirmFileUpload'), 'yn', 'y');
2046 # if confirmed, upload the file in the DB
2047 unless ($response =~/^n/i) {
2048 $FileToUpload =~ s/\.txt/\.sql/;
2049 system("$mysqldir/bin/mysql -u$user $database <scripts/misc/sql-datas/$sqluploaddir/$FileToUpload");
2063 Asks the user whether to restart Apache, and restart it if the user
2068 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
2069 The web server daemon needs to be restarted to load the new configuration for Koha.
2070 The installer can do this if you are using Apache and give the root password.
2072 Would you like to try to restart Apache now? [Y]/N: |;
2075 my ($auto_install)=@_;
2077 $response=showmessage(getmessage('RestartApache'), 'yn', 'y') unless ($auto_install->{NoPressEnter});
2078 $response='y' if ($auto_install->{NoPressEnter});
2080 unless ($response=~/^n/i) {
2082 # Need to support other init structures here?
2083 if (-e "/etc/rc.d/init.d/httpd") {
2084 system('su root -c "/etc/rc.d/init.d/httpd restart"');
2085 } elsif (-e "/etc/init.d/apache") {
2086 system('su root -c "/etc/init.d/apache restart"');
2087 } elsif (-e "/etc/init.d/apache-ssl") {
2088 system('su root -c "/etc/init.d/apache-ssl restart"');
2097 This function attempts to back up all koha's details.
2101 $messages->{'BackupDir'}->{en} = heading('BACKUP STORAGE').qq|
2102 The upgrader will now try to backup your old files.
2104 Please specify a directory to store the backup in [%s]: |;
2106 $messages->{'BackupSummary'}->{en} = heading('BACKUP SUMMARY').qq|
2110 %6d biblioitems entries
2115 ---------------------------------------------------------------------
2117 ---------------------------------------------------------------------
2119 Does this look right? ([Y]/N): |;
2121 #FIXME: rewrite to use Install.pm
2123 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
2124 my $backupdir=$ENV{prefix}.'/backups';
2126 my $answer = showmessage(getmessage('BackupDir',[$backupdir]),'free',$backupdir);
2127 $backupdir = $answer;
2129 if (! -e $backupdir) {
2130 my $result=mkdir ($backupdir, oct(770));
2132 my @dirs = split(m#/#, $backupdir);
2136 unless (-e "$checkdir") {
2137 mkdir($checkdir, 0775);
2143 chmod 0770, $backupdir;
2145 # Backup MySql database
2148 my $mysqldir = getmysqldir();
2150 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
2153 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
2155 setmysqlclipass($pass);
2156 open (MD, "$mysqldir/bin/mysqldump --user=$user --host=$hostname $database|");
2158 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
2161 my $bibliocounter=0;
2162 my $biblioitemcounter=0;
2163 my $membercounter=0;
2166 (/insert into items /i) && ($itemcounter++);
2167 (/insert into biblioitems /i) && ($biblioitemcounter++);
2168 (/insert into biblio /i) && ($bibliocounter++);
2169 (/insert into borrowers /i) && ($membercounter++);
2176 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
2178 $answer = showmessage(getmessage('BackupSummary',[$bibliocounter, $biblioitemcounter, $itemcounter, $membercounter, $filels]),'yn');
2180 if ($answer=~/^n/i) {
2183 Aborting. The database dump is located in:
2185 $backupdir/Koha.backup_$date
2190 print "Great! continuing upgrade... \n";
2197 =item finalizeconfigfile
2201 This function must be called when the installation is complete,
2202 to rename the koha.conf.tmp file to koha.conf.
2204 Currently, failure to rename the file results only in a warning.
2208 sub finalizeconfigfile {
2210 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
2211 || showmessage(<<EOF, 'PressEnter', undef, 1);
2212 An unexpected error, $!, occurred
2213 while the Koha config file is being saved to its final location,
2216 Couldn't rename file at $etcdir. Must have write capability.
2218 Press Enter to continue.
2224 =item loadconfigfile
2228 Open the existing koha.conf file and get its values,
2229 saving the values to some global variables.
2231 If the existing koha.conf file cannot be opened for any reason,
2232 the file is silently ignored.
2236 sub loadconfigfile {
2239 #MJR: reverted to r1.53. Please call setetcdir(). Do NOT hardcode this.
2240 #FIXME: make a dated backup
2241 open (KC, "<$etcdir/koha.conf");
2244 (next) if (/^\s*#/);
2245 if (/(.*)\s*=\s*(.*)/) {
2248 # Clean up white space at beginning and end
2249 $variable=~s/^\s*//g;
2250 $variable=~s/\s*$//g;
2253 $configfile{$variable}=$value;
2257 #MJR: Reverted this too. You do not mess with my privates. Please ask for new functions if required.
2258 $intranetdir=$configfile{'intranetdir'};
2259 $opacdir=$configfile{'opacdir'};
2260 $kohaversion=$configfile{'kohaversion'};
2261 $kohalogdir=$configfile{'kohalogdir'};
2262 $database=$configfile{'database'};
2263 $hostname=$configfile{'hostname'};
2264 $user=$configfile{'user'};
2265 $pass=$configfile{'pass'};
2268 END { } # module clean-up code here (global destructor)
2270 ### These things may move
2274 my $t = POSIX::Termios->new;
2278 $t->setlflag(($t->getlflag) | &POSIX::ECHO);
2281 $t->setlflag(($t->getlflag) & !(&POSIX::ECHO));
2286 sub setmysqlclipass {
2288 open(MYCNF,">$mycnf");
2290 print MYCNF "[client]\npassword=$pass\n";
2296 rename $mycnf,$mytmpcnf;
2301 if (defined $mycnf && -e $mycnf) {
2304 if (defined $mytmpcnf && -e $mytmpcnf) {
2305 rename $mytmpcnf,$mycnf;