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
48 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
49 $messages->{'WelcomeToKohaInstaller'}->{en}=qq|
50 =================================
51 = Welcome to the Koha Installer =
52 =================================
54 Welcome to the Koha install script! This script will prompt you for some
55 basic information about your desired setup, then install Koha according to
56 your specifications. To accept the default value for any question, simply hit
59 Please be sure to read the documentation, or visit the Koha website at
60 http://www.koha.org for more information.
62 Are you ready to begin the installation? (Y/[N]): |;
63 $messages->{'ReleaseCandidateWarning'}->{en}=qq|
68 WARNING WARNING WARNING WARNING WARNING
70 You are about to install Koha version %s. This version of Koha is a
71 release candidate. It is not intended to be installed on production systems.
72 It is being released so that users can test it before we release a final
75 Are you sure you want to install Koha %s? (Y/[N]): |;
76 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
78 Watch for announcements of Koha releases on the Koha mailing list or the Koha
79 web site (http://www.koha.org/).
83 $messages->{'NETZ3950Missing'}->{en}=qq|
85 The Net::Z3950 module is missing. This module is necessary if you want to use
86 Koha's Z39.50 client to download bibliographic records from other libraries.
87 To install this module, you will need the yaz client installed from
88 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
91 perl -MCPAN -e 'install Net::Z3950'
93 Press the <ENTER> key to continue: |;
95 $messages->{'CheckingPerlModules'}->{en}=qq|
101 Checking perl modules ...
104 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
106 $messages->{'MissingPerlModules'}->{en}=qq|
108 ========================
109 = MISSING PERL MODULES =
110 ========================
112 You are missing some Perl modules which are required by Koha.
113 Once these modules have been installed, rerun this installer.
114 They can be installed by running (as root) the following:
119 $messages->{'AllPerlModulesInstalled'}->{en}=qq|
121 ==============================
122 = ALL PERL MODULES INSTALLED =
123 ==============================
125 All mandatory perl modules are installed.
127 Press <ENTER> to continue: |;
128 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
129 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
130 $messages->{'KohaAlreadyInstalled'}->{en}=qq|
131 ==========================
132 = Koha already installed =
133 ==========================
135 It looks like Koha is already installed on your system (/etc/koha.conf exists
136 already). If you would like to upgrade your system to %s, please use
137 the koha.upgrade script in this directory.
142 $messages->{'GetOpacDir'}->{en}=qq|
147 Please supply the directory you want Koha to store its OPAC files in. This
148 directory will be auto-created for you if it doesn't exist.
150 OPAC Directory [%s]: |;
152 $messages->{'GetIntranetDir'}->{en}=qq|
153 =================================
154 = INTRANET/LIBRARIANS DIRECTORY =
155 =================================
157 Please supply the directory you want Koha to store its Intranet/Librarians
158 files in. This directory will be auto-created for you if it doesn't exist.
160 Intranet Directory [%s]: |;
162 $messages->{'GetKohaLogDir'}->{en}=qq|
163 ======================
164 = KOHA LOG DIRECTORY =
165 ======================
167 Specify a log directory where any Koha daemons can create log files.
169 Koha Log Directory [%s]: |;
171 $messages->{'AuthenticationWarning'}->{en}=qq|
176 This release of Koha has a new authentication module. If you are not already
177 using basic authentication on your intranet, you will be required to log in to
178 access some of the features of the intranet. You can log in using the userid
179 and password from the /etc/koha.conf configuration file at any time. Use the
180 "Members" module to add passwords for other accounts and set their permissions.
182 [NOTE PERMISSIONS ARE NOT COMPLETED AS OF THIS RELEASE. Do not give passwords
183 to any patrons unless you want them to have full access to your intranet.]
185 Press the <ENTER> key to continue: |;
187 $messages->{'Completed'}->{en}=qq|
188 ==============================
189 = KOHA INSTALLATION COMPLETE =
190 ==============================
192 Congratulations ... your Koha installation is complete!
194 You will be able to connect to your Librarian interface at:
198 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');
224 # Test for Perl and Modules
227 sub checkperlmodules {
228 my $message = getmessage('CheckingPerlModules');
229 showmessage($message, 'none');
231 unless (eval "require 5.6.0") {
232 die getmessage('PerlVersionFailure', ['5.6.0']);
236 unless (eval {require DBI}) { push @missing,"DBI" };
237 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
238 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
239 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
240 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
241 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
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/httpd/conf/httpd.conf
631 /etc/httpd/httpd.conf)) {
632 if ( -f $httpdconf ) {
633 push @confpossibilities, $httpdconf;
637 if ($#confpossibilities==-1) {
638 my $message=getmessage('NoApacheConfFiles');
641 $choice=showmessage($message, "free", 1);
642 unless (-f $choice) {
643 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
646 } elsif ($#confpossibilities>0) {
650 foreach (@confpossibilities) {
651 $conffiles.=" $counter: $_\n";
652 $options.="$counter";
655 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
656 my $choice=showmessage($message, "restrictchar $options", 1);
657 $::realhttpdconf=$confpossibilities[$choice-1];
659 $::realhttpdconf=$confpossibilities[0];
661 open (HTTPDCONF, $::realhttpdconf) or warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
662 while (<HTTPDCONF>) {
663 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
672 unless ($::httpduser) {
673 my $message=getmessage('EnterApacheUser');
674 until (length($::httpduser) && getpwnam($::httpduser)) {
675 $::httpduser=showmessage($message, "free", '');
676 if (length($::httpduser)>0) {
677 unless (getpwnam($::httpduser)) {
678 my $message=getmessage('InvalidUserid', [$::httpduser]);
679 showmessage($message,'PressEnter');
684 print "AU: $::httpduser\n";
689 $messages->{'ApacheConfigIntroduction'}->{en}=qq|
690 ========================
691 = APACHE CONFIGURATION =
692 ========================
694 Koha needs to setup your Apache configuration file for the
695 OPAC and LIBRARIAN virtual hosts. By default this installer
696 will do this by using one ip address and two different ports
697 for the virtual hosts. There are other ways to set this up,
698 and the installer will leave comments in httpd.conf detailing
699 what these other options are.
702 Press <ENTER> to continue: |;
704 $messages->{'GetVirtualHostEmail'}->{en}=qq|
705 =============================
706 = WEB SERVER E-MAIL CONTACT =
707 =============================
709 Enter the e-mail address to be used as a contact for the virtual hosts (this
710 address is displayed if any errors are encountered).
712 E-mail contact [%s]: |;
714 $messages->{'GetServerName'}->{en}=qq|
715 ======================================
716 = WEB SERVER HOST NAME OR IP ADDRESS =
717 ======================================
719 Please enter the domain name or ip address of your computer.
721 Host name or IP Address [%s]: |;
723 $messages->{'GetOpacPort'}->{en}=qq|
724 ==========================
725 = OPAC VIRTUAL HOST PORT =
726 ==========================
728 Please enter the port for your OPAC interface. This defaults to port 80, but
729 if you are already serving web content from this server, you should change it
730 to a different port (8000 might be a good choice).
732 Enter the OPAC Port [%s]: |;
734 $messages->{'GetIntranetPort'}->{en}=qq|
735 ==============================
736 = INTRANET VIRTUAL HOST PORT =
737 ==============================
739 Please enter the port for your Intranet interface. This must be different from
742 Enter the Intranet Port [%s]: |;
745 sub getapachevhostinfo {
747 $::svr_admin = "webmaster\@$::domainname";
748 $::servername=`hostname -f`;
751 $::intranetport=8080;
753 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
755 $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
756 $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
759 $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
760 $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
764 $messages->{'StartUpdateApache'}->{en}=qq|
765 =================================
766 = UPDATING APACHE CONFIGURATION =
767 =================================
769 Checking for modules that need to be loaded...
772 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
774 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
776 $messages->{'ApacheConfigBackupFailed'}->{en}=qq|
777 ======================================
778 = APACHE CONFIGURATION BACKUP FAILED =
779 ======================================
781 An error occurred while trying to make a backup copy of %s.
785 No changes will be made to the apache configuration file at this time.
787 Press <ENTER> to continue: |;
790 $messages->{'ApacheAlreadyConfigured'}->{en}=qq|
791 =============================
792 = APACHE ALREADY CONFIGURED =
793 =============================
795 %s appears to already have an entry for Koha
796 Virtual Hosts. You may need to edit %s
797 f anything has changed since it was last set up. This
798 script will not attempt to modify an existing Koha apache
801 Press <ENTER> to continue: |;
803 sub updateapacheconf {
804 my $logfiledir=`grep ^ErrorLog $::realhttpdconf`;
808 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
812 unless ($logfiledir) {
816 showmessage(getmessage('StartUpdateApache'), 'none');
820 my $includesmodule=0;
821 open HC, $::realhttpdconf;
823 if (/^\s*#\s*LoadModule env_module /) {
825 showmessage(getmessage('LoadingApacheModuleModEnv'));
828 if (/^\s*#\s*LoadModule includes_module /) {
830 showmessage(getmessage('LoadingApacheModuleModInc'));
832 if (/\s*LoadModule includes_module / ) {
839 $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
841 showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
845 if ($envmodule || $includesmodule) {
846 open HC, ">$::realhttpdconf";
853 if (`grep 'VirtualHost $::servername' $::realhttpdconf`) {
854 showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
857 my $includesdirectives='';
858 if ($includesmodule) {
859 $includesdirectives.="Options +Includes\n";
860 $includesdirectives.=" AddHandler server-parsed .html\n";
862 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
864 if ($::opacport != 80) {
865 $opaclisten="Listen $::opacport";
867 my $intranetlisten = '';
868 if ($::intranetport != 80) {
869 $intranetlisten="Listen $::intranetport";
873 # Ports to listen to for Koha
877 # NameVirtualHost is used by one of the optional configurations detailed below
879 #NameVirtualHost 11.22.33.44
881 # KOHA's OPAC Configuration
882 <VirtualHost $::servername\:$::opacport>
883 ServerAdmin $::svr_admin
884 DocumentRoot $::opacdir/htdocs
885 ServerName $::servername
886 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
887 ErrorLog $logfiledir/opac-error_log
888 TransferLog $logfiledir/opac-access_log
889 SetEnv PERL5LIB "$::intranetdir/modules"
893 # KOHA's INTRANET Configuration
894 <VirtualHost $::servername\:$::intranetport>
895 ServerAdmin $::svr_admin
896 DocumentRoot $::intranetdir/htdocs
897 ServerName $::servername
898 ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
899 ErrorLog $logfiledir/koha-error_log
900 TransferLog $logfiledir/koha-access_log
901 SetEnv PERL5LIB "$::intranetdir/modules"
905 # If you want to use name based Virtual Hosting:
906 # 1. remove the two Listen lines
907 # 2. replace $::servername\:$::opacport wih your.opac.domain.name
908 # 3. replace ServerName $::servername wih ServerName your.opac.domain.name
909 # 4. replace $::servername\:$::intranetport wih your intranet domain name
910 # 5. replace ServerName $::servername wih ServerName your.intranet.domain.name
912 # If you want to use NameVirtualHost'ing (using two names on one ip address):
913 # 1. Follow steps 1-5 above
914 # 2. Uncomment the NameVirtualHost line and set the correct ip address
922 $messages->{'IntranetAuthenticationQuestion'}->{en}=qq|
923 ===========================
924 = INTRANET AUTHENTICATION =
925 ===========================
927 I can set it up so that the Intranet/Librarian site is password protected using
928 Apache's Basic Authorization.
930 Would you like to do this ([Y]/N): |;
932 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
933 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
934 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
936 sub basicauthentication {
937 my $message=getmessage('IntranetAuthenticationQuestion');
938 my $answer=showmessage($message, 'yn', 'y');
940 my $apacheauthusername='librarian';
941 my $apacheauthpassword='';
942 if ($answer=~/^y/i) {
943 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
944 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
945 while (! $apacheauthpassword) {
946 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
947 if (!$apacheauthpassword) {
948 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
951 open AUTH, ">/etc/kohaintranet.pass";
952 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
953 my $salt=substr($chars, int(rand(length($chars))),1);
954 $salt.=substr($chars, int(rand(length($chars))),1);
955 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
957 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
960 <Directory $::intranetdir>
961 AuthUserFile /etc/kohaintranet.pass
963 AuthName "Koha Intranet (for librarians only)"
971 $messages->{'InstallFiles'}->{en}=qq|
976 Copying files to installation directories:
981 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
988 showmessage(getmessage('InstallFiles'),'none');
989 print getmessage('CopyingFiles', ['internet-html', "$::intranetdir/htdocs" ]);
990 system("cp -R intranet-html/* $::intranetdir/htdocs/");
991 print getmessage('CopyingFiles', ['internet-cgi', "$::intranetdir/cgi-bin" ]);
992 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
993 print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
994 system("cp -R scripts/* $::intranetdir/scripts/");
995 print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
996 system("cp -R modules/* $::intranetdir/modules/");
997 print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
998 system("cp -R opac-html/* $::opacdir/htdocs/");
999 print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
1000 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
1001 system("touch $::opacdir/cgi-bin/opac");
1003 system("chown -R root.$::httpduser $::opacdir");
1004 system("chown -R root.$::httpduser $::intranetdir");
1006 # Create /etc/koha.conf
1008 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1009 open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1012 hostname=$::hostname
1015 includes=$::intranetdir/htdocs/includes
1016 intranetdir=$::intranetdir
1018 kohalogdir=$::kohalogdir
1019 kohaversion=$::kohaversion
1020 httpduser=$::httpduser
1025 chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1026 chmod 0440, "$::etcdir/koha.conf.tmp";
1028 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1029 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1030 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
1031 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1032 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
1036 $messages->{'MysqlRootPassword'}->{en}=qq|
1037 ============================
1038 = MYSQL ROOT USER PASSWORD =
1039 ============================
1041 To allow us to create the koha database please supply your
1042 mysql server's root user password:
1044 Enter MySql root user password: |;
1046 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password. Please try again.";
1048 $messages->{'CreatingDatabase'}->{en}=qq|
1049 =====================
1050 = CREATING DATABASE =
1051 =====================
1053 Creating the MySql database for Koha...
1057 $messages->{'CreatingDatabaseError'}->{en}=qq|
1058 ===========================
1059 = ERROR CREATING DATABASE =
1060 ===========================
1062 Couldn't connect to the MySQL server for the reason given above.
1063 This is a serious problem, the database will not get installed.
\a
1065 Press <ENTER> to continue: |;
1067 $messages->{'SampleData'}->{en}=qq|
1072 If you are installing Koha for evaluation purposes, I have a batch of sample
1073 data that you can install now.
1075 If you are installing Koha with the intention of populating it with your own
1076 data, you probably don't want this sample data installed.
1078 Would you like to install the sample data? Y/[N]: |;
1080 $messages->{'SampleDataInstalled'}->{en}=qq|
1081 =========================
1082 = SAMPLE DATA INSTALLED =
1083 =========================
1085 Sample data has been installed. For some suggestions on testing Koha, please
1086 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1087 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1088 question through the koha-devel mailing list, or you can check for a developer
1089 online at +irc.katipo.co.nz:6667 channel #koha.
1091 You can find instructions for subscribing to the Koha mailing lists at:
1096 Press <ENTER> to continue: |;
1098 $messages->{'AddBranchPrinter'}->{en}=qq|
1099 ==========================
1100 = Add Branch and Printer =
1101 ==========================
1103 Would you like to install an initial branch and printer? [Y]/N: |;
1105 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1106 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1107 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1108 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1112 $::mysqluser = 'root';
1115 foreach my $mysql (qw(/usr/local/mysql
1119 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1124 print "I don't see mysql in the usual places.\n";
1126 print "Where have you installed mysql? ";
1127 chomp($mysqldir = <STDIN>);
1128 last if -f "$mysqldir/bin/mysqladmin";
1131 I can't find it there either. If you compiled mysql yourself,
1132 please give the value of --prefix when you ran configure.
1134 The file mysqladmin should be in bin/mysqladmin under the directory that you
1143 while ($needpassword) {
1144 $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1145 $::mysqlpass_quoted = $::mysqlpass;
1146 $::mysqlpass_quoted =~ s/"/\\"/g;
1147 my $result=system("$mysqldir/bin/mysqladmin -u$::mysqluser -p\"$::mysqlpass_quoted\" proc > /dev/null 2>&1");
1149 print getmessage('InvalidMysqlRootPassword');
1155 showmessage(getmessage('CreatingDatabase'),'none');
1157 my $result=system("$mysqldir/bin/mysqladmin -u$::mysqluser -p$::mysqlpass create $::dbname");
1159 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1161 # Populate the Koha database
1162 system("$mysqldir/bin/mysql -u$::mysqluser -p\"$::mysqlpass_quoted\" $::dbname < koha.mysql");
1163 # Set up permissions
1164 system("$mysqldir/bin/mysql -u$::mysqluser -p\"$::mysqlpass_quoted\" mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1165 system("$mysqldir/bin/mysql -u$::mysqluser -p\"$::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')\"");
1166 system("$mysqldir/bin/mysqladmin -u$::mysqluser -p\"$::mysqlpass_quoted\" reload");
1168 system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1171 my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1172 if ($response =~/^y/i) {
1173 system("gunzip sampledata-1.2.gz");
1174 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname");
1175 system("gzip -9 sampledata-1.2");
1176 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1177 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1178 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1179 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1180 showmessage(getmessage('SampleDataInstalled'), 'PressEnter');
1183 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1185 unless ($response =~/^n/i) {
1186 my $branch='Main Library';
1187 print "Enter a name for the library branch [$branch]: ";
1188 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1189 $branch=~s/[^A-Za-z0-9\s]//g;
1191 my $branchcode=$branch;
1192 $branchcode=~s/[^A-Za-z0-9]//g;
1193 $branchcode=uc($branchcode);
1194 $branchcode=substr($branchcode,0,4);
1195 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1196 $branchcode=~s/[^A-Z]//g;
1197 $branchcode=uc($branchcode);
1198 $branchcode=substr($branchcode,0,4);
1200 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1201 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1202 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1204 my $printername='Library Printer';
1205 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1206 $printername=~s/[^A-Za-z0-9\s]//g;
1208 my $printerqueue='lp';
1209 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1210 $printerqueue=~s/[^A-Za-z0-9]//g;
1211 system("$mysqldir/bin/mysql -u$::mysqluser -p$::mysqlpass $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1221 $messages->{'RestartApache'}->{en}=qq|
1226 Apache needs to be restarted to load the new configuration for Koha.
1228 Would you like to restart Apache now? [Y]/N: |;
1232 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1236 unless ($response=~/^n/i) {
1237 # Need to support other init structures here?
1238 if (-e "/etc/rc.d/init.d/httpd") {
1239 system('/etc/rc.d/init.d/httpd restart');
1240 } elsif (-e "/etc/init.d/apache") {
1241 system('/etc//init.d/apache restart');
1242 } elsif (-e "/etc/init.d/apache-ssl") {
1243 system('/etc/init.d/apache-ssl restart');
1249 # Installation is complete. Rename the koha.conf.tmp file
1251 rename "$::etcdir/koha.conf.tmp", "$::etcdir/koha.conf" || warn "Couldn't rename file at $::etcdir. Must have write capability.\n";
1253 sub loadconfigfile {
1256 open (KC, "/etc/koha.conf");
1259 (next) if (/^\s*#/);
1260 if (/(.*)\s*=\s*(.*)/) {
1263 # Clean up white space at beginning and end
1264 $variable=~s/^\s*//g;
1265 $variable=~s/\s*$//g;
1268 $configfile{$variable}=$value;
1272 $::intranetdir=$configfile{'intranetdir'};
1273 $::opacdir=$configfile{'opacdir'};
1274 $::kohaversion=$configfile{'kohaversion'};
1275 $::kohalogdir=$configfile{'kohalogdir'};
1276 $::database=$configfile{'database'};
1277 $::hostname=$configfile{'hostname'};
1278 $::user=$configfile{'user'};
1279 $::pass=$configfile{'pass'};
1282 END { } # module clean-up code here (global destructor)