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
24 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
26 # set the version for version checking
30 @EXPORT = qw( &checkperlmodules
33 &releasecandidatewarning
34 &getinstallationdirectories
50 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
51 $messages->{'WelcomeToKohaInstaller'}->{en}=qq|
52 =================================
53 = Welcome to the Koha Installer =
54 =================================
56 Welcome to the Koha install script! This script will prompt you for some
57 basic information about your desired setup, then install Koha according to
58 your specifications. To accept the default value for any question, simply hit
61 Please be sure to read the documentation, or visit the Koha website at
62 http://www.koha.org for more information.
64 Are you ready to begin the installation? (Y/[N]): |;
65 $messages->{'ReleaseCandidateWarning'}->{en}=qq|
70 WARNING WARNING WARNING WARNING WARNING
72 You are about to install Koha version %s. This version of Koha is a
73 release candidate. It is not intended to be installed on production systems.
74 It is being released so that users can test it before we release a final
77 Are you sure you want to install Koha %s? (Y/[N]): |;
78 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
80 Watch for announcements of Koha releases on the Koha mailing list or the Koha
81 web site (http://www.koha.org/).
85 $messages->{'NETZ3950Missing'}->{en}=qq|
87 The Net::Z3950 module is missing. This module is necessary if you want to use
88 Koha's Z39.50 client to download bibliographic records from other libraries.
89 To install this module, you will need the yaz client installed from
90 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
93 perl -MCPAN -e 'install Net::Z3950'
95 Press the <ENTER> key to continue: |;
97 $messages->{'CheckingPerlModules'}->{en}=qq|
103 Checking perl modules ...
106 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
108 $messages->{'MissingPerlModules'}->{en}=qq|
110 ========================
111 = MISSING PERL MODULES =
112 ========================
114 You are missing some Perl modules which are required by Koha.
115 Once these modules have been installed, rerun this installer.
116 They can be installed by running (as root) the following:
121 $messages->{'AllPerlModulesInstalled'}->{en}=qq|
123 ==============================
124 = ALL PERL MODULES INSTALLED =
125 ==============================
127 All mandatory perl modules are installed.
129 Press <ENTER> to continue: |;
130 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
131 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
132 $messages->{'KohaAlreadyInstalled'}->{en}=qq|
133 ==========================
134 = Koha already installed =
135 ==========================
137 It looks like Koha is already installed on your system (/etc/koha.conf exists
138 already). If you would like to upgrade your system to %s, please use
139 the koha.upgrade script in this directory.
144 $messages->{'GetOpacDir'}->{en}=qq|
149 Please supply the directory you want Koha to store its OPAC files in. This
150 directory will be auto-created for you if it doesn't exist.
152 OPAC Directory [%s]: |;
154 $messages->{'GetIntranetDir'}->{en}=qq|
155 =================================
156 = INTRANET/LIBRARIANS DIRECTORY =
157 =================================
159 Please supply the directory you want Koha to store its Intranet/Librarians
160 files in. This directory will be auto-created for you if it doesn't exist.
162 Intranet Directory [%s]: |;
164 $messages->{'GetKohaLogDir'}->{en}=qq|
165 ======================
166 = KOHA LOG DIRECTORY =
167 ======================
169 Specify a log directory where any Koha daemons can create log files.
171 Koha Log Directory [%s]: |;
173 $messages->{'AuthenticationWarning'}->{en}=qq|
178 This release of Koha has a new authentication module. If you are not already
179 using basic authentication on your intranet, you will be required to log in to
180 access some of the features of the intranet. You can log in using the userid
181 and password from the /etc/koha.conf configuration file at any time. Use the
182 "Members" module to add passwords for other accounts and set their permissions.
184 Press the <ENTER> key to continue: |;
186 $messages->{'Completed'}->{en}=qq|
187 ==============================
188 = KOHA INSTALLATION COMPLETE =
189 ==============================
191 Congratulations ... your Koha installation is complete!
193 You will be able to connect to your Librarian interface at:
197 and the OPAC interface at :
202 Be sure to read the INSTALL, and Hints files.
204 For more information visit http://www.koha.org
206 Press <ENTER> to exit the installer: |;
208 sub releasecandidatewarning {
209 my $message=getmessage('ReleaseCandidateWarning', [$::newversion, $::newversion]);
210 my $answer=showmessage($message, 'yn', 'n');
212 if ($answer =~ /y/i) {
213 print getmessage('continuing');
215 my $message=getmessage('WatchForReleaseAnnouncements');
223 # Test for Perl and Modules
226 sub checkperlmodules {
227 my $message = getmessage('CheckingPerlModules');
228 showmessage($message, 'none');
230 unless (eval "require 5.006_000") {
231 die getmessage('PerlVersionFailure', ['5.6.0']);
235 unless (eval {require DBI}) { push @missing,"DBI" };
236 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
237 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
238 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
239 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
240 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
241 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
242 unless (eval {require Net::Z3950}) {
243 my $message = getmessage('NETZ3950Missing');
244 showmessage($message, 'PressEnter', '', 1);
246 push @missing, "Net::Z3950";
251 # Print out a list of any missing modules
256 foreach my $module (@missing) {
257 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
259 my $message=getmessage('MissingPerlModules', [$missing]);
260 showmessage($message, 'none');
263 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
267 unless (-x "/usr/bin/perl") {
268 my $realperl=`which perl`;
270 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
271 until (-x $realperl) {
272 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
274 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
275 unless ($response eq 'n') {
276 system("ln -s $realperl /usr/bin/perl");
283 $messages->{'NoUsrBinPerl'}->{en}=qq|
285 ========================================
286 = Perl is not located in /usr/bin/perl =
287 ========================================
289 The Koha perl scripts expect to find the perl executable in the /usr/bin
290 directory. It is not there on your system.
294 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
295 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
296 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
298 May I create this symlink? ([Y]/N):
302 my $messagename=shift;
304 my $message=$messages->{$messagename}->{$::language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
305 if (defined($variables)) {
306 $message=sprintf $message, @$variables;
314 my $responsetype=shift;
315 my $defaultresponse=shift;
317 ($noclear) || (system('clear'));
318 if ($responsetype =~ /^yn$/) {
319 $responsetype='restrictchar yn';
323 if ($responsetype =~/^restrictchar (.*)/i) {
326 until ($options=~/$response/) {
327 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
330 (length($response)) || ($response=$defaultresponse);
331 unless ($options=~/$response/) {
332 ($noclear) || (system('clear'));
333 print "Invalid Response. Choose from [$options].\n\n";
339 if ($responsetype =~/^free$/i) {
340 (defined($defaultresponse)) || ($defaultresponse='');
341 my $response=<STDIN>;
343 ($response) || ($response=$defaultresponse);
346 if ($responsetype =~/^numerical$/i) {
347 (defined($defaultresponse)) || ($defaultresponse='');
349 until ($response=~/^\d+$/) {
352 ($response) || ($response=$defaultresponse);
353 unless ($response=~/^\d+$/) {
354 ($noclear) || (system('clear'));
355 print "Invalid Response ($response). Response must be a number.\n\n";
361 if ($responsetype =~/^email$/i) {
362 (defined($defaultresponse)) || ($defaultresponse='');
364 until ($response=~/.*\@.*\..*/) {
367 ($response) || ($response=$defaultresponse);
368 unless ($response=~/.*\@.*\..*/) {
369 ($noclear) || (system('clear'));
370 print "Invalid Response ($response). Response must be a valid email address.\n\n";
376 if ($responsetype =~/^PressEnter$/i) {
380 if ($responsetype =~/^none$/i) {
386 sub getinstallationdirectories {
387 $::opacdir = '/usr/local/koha/opac';
388 $::intranetdir = '/usr/local/koha/intranet';
390 while ($getdirinfo) {
391 # Loop until opac directory and koha directory are different
392 my $message=getmessage('GetOpacDir', [$::opacdir]);
393 $::opacdir=showmessage($message, 'free', $::opacdir);
395 $message=getmessage('GetIntranetDir', [$::intranetdir]);
396 $::intranetdir=showmessage($message, 'free', $::intranetdir);
398 if ($::intranetdir eq $::opacdir) {
401 You must specify different directories for the OPAC and INTRANET files!
402 :: $::intranetdir :: $::opacdir ::
409 $::kohalogdir='/var/log/koha';
410 my $message=getmessage('GetKohaLogDir', [$::kohalogdir]);
411 $::kohalogdir=showmessage($message, 'free', $::kohalogdir);
414 unless ( -d $::intranetdir ) {
415 my $result=mkdir ($::intranetdir, oct(770));
417 my @dirs = split(m#/#, $::intranetdir);
421 unless (-e "$checkdir") {
422 mkdir($checkdir, 0775);
426 chown (oct(0), (getgrnam($::httpduser))[2], "$::intranetdir");
427 chmod (oct(770), "$::intranetdir");
429 unless ( -d "$::intranetdir/htdocs" ) {
430 mkdir ("$::intranetdir/htdocs", oct(750));
432 unless ( -d "$::intranetdir/cgi-bin" ) {
433 mkdir ("$::intranetdir/cgi-bin", oct(750));
435 unless ( -d "$::intranetdir/modules" ) {
436 mkdir ("$::intranetdir/modules", oct(750));
438 unless ( -d "$::intranetdir/scripts" ) {
439 mkdir ("$::intranetdir/scripts", oct(750));
441 unless ( -d $::opacdir ) {
442 my $result=mkdir ($::opacdir, oct(770));
444 my @dirs = split(m#/#, $::opacdir);
448 unless (-e "$checkdir") {
449 mkdir($checkdir, 0775);
453 chown (oct(0), (getgrnam($::httpduser))[2], "$::opacdir");
454 chmod (oct(770), "$::opacdir");
456 unless ( -d "$::opacdir/htdocs" ) {
457 mkdir ("$::opacdir/htdocs", oct(750));
459 unless ( -d "$::opacdir/cgi-bin" ) {
460 mkdir ("$::opacdir/cgi-bin", oct(750));
464 unless ( -d $::kohalogdir ) {
465 my $result=mkdir ($::kohalogdir, oct(770));
467 my @dirs = split(m#/#, $::kohalogdir);
471 unless (-e "$checkdir") {
472 mkdir($checkdir, 0775);
477 chown (oct(0), (getgrnam($::httpduser))[2,3], "$::kohalogdir");
478 chmod (oct(770), "$::kohalogdir");
484 $messages->{'DatabaseName'}->{en}=qq|
485 ==========================
486 = Name of MySQL database =
487 ==========================
489 Please provide the name of the mysql database for your koha installation.
491 Database name [%s]: |;
493 $messages->{'DatabaseHost'}->{en}=qq|
498 Please provide the hostname for mysql. Unless the database is located on
499 another machine this will be "localhost".
501 Database host [%s]: |;
503 $messages->{'DatabaseUser'}->{en}=qq|
508 Please provide the name of the user, who will have full administrative rights
509 to the %s database, when authenticating from %s.
511 Database user [%s]: |;
513 $messages->{'DatabasePassword'}->{en}=qq|
514 =====================
515 = Database Password =
516 =====================
518 Please provide a good password for the user %s.
520 Database Password: |;
522 $messages->{'BlankPassword'}->{en}=qq|
527 You must not use a blank password for your MySQL user!
529 Press <ENTER> to try again:
532 sub getdatabaseinfo {
535 $::hostname = 'localhost';
536 $::user = 'kohaadmin';
539 #Get the database name
541 my $message=getmessage('DatabaseName', [$::dbname]);
542 $::dbname=showmessage($message, 'free', $::dbname);
544 #Get the hostname for the database
546 $message=getmessage('DatabaseHost', [$::hostname]);
547 $::hostname=showmessage($message, 'free', $::hostname);
549 #Get the username for the database
551 $message=getmessage('DatabaseUser', [$::dbname, $::hostname, $::user]);
552 $::user=showmessage($message, 'free', $::user);
554 #Get the password for the database user
556 while ($::pass eq '') {
557 my $message=getmessage('DatabasePassword', [$::user]);
558 $::pass=showmessage($message, 'free', $::pass);
560 my $message=getmessage('BlankPassword');
561 showmessage($message,'PressEnter');
568 $messages->{'FoundMultipleApacheConfFiles'}->{en}=qq|
569 ================================
570 = MULTIPLE APACHE CONFIG FILES =
571 ================================
573 I found more than one possible Apache configuration file:
577 Choose the correct file [1]: |;
579 $messages->{'NoApacheConfFiles'}->{en}=qq|
580 ===============================
581 = NO APACHE CONFIG FILE FOUND =
582 ===============================
584 I was not able to find your Apache configuration file.
586 The file is usually called httpd.conf or apache.conf.
588 Please specify the location of your config file: |;
590 $messages->{'NotAFile'}->{en}=qq|
591 =======================
592 = FILE DOES NOT EXIST =
593 =======================
595 The file %s does not exist.
597 Please press <ENTER> to continue: |;
599 $messages->{'EnterApacheUser'}->{en}=qq|
604 I was not able to determine the user that Apache is running as. This
605 information is necessary in order to set the access privileges correctly on
606 /etc/koha.conf. This user should be set in one of the Apache configuration
607 files using the "User" directive.
609 Enter the Apache userid: |;
611 $messages->{'InvalidUserid'}->{en}=qq|
616 The userid %s is not a valid userid on this system.
618 Press <ENTER> to continue: |;
621 my @confpossibilities;
623 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
624 /usr/local/etc/apache/httpd.conf
625 /usr/local/etc/apache/apache.conf
626 /var/www/conf/httpd.conf
627 /etc/apache/conf/httpd.conf
628 /etc/apache/conf/apache.conf
629 /etc/apache-ssl/conf/apache.conf
630 /etc/apache-ssl/httpd.conf
631 /etc/httpd/conf/httpd.conf
632 /etc/httpd/httpd.conf)) {
633 if ( -f $httpdconf ) {
634 push @confpossibilities, $httpdconf;
638 if ($#confpossibilities==-1) {
639 my $message=getmessage('NoApacheConfFiles');
642 $choice=showmessage($message, "free", 1);
644 $::realhttpdconf=$choice;
646 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
649 } elsif ($#confpossibilities>0) {
653 foreach (@confpossibilities) {
654 $conffiles.=" $counter: $_\n";
655 $options.="$counter";
658 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
659 my $choice=showmessage($message, "restrictchar $options", 1);
660 $::realhttpdconf=$confpossibilities[$choice-1];
662 $::realhttpdconf=$confpossibilities[0];
664 unless (open (HTTPDCONF, $::realhttpdconf)) {
665 warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
669 while (<HTTPDCONF>) {
670 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
679 unless ($::httpduser) {
680 my $message=getmessage('EnterApacheUser');
681 until (length($::httpduser) && getpwnam($::httpduser)) {
682 $::httpduser=showmessage($message, "free", '');
683 if (length($::httpduser)>0) {
684 unless (getpwnam($::httpduser)) {
685 my $message=getmessage('InvalidUserid', [$::httpduser]);
686 showmessage($message,'PressEnter');
691 print "AU: $::httpduser\n";
696 $messages->{'ApacheConfigIntroduction'}->{en}=qq|
697 ========================
698 = APACHE CONFIGURATION =
699 ========================
701 Koha needs to setup your Apache configuration file for the
702 OPAC and LIBRARIAN virtual hosts. By default this installer
703 will do this by using one ip address and two different ports
704 for the virtual hosts. There are other ways to set this up,
705 and the installer will leave comments in httpd.conf detailing
706 what these other options are.
709 Press <ENTER> to continue: |;
711 $messages->{'GetVirtualHostEmail'}->{en}=qq|
712 =============================
713 = WEB SERVER E-MAIL CONTACT =
714 =============================
716 Enter the e-mail address to be used as a contact for the virtual hosts (this
717 address is displayed if any errors are encountered).
719 E-mail contact [%s]: |;
721 $messages->{'GetServerName'}->{en}=qq|
722 ======================================
723 = WEB SERVER HOST NAME OR IP ADDRESS =
724 ======================================
726 Please enter the domain name or ip address of your computer.
728 Host name or IP Address [%s]: |;
730 $messages->{'GetOpacPort'}->{en}=qq|
731 ==========================
732 = OPAC VIRTUAL HOST PORT =
733 ==========================
735 Please enter the port for your OPAC interface. This defaults to port 80, but
736 if you are already serving web content from this server, you should change it
737 to a different port (8000 might be a good choice).
739 Enter the OPAC Port [%s]: |;
741 $messages->{'GetIntranetPort'}->{en}=qq|
742 ==============================
743 = INTRANET VIRTUAL HOST PORT =
744 ==============================
746 Please enter the port for your Intranet interface. This must be different from
749 Enter the Intranet Port [%s]: |;
752 sub getapachevhostinfo {
754 $::svr_admin = "webmaster\@$::domainname";
755 $::servername=`hostname -f`;
758 $::intranetport=8080;
760 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
762 $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
763 $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
766 $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
767 $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
771 $messages->{'StartUpdateApache'}->{en}=qq|
772 =================================
773 = UPDATING APACHE CONFIGURATION =
774 =================================
776 Checking for modules that need to be loaded...
779 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
781 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
783 $messages->{'ApacheConfigBackupFailed'}->{en}=qq|
784 ======================================
785 = APACHE CONFIGURATION BACKUP FAILED =
786 ======================================
788 An error occurred while trying to make a backup copy of %s.
792 No changes will be made to the apache configuration file at this time.
794 Press <ENTER> to continue: |;
797 $messages->{'ApacheAlreadyConfigured'}->{en}=qq|
798 =============================
799 = APACHE ALREADY CONFIGURED =
800 =============================
802 %s appears to already have an entry for Koha
803 Virtual Hosts. You may need to edit %s
804 f anything has changed since it was last set up. This
805 script will not attempt to modify an existing Koha apache
808 Press <ENTER> to continue: |;
810 sub updateapacheconf {
811 my $logfiledir=`grep ^ErrorLog $::realhttpdconf`;
815 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
819 unless ($logfiledir) {
823 showmessage(getmessage('StartUpdateApache'), 'none');
827 my $includesmodule=0;
828 open HC, $::realhttpdconf;
830 if (/^\s*#\s*LoadModule env_module /) {
832 showmessage(getmessage('LoadingApacheModuleModEnv'));
835 if (/^\s*#\s*LoadModule includes_module /) {
837 showmessage(getmessage('LoadingApacheModuleModInc'));
839 if (/\s*LoadModule includes_module / ) {
846 $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
848 showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
852 if ($envmodule || $includesmodule) {
853 open HC, ">$::realhttpdconf";
860 if (`grep 'VirtualHost $::servername' $::realhttpdconf`) {
861 showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
864 my $includesdirectives='';
865 if ($includesmodule) {
866 $includesdirectives.="Options +Includes\n";
867 $includesdirectives.=" AddHandler server-parsed .html\n";
869 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
871 if ($::opacport != 80) {
872 $opaclisten="Listen $::opacport";
874 my $intranetlisten = '';
875 if ($::intranetport != 80) {
876 $intranetlisten="Listen $::intranetport";
880 # Ports to listen to for Koha
884 # NameVirtualHost is used by one of the optional configurations detailed below
886 #NameVirtualHost 11.22.33.44
888 # KOHA's OPAC Configuration
889 <VirtualHost $::servername\:$::opacport>
890 ServerAdmin $::svr_admin
891 DocumentRoot $::opacdir/htdocs
892 ServerName $::servername
893 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
894 ErrorLog $logfiledir/opac-error_log
895 TransferLog $logfiledir/opac-access_log
896 SetEnv PERL5LIB "$::intranetdir/modules"
900 # KOHA's INTRANET Configuration
901 <VirtualHost $::servername\:$::intranetport>
902 ServerAdmin $::svr_admin
903 DocumentRoot $::intranetdir/htdocs
904 ServerName $::servername
905 ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
906 ErrorLog $logfiledir/koha-error_log
907 TransferLog $logfiledir/koha-access_log
908 SetEnv PERL5LIB "$::intranetdir/modules"
912 # If you want to use name based Virtual Hosting:
913 # 1. remove the two Listen lines
914 # 2. replace $::servername\:$::opacport wih your.opac.domain.name
915 # 3. replace ServerName $::servername wih ServerName your.opac.domain.name
916 # 4. replace $::servername\:$::intranetport wih your intranet domain name
917 # 5. replace ServerName $::servername wih ServerName your.intranet.domain.name
919 # If you want to use NameVirtualHost'ing (using two names on one ip address):
920 # 1. Follow steps 1-5 above
921 # 2. Uncomment the NameVirtualHost line and set the correct ip address
929 $messages->{'IntranetAuthenticationQuestion'}->{en}=qq|
930 ===========================
931 = INTRANET AUTHENTICATION =
932 ===========================
934 I can set it up so that the Intranet/Librarian site is password protected using
935 Apache's Basic Authorization.
937 Would you like to do this ([Y]/N): |;
939 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
940 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
941 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
943 sub basicauthentication {
944 my $message=getmessage('IntranetAuthenticationQuestion');
945 my $answer=showmessage($message, 'yn', 'y');
947 my $apacheauthusername='librarian';
948 my $apacheauthpassword='';
949 if ($answer=~/^y/i) {
950 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
951 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
952 while (! $apacheauthpassword) {
953 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
954 if (!$apacheauthpassword) {
955 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
958 open AUTH, ">/etc/kohaintranet.pass";
959 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
960 my $salt=substr($chars, int(rand(length($chars))),1);
961 $salt.=substr($chars, int(rand(length($chars))),1);
962 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
964 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
967 <Directory $::intranetdir>
968 AuthUserFile /etc/kohaintranet.pass
970 AuthName "Koha Intranet (for librarians only)"
978 $messages->{'InstallFiles'}->{en}=qq|
983 Copying files to installation directories:
988 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
995 showmessage(getmessage('InstallFiles'),'none');
996 print getmessage('CopyingFiles', ['intranet-html', "$::intranetdir/htdocs" ]);
997 system("cp -R intranet-html/* $::intranetdir/htdocs/");
998 print getmessage('CopyingFiles', ['intranet-cgi', "$::intranetdir/cgi-bin" ]);
999 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
1000 print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
1001 system("cp -R scripts/* $::intranetdir/scripts/");
1002 print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
1003 system("cp -R modules/* $::intranetdir/modules/");
1004 print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
1005 system("cp -R opac-html/* $::opacdir/htdocs/");
1006 print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
1007 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
1008 system("touch $::opacdir/cgi-bin/opac");
1010 system("chown -R root.$::httpduser $::opacdir");
1011 system("chown -R root.$::httpduser $::intranetdir");
1013 # Create /etc/koha.conf
1015 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1016 open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1019 hostname=$::hostname
1022 includes=$::intranetdir/htdocs/includes
1023 intranetdir=$::intranetdir
1025 kohalogdir=$::kohalogdir
1026 kohaversion=$::kohaversion
1027 httpduser=$::httpduser
1032 chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1033 chmod 0440, "$::etcdir/koha.conf.tmp";
1035 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1036 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1037 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
1038 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1039 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
1043 $messages->{'MysqlRootPassword'}->{en}=qq|
1044 ============================
1045 = MYSQL ROOT USER PASSWORD =
1046 ============================
1048 To allow us to create the koha database please supply your
1049 mysql server's root user password:
1051 Enter MySql root user password: |;
1053 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password. Please try again.";
1055 $messages->{'CreatingDatabase'}->{en}=qq|
1056 =====================
1057 = CREATING DATABASE =
1058 =====================
1060 Creating the MySql database for Koha...
1064 $messages->{'CreatingDatabaseError'}->{en}=qq|
1065 ===========================
1066 = ERROR CREATING DATABASE =
1067 ===========================
1069 Couldn't connect to the MySQL server for the reason given above.
1070 This is a serious problem, the database will not get installed.
\a
1072 Press <ENTER> to continue: |;
1074 $messages->{'SampleData'}->{en}=qq|
1079 If you are installing Koha for evaluation purposes, I have a batch of sample
1080 data that you can install now.
1082 If you are installing Koha with the intention of populating it with your own
1083 data, you probably don't want this sample data installed.
1085 Would you like to install the sample data? Y/[N]: |;
1087 $messages->{'SampleDataInstalled'}->{en}=qq|
1088 =========================
1089 = SAMPLE DATA INSTALLED =
1090 =========================
1092 Sample data has been installed. For some suggestions on testing Koha, please
1093 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1094 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1095 question through the koha-devel mailing list, or you can check for a developer
1096 online at +irc.katipo.co.nz:6667 channel #koha.
1098 You can find instructions for subscribing to the Koha mailing lists at:
1103 Press <ENTER> to continue: |;
1105 $messages->{'AddBranchPrinter'}->{en}=qq|
1106 ==========================
1107 = Add Branch and Printer =
1108 ==========================
1110 Would you like to install an initial branch and printer? [Y]/N: |;
1112 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1113 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1114 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1115 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1116 $messages->{'BlankMysqlPassword'}->{en}=qq|
1117 ========================
1118 = Blank MySql Password =
1119 ========================
1121 Do not leave your MySql root password blank unless you know exactly what you
1122 are doing. To change your MySql root password use the mysqladmin command:
1124 mysqladmin password NEWPASSWORDHERE
1126 Press <ENTER> to continue:
1130 $::mysqluser = 'root';
1133 foreach my $mysql (qw(/usr/local/mysql
1137 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1142 print "I don't see mysql in the usual places.\n";
1144 print "Where have you installed mysql? ";
1145 chomp($::mysqldir = <STDIN>);
1146 last if -f "$::mysqldir/bin/mysqladmin";
1149 I can't find it there either. If you compiled mysql yourself,
1150 please give the value of --prefix when you ran configure.
1152 The file mysqladmin should be in bin/mysqladmin under the directory that you
1161 while ($needpassword) {
1162 $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1163 $::mysqlpass_quoted = $::mysqlpass;
1164 $::mysqlpass_quoted =~ s/"/\\"/g;
1165 $::mysqlpass_quoted="-p\"$::mysqlpass_quoted\"";
1166 $::mysqlpass eq '' and $::mysqlpass_quoted='';
1167 my $result=system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted proc > /dev/null 2>&1");
1169 print getmessage('InvalidMysqlRootPassword');
1171 if ($::mysqlpass eq '') {
1172 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1178 showmessage(getmessage('CreatingDatabase'),'none');
1180 my $result=system("$::mysqldir/bin/mysqladmin", "-u$::mysqluser", "-p$::mysqlpass", "create", "$::dbname");
1182 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1184 # Populate the Koha database
1185 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname < koha.mysql");
1186 # Set up permissions
1187 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1188 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')\"");
1189 system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted reload");
1199 $messages->{'UpdateMarcTables'}->{en}=qq|
1200 =========================================
1201 = UPDATING MARC FIELD DEFINITION TABLES =
1202 =========================================
1204 You can import marc parameters for :
1210 Please choose which parameter you want to install. Note if you choose 3,
1211 nothing will be added, and it can be a BIG job to manually create those tables
1213 Choose MARC definition [1]: |;
1216 sub updatedatabase {
1217 my $result=system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1219 print "Problem updating database...\n";
1223 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 123', '1');
1225 if ($response == 1) {
1226 system("cat script/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
1228 if ($response == 2) {
1229 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
1230 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
1233 system ("perl -I $kohadir/modules scripts/marc/updatedb2marc.pl");
1236 print "\n\nFinished updating database. Press <ENTER> to continue...";
1240 sub populatedatabase {
1241 my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1242 if ($response =~/^y/i) {
1243 system("gunzip sampledata-1.2.gz");
1244 system("cat sampledata-1.2 | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1245 system("gzip -9 sampledata-1.2");
1246 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1247 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1248 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1249 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1250 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1253 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1255 unless ($response =~/^n/i) {
1256 my $branch='Main Library';
1257 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1258 $branch=~s/[^A-Za-z0-9\s]//g;
1260 my $branchcode=$branch;
1261 $branchcode=~s/[^A-Za-z0-9]//g;
1262 $branchcode=uc($branchcode);
1263 $branchcode=substr($branchcode,0,4);
1264 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1265 $branchcode=~s/[^A-Za-z0-9]//g;
1266 $branchcode=uc($branchcode);
1267 $branchcode=substr($branchcode,0,4);
1268 $branchcode or $branchcode='DEF';
1270 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1271 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1272 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1274 my $printername='Library Printer';
1275 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1276 $printername=~s/[^A-Za-z0-9\s]//g;
1278 my $printerqueue='lp';
1279 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1280 $printerqueue=~s/[^A-Za-z0-9]//g;
1281 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1287 $messages->{'RestartApache'}->{en}=qq|
1292 Apache needs to be restarted to load the new configuration for Koha.
1294 Would you like to restart Apache now? [Y]/N: |;
1298 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1302 unless ($response=~/^n/i) {
1303 # Need to support other init structures here?
1304 if (-e "/etc/rc.d/init.d/httpd") {
1305 system('/etc/rc.d/init.d/httpd restart');
1306 } elsif (-e "/etc/init.d/apache") {
1307 system('/etc//init.d/apache restart');
1308 } elsif (-e "/etc/init.d/apache-ssl") {
1309 system('/etc/init.d/apache-ssl restart');
1316 sub loadconfigfile {
1319 open (KC, "/etc/koha.conf");
1322 (next) if (/^\s*#/);
1323 if (/(.*)\s*=\s*(.*)/) {
1326 # Clean up white space at beginning and end
1327 $variable=~s/^\s*//g;
1328 $variable=~s/\s*$//g;
1331 $configfile{$variable}=$value;
1335 $::intranetdir=$configfile{'intranetdir'};
1336 $::opacdir=$configfile{'opacdir'};
1337 $::kohaversion=$configfile{'kohaversion'};
1338 $::kohalogdir=$configfile{'kohalogdir'};
1339 $::database=$configfile{'database'};
1340 $::hostname=$configfile{'hostname'};
1341 $::user=$configfile{'user'};
1342 $::pass=$configfile{'pass'};
1345 END { } # module clean-up code here (global destructor)