1 package Install; #assumes Install.pm
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
27 # set the version for version checking
31 @EXPORT = qw( &checkperlmodules
35 &releasecandidatewarning
36 &getinstallationdirectories
52 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
53 $messages->{'WelcomeToKohaInstaller'}->{en}=qq|
54 =================================
55 = Welcome to the Koha Installer =
56 =================================
58 Welcome to the Koha install script! This script will prompt you for some
59 basic information about your desired setup, then install Koha according to
60 your specifications. To accept the default value for any question, simply hit
63 Please be sure to read the documentation, or visit the Koha website at
64 http://www.koha.org for more information.
66 Are you ready to begin the installation? (Y/[N]): |;
67 $messages->{'ReleaseCandidateWarning'}->{en}=qq|
72 WARNING WARNING WARNING WARNING WARNING
74 You are about to install Koha version %s. This version of Koha is a
75 release candidate. It is not intended to be installed on production systems.
76 It is being released so that users can test it before we release a final
79 Are you sure you want to install Koha %s? (Y/[N]): |;
80 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
82 Watch for announcements of Koha releases on the Koha mailing list or the Koha
83 web site (http://www.koha.org/).
87 $messages->{'NETZ3950Missing'}->{en}=qq|
89 The Net::Z3950 module is missing. This module is necessary if you want to use
90 Koha's Z39.50 client to download bibliographic records from other libraries.
91 To install this module, you will need the yaz client installed from
92 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
95 perl -MCPAN -e 'install Net::Z3950'
97 Press the <ENTER> key to continue: |;
99 $messages->{'CheckingPerlModules'}->{en}=qq|
105 Checking perl modules ...
108 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
110 $messages->{'MissingPerlModules'}->{en}=qq|
112 ========================
113 = MISSING PERL MODULES =
114 ========================
116 You are missing some Perl modules which are required by Koha.
117 Once these modules have been installed, rerun this installer.
118 They can be installed by running (as root) the following:
123 $messages->{'AllPerlModulesInstalled'}->{en}=qq|
125 ==============================
126 = ALL PERL MODULES INSTALLED =
127 ==============================
129 All mandatory perl modules are installed.
131 Press <ENTER> to continue: |;
132 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
133 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
134 $messages->{'KohaAlreadyInstalled'}->{en}=qq|
135 ==========================
136 = Koha already installed =
137 ==========================
139 It looks like Koha is already installed on your system (%s/koha.conf exists
140 already). If you would like to upgrade your system to %s, please use
141 the koha.upgrade script in this directory.
146 $messages->{'GetOpacDir'}->{en}=qq|
151 Please supply the directory you want Koha to store its OPAC files in. This
152 directory will be auto-created for you if it doesn't exist.
154 OPAC Directory [%s]: |;
156 $messages->{'GetIntranetDir'}->{en}=qq|
157 =================================
158 = INTRANET/LIBRARIANS DIRECTORY =
159 =================================
161 Please supply the directory you want Koha to store its Intranet/Librarians
162 files in. This directory will be auto-created for you if it doesn't exist.
164 Intranet Directory [%s]: |;
166 $messages->{'GetKohaLogDir'}->{en}=qq|
167 ======================
168 = KOHA LOG DIRECTORY =
169 ======================
171 Specify a log directory where any Koha daemons can create log files.
173 Koha Log Directory [%s]: |;
175 $messages->{'AuthenticationWarning'}->{en}=qq|
180 This release of Koha has a new authentication module. If you are not already
181 using basic authentication on your intranet, you will be required to log in to
182 access some of the features of the intranet. You can log in using the userid
183 and password from the %s/koha.conf configuration file at any time. Use the
184 "Members" module to add passwords for other accounts and set their permissions.
186 Press the <ENTER> key to continue: |;
188 $messages->{'Completed'}->{en}=qq|
189 ==============================
190 = KOHA INSTALLATION COMPLETE =
191 ==============================
193 Congratulations ... your Koha installation is complete!
195 You will be able to connect to your Librarian interface at:
199 and the OPAC interface at :
203 Be sure to read the INSTALL, and Hints files.
205 For more information visit http://www.koha.org
207 Press <ENTER> to exit the installer: |;
209 sub releasecandidatewarning {
210 my $message=getmessage('ReleaseCandidateWarning', [$::newversion, $::newversion]);
211 my $answer=showmessage($message, 'yn', 'n');
213 if ($answer =~ /y/i) {
214 print getmessage('continuing');
216 my $message=getmessage('WatchForReleaseAnnouncements');
227 Does the equivalent of dirname(1). Given a path $path, return the
228 parent directory of $path (best guess), except when $path seems to
229 be the same as /, in which case $path itself is returned unchanged.
235 if ($path =~ /[^\/]/s) {
237 $path =~ s/\/+[^\/]+\/*$//s;
248 mkdir_parents $path, $mode;
250 Does the equivalent of mkdir -p. Given a path $path, create the path
251 $path, recursively creating any intermediate directories. If $mode
252 is given, the directory will be created with mode $mode.
254 WARNING: If $path already exists, mkdir_parents will just return
255 successfully (just like mkdir -p), whether the mode of $path conforms
260 sub mkdir_parents ($;$) {
261 my($path, $mode) = @_;
262 my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
264 if (!$ok && $! == ENOENT) {
265 my $parent = dirname($path);
266 $ok = mkdir_parents($parent, $mode);
268 # retry and at the same time make sure that $! is set correctly
269 $ok = defined $mode? mkdir($path, $mode): mkdir($path);
274 =item checkabortedinstall
278 Assuming that Koha will be installed on a modern Unix with symlinks,
279 it is possible to code the installer so that aborted installs can be
280 detected. In case of such an event we can do our best to "roll back"
283 FIXME: The "roll back" is not complete!
287 sub checkabortedinstall () {
288 if (-l("$::etcdir/koha.conf")
289 && readlink("$::etcdir/koha.conf") =~ /\.tmp$/
292 I have detected that you tried to install Koha before, but the installation
293 was aborted. I will try to continue, but there might be problems if the
294 database is already created.
297 print "Please press <ENTER> to continue: ";
300 # Remove the symlink after the <STDIN>, so the user can back out
301 unlink "$::etcdir/koha.conf"
302 || die "Failed to remove incomplete $::etcdir/koha.conf: $!\n";
307 # Test for Perl and Modules
310 sub checkperlmodules {
311 my $message = getmessage('CheckingPerlModules');
312 showmessage($message, 'none');
314 unless (eval "require 5.006_000") {
315 die getmessage('PerlVersionFailure', ['5.6.0']);
319 unless (eval {require DBI}) { push @missing,"DBI" };
320 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
321 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
322 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
323 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
324 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
325 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
326 unless (eval {require Net::Z3950}) {
327 my $message = getmessage('NETZ3950Missing');
328 showmessage($message, 'PressEnter', '', 1);
330 push @missing, "Net::Z3950";
335 # Print out a list of any missing modules
340 foreach my $module (@missing) {
341 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
343 my $message=getmessage('MissingPerlModules', [$missing]);
344 showmessage($message, 'none');
347 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
351 unless (-x "/usr/bin/perl") {
352 my $realperl=`which perl`;
354 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
355 until (-x $realperl) {
356 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
358 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
359 unless ($response eq 'n') {
360 system("ln -s $realperl /usr/bin/perl");
367 $messages->{'NoUsrBinPerl'}->{en}=qq|
369 ========================================
370 = Perl is not located in /usr/bin/perl =
371 ========================================
373 The Koha perl scripts expect to find the perl executable in the /usr/bin
374 directory. It is not there on your system.
378 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
379 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
380 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
382 May I create this symlink? ([Y]/N):
386 my $messagename=shift;
388 my $message=$messages->{$messagename}->{$::language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
389 if (defined($variables)) {
390 $message=sprintf $message, @$variables;
398 my $responsetype=shift;
399 my $defaultresponse=shift;
401 ($noclear) || (system('clear'));
402 if ($responsetype =~ /^yn$/) {
403 $responsetype='restrictchar yn';
407 if ($responsetype =~/^restrictchar (.*)/i) {
410 until ($options=~/$response/) {
411 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
414 (length($response)) || ($response=$defaultresponse);
415 unless ($options=~/$response/) {
416 ($noclear) || (system('clear'));
417 print "Invalid Response. Choose from [$options].\n\n";
423 if ($responsetype =~/^free$/i) {
424 (defined($defaultresponse)) || ($defaultresponse='');
425 my $response=<STDIN>;
427 ($response) || ($response=$defaultresponse);
430 if ($responsetype =~/^numerical$/i) {
431 (defined($defaultresponse)) || ($defaultresponse='');
433 until ($response=~/^\d+$/) {
436 ($response) || ($response=$defaultresponse);
437 unless ($response=~/^\d+$/) {
438 ($noclear) || (system('clear'));
439 print "Invalid Response ($response). Response must be a number.\n\n";
445 if ($responsetype =~/^email$/i) {
446 (defined($defaultresponse)) || ($defaultresponse='');
448 until ($response=~/.*\@.*\..*/) {
451 ($response) || ($response=$defaultresponse);
452 unless ($response=~/.*\@.*\..*/) {
453 ($noclear) || (system('clear'));
454 print "Invalid Response ($response). Response must be a valid email address.\n\n";
460 if ($responsetype =~/^PressEnter$/i) {
464 if ($responsetype =~/^none$/i) {
470 sub getinstallationdirectories {
471 $::opacdir = '/usr/local/koha/opac';
472 $::intranetdir = '/usr/local/koha/intranet';
474 while ($getdirinfo) {
475 # Loop until opac directory and koha directory are different
476 my $message=getmessage('GetOpacDir', [$::opacdir]);
477 $::opacdir=showmessage($message, 'free', $::opacdir);
479 $message=getmessage('GetIntranetDir', [$::intranetdir]);
480 $::intranetdir=showmessage($message, 'free', $::intranetdir);
482 if ($::intranetdir eq $::opacdir) {
485 You must specify different directories for the OPAC and INTRANET files!
486 :: $::intranetdir :: $::opacdir ::
493 $::kohalogdir='/var/log/koha';
494 my $message=getmessage('GetKohaLogDir', [$::kohalogdir]);
495 $::kohalogdir=showmessage($message, 'free', $::kohalogdir);
498 # FIXME: Missing error handling for all mkdir calls here
499 unless ( -d $::intranetdir ) {
500 mkdir_parents (dirname($::intranetdir), 0775);
501 mkdir ($::intranetdir, 0770);
502 chown (oct(0), (getgrnam($::httpduser))[2], "$::intranetdir");
503 chmod (oct(770), "$::intranetdir");
505 mkdir_parents ("$::intranetdir/htdocs", 0750);
506 mkdir_parents ("$::intranetdir/cgi-bin", 0750);
507 mkdir_parents ("$::intranetdir/modules", 0750);
508 mkdir_parents ("$::intranetdir/scripts", 0750);
509 unless ( -d $::opacdir ) {
510 mkdir_parents (dirname($::opacdir), 0775);
511 mkdir ($::opacdir, 0770);
512 chown (oct(0), (getgrnam($::httpduser))[2], "$::opacdir");
513 chmod (oct(770), "$::opacdir");
515 mkdir_parents ("$::opacdir/htdocs", 0750);
516 mkdir_parents ("$::opacdir/cgi-bin", 0750);
519 unless ( -d $::kohalogdir ) {
520 mkdir_parents (dirname($::kohalogdir), 0775);
521 mkdir ($::kohalogdir, 0770);
522 chown (oct(0), (getgrnam($::httpduser))[2,3], "$::kohalogdir");
523 chmod (oct(770), "$::kohalogdir");
529 $messages->{'DatabaseName'}->{en}=qq|
530 ==========================
531 = Name of MySQL database =
532 ==========================
534 Please provide the name of the mysql database for your koha installation.
536 Database name [%s]: |;
538 $messages->{'DatabaseHost'}->{en}=qq|
543 Please provide the hostname for mysql. Unless the database is located on
544 another machine this will be "localhost".
546 Database host [%s]: |;
548 $messages->{'DatabaseUser'}->{en}=qq|
553 Please provide the name of the user, who will have full administrative rights
554 to the %s database, when authenticating from %s.
556 This user will also be used to access Koha's INTRANET interface.
558 Database user [%s]: |;
560 $messages->{'DatabasePassword'}->{en}=qq|
561 =====================
562 = Database Password =
563 =====================
565 Please provide a good password for the user %s.
567 Database Password: |;
569 $messages->{'BlankPassword'}->{en}=qq|
574 You must not use a blank password for your MySQL user!
576 Press <ENTER> to try again:
579 sub getdatabaseinfo {
582 $::hostname = 'localhost';
583 $::user = 'kohaadmin';
586 #Get the database name
588 my $message=getmessage('DatabaseName', [$::dbname]);
589 $::dbname=showmessage($message, 'free', $::dbname);
591 #Get the hostname for the database
593 $message=getmessage('DatabaseHost', [$::hostname]);
594 $::hostname=showmessage($message, 'free', $::hostname);
596 #Get the username for the database
598 $message=getmessage('DatabaseUser', [$::dbname, $::hostname, $::user]);
599 $::user=showmessage($message, 'free', $::user);
601 #Get the password for the database user
603 while ($::pass eq '') {
604 my $message=getmessage('DatabasePassword', [$::user]);
605 $::pass=showmessage($message, 'free', $::pass);
607 my $message=getmessage('BlankPassword');
608 showmessage($message,'PressEnter');
615 $messages->{'FoundMultipleApacheConfFiles'}->{en}=qq|
616 ================================
617 = MULTIPLE APACHE CONFIG FILES =
618 ================================
620 I found more than one possible Apache configuration file:
624 Choose the correct file [1]: |;
626 $messages->{'NoApacheConfFiles'}->{en}=qq|
627 ===============================
628 = NO APACHE CONFIG FILE FOUND =
629 ===============================
631 I was not able to find your Apache configuration file.
633 The file is usually called httpd.conf or apache.conf.
635 Please specify the location of your config file: |;
637 $messages->{'NotAFile'}->{en}=qq|
638 =======================
639 = FILE DOES NOT EXIST =
640 =======================
642 The file %s does not exist.
644 Please press <ENTER> to continue: |;
646 $messages->{'EnterApacheUser'}->{en}=qq|
651 I was not able to determine the user that Apache is running as. This
652 information is necessary in order to set the access privileges correctly on
653 %s/koha.conf. This user should be set in one of the Apache configuration
654 files using the "User" directive.
656 Enter the Apache userid: |;
658 $messages->{'InvalidUserid'}->{en}=qq|
663 The userid %s is not a valid userid on this system.
665 Press <ENTER> to continue: |;
668 my @confpossibilities;
670 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
671 /usr/local/etc/apache/httpd.conf
672 /usr/local/etc/apache/apache.conf
673 /var/www/conf/httpd.conf
674 /etc/apache/conf/httpd.conf
675 /etc/apache/conf/apache.conf
676 /etc/apache-ssl/conf/apache.conf
677 /etc/apache-ssl/httpd.conf
678 /etc/httpd/conf/httpd.conf
679 /etc/httpd/httpd.conf)) {
680 if ( -f $httpdconf ) {
681 push @confpossibilities, $httpdconf;
685 if ($#confpossibilities==-1) {
686 my $message=getmessage('NoApacheConfFiles');
688 until (-f $::realhttpdconf) {
689 $choice=showmessage($message, "free", 1);
691 $::realhttpdconf=$choice;
693 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
696 } elsif ($#confpossibilities>0) {
700 foreach (@confpossibilities) {
701 $conffiles.=" $counter: $_\n";
702 $options.="$counter";
705 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
706 my $choice=showmessage($message, "restrictchar $options", 1);
707 $::realhttpdconf=$confpossibilities[$choice-1];
709 $::realhttpdconf=$confpossibilities[0];
711 unless (open (HTTPDCONF, "<$::realhttpdconf")) {
712 warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
716 while (<HTTPDCONF>) {
717 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
726 unless ($::httpduser) {
727 my $message=getmessage('EnterApacheUser', [$::etcdir]);
728 until (length($::httpduser) && getpwnam($::httpduser)) {
729 $::httpduser=showmessage($message, "free", '');
730 if (length($::httpduser)>0) {
731 unless (getpwnam($::httpduser)) {
732 my $message=getmessage('InvalidUserid', [$::httpduser]);
733 showmessage($message,'PressEnter');
738 print "AU: $::httpduser\n";
743 $messages->{'ApacheConfigIntroduction'}->{en}=qq|
744 ========================
745 = APACHE CONFIGURATION =
746 ========================
748 Koha needs to setup your Apache configuration file for the
749 OPAC and LIBRARIAN virtual hosts. By default this installer
750 will do this by using one ip address and two different ports
751 for the virtual hosts. There are other ways to set this up,
752 and the installer will leave comments in httpd.conf detailing
753 what these other options are.
756 Press <ENTER> to continue: |;
758 $messages->{'GetVirtualHostEmail'}->{en}=qq|
759 =============================
760 = WEB SERVER E-MAIL CONTACT =
761 =============================
763 Enter the e-mail address to be used as a contact for the virtual hosts (this
764 address is displayed if any errors are encountered).
766 E-mail contact [%s]: |;
768 $messages->{'GetServerName'}->{en}=qq|
769 ======================================
770 = WEB SERVER HOST NAME OR IP ADDRESS =
771 ======================================
773 Please enter the domain name or ip address of your computer.
775 Host name or IP Address [%s]: |;
777 $messages->{'GetOpacPort'}->{en}=qq|
778 ==========================
779 = OPAC VIRTUAL HOST PORT =
780 ==========================
782 Please enter the port for your OPAC interface. This defaults to port 80, but
783 if you are already serving web content from this server, you should change it
784 to a different port (8000 might be a good choice).
786 Enter the OPAC Port [%s]: |;
788 $messages->{'GetIntranetPort'}->{en}=qq|
789 ==============================
790 = INTRANET VIRTUAL HOST PORT =
791 ==============================
793 Please enter the port for your Intranet interface. This must be different from
796 Enter the Intranet Port [%s]: |;
799 sub getapachevhostinfo {
801 $::svr_admin = "webmaster\@$::domainname";
802 $::servername=`hostname`;
805 $::intranetport=8080;
807 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
809 $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
810 $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
813 $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
814 $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
818 $messages->{'StartUpdateApache'}->{en}=qq|
819 =================================
820 = UPDATING APACHE CONFIGURATION =
821 =================================
823 Checking for modules that need to be loaded...
826 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
828 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
830 $messages->{'ApacheConfigBackupFailed'}->{en}=qq|
831 ======================================
832 = APACHE CONFIGURATION BACKUP FAILED =
833 ======================================
835 An error occurred while trying to make a backup copy of %s.
839 No changes will be made to the apache configuration file at this time.
841 Press <ENTER> to continue: |;
844 $messages->{'ApacheAlreadyConfigured'}->{en}=qq|
845 =============================
846 = APACHE ALREADY CONFIGURED =
847 =============================
849 %s appears to already have an entry for Koha
850 Virtual Hosts. You may need to edit %s
851 f anything has changed since it was last set up. This
852 script will not attempt to modify an existing Koha apache
855 Press <ENTER> to continue: |;
857 sub updateapacheconf {
858 my $logfiledir=`grep ^ErrorLog "$::realhttpdconf"`;
862 $logfiledir=~m#ErrorLog (.*)/[^/]*$#
863 or die "Can't parse ErrorLog directive\n";
867 unless ($logfiledir) {
871 showmessage(getmessage('StartUpdateApache'), 'none');
875 my $includesmodule=0;
876 open HC, "<$::realhttpdconf";
878 if (/^\s*#\s*LoadModule env_module /) {
880 showmessage(getmessage('LoadingApacheModuleModEnv'));
883 if (/^\s*#\s*LoadModule includes_module /) {
885 showmessage(getmessage('LoadingApacheModuleModInc'));
887 if (/\s*LoadModule includes_module / ) {
894 $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
896 showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
900 if ($envmodule || $includesmodule) {
901 open HC, ">$::realhttpdconf";
908 if (`grep 'VirtualHost $::servername' "$::realhttpdconf"`) {
909 showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
912 my $includesdirectives='';
913 if ($includesmodule) {
914 $includesdirectives.="Options +Includes\n";
915 $includesdirectives.=" AddHandler server-parsed .html\n";
917 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
919 if ($::opacport != 80) {
920 $opaclisten="Listen $::opacport";
922 my $intranetlisten = '';
923 if ($::intranetport != 80) {
924 $intranetlisten="Listen $::intranetport";
928 # Ports to listen to for Koha
932 # NameVirtualHost is used by one of the optional configurations detailed below
934 #NameVirtualHost 11.22.33.44
936 # KOHA's OPAC Configuration
937 <VirtualHost $::servername\:$::opacport>
938 ServerAdmin $::svr_admin
939 DocumentRoot $::opacdir/htdocs
940 ServerName $::servername
941 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
942 ErrorLog $logfiledir/opac-error_log
943 TransferLog $logfiledir/opac-access_log
944 SetEnv PERL5LIB "$::intranetdir/modules"
948 # KOHA's INTRANET Configuration
949 <VirtualHost $::servername\:$::intranetport>
950 ServerAdmin $::svr_admin
951 DocumentRoot $::intranetdir/htdocs
952 ServerName $::servername
953 ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
954 ErrorLog $logfiledir/koha-error_log
955 TransferLog $logfiledir/koha-access_log
956 SetEnv PERL5LIB "$::intranetdir/modules"
960 # If you want to use name based Virtual Hosting:
961 # 1. remove the two Listen lines
962 # 2. replace $::servername\:$::opacport wih your.opac.domain.name
963 # 3. replace ServerName $::servername wih ServerName your.opac.domain.name
964 # 4. replace $::servername\:$::intranetport wih your intranet domain name
965 # 5. replace ServerName $::servername wih ServerName your.intranet.domain.name
967 # If you want to use NameVirtualHost'ing (using two names on one ip address):
968 # 1. Follow steps 1-5 above
969 # 2. Uncomment the NameVirtualHost line and set the correct ip address
977 $messages->{'IntranetAuthenticationQuestion'}->{en}=qq|
978 ===========================
979 = INTRANET AUTHENTICATION =
980 ===========================
982 I can set it up so that the Intranet/Librarian site is password protected using
983 Apache's Basic Authorization.
985 This is going to be phased out very soon. However, setting this up can provide
986 an extra layer of security before the new authentication system is completely
989 Would you like to do this ([Y]/N): |;
991 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
992 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
993 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
995 sub basicauthentication {
996 my $message=getmessage('IntranetAuthenticationQuestion');
997 my $answer=showmessage($message, 'yn', 'y');
999 my $apacheauthusername='librarian';
1000 my $apacheauthpassword='';
1001 if ($answer=~/^y/i) {
1002 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1003 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1004 while (! $apacheauthpassword) {
1005 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1006 if (!$apacheauthpassword) {
1007 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1010 open AUTH, ">$::etcdir/kohaintranet.pass";
1011 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1012 my $salt=substr($chars, int(rand(length($chars))),1);
1013 $salt.=substr($chars, int(rand(length($chars))),1);
1014 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1016 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
1019 <Directory $::intranetdir>
1020 AuthUserFile $::etcdir/kohaintranet.pass
1022 AuthName "Koha Intranet (for librarians only)"
1030 $messages->{'InstallFiles'}->{en}=qq|
1031 ====================
1032 = INSTALLING FILES =
1033 ====================
1035 Copying files to installation directories:
1040 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1047 showmessage(getmessage('InstallFiles'),'none');
1048 print getmessage('CopyingFiles', ['intranet-html', "$::intranetdir/htdocs" ]);
1049 system("cp -R intranet-html/* $::intranetdir/htdocs/");
1050 print getmessage('CopyingFiles', ['intranet-cgi', "$::intranetdir/cgi-bin" ]);
1051 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
1052 print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
1053 system("cp -R scripts/* $::intranetdir/scripts/");
1054 print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
1055 system("cp -R modules/* $::intranetdir/modules/");
1056 print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
1057 system("cp -R opac-html/* $::opacdir/htdocs/");
1058 print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
1059 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
1060 system("touch $::opacdir/cgi-bin/opac");
1062 system("chown -R root:$::httpduser $::opacdir");
1063 system("chown -R root:$::httpduser $::intranetdir");
1065 # Create /etc/koha.conf
1067 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1068 open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1071 hostname=$::hostname
1074 includes=$::opacdir/htdocs/includes
1075 intranetdir=$::intranetdir
1077 kohalogdir=$::kohalogdir
1078 kohaversion=$::kohaversion
1079 httpduser=$::httpduser
1080 intrahtdocs=$::intranetdir/htdocs/intranet-tmpl
1081 opachtdocs=$::opacdir/htdocs/opac-tmpl
1086 chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1087 chmod 0440, "$::etcdir/koha.conf.tmp";
1089 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1090 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1091 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
1092 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1093 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
1097 $messages->{'MysqlRootPassword'}->{en}=qq|
1098 ============================
1099 = MYSQL ROOT USER PASSWORD =
1100 ============================
1102 To allow us to create the koha database please supply your
1103 mysql server's root user password:
1105 Enter MySQL root user password: |;
1107 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password. Please try again.";
1109 $messages->{'CreatingDatabase'}->{en}=qq|
1110 =====================
1111 = CREATING DATABASE =
1112 =====================
1114 Creating the MySQL database for Koha...
1118 $messages->{'CreatingDatabaseError'}->{en}=qq|
1119 ===========================
1120 = ERROR CREATING DATABASE =
1121 ===========================
1123 Couldn't connect to the MySQL server for the reason given above.
1124 This is a serious problem, the database will not get installed.
\a
1126 Press <ENTER> to continue: |;
1128 $messages->{'SampleData'}->{en}=qq|
1133 If you are installing Koha for evaluation purposes, I have a batch of sample
1134 data that you can install now.
1136 If you are installing Koha with the intention of populating it with your own
1137 data, you probably don't want this sample data installed.
1139 Would you like to install the sample data? Y/[N]: |;
1141 $messages->{'SampleDataInstalled'}->{en}=qq|
1142 =========================
1143 = SAMPLE DATA INSTALLED =
1144 =========================
1146 Sample data has been installed. For some suggestions on testing Koha, please
1147 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1148 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1149 question through the koha-devel mailing list, or you can check for a developer
1150 online at +irc.katipo.co.nz:6667 channel #koha.
1152 You can find instructions for subscribing to the Koha mailing lists at:
1157 Press <ENTER> to continue: |;
1159 $messages->{'AddBranchPrinter'}->{en}=qq|
1160 ==========================
1161 = Add Branch and Printer =
1162 ==========================
1164 Would you like to install an initial branch and printer? [Y]/N: |;
1166 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1167 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1168 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1169 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1170 $messages->{'BlankMysqlPassword'}->{en}=qq|
1171 ========================
1172 = Blank MySql Password =
1173 ========================
1175 Do not leave your MySql root password blank unless you know exactly what you
1176 are doing. To change your MySql root password use the mysqladmin command:
1178 mysqladmin password NEWPASSWORDHERE
1180 Press <ENTER> to continue:
1184 $::mysqluser = 'root';
1187 foreach my $mysql (qw(/usr/local/mysql
1191 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1196 print "I don't see mysql in the usual places.\n";
1198 print "Where have you installed mysql? ";
1199 chomp($::mysqldir = <STDIN>);
1200 last if -f "$::mysqldir/bin/mysqladmin";
1203 I can't find it there either. If you compiled mysql yourself,
1204 please give the value of --prefix when you ran configure.
1206 The file mysqladmin should be in bin/mysqladmin under the directory that you
1215 while ($needpassword) {
1216 $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1217 $::mysqlpass_quoted = $::mysqlpass;
1218 $::mysqlpass_quoted =~ s/"/\\"/g;
1219 $::mysqlpass_quoted="-p\"$::mysqlpass_quoted\"";
1220 $::mysqlpass eq '' and $::mysqlpass_quoted='';
1221 my $result=system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted proc > /dev/null 2>&1");
1223 print getmessage('InvalidMysqlRootPassword');
1225 if ($::mysqlpass eq '') {
1226 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1232 showmessage(getmessage('CreatingDatabase'),'none');
1234 my $result=system("$::mysqldir/bin/mysqladmin", "-u$::mysqluser", "-p$::mysqlpass", "create", "$::dbname");
1236 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1238 # Populate the Koha database
1239 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname < koha.mysql");
1240 # Set up permissions
1241 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1242 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$::dbname','$::user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
1243 system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted reload");
1253 $messages->{'UpdateMarcTables'}->{en}=qq|
1254 =========================================
1255 = UPDATING MARC FIELD DEFINITION TABLES =
1256 =========================================
1258 You can import marc parameters for :
1264 Please choose which parameter you want to install. Note if you choose 3,
1265 nothing will be added, and it can be a BIG job to manually create those tables
1267 Choose MARC definition [1]: |;
1269 $messages->{'Language'}->{en}=qq|
1270 ====================
1271 = CHOOSE LANGUAGES =
1272 ====================
1273 This version of koha supports a few languages.
1274 Enter you languages preferences : either en, fr, es or pl.
1275 Note that the en is always choosen when the system does not finds the
1276 language you choose in a specific screen.
1277 fr : opac is translated (except pictures)
1278 es : a few intranet is translated (including pictures)
1279 pl : opac is translated (UNTESTED in this release)
1282 sub updatedatabase {
1283 # At this point, $::etcdir/koha.conf must exist, for C4::Context
1284 # We must somehow temporarily enable $::etcdir/koha.conf. A symlink can
1285 # do this & at the same time facilitate detection of aborted installs.
1286 my $result=system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1288 print "Problem updating database...\n";
1292 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 123', '1');
1294 if ($response == 1) {
1295 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1297 if ($response == 2) {
1298 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1299 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1302 $result = system ("perl -I $::intranetdir/modules scripts/marc/updatedb2marc.pl");
1304 print "Problem updating database to MARC...\n";
1308 print "\n\nFinished updating of database. Press <ENTER> to continue...";
1312 sub populatedatabase {
1313 my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1314 if ($response =~/^y/i) {
1315 system("gunzip -d < sampledata-1.2.gz | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1316 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1317 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1318 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1319 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1320 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1323 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1325 unless ($response =~/^n/i) {
1326 my $branch='Main Library';
1327 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1328 $branch=~s/[^A-Za-z0-9\s]//g;
1330 my $branchcode=$branch;
1331 $branchcode=~s/[^A-Za-z0-9]//g;
1332 $branchcode=uc($branchcode);
1333 $branchcode=substr($branchcode,0,4);
1334 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1335 $branchcode=~s/[^A-Za-z0-9]//g;
1336 $branchcode=uc($branchcode);
1337 $branchcode=substr($branchcode,0,4);
1338 $branchcode or $branchcode='DEF';
1340 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1341 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1342 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1344 my $printername='Library Printer';
1345 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1346 $printername=~s/[^A-Za-z0-9\s]//g;
1348 my $printerqueue='lp';
1349 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1350 $printerqueue=~s/[^A-Za-z0-9]//g;
1351 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1353 my $language=showmessage(getmessage('Language'), 'free', 'en');
1354 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1358 $messages->{'RestartApache'}->{en}=qq|
1363 Apache needs to be restarted to load the new configuration for Koha.
1365 Would you like to restart Apache now? [Y]/N: |;
1369 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1373 unless ($response=~/^n/i) {
1374 # Need to support other init structures here?
1375 if (-e "/etc/rc.d/init.d/httpd") {
1376 system('/etc/rc.d/init.d/httpd restart');
1377 } elsif (-e "/etc/init.d/apache") {
1378 system('/etc//init.d/apache restart');
1379 } elsif (-e "/etc/init.d/apache-ssl") {
1380 system('/etc/init.d/apache-ssl restart');
1387 sub loadconfigfile {
1390 open (KC, "<$::etcdir/koha.conf");
1393 (next) if (/^\s*#/);
1394 if (/(.*)\s*=\s*(.*)/) {
1397 # Clean up white space at beginning and end
1398 $variable=~s/^\s*//g;
1399 $variable=~s/\s*$//g;
1402 $configfile{$variable}=$value;
1406 $::intranetdir=$configfile{'intranetdir'};
1407 $::opacdir=$configfile{'opacdir'};
1408 $::kohaversion=$configfile{'kohaversion'};
1409 $::kohalogdir=$configfile{'kohalogdir'};
1410 $::database=$configfile{'database'};
1411 $::hostname=$configfile{'hostname'};
1412 $::user=$configfile{'user'};
1413 $::pass=$configfile{'pass'};
1416 END { } # module clean-up code here (global destructor)