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
58 &read_autoinstall_file
63 &releasecandidatewarning
64 &getinstallationdirectories
82 use vars qw( $kohaversion $newversion ); # set in loadconfigfile and installer.pl
83 use vars qw( $language ); # set in installer.pl
84 use vars qw( $domainname ); # set in installer.pl
86 use vars qw( $etcdir ); # set in installer.pl, usu. /etc
87 use vars qw( $intranetdir $opacdir $kohalogdir );
88 use vars qw( $realhttpdconf $httpduser );
89 use vars qw( $servername $svr_admin $opacport $intranetport );
90 use vars qw( $mysqldir );
91 use vars qw( $database $mysqluser );
92 use vars qw( $mysqlpass ); # normally should not be used
93 use vars qw( $hostname $user $pass ); # virtual hosting
97 $messages->{'WelcomeToKohaInstaller'
98 = heading('Welcome to the Koha Installer') . qq|...|;
100 The heading function takes one string, the text to be displayed as
101 the heading, and returns a formatted heading (currently formatted
104 This reduces the likelihood of pod2man(1) etc. misinterpreting
105 a line of equal signs as illegal POD directives.
109 my $termios = POSIX::Termios->new();
111 my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
112 my $clear_string = "\n";
117 return($clear_string.ON_BLUE.WHITE.BOLD." "x$bal.uc($title)." "x$bal.RESET."\n\n");
120 my $mycnf = $ENV{HOME}."/.my.cnf";
121 my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
125 $messages->{'continuing'}->{en}="Great! Continuing...\n\n";
126 $messages->{'WelcomeToKohaInstaller'}->{en} =
127 heading('Welcome to the Koha Installer') . qq|
128 This program will ask some questions and try to install koha for you.
129 You need to know: where most koha files should be stored (you can set
130 the prefix environment variable for this); the username and password of
131 a mysql superuser; and details of your library setup. You may also need
132 to know details of your Apache setup.
134 If you want to install the Koha configuration files somewhere other than
135 /etc (for multiple Koha versions on one system, for example), you should
136 set the etcdir environment variable. Please look at your manuals for
137 details of how to set that.
139 Recommended answers are given in brackets after each question. To accept
140 the default value for any question (indicated by []), simply hit Enter
143 You also can define an auto_install_file, that will answer every question automatically.
144 To use this feature, run ./installer.pl -i /path/to/auto_install_file
146 Are you ready to begin the installation? ([Y]/N): |;
148 $messages->{'WelcomeToUpgrader'}->{en} =
149 heading('Welcome to the Koha Upgrader') . qq|
150 You are attempting to upgrade from Koha %s to %s.
152 We recommend that you do a complete backup of all your files before upgrading.
153 This upgrade script will make a backup copy of your files for you.
155 Would you like to proceed? (Y/[N]):|;
157 $messages->{'AbortingInstall'}->{en} =
158 heading('ABORTING') . qq|
159 Aborting as requested. Please rerun when you are ready.
162 $messages->{'ReleaseCandidateWarning'}->{en} =
163 heading('RELEASE CANDIDATE') . qq|
164 WARNING: You are about to install Koha version %s. This is a
165 release candidate, It is NOT bugfree.
166 However, it works, and has been declared stable enough to
169 Most people should answer Yes here.
171 Are you sure you want to install Koha %s? (Y/[N]): |;
172 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
174 Watch for announcements of Koha releases on the Koha mailing list or the Koha
175 web site (http://www.koha.org/).
179 $messages->{'NETZ3950Missing'}->{en}=qq|
181 The Net::Z3950 module is missing. This module is necessary if you want to use
182 Koha's Z39.50 client to download bibliographic records from other libraries.
184 To install this module, you will need the yaz client installed from
185 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
188 perl -MCPAN -e 'install Net::Z3950'
190 ...or by installing packages for your distribution, if available.
192 IMPORTANT NOTE : If you use Perl 5.8.0, you might need to
193 edit NET::Z3950's Makefile.PL and yazwrap/Makefile.PL to include:
195 'DEFINE' => '-D_GNU_SOURCE',
197 Also note that some installations of Perl on Red Hat will generate a lot of
198 "'my_perl' undeclared" errors when running make in Net-Z3950. This is fixed by
199 inserting in yazwrap/ywpriv.h a line saying #include "XSUB.h"
201 Press the <ENTER> key to continue: |; #'
203 $messages->{'CheckingPerlModules'}->{en} = heading('PERL MODULES') . qq|
204 Checking perl modules ...
207 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
209 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
210 You are missing some Perl modules required by Koha.
211 Please run this again after installing them.
212 They may be installed by finding packages from your operating system supplier, or running (as root) the following commands:
217 $messages->{'AllPerlModulesInstalled'}->{en} =
218 heading('PERL MODULES AVAILABLE') . qq|
219 All required perl modules are installed.
221 Press <ENTER> to continue: |;
222 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
223 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
224 $messages->{'KohaAlreadyInstalled'}->{en} =
225 heading('Koha already installed') . qq|
226 It looks like Koha is already installed on your system (%s/koha.conf exists).
227 If you would like to upgrade your system to %s, please use
228 the koha.upgrade script in this directory.
233 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
234 Please supply the directory you want Koha to store its OPAC files in. This
235 directory will be auto-created for you if it doesn't exist.
237 OPAC Directory [%s]: |; #'
239 $messages->{'GetIntranetDir'}->{en} =
240 heading('LIBRARIAN DIRECTORY') . qq|
241 Please supply the directory you want Koha to store its Librarian interface
242 files in. This directory will be auto-created for you if it doesn't exist.
244 Intranet Directory [%s]: |; #'
246 $messages->{'GetKohaLogDir'}->{en} = heading('LOG DIRECTORY') . qq|
247 Specify a directory where log files will be written.
249 Koha Log Directory [%s]: |;
251 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
252 This release of Koha has a new authentication module.
253 You will be required to log in to
254 access some features.
256 IMPORTANT: You can log in using the userid and password from the %s/koha.conf configuration file at any time.
257 Use the "Members" screen to add passwords for other accounts and set their flags.
259 Press the <ENTER> key to continue: |;
261 $messages->{'Completed'}->{en} = heading('INSTALLATION COMPLETE') . qq|
262 Congratulations ... your Koha installation is complete!
263 You will be able to connect to your Librarian interface at:
265 use the koha admin mysql login and password to connect to this interface.
266 and the OPAC interface at:
268 Please read the Hints file and visit http://www.koha.org
269 Press <ENTER> to exit the installer: |;
271 $messages->{'UpgradeCompleted'}->{en} = heading('UPGRADE COMPLETE') . qq|
272 Congratulations ... your Koha upgrade is finished!
274 If you are upgrading from a version of Koha
275 prior to 1.2.1, it is likely that you will have to modify your Apache
276 configuration to point it to the new files.
278 In your INTRANET VirtualHost section you should have:
279 DocumentRoot %s/htdocs
280 ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
281 SetEnv PERL5LIB %s/modules
283 In the OPAC VirtualHost section you should have:
284 DocumentRoot %s/htdocs
285 ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
286 SetEnv PERL5LIB %s/modules
288 You may also need to uncomment a "LoadModules env_module ... " line and restart
290 If you're upgrading from 1.2.x version of Koha note that the MARC DB is NOT populated.
293 * Go to Parameters >> Marc structure option and Koha-MARC links option.
294 * Modify default MARC structure to fit your needs.
297 cd /path/to/koha/misc
298 export PERL5LIB=/path/to/koha
300 the old DB is "copied" in the new MARC one.
301 Koha 2.0.0 is ready :-)
303 Please report any problems you encounter through http://bugs.koha.org/
305 Press <ENTER> to exit the installer: |;
308 sub releasecandidatewarning {
309 my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
310 my $answer=showmessage($message, 'yn', 'n');
312 if ($answer =~ /y/i) {
313 print getmessage('continuing');
315 my $message=getmessage('WatchForReleaseAnnouncements');
321 sub read_autoinstall_file
323 my $fname = shift; # Config file to read
324 my $retval = {}; # Return value: ref-to-hash holding the
327 open (CONF, $fname) or return undef;
331 my $var; # Variable name
332 my $value; # Variable value
335 s/#.*//; # Strip comments
336 next if /^\s*$/; # Ignore blank lines
338 # Look for a line of the form
340 if (!/^\s*(\w+)\s*=\s*(.*?)\s*$/)
345 # Found a variable assignment
346 # variable that was already set.
349 $retval->{$var} = $value;
352 if ($retval->{MysqlRootPassword} eq "XXX") {
353 print "ERROR : the root password is XXX. It is NOT valid. Edit your auto_install_file\n";
360 =head2 Accessor functions (for installer.pl)
370 Sets the installation language, normally "en" (English).
371 In fact, only "en" is supported.
375 sub setlanguage ($) {
381 setdomainname('example.org');
383 Sets the domain name of the host.
385 The domain name should not contain a leading dot;
386 otherwise, the results are undefined.
390 sub setdomainname ($) {
398 Sets the sysconfdir, normally /etc.
399 This should be an absolute path; a trailing / is not required.
411 Gets the Koha version as known by the previous config file.
415 sub getkohaversion () {
416 return($kohaversion);
421 setkohaversion('1.3.3RC26');
423 Sets the Koha version as known by the installer.
427 sub setkohaversion ($) {
433 my $servername = getservername;
435 Gets the name of the Koha virtual server as specified by the user.
439 sub getservername () {
447 Gets the port that will run the Koha OPAC virtual server,
448 as specified by the user.
456 =item getintranetport
458 $port = getintranetport;
460 Gets the port that will run the Koha INTRANET virtual server,
461 as specified by the user.
465 sub getintranetport () {
471 =head2 Miscellaneous utility functions
481 Does the equivalent of dirname(1). Given a path $path, return the
482 parent directory of $path (best guess), except when $path seems to
483 be the same as /, in which case $path itself is returned unchanged.
489 if ($path =~ /[^\/]/s) {
491 $path =~ s/\/+[^\/]+\/*$//s;
502 mkdir_parents $path, $mode;
504 Does the equivalent of mkdir -p, or mkdir --parents. Given a path $path,
505 create the directory $path, recursively creating any intermediate
506 directories. If $mode is given, the directory will be created with
509 WARNING: If $path already exists, mkdir_parents will just return
510 successfully (just like mkdir -p), whether the mode of $path conforms
511 to $mode or not. (This is the behaviour of the mkdir -p command.)
516 my($path, $mode) = @_;
517 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
519 if (!$ok && $! == ENOENT) {
520 my $parent = dirname($path);
521 $ok = mkdir_parents($parent, $mode);
523 # retry and at the same time make sure that $! is set correctly
524 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
533 getmessage($msgid, $variables);
535 Gets a localized message (format string) with message id $msgid,
536 and, if an array reference of variables $variables is given,
537 substitutes variables in the format string with @$variables.
538 Returns the found message string, with variable substitutions
541 $msgid must be the message identifier corresponding to a defined
542 message string (a valid key to the $messages hash in the Installer
543 package). getmessage throws an exception if the message cannot be
549 my $messagename=shift;
551 my $message=$messages->{$messagename}->{$language} || $messages->{$messagename}->{en} || RED.BOLD."Error: No message named $messagename in Install.pm\n";
552 if (defined($variables)) {
553 $message=sprintf $message, @$variables;
561 showmessage($message, 'none');
562 showmessage($message, 'none', undef, $noclear);
564 $result = showmessage($message, 'yn');
565 $result = showmessage($message, 'yn', $defaultresponse);
566 $result = showmessage($message, 'yn', $defaultresponse, $noclear);
568 $result = showmessage($message, 'restrictchar CHARS');
569 $result = showmessage($message, 'free');
570 $result = showmessage($message, 'silentfree');
571 $result = showmessage($message, 'numerical');
572 $result = showmessage($message, 'email');
573 $result = showmessage($message, 'PressEnter');
575 Shows a message and optionally gets a response from the user.
577 The first two arguments, the message and the response type,
578 are mandatory. The message must be the actual string to
579 display; the caller is responsible for calling getmessage if
582 The response type must be one of "none", "yn", "free", "silentfree"
583 "numerical", "email", "PressEnter", or a string consisting
584 of "restrictchar " followed by a list of allowed characters
585 (space can be specified). (Case is not significant, but case is
586 significant in the list of allowed characters.) If a response
587 type other than the above-listed is specified, the result is
590 Note that the response type "yn" is equivalent to "restrictchar yn".
591 Because "restrictchar" is case-sensitive, the user is expected
592 to enter "y" or "n" in lowercase only.
594 Note that the response type of "email" does not actually
595 guarantee that the returned value is a well-formed RFC-822
596 email address, nor does it accept all well-formed RFC-822 email
597 addresses. What it does is to restrict the returned value to a
598 string that is looks reasonably likely to be an email address
599 in the "real world", given the premise that the user is trying
600 to enter a real email address.
602 If a response type other than "none" or "PressEnter" is
603 specified, a third argument, specifying the default value, can
604 be specified: If this default response is not specified, the
605 default response is the first allowed character if the response
606 type is "restrictchar", otherwise the default response is the
607 empty string. This default response is used when the user does
608 not specify a value (i.e., presses Enter without typing in
609 anything), showmessage will assume that the default response is
612 Note that because the response type "yn" is equivalent to
613 "restrictchar yn", the default value for response type "yn",
614 if unspecified, is "y".
616 The screen is normally cleared before the message is displayed;
617 if a fourth argument is specified and is nonzero, this
618 screen-clearing is not done.
624 #MJR: Maybe refactor to use anonymous functions that
625 # check the responses instead of RnP branching.
626 my $message=join('',fill('','',(shift)));
627 my $responsetype=shift;
628 my $defaultresponse=shift;
630 $noclear = 0 unless defined $noclear; # defaults to "clear"
631 ($noclear) || (print $clear_string);
632 if ($responsetype =~ /^yn$/) {
633 $responsetype='restrictchar ynYN';
635 print RESET.$message;
636 if ($responsetype =~/^restrictchar (.*)/i) {
639 until ($options=~/$response/) {
640 (defined($defaultresponse)) || ($defaultresponse=substr($options,0,1));
643 (length($response)) || ($response=$defaultresponse);
644 if ( $response=~/.*[\:\(\)\^\$\*\!\\].*/ ) {
645 ($noclear) || (print $clear_string);
646 print RED."Response contains invalid characters. Choose from [$options].\n\n";
647 print RESET.$message;
650 unless ($options=~/$response/) {
651 ($noclear) || (print $clear_string);
652 print RED."Invalid Response. Choose from [$options].\n\n";
653 print RESET.$message;
658 } elsif ($responsetype =~/^(silent)?free$/i) {
659 (defined($defaultresponse)) || ($defaultresponse='');
660 if ($responsetype =~/^(silent)/i) { setecho(0) };
661 my $response=<STDIN>;
662 if ($responsetype =~/^(silent)/i) { setecho(1) };
664 ($response) || ($response=$defaultresponse);
666 } elsif ($responsetype =~/^numerical$/i) {
667 (defined($defaultresponse)) || ($defaultresponse='');
669 until ($response=~/^\d+$/) {
672 ($response) || ($response=$defaultresponse);
673 unless ($response=~/^\d+$/) {
674 ($noclear) || (print $clear_string);
675 print RED."Invalid Response ($response). Response must be a number.\n\n";
676 print RESET.$message;
680 } elsif ($responsetype =~/^email$/i) {
681 (defined($defaultresponse)) || ($defaultresponse='');
683 until ($response=~/.*\@.*\..*/) {
686 ($response) || ($response=$defaultresponse);
687 if ($response!~/.*\@.*\..*/) {
688 ($noclear) || (print $clear_string);
689 print RED."Invalid Response ($response). Response must be a valid email address.\n\n";
690 print RESET.$message;
694 } elsif ($responsetype =~/^PressEnter$/i) {
697 } elsif ($responsetype =~/^none$/i) {
700 # FIXME: There are a few places where we will get an undef as the
701 # response type. Should we thrown an exception here, or should we
702 # legitimize this usage and say "none" is the default if not specified?
703 #die "Illegal response type \"$responsetype\"";
714 Changes the display to show system output until the next showmessage call.
715 At the time of writing, this means using red text.
726 =head2 Subtasks of doing an installation
732 =item checkabortedinstall
736 Checks whether a previous installation process has been abnormally
737 aborted, by checking whether $etcidr/koha.conf is a symlink matching
738 a particular pattern. If an aborted installation is detected, give
739 the user a chance to abort, before trying to recover the aborted
742 FIXME: The recovery is not complete; it only partially rolls back
747 sub checkabortedinstall () {
748 if (-l("$etcdir/koha.conf")
749 && readlink("$etcdir/koha.conf") =~ /\.tmp$/
752 I have detected that you tried to install Koha before, but the installation
753 was aborted. I will try to continue, but there might be problems if the
754 database is already created.
757 print "Please press <ENTER> to continue: ";
760 # Remove the symlink after the <STDIN>, so the user can back out
761 unlink "$etcdir/koha.conf"
762 || die "Failed to remove incomplete $etcdir/koha.conf: $!\n";
770 Make sure that we loaded the right dirs from an old koha.conf
774 #FIXME: update to use Install.pm
776 if ($opacdir && $intranetdir) {
779 I believe that your old files are located in:
782 LIBRARIAN: $intranetdir
785 Does this look right? ([Y]/N):
787 my $answer = <STDIN>;
790 if ($answer =~/n/i) {
794 print "Great! continuing upgrade... \n";
798 if (!$opacdir || !$intranetdir) {
801 while (!$intranetdir) {
802 print "Please specify the location of your LIBRARIAN files: ";
804 my $answer = <STDIN>;
808 $intranetdir=$answer;
810 if (! -e "$intranetdir/htdocs") {
811 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
816 print "Please specify the location of your OPAC files: ";
818 my $answer = <STDIN>;
824 if (! -e "$opacdir/htdocs") {
825 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
833 =item checkperlmodules
837 Test whether the version of Perl is new enough, whether Perl is
838 found at the expected location, and whether all required modules
843 sub checkperlmodules {
845 # Test for Perl and Modules
847 my ($auto_install) = @_;
848 my $message = getmessage('CheckingPerlModules');
849 showmessage($message, 'none');
851 unless ($] >= 5.006001) { # Bug 179
852 die getmessage('PerlVersionFailure', ['5.6.1']);
857 unless (eval {require DBI}) { push @missing,"DBI" };
858 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
859 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
860 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
861 # unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
862 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
863 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
864 unless (eval {require Mail::Sendmail}) { push @missing,"Mail::Sendmail" };
865 unless (eval {require Event}) {
866 if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
867 push @missing, "Event";
870 unless (eval {require Net::Z3950}) {
871 showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
872 if ($#missing>=0) { # see above note
873 push @missing, "Net::Z3950";
878 # Print out a list of any missing modules
883 if (POSIX::setlocale(LC_ALL) ne "C") {
884 $missing.=" export LC_ALL=C\n";
886 foreach my $module (@missing) {
887 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
889 my $message=getmessage('MissingPerlModules', [$missing]);
890 showmessage($message, 'none');
894 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1) unless $auto_install->{NoPressEnter};
899 unless (-x "/usr/bin/perl") {
900 my $realperl=`which perl`;
902 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
903 until (-x $realperl) {
904 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
906 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
907 unless ($response eq 'n') {
909 system("ln -s $realperl /usr/bin/perl");
916 $messages->{'NoUsrBinPerl'}->{en} =
917 heading('No /usr/bin/perl') . qq|
918 Koha expects to find the perl executable in the /usr/bin
919 directory. It is not there on your system.
923 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable [%s]: |;
924 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
925 Some Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
927 Most users should answer Y here.
929 May I try to create this symlink? ([Y]/N):|;
931 $messages->{'DirFailed'}->{en} = RED.qq|
932 We could not create %s, but continuing anyway...
938 =item getinstallationdirectories
940 getinstallationdirectories;
942 Get the various installation directories from the user, and then
943 create those directories (if they do not already exist).
945 These pieces of information are saved to global variables; the
946 function does not return any values.
950 sub getinstallationdirectories {
951 my ($auto_install) = @_;
952 if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; } #"
953 $opacdir = $ENV{prefix}.'/koha/opac';
954 $intranetdir = $ENV{prefix}.'/koha/intranet';
956 while ($getdirinfo) {
957 # Loop until opac directory and koha directory are different
959 if ($auto_install->{GetOpacDir}) {
960 $opacdir=$auto_install->{GetOpacDir};
961 print ON_YELLOW.BLACK."auto-setting OpacDir to : $opacdir".RESET."\n";
963 $message=getmessage('GetOpacDir', [$opacdir]);
964 $opacdir=showmessage($message, 'free', $opacdir);
966 if ($auto_install->{GetIntranetDir}) {
967 $intranetdir=$auto_install->{GetIntranetDir};
968 print ON_YELLOW.BLACK."auto-setting IntranetDir to : $intranetdir".RESET."\n";
970 $message=getmessage('GetIntranetDir', [$intranetdir]);
971 $intranetdir=showmessage($message, 'free', $intranetdir);
973 if ($intranetdir eq $opacdir) {
976 You must specify different directories for the OPAC and INTRANET files!
977 :: $intranetdir :: $opacdir ::
984 $kohalogdir=$ENV{prefix}.'/koha/log';
985 if ($auto_install->{GetOpacDir}) {
986 $kohalogdir=$auto_install->{KohaLogDir};
987 print ON_YELLOW.BLACK."auto-setting log dir to : $kohalogdir".RESET."\n";
989 my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
990 $kohalogdir=showmessage($message, 'free', $kohalogdir);
994 # FIXME: Need better error handling for all mkdir calls here
995 unless ( -d $intranetdir ) {
996 mkdir_parents (dirname($intranetdir), 0775) || print getmessage('DirFailed',['parents of '.$intranetdir]);
997 mkdir ($intranetdir, 0770) || print getmessage('DirFailed',[$intranetdir]);
998 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir"); }
999 chmod 0770, "$intranetdir";
1001 mkdir_parents ("$intranetdir/htdocs", 0750);
1002 mkdir_parents ("$intranetdir/cgi-bin", 0750);
1003 mkdir_parents ("$intranetdir/modules", 0750);
1004 mkdir_parents ("$intranetdir/scripts", 0750);
1005 unless ( -d $opacdir ) {
1006 mkdir_parents (dirname($opacdir), 0775) || print getmessage('DirFailed',['parents of '.$opacdir]);
1007 mkdir ($opacdir, 0770) || print getmessage('DirFailed',[$opacdir]);
1008 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2], "$opacdir"); }
1009 chmod (oct(770), "$opacdir");
1011 mkdir_parents ("$opacdir/htdocs", 0750);
1012 mkdir_parents ("$opacdir/cgi-bin", 0750);
1015 unless ( -d $kohalogdir ) {
1016 mkdir_parents (dirname($kohalogdir), 0775) || print getmessage('DirFailed',['parents of '.$kohalogdir]);
1017 mkdir ($kohalogdir, 0770) || print getmessage('DirFailed',[$kohalogdir]);
1018 if ($>==0) { chown (oct(0), (getgrnam($httpduser))[2,3], "$kohalogdir"); }
1019 chmod (oct(770), "$kohalogdir");
1027 Get the MySQL database server installation directory, automatically if possible.
1031 $messages->{'WhereIsMySQL'}->{en} = heading('MYSQL LOCATION').qq|
1032 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.
1033 If you compiled mysql yourself,
1034 please give the value of --prefix when you ran configure.
1035 The file mysqladmin should be in bin/mysqladmin under the directory that you give here.
1037 MySQL installation directory: |;
1040 foreach my $mysql (qw(/usr/local/mysql
1045 if ( -d $mysql && -f "$mysql/bin/mysqladmin") { #"
1051 $mysqldir = showmessage(getmessage('WhereIsMySQL'),'free');
1052 last if -f "$mysqldir/bin/mysqladmin";
1058 =item getdatabaseinfo
1062 Get various pieces of information related to the Koha database:
1063 the name of the database, the host on which the SQL server is
1064 running, and the database user name.
1066 These pieces of information are saved to global variables; the
1067 function does not return any values.
1071 $messages->{'DatabaseName'}->{en} = heading('Database Name') . qq|
1072 Please provide the name that you wish to give your koha database.
1073 It must not exist already on the database server.
1075 Most users give a short single-word name for their library here.
1077 Database name [%s]: |;
1079 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
1080 Please provide the mysql server name. Unless the database is stored on
1081 another machine, this should be "localhost".
1083 Database host [%s]: |;
1085 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
1086 We are going to create a new mysql user for Koha. This user will have full administrative rights
1087 to the database called %s when they connect from %s.
1088 This is also the name of the Koha librarian superuser.
1090 Most users give a single-word name here.
1092 Database user [%s]: |;
1094 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
1095 Please provide a good password for the user %s.
1097 IMPORTANT: You can log in using this user and password at any time.
1099 Password for database user %s: |;
1101 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
1102 You must not use a blank password for your MySQL user.
1104 Press <ENTER> to try again:
1107 sub getdatabaseinfo {
1108 my ($auto_install) = @_;
1110 $hostname = 'localhost';
1111 $user = 'kohaadmin';
1114 #Get the database name
1117 if ($auto_install->{database}) {
1118 $database=$auto_install->{database};
1119 print ON_YELLOW.BLACK."auto-setting database to : $database".RESET."\n";
1121 $message=getmessage('DatabaseName', [$database]);
1122 $database=showmessage($message, 'free', $database);
1124 #Get the hostname for the database
1126 if ($auto_install->{DatabaseHost}) {
1127 $hostname=$auto_install->{DatabaseHost};
1128 print ON_YELLOW.BLACK."auto-setting database host to : $hostname".RESET."\n";
1130 $message=getmessage('DatabaseHost', [$hostname]);
1131 $hostname=showmessage($message, 'free', $hostname);
1133 #Get the username for the database
1135 if ($auto_install->{DatabaseUser}) {
1136 $user=$auto_install->{DatabaseUser};
1137 print ON_YELLOW.BLACK."auto-setting DB user to : $user".RESET."\n";
1139 $message=getmessage('DatabaseUser', [$database, $hostname, $user]);
1140 $user=showmessage($message, 'free', $user);
1142 #Get the password for the database user
1144 while ($pass eq '') {
1145 my $message=getmessage('DatabasePassword', [$user, $user]);
1146 if ($auto_install->{DatabasePassword}) {
1147 $pass=$auto_install->{DatabasePassword};
1148 print ON_YELLOW.BLACK."auto-setting database password to : $pass".RESET."\n";
1150 $pass=showmessage($message, 'free', $pass);
1153 my $message=getmessage('BlankPassword');
1154 showmessage($message,'PressEnter');
1165 Get various pieces of information related to the Apache server:
1166 the location of the configuration file and, if needed, the Unix
1167 user that the Koha CGI will be run under.
1169 These pieces of information are saved to global variables; the
1170 function does not return any values.
1174 $messages->{'FoundMultipleApacheConfFiles'}->{en} =
1175 heading('MULTIPLE APACHE CONFIG FILES FOUND') . qq|
1176 I found more than one possible Apache configuration file:
1180 Enter number of the file to read [1]: |;
1182 $messages->{'NoApacheConfFiles'}->{en} =
1183 heading('NO APACHE CONFIG FILE FOUND') . qq|
1184 I was not able to find your Apache configuration file.
1186 The file is usually called httpd.conf, apache.conf or similar.
1188 Please enter the full name, starting with /: |;
1190 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
1191 The file %s does not exist.
1193 Please press <ENTER> to continue: |;
1195 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq\
1196 The installer could not find the User setting in the Apache configuration file.
1197 This is used to set up access permissions for
1198 %s/koha.conf. This user should be set in one of the Apache configuration.
1199 Please try to find it and enter the user name below. You might find
1200 that "ps u|grep apache" will tell you. It probably is NOT "root".
1202 Enter the Apache userid: \;
1204 $messages->{'InvalidUserid'}->{en} = heading('INVALID USER') . qq|
1205 The userid %s is not a valid userid on this system.
1207 Press <ENTER> to continue: |;
1210 my ($auto_install) = @_;
1211 my @confpossibilities;
1213 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
1214 /usr/local/etc/apache/httpd.conf
1215 /usr/local/etc/apache/apache.conf
1216 /var/www/conf/httpd.conf
1217 /etc/apache2/httpd.conf
1218 /etc/apache2/apache2.conf
1219 /etc/apache/conf/httpd.conf
1220 /etc/apache/conf/apache.conf
1221 /etc/apache/httpd.conf
1222 /etc/apache-ssl/conf/apache.conf
1223 /etc/apache-ssl/httpd.conf
1224 /etc/httpd/conf/httpd.conf
1225 /etc/httpd/httpd.conf
1226 /etc/httpd/2.0/conf/httpd2.conf
1228 if ( -f $httpdconf ) {
1229 push @confpossibilities, $httpdconf;
1233 if ($#confpossibilities==-1) {
1234 my $message=getmessage('NoApacheConfFiles');
1237 until (-f $realhttpdconf) {
1238 $choice=showmessage($message, "free", 1);
1240 $realhttpdconf=$choice;
1242 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
1245 } elsif ($#confpossibilities>0) {
1249 foreach (@confpossibilities) {
1250 $conffiles.=" $counter: $_\n";
1251 $options.="$counter";
1254 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
1255 my $choice=showmessage($message, "restrictchar $options", 1);
1256 $realhttpdconf=$confpossibilities[$choice-1];
1258 $realhttpdconf=$confpossibilities[0];
1260 unless (open (HTTPDCONF, "<$realhttpdconf")) {
1261 warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
1265 while (<HTTPDCONF>) {
1266 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
1272 unless (defined($httpduser)) {
1274 if ($auto_install->{EnterApacheUser}) {
1275 $message = $auto_install->{EnterApacheUser};
1276 print ON_YELLOW.BLACK."auto-setting Apache User to : $message".RESET."\n";
1278 $message=getmessage('EnterApacheUser', [$etcdir]);
1280 until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
1281 if ($auto_install->{EnterApacheUser}) {
1282 $httpduser = $auto_install->{EnterApacheUser};
1284 $httpduser=showmessage($message, "free", '');
1286 if (length($httpduser)>0) {
1287 unless (getpwnam($httpduser)) {
1288 my $message=getmessage('InvalidUserid', [$httpduser]);
1289 showmessage($message,'PressEnter');
1298 =item getapachevhostinfo
1302 Gets various pieces of information related to virtual hosting:
1303 the webmaster email address, virtual hostname, and the ports
1304 that the OPAC and INTRANET modules run on.
1306 These pieces of information are saved to global variables; the
1307 function does not return any values.
1311 $messages->{'ApacheConfigIntroduction'}->{en} =
1312 heading('APACHE CONFIGURATION') . qq|
1313 Koha needs to write an Apache configuration file for the
1314 OPAC and Librarian sites. By default this installer
1315 will do this by using one name and two different ports
1316 for the virtual hosts. There are other ways to set this up,
1317 and the installer will leave comments in
1318 %s/koha-httpd.conf about them.
1320 NOTE: You will need to add lines to your main httpd.conf to
1321 include %s/koha-httpd.conf
1322 and to make sure it is listening on the right ports
1323 (using the Listen directive).
1325 Press <ENTER> to continue: |;
1327 $messages->{'GetVirtualHostEmail'}->{en} =
1328 heading('WEB E-MAIL CONTACT') . qq|
1329 Enter the e-mail address to be used as a contact for Koha. This
1330 address is displayed if fatal errors are encountered.
1332 E-mail contact [%s]: |;
1334 $messages->{'GetServerName'}->{en} =
1335 heading('WEB HOST NAME OR IP ADDRESS') . qq|
1336 Please enter the host name or IP address that you wish to use for koha.
1337 Normally, this should be a name or IP that belongs to this machine.
1339 Host name or IP Address [%s]: |;
1341 $messages->{'GetOpacPort'}->{en} = heading('OPAC PORT') . qq|
1342 Please enter the port for your OPAC interface. This defaults to port 80, but
1343 if you are already serving web content with this hostname, you should change it
1344 to a different port (8000 might be a good choice, but check any firewalls).
1346 Enter the OPAC Port [%s]: |;
1348 $messages->{'GetIntranetPort'}->{en} =
1349 heading('LIBRARIAN PORT') . qq|
1350 Please enter the port for your Librarian interface. This must be different from
1353 Enter the Intranet Port [%s]: |;
1356 sub getapachevhostinfo {
1357 my ($auto_install) = @_;
1358 $svr_admin = "webmaster\@$domainname";
1359 $servername=`hostname`;
1364 if ($auto_install->{GetVirtualHostEmail}) {
1365 $svr_admin=$auto_install->{GetVirtualHostEmail};
1366 print ON_YELLOW.BLACK."auto-setting VirtualHostEmail to : $svr_admin".RESET."\n";
1368 showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
1369 $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
1371 if ($auto_install->{servername}) {
1372 $servername=$auto_install->{servername};
1373 print ON_YELLOW.BLACK."auto-setting server name to : $servername".RESET."\n";
1375 $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
1377 if ($auto_install->{opacport}) {
1378 $opacport=$auto_install->{opacport};
1379 print ON_YELLOW.BLACK."auto-setting opac port to : $opacport".RESET."\n";
1381 $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
1383 if ($auto_install->{intranetport}) {
1384 $intranetport=$auto_install->{intranetport};
1385 print ON_YELLOW.BLACK."auto-setting intranet port to : $intranetport".RESET."\n";
1387 $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
1393 =item updateapacheconf
1397 Updates the Apache config file according to parameters previously
1398 specified by the user.
1400 It will append fully-commented directives at the end of the original
1401 Apache config file. The old config file is renamed with an extension
1404 If you need to uninstall Koha for any reason, the lines between
1406 # Ports to listen to for Koha
1408 and the block of comments beginning with
1410 # If you want to use name based Virtual Hosting:
1416 $messages->{'StartUpdateApache'}->{en} =
1417 heading('UPDATING APACHE CONFIGURATION') . qq|
1418 Checking for modules that need to be loaded...
1421 $messages->{'ApacheConfigMissingModules'}->{en} =
1422 heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
1423 Koha uses the mod_env and mod_include apache features, but the
1424 installer did not find them in your config. Please
1425 make sure that they are enabled for your Koha site.
1427 Press <ENTER> to continue: |;
1430 $messages->{'ApacheAlreadyConfigured'}->{en} =
1431 heading('APACHE ALREADY CONFIGURED') . qq|
1432 %s appears to already have an entry for Koha. You may need to edit %s
1433 if anything has changed since it was last set up. This
1434 script will not attempt to modify an existing Koha apache
1437 Press <ENTER> to continue: |;
1439 sub updateapacheconf {
1440 my ($auto_install)=@_;
1441 my $logfiledir=$kohalogdir;
1442 my $httpdconf = $etcdir."/koha-httpd.conf";
1444 showmessage(getmessage('StartUpdateApache'), 'none') unless $auto_install->{NoPressEnter};
1445 # to be polite about it: I don't think this should touch the main httpd.conf
1447 # QUESTION: Should we warn for includes_module too?
1449 my $includesmodule=0;
1450 open HC, "<$realhttpdconf";
1452 if (/^\s*#\s*LoadModule env_module /) {
1453 showmessage(getmessage('ApacheConfigMissingModules'));
1456 if (/\s*LoadModule includes_module / ) {
1462 if (`grep -q 'VirtualHost $servername' "$httpdconf" 2>/dev/null`) {
1463 showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
1466 my $includesdirectives='';
1467 if ($includesmodule) {
1468 $includesdirectives.="Options +Includes\n";
1469 $includesdirectives.=" AddHandler server-parsed .html\n";
1471 open(SITE,">$httpdconf") or warn "Insufficient priveleges to open $httpdconf for writing.\n";
1472 my $opaclisten = '';
1473 if ($opacport != 80) {
1474 $opaclisten="Listen $opacport";
1476 my $intranetlisten = '';
1477 if ($intranetport != 80) {
1478 $intranetlisten="Listen $intranetport";
1482 # Ports to listen to for Koha
1483 # uncomment these if they aren't already in main httpd.conf
1487 # NameVirtualHost is used by one of the optional configurations detailed below
1489 #NameVirtualHost 11.22.33.44
1491 # KOHA's OPAC Configuration
1492 <VirtualHost $servername\:$opacport>
1493 ServerAdmin $svr_admin
1494 DocumentRoot $opacdir/htdocs
1495 ServerName $servername
1496 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
1497 ErrorLog $logfiledir/opac-error_log
1498 TransferLog $logfiledir/opac-access_log
1499 SetEnv PERL5LIB "$intranetdir/modules"
1500 SetEnv KOHA_CONF "$etcdir/koha.conf"
1504 # KOHA's INTRANET Configuration
1505 <VirtualHost $servername\:$intranetport>
1506 ServerAdmin $svr_admin
1507 DocumentRoot $intranetdir/htdocs
1508 ServerName $servername
1509 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
1510 ErrorLog $logfiledir/koha-error_log
1511 TransferLog $logfiledir/koha-access_log
1512 SetEnv PERL5LIB "$intranetdir/modules"
1513 SetEnv KOHA_CONF "$etcdir/koha.conf"
1517 # If you want to use name based Virtual Hosting:
1518 # 1. remove the two Listen lines
1519 # 2. replace $servername\:$opacport wih your.opac.domain.name
1520 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
1521 # 4. replace $servername\:$intranetport wih your intranet domain name
1522 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
1524 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1525 # 1. Follow steps 1-5 above
1526 # 2. Uncomment the NameVirtualHost line and set the correct ip address
1535 =item basicauthentication
1537 basicauthentication;
1539 Asks the user whether HTTP basic authentication is wanted, and,
1540 if so, the user name and password for the basic authentication.
1542 These pieces of information are saved to global variables; the
1543 function does not return any values.
1547 # $messages->{'IntranetAuthenticationQuestion'}->{en} =
1548 # heading('LIBRARIAN AUTHENTICATION') . qq|
1549 # The Librarian site can be password protected using
1550 # Apache's Basic Authorization instead of Koha user details.
1552 # This method going to be phased out very soon. Most users should answer N here.
1554 # Would you like to do this (Y/[N]): |; #'
1556 # $messages->{'BasicAuthUsername'}->{en}="Please enter a username for librarian access [%s]: ";
1557 # $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1558 # $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1560 # sub basicauthentication {
1561 # my $message=getmessage('IntranetAuthenticationQuestion');
1562 # my $answer=showmessage($message, 'yn', 'n');
1563 # my $httpdconf = $etcdir."/koha-httpd.conf";
1565 # my $apacheauthusername='librarian';
1566 # my $apacheauthpassword='';
1567 # if ($answer=~/^y/i) {
1568 # ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1569 # $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1570 # while (! $apacheauthpassword) {
1571 # ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1572 # if (!$apacheauthpassword) {
1573 # ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1576 # open AUTH, ">$etcdir/kohaintranet.pass";
1577 # my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1578 # my $salt=substr($chars, int(rand(length($chars))),1);
1579 # $salt.=substr($chars, int(rand(length($chars))),1);
1580 # print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1582 # open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
1585 # <Directory $intranetdir>
1586 # AuthUserFile $etcdir/kohaintranet.pass
1588 # AuthName "Koha Intranet (for librarians only)"
1589 # Require valid-user
1601 Install the Koha files to the specified OPAC and INTRANET
1602 directories (usually in /usr/local/koha).
1604 The koha.conf file is created, but as koha.conf.tmp. The
1605 caller is responsible for calling finalizeconfigfile when
1606 installation is completed, to rename it back to koha.conf.
1610 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1611 Copying files to installation directories:
1615 $messages->{'OldFiles'}->{en} = heading('OLD FILES') . qq|
1616 Any files from the previous edition of Koha have been
1617 copied to a dated backup directory alongside the new
1618 installation. You should move any custom files that you
1619 want to keep (such as your site templates) into the new
1620 directories and then move the backup off of the live
1623 Press ENTER to continue:|;
1626 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1632 my ($auto_install) = @_;
1633 #MJR: preserve old files, just in case
1639 print getmessage('CopyingFiles', ["old ".$desc,$tgt.strftime("%Y%m%d%H%M",localtime())]) unless ($auto_install->{NoPressEnter});
1641 system("mv ".$tgt." ".$tgt.strftime("%Y%m%d%H%M",localtime()));
1643 print getmessage('CopyingFiles', [$desc,$tgt]) unless ($auto_install->{NoPressEnter});
1645 system("cp -R ".$src." ".$tgt);
1648 my ($auto_install) = @_;
1649 showmessage(getmessage('InstallFiles'),'none') unless ($auto_install->{NoPressEnter});
1651 neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs");
1652 neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin");
1653 neatcopy("main scripts", 'scripts', "$intranetdir/scripts");
1654 neatcopy("perl modules", 'modules', "$intranetdir/modules");
1655 neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs");
1656 neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin");
1658 system("touch $opacdir/cgi-bin/opac");
1660 #MJR: is this necessary?
1662 system("chown -R $httpduser:$httpduser $opacdir $intranetdir");
1664 system("chmod -R a+rx $opacdir $intranetdir");
1666 # Create /etc/koha.conf
1668 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1669 open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
1675 intranetdir=$intranetdir
1677 kohalogdir=$kohalogdir
1678 kohaversion=$newversion
1679 httpduser=$httpduser
1680 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
1681 opachtdocs=$opacdir/htdocs/opac-tmpl
1687 #MJR: can't help but this be broken, can we?
1688 chmod 0440, "$etcdir/koha.conf.tmp";
1690 #MJR: does this contain any passwords?
1691 chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
1693 #MJR: generate our own settings, to remove the /home/paul hardwired links
1694 open(FILE,">$intranetdir/scripts/z3950daemon/z3950-daemon-options");
1695 print FILE "RunAsUser=$httpduser\nKohaZ3950Dir=$intranetdir/scripts/z3950daemon\nKohaModuleDir=$intranetdir/modules\nLogDir=$kohalogdir\nKohaConf=$etcdir/koha.conf";
1699 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1700 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1701 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
1702 } #MJR: report that we haven't chown()d.
1704 print "Please check permissions in $intranetdir/scripts/z3950daemon\n";
1706 showmessage(getmessage('OldFiles'),'PressEnter') unless $auto_install->{NoPressEnter};
1714 Finds out where the MySQL utitlities are located in the system,
1715 then create the Koha database structure and MySQL permissions.
1719 $messages->{'MysqlRootPassword'}->{en} =
1720 heading('MYSQL ROOT USER PASSWORD') . qq|
1721 To create the koha database, please enter your
1722 mysql server's root user password:
1726 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1727 Creating the MySQL database for Koha...
1731 $messages->{'CreatingDatabaseError'}->{en} =
1732 heading('ERROR CREATING DATABASE') . qq|
1733 Couldn't connect to the MySQL server for the reason given above.
1734 This is a serious problem, the database will not get installed.
1736 Press <ENTER> to continue: |; #'
1738 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1739 If you are installing Koha for evaluation purposes,
1740 you can install some sample data now.
1742 If you are installing Koha to use your own
1743 data, you probably don't want this sample data installed.
1745 Would you like to install the sample data? Y/[N]: |; #'
1747 $messages->{'SampleDataInstalled'}->{en} =
1748 heading('SAMPLE DATA INSTALLED') . qq|
1749 Sample data has been installed. For some suggestions on testing Koha, please
1750 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1751 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1752 question through the koha-devel mailing list, or you can check for a developer
1753 online at irc.katipo.co.nz:6667 channel #koha.
1755 You can find instructions for subscribing to the Koha mailing lists at:
1760 Press <ENTER> to continue: |;
1762 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1763 Would you like to describe an initial branch and printer? [Y]/N: |;
1765 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1766 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1767 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1768 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1771 my ($auto_install) = @_;
1772 $mysqluser = 'root';
1774 my $mysqldir = getmysqldir();
1776 if ($auto_install->{MysqlRootPassword}) {
1777 $mysqlpass=$auto_install->{MysqlRootPassword};
1779 # we must not put the mysql root password on the command line
1780 $mysqlpass= showmessage(getmessage('MysqlRootPassword'),'silentfree');
1783 showmessage(getmessage('CreatingDatabase'),'none') unless ($auto_install->{NoPressEnter});
1785 setmysqlclipass($mysqlpass);
1786 # Set up permissions
1788 print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");#"
1789 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 ('%','$database','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
1790 system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
1791 # Change to admin user login
1792 setmysqlclipass($pass);
1793 my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$database");
1795 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1797 # Create the database structure
1799 system("$mysqldir/bin/mysql -u$user $database < koha.mysql");
1805 =item updatedatabase
1809 Updates the Koha database structure, including the addition of
1812 The MARC tables are also populated in addition to being created.
1814 Because updatedatabase calls scripts/updater/updatedatabase to
1815 do the actual update, and that script uses C4::Context,
1816 $etcdir/koha.conf must exist at this point. We use the KOHA_CONF
1817 environment variable to do this.
1819 FIXME: (See checkabortedinstall as it depends on old symlink way.)
1823 $messages->{'UpdateMarcTables'}->{en} =
1824 heading('MARC FIELD DEFINITIONS') . qq|
1825 You can import MARC settings for:
1831 NOTE: If you choose N,
1832 nothing will be added, and you must create them all yourself.
1833 Only choose N if you want to use a MARC format not listed here,
1834 such as DANMARC. We would like to hear from you if you do.
1836 Choose MARC definition [1]: |;
1838 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGE') . qq|
1839 This version of koha supports a few languages.
1841 en : default language, all pages available
1842 fr : complete translation (except pictures)
1843 es : partial librarian site translation (including pictures)
1844 pl : complete OPAC and partial librarian translation
1845 zh_TW : partial translation
1847 en is used when a screen is not available in your language
1849 If you specify a language here, you can still
1850 change it from the system preferences screen in the librarian sit.
1852 Which language do you choose? |;
1854 sub updatedatabase {
1855 my ($auto_install) = @_;
1856 # At this point, $etcdir/koha.conf must exist, for C4::Context
1857 $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf';
1858 if (! -e $ENV{"KOHA_CONF"}) { $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp'; }
1860 my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase -s");
1863 print "Problem updating database...\n";
1867 if ($auto_install->{UpdateMarcTables}) {
1868 $response=$auto_install->{UpdateMarcTables};
1869 print ON_YELLOW.BLACK."auto-setting UpdateMarcTable to : $response".RESET."\n";
1871 $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
1874 if ($response eq '1') {
1875 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1876 system("cat scripts/misc/lang-datas/en/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
1878 if ($response eq '2') {
1879 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
1880 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
1882 delete($ENV{"KOHA_CONF"});
1884 print RESET."\nFinished updating of database. Press <ENTER> to continue..." unless ($auto_install->{NoPressEnter});
1885 <STDIN> unless ($auto_install->{NoPressEnter});
1889 =item populatedatabase
1893 Populate the non-MARC tables. If the user wants to install the
1894 sample data, install them.
1898 $messages->{'ConfirmFileUpload'}->{en} = qq|
1899 Confirm loading of this file into Koha [Y]/N: |;
1901 sub populatedatabase {
1902 my ($auto_install) = @_;
1906 if ($auto_install->{BranchName}) {
1907 $branch=$auto_install->{BranchName};
1908 print ON_YELLOW.BLACK."auto-setting a branch : $branch".RESET."\n";
1910 $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1911 unless ($response =~/^n/i) {
1912 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1913 $branch=~s/[^A-Za-z0-9\s]//g;
1917 my $branchcode=$branch;
1918 $branchcode=~s/[^A-Za-z0-9]//g;
1919 $branchcode=uc($branchcode);
1920 $branchcode=substr($branchcode,0,4);
1921 if ($auto_install->{BranchCode}) {
1922 $branchcode=$auto_install->{BranchCode};
1923 print ON_YELLOW.BLACK."auto-setting branch code : $branchcode".RESET."\n";
1925 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1927 $branchcode=~s/[^A-Za-z0-9]//g;
1928 $branchcode=uc($branchcode);
1929 $branchcode=substr($branchcode,0,4);
1930 $branchcode or $branchcode='DEF';
1933 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1934 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1935 system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1939 if ($auto_install->{PrinterName}) {
1940 $printername=$auto_install->{PrinterName};
1941 print ON_YELLOW.BLACK."auto-setting a printer : $printername".RESET."\n";
1943 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1944 $printername=~s/[^A-Za-z0-9\s]//g;
1946 if ($auto_install->{PrinterQueue}) {
1947 $printerqueue=$auto_install->{PrinterQueue};
1948 print ON_YELLOW.BLACK."auto-setting printer queue to : $printerqueue".RESET."\n";
1950 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1951 $printerqueue=~s/[^A-Za-z0-9]//g;
1954 system("$mysqldir/bin/mysql -u$user $database -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1957 if ($auto_install->{Language}) {
1958 $language=$auto_install->{Language};
1959 print ON_YELLOW.BLACK."auto-setting language to : $language".RESET."\n";
1961 $language=showmessage(getmessage('Language'), 'free', 'en');
1964 system("$mysqldir/bin/mysql -u$user $database -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1965 # CHECK for any other file to append...
1967 push @sql,"FINISHED";
1968 if (-d "scripts/misc/sql-datas") {
1969 opendir D, "scripts/misc/sql-datas";
1970 foreach my $sql (readdir D) {
1971 next unless ($sql =~ /.txt$/);
1976 while (not $loopend) {
1977 print heading("SELECT SQL FILE");
1979 Select a file to append to the Koha DB.
1980 enter a number. A detailled explanation of the file will be given
1981 if you confirm, the file will be added to the DB
1983 for (my $i=0;$i<=$#sql;$i++) {
1984 print "$i => ".$sql[$i]."\n";
1986 my $response =<STDIN>;
1990 # show the content of the file
1991 my $FileToUpload = $sql[$response];
1992 open FILE,"scripts/misc/sql-datas/$FileToUpload";
1993 my $content = <FILE>;
1994 print heading("INSERT $FileToUpload ?")."$content\n";
1996 $response=showmessage(getmessage('ConfirmFileUpload'), 'yn', 'y');
1997 # if confirmed, upload the file in the DB
1998 unless ($response =~/^n/i) {
1999 $FileToUpload =~ s/\.txt/\.sql/;
2000 system("$mysqldir/bin/mysql -u$user $database <scripts/misc/sql-datas/$FileToUpload");
2010 Asks the user whether to restart Apache, and restart it if the user
2015 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
2016 The web server daemon needs to be restarted to load the new configuration for Koha.
2017 The installer can do this if you are using Apache and give the root password.
2019 Would you like to try to restart Apache now? [Y]/N: |;
2022 my ($auto_install)=@_;
2024 $response=showmessage(getmessage('RestartApache'), 'yn', 'y') unless ($auto_install->{NoPressEnter});
2025 $response='y' if ($auto_install->{NoPressEnter});
2027 unless ($response=~/^n/i) {
2029 # Need to support other init structures here?
2030 if (-e "/etc/rc.d/init.d/httpd") {
2031 system('su root -c "/etc/rc.d/init.d/httpd restart"');
2032 } elsif (-e "/etc/init.d/apache") {
2033 system('su root -c "/etc/init.d/apache restart"');
2034 } elsif (-e "/etc/init.d/apache-ssl") {
2035 system('su root -c "/etc/init.d/apache-ssl restart"');
2044 This function attempts to back up all koha's details.
2048 $messages->{'BackupDir'}->{en} = heading('BACKUP STORAGE').qq|
2049 The upgrader will now try to backup your old files.
2051 Please specify a directory to store the backup in [%s]: |;
2053 $messages->{'BackupSummary'}->{en} = heading('BACKUP SUMMARY').qq|
2057 %6d biblioitems entries
2062 ---------------------------------------------------------------------
2064 ---------------------------------------------------------------------
2066 Does this look right? ([Y]/N): |;
2068 #FIXME: rewrite to use Install.pm
2070 my $backupdir=$ENV{'prefix'}.'/backups';
2072 my $answer = showmessage(getmessage('BackupDir',[$backupdir]),'free',$backupdir);
2074 if (! -e $backupdir) {
2075 my $result=mkdir ($backupdir, oct(770));
2077 my @dirs = split(m#/#, $backupdir);
2081 unless (-e "$checkdir") {
2082 mkdir($checkdir, 0775);
2088 chmod 0770, $backupdir;
2090 # Backup MySql database
2093 my $mysqldir = getmysqldir();
2095 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
2098 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
2100 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
2102 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
2105 my $bibliocounter=0;
2106 my $biblioitemcounter=0;
2107 my $membercounter=0;
2110 (/insert into items /i) && ($itemcounter++);
2111 (/insert into biblioitems /i) && ($biblioitemcounter++);
2112 (/insert into biblio /i) && ($bibliocounter++);
2113 (/insert into borrowers /i) && ($membercounter++);
2120 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
2122 $answer = showmessage(getmessage('BackupSummary',[$bibliocounter, $biblioitemcounter, $itemcounter, $membercounter, $filels]),'yn');
2124 if ($answer=~/^n/i) {
2127 Aborting. The database dump is located in:
2129 $backupdir/Koha.backup_$date
2134 print "Great! continuing upgrade... \n";
2141 =item finalizeconfigfile
2145 This function must be called when the installation is complete,
2146 to rename the koha.conf.tmp file to koha.conf.
2148 Currently, failure to rename the file results only in a warning.
2152 sub finalizeconfigfile {
2154 rename "$etcdir/koha.conf.tmp", "$etcdir/koha.conf"
2155 || showmessage(<<EOF, 'PressEnter', undef, 1);
2156 An unexpected error, $!, occurred
2157 while the Koha config file is being saved to its final location,
2160 Couldn't rename file at $etcdir. Must have write capability.
2162 Press Enter to continue.
2168 =item loadconfigfile
2172 Open the existing koha.conf file and get its values,
2173 saving the values to some global variables.
2175 If the existing koha.conf file cannot be opened for any reason,
2176 the file is silently ignored.
2180 sub loadconfigfile {
2183 #MJR: reverted to r1.53. Please call setetcdir(). Do NOT hardcode this.
2184 #FIXME: make a dated backup
2185 open (KC, "<$etcdir/koha.conf");
2188 (next) if (/^\s*#/);
2189 if (/(.*)\s*=\s*(.*)/) {
2192 # Clean up white space at beginning and end
2193 $variable=~s/^\s*//g;
2194 $variable=~s/\s*$//g;
2197 $configfile{$variable}=$value;
2201 #MJR: Reverted this too. You do not mess with my privates. Please ask for new functions if required.
2202 $intranetdir=$configfile{'intranetdir'};
2203 $opacdir=$configfile{'opacdir'};
2204 $kohaversion=$configfile{'kohaversion'};
2205 $kohalogdir=$configfile{'kohalogdir'};
2206 $database=$configfile{'database'};
2207 $hostname=$configfile{'hostname'};
2208 $user=$configfile{'user'};
2209 $pass=$configfile{'pass'};
2212 END { } # module clean-up code here (global destructor)
2214 ### These things may move
2218 my $t = POSIX::Termios->new;
2222 $t->setlflag(($t->getlflag) | &POSIX::ECHO);
2225 $t->setlflag(($t->getlflag) & !(&POSIX::ECHO));
2230 sub setmysqlclipass {
2232 open(MYCNF,">$mycnf");
2234 print MYCNF "[client]\npassword=$pass\n";
2240 rename $mycnf,$mytmpcnf;
2245 if (defined $mycnf && -e $mycnf) {
2248 if (defined $mytmpcnf && -e $mytmpcnf) {
2249 rename $mytmpcnf,$mycnf;