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
34 &releasecandidatewarning
35 &getinstallationdirectories
51 $messages->{'continuing'}->{en}="Great! Continuing setup.\n\n";
52 $messages->{'WelcomeToKohaInstaller'}->{en}=qq|
53 =================================
54 = Welcome to the Koha Installer =
55 =================================
57 Welcome to the Koha install script! This script will prompt you for some
58 basic information about your desired setup, then install Koha according to
59 your specifications. To accept the default value for any question, simply hit
62 Please be sure to read the documentation, or visit the Koha website at
63 http://www.koha.org for more information.
65 Are you ready to begin the installation? (Y/[N]): |;
66 $messages->{'ReleaseCandidateWarning'}->{en}=qq|
71 WARNING WARNING WARNING WARNING WARNING
73 You are about to install Koha version %s. This version of Koha is a
74 release candidate. It is not intended to be installed on production systems.
75 It is being released so that users can test it before we release a final
78 Are you sure you want to install Koha %s? (Y/[N]): |;
79 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
81 Watch for announcements of Koha releases on the Koha mailing list or the Koha
82 web site (http://www.koha.org/).
86 $messages->{'NETZ3950Missing'}->{en}=qq|
88 The Net::Z3950 module is missing. This module is necessary if you want to use
89 Koha's Z39.50 client to download bibliographic records from other libraries.
90 To install this module, you will need the yaz client installed from
91 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
94 perl -MCPAN -e 'install Net::Z3950'
96 Press the <ENTER> key to continue: |;
98 $messages->{'CheckingPerlModules'}->{en}=qq|
104 Checking perl modules ...
107 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
109 $messages->{'MissingPerlModules'}->{en}=qq|
111 ========================
112 = MISSING PERL MODULES =
113 ========================
115 You are missing some Perl modules which are required by Koha.
116 Once these modules have been installed, rerun this installer.
117 They can be installed by running (as root) the following:
122 $messages->{'AllPerlModulesInstalled'}->{en}=qq|
124 ==============================
125 = ALL PERL MODULES INSTALLED =
126 ==============================
128 All mandatory perl modules are installed.
130 Press <ENTER> to continue: |;
131 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
132 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
133 $messages->{'KohaAlreadyInstalled'}->{en}=qq|
134 ==========================
135 = Koha already installed =
136 ==========================
138 It looks like Koha is already installed on your system (%s/koha.conf exists
139 already). If you would like to upgrade your system to %s, please use
140 the koha.upgrade script in this directory.
145 $messages->{'GetOpacDir'}->{en}=qq|
150 Please supply the directory you want Koha to store its OPAC files in. This
151 directory will be auto-created for you if it doesn't exist.
153 OPAC Directory [%s]: |;
155 $messages->{'GetIntranetDir'}->{en}=qq|
156 =================================
157 = INTRANET/LIBRARIANS DIRECTORY =
158 =================================
160 Please supply the directory you want Koha to store its Intranet/Librarians
161 files in. This directory will be auto-created for you if it doesn't exist.
163 Intranet Directory [%s]: |;
165 $messages->{'GetKohaLogDir'}->{en}=qq|
166 ======================
167 = KOHA LOG DIRECTORY =
168 ======================
170 Specify a log directory where any Koha daemons can create log files.
172 Koha Log Directory [%s]: |;
174 $messages->{'AuthenticationWarning'}->{en}=qq|
179 This release of Koha has a new authentication module. If you are not already
180 using basic authentication on your intranet, you will be required to log in to
181 access some of the features of the intranet. You can log in using the userid
182 and password from the %s/koha.conf configuration file at any time. Use the
183 "Members" module to add passwords for other accounts and set their permissions.
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 :
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 # Assuming that Koha will be installed on a modern Unix with symlinks,
224 # it is possible to code the installer so that aborted installs can be
225 # detected. In case of such an event we can do our best to "roll back"
226 # the aborted install.
228 # FIXME: The "roll back" is not complete!
231 sub checkabortedinstall {
232 if (-l("$::etcdir/koha.conf")
233 && readlink("$::etcdir/koha.conf") =~ /\.tmp$/
236 I have detected that you tried to install Koha before, but the installation
237 was aborted. I will try to continue, but there might be problems if the
238 database is already created.
241 print "Please press <ENTER> to continue: ";
244 # Remove the symlink after the <STDIN>, so the user can back out
245 unlink "$::etcdir/koha.conf"
246 || die "Failed to remove incomplete $::etcdir/koha.conf: $!\n";
251 # Test for Perl and Modules
254 sub checkperlmodules {
255 my $message = getmessage('CheckingPerlModules');
256 showmessage($message, 'none');
258 unless (eval "require 5.006_000") {
259 die getmessage('PerlVersionFailure', ['5.6.0']);
263 unless (eval {require DBI}) { push @missing,"DBI" };
264 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
265 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
266 unless (eval {require HTML::Template}) { push @missing,"HTML::Template" };
267 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
268 unless (eval {require Digest::MD5}) { push @missing,"Digest::MD5" };
269 unless (eval {require MARC::Record}) { push @missing,"MARC::Record" };
270 unless (eval {require Net::Z3950}) {
271 my $message = getmessage('NETZ3950Missing');
272 showmessage($message, 'PressEnter', '', 1);
274 push @missing, "Net::Z3950";
279 # Print out a list of any missing modules
284 foreach my $module (@missing) {
285 $missing.=" perl -MCPAN -e 'install \"$module\"'\n";
287 my $message=getmessage('MissingPerlModules', [$missing]);
288 showmessage($message, 'none');
291 showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
295 unless (-x "/usr/bin/perl") {
296 my $realperl=`which perl`;
298 $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
299 until (-x $realperl) {
300 $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
302 my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
303 unless ($response eq 'n') {
304 system("ln -s $realperl /usr/bin/perl");
311 $messages->{'NoUsrBinPerl'}->{en}=qq|
313 ========================================
314 = Perl is not located in /usr/bin/perl =
315 ========================================
317 The Koha perl scripts expect to find the perl executable in the /usr/bin
318 directory. It is not there on your system.
322 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
323 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
324 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
326 May I create this symlink? ([Y]/N):
330 my $messagename=shift;
332 my $message=$messages->{$messagename}->{$::language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
333 if (defined($variables)) {
334 $message=sprintf $message, @$variables;
342 my $responsetype=shift;
343 my $defaultresponse=shift;
345 ($noclear) || (system('clear'));
346 if ($responsetype =~ /^yn$/) {
347 $responsetype='restrictchar yn';
351 if ($responsetype =~/^restrictchar (.*)/i) {
354 until ($options=~/$response/) {
355 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
358 (length($response)) || ($response=$defaultresponse);
359 unless ($options=~/$response/) {
360 ($noclear) || (system('clear'));
361 print "Invalid Response. Choose from [$options].\n\n";
367 if ($responsetype =~/^free$/i) {
368 (defined($defaultresponse)) || ($defaultresponse='');
369 my $response=<STDIN>;
371 ($response) || ($response=$defaultresponse);
374 if ($responsetype =~/^numerical$/i) {
375 (defined($defaultresponse)) || ($defaultresponse='');
377 until ($response=~/^\d+$/) {
380 ($response) || ($response=$defaultresponse);
381 unless ($response=~/^\d+$/) {
382 ($noclear) || (system('clear'));
383 print "Invalid Response ($response). Response must be a number.\n\n";
389 if ($responsetype =~/^email$/i) {
390 (defined($defaultresponse)) || ($defaultresponse='');
392 until ($response=~/.*\@.*\..*/) {
395 ($response) || ($response=$defaultresponse);
396 unless ($response=~/.*\@.*\..*/) {
397 ($noclear) || (system('clear'));
398 print "Invalid Response ($response). Response must be a valid email address.\n\n";
404 if ($responsetype =~/^PressEnter$/i) {
408 if ($responsetype =~/^none$/i) {
414 sub getinstallationdirectories {
415 $::opacdir = '/usr/local/koha/opac';
416 $::intranetdir = '/usr/local/koha/intranet';
418 while ($getdirinfo) {
419 # Loop until opac directory and koha directory are different
420 my $message=getmessage('GetOpacDir', [$::opacdir]);
421 $::opacdir=showmessage($message, 'free', $::opacdir);
423 $message=getmessage('GetIntranetDir', [$::intranetdir]);
424 $::intranetdir=showmessage($message, 'free', $::intranetdir);
426 if ($::intranetdir eq $::opacdir) {
429 You must specify different directories for the OPAC and INTRANET files!
430 :: $::intranetdir :: $::opacdir ::
437 $::kohalogdir='/var/log/koha';
438 my $message=getmessage('GetKohaLogDir', [$::kohalogdir]);
439 $::kohalogdir=showmessage($message, 'free', $::kohalogdir);
442 unless ( -d $::intranetdir ) {
443 my $result=mkdir ($::intranetdir, oct(770));
445 my @dirs = split(m#/#, $::intranetdir);
449 unless (-e "$checkdir") {
450 mkdir($checkdir, 0775);
454 chown (oct(0), (getgrnam($::httpduser))[2], "$::intranetdir");
455 chmod (oct(770), "$::intranetdir");
457 unless ( -d "$::intranetdir/htdocs" ) {
458 mkdir ("$::intranetdir/htdocs", oct(750));
460 unless ( -d "$::intranetdir/cgi-bin" ) {
461 mkdir ("$::intranetdir/cgi-bin", oct(750));
463 unless ( -d "$::intranetdir/modules" ) {
464 mkdir ("$::intranetdir/modules", oct(750));
466 unless ( -d "$::intranetdir/scripts" ) {
467 mkdir ("$::intranetdir/scripts", oct(750));
469 unless ( -d $::opacdir ) {
470 my $result=mkdir ($::opacdir, oct(770));
472 my @dirs = split(m#/#, $::opacdir);
476 unless (-e "$checkdir") {
477 mkdir($checkdir, 0775);
481 chown (oct(0), (getgrnam($::httpduser))[2], "$::opacdir");
482 chmod (oct(770), "$::opacdir");
484 unless ( -d "$::opacdir/htdocs" ) {
485 mkdir ("$::opacdir/htdocs", oct(750));
487 unless ( -d "$::opacdir/cgi-bin" ) {
488 mkdir ("$::opacdir/cgi-bin", oct(750));
492 unless ( -d $::kohalogdir ) {
493 my $result=mkdir ($::kohalogdir, oct(770));
495 my @dirs = split(m#/#, $::kohalogdir);
499 unless (-e "$checkdir") {
500 mkdir($checkdir, 0775);
505 chown (oct(0), (getgrnam($::httpduser))[2,3], "$::kohalogdir");
506 chmod (oct(770), "$::kohalogdir");
512 $messages->{'DatabaseName'}->{en}=qq|
513 ==========================
514 = Name of MySQL database =
515 ==========================
517 Please provide the name of the mysql database for your koha installation.
519 Database name [%s]: |;
521 $messages->{'DatabaseHost'}->{en}=qq|
526 Please provide the hostname for mysql. Unless the database is located on
527 another machine this will be "localhost".
529 Database host [%s]: |;
531 $messages->{'DatabaseUser'}->{en}=qq|
536 Please provide the name of the user, who will have full administrative rights
537 to the %s database, when authenticating from %s.
539 This user will also be used to access Koha's INTRANET interface.
541 Database user [%s]: |;
543 $messages->{'DatabasePassword'}->{en}=qq|
544 =====================
545 = Database Password =
546 =====================
548 Please provide a good password for the user %s.
550 Database Password: |;
552 $messages->{'BlankPassword'}->{en}=qq|
557 You must not use a blank password for your MySQL user!
559 Press <ENTER> to try again:
562 sub getdatabaseinfo {
565 $::hostname = 'localhost';
566 $::user = 'kohaadmin';
569 #Get the database name
571 my $message=getmessage('DatabaseName', [$::dbname]);
572 $::dbname=showmessage($message, 'free', $::dbname);
574 #Get the hostname for the database
576 $message=getmessage('DatabaseHost', [$::hostname]);
577 $::hostname=showmessage($message, 'free', $::hostname);
579 #Get the username for the database
581 $message=getmessage('DatabaseUser', [$::dbname, $::hostname, $::user]);
582 $::user=showmessage($message, 'free', $::user);
584 #Get the password for the database user
586 while ($::pass eq '') {
587 my $message=getmessage('DatabasePassword', [$::user]);
588 $::pass=showmessage($message, 'free', $::pass);
590 my $message=getmessage('BlankPassword');
591 showmessage($message,'PressEnter');
598 $messages->{'FoundMultipleApacheConfFiles'}->{en}=qq|
599 ================================
600 = MULTIPLE APACHE CONFIG FILES =
601 ================================
603 I found more than one possible Apache configuration file:
607 Choose the correct file [1]: |;
609 $messages->{'NoApacheConfFiles'}->{en}=qq|
610 ===============================
611 = NO APACHE CONFIG FILE FOUND =
612 ===============================
614 I was not able to find your Apache configuration file.
616 The file is usually called httpd.conf or apache.conf.
618 Please specify the location of your config file: |;
620 $messages->{'NotAFile'}->{en}=qq|
621 =======================
622 = FILE DOES NOT EXIST =
623 =======================
625 The file %s does not exist.
627 Please press <ENTER> to continue: |;
629 $messages->{'EnterApacheUser'}->{en}=qq|
634 I was not able to determine the user that Apache is running as. This
635 information is necessary in order to set the access privileges correctly on
636 %s/koha.conf. This user should be set in one of the Apache configuration
637 files using the "User" directive.
639 Enter the Apache userid: |;
641 $messages->{'InvalidUserid'}->{en}=qq|
646 The userid %s is not a valid userid on this system.
648 Press <ENTER> to continue: |;
651 my @confpossibilities;
653 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
654 /usr/local/etc/apache/httpd.conf
655 /usr/local/etc/apache/apache.conf
656 /var/www/conf/httpd.conf
657 /etc/apache/conf/httpd.conf
658 /etc/apache/conf/apache.conf
659 /etc/apache-ssl/conf/apache.conf
660 /etc/apache-ssl/httpd.conf
661 /etc/httpd/conf/httpd.conf
662 /etc/httpd/httpd.conf)) {
663 if ( -f $httpdconf ) {
664 push @confpossibilities, $httpdconf;
668 if ($#confpossibilities==-1) {
669 my $message=getmessage('NoApacheConfFiles');
671 until (-f $::realhttpdconf) {
672 $choice=showmessage($message, "free", 1);
674 $::realhttpdconf=$choice;
676 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
679 } elsif ($#confpossibilities>0) {
683 foreach (@confpossibilities) {
684 $conffiles.=" $counter: $_\n";
685 $options.="$counter";
688 my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
689 my $choice=showmessage($message, "restrictchar $options", 1);
690 $::realhttpdconf=$confpossibilities[$choice-1];
692 $::realhttpdconf=$confpossibilities[0];
694 unless (open (HTTPDCONF, "<$::realhttpdconf")) {
695 warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
699 while (<HTTPDCONF>) {
700 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
709 unless ($::httpduser) {
710 my $message=getmessage('EnterApacheUser', [$::etcdir]);
711 until (length($::httpduser) && getpwnam($::httpduser)) {
712 $::httpduser=showmessage($message, "free", '');
713 if (length($::httpduser)>0) {
714 unless (getpwnam($::httpduser)) {
715 my $message=getmessage('InvalidUserid', [$::httpduser]);
716 showmessage($message,'PressEnter');
721 print "AU: $::httpduser\n";
726 $messages->{'ApacheConfigIntroduction'}->{en}=qq|
727 ========================
728 = APACHE CONFIGURATION =
729 ========================
731 Koha needs to setup your Apache configuration file for the
732 OPAC and LIBRARIAN virtual hosts. By default this installer
733 will do this by using one ip address and two different ports
734 for the virtual hosts. There are other ways to set this up,
735 and the installer will leave comments in httpd.conf detailing
736 what these other options are.
739 Press <ENTER> to continue: |;
741 $messages->{'GetVirtualHostEmail'}->{en}=qq|
742 =============================
743 = WEB SERVER E-MAIL CONTACT =
744 =============================
746 Enter the e-mail address to be used as a contact for the virtual hosts (this
747 address is displayed if any errors are encountered).
749 E-mail contact [%s]: |;
751 $messages->{'GetServerName'}->{en}=qq|
752 ======================================
753 = WEB SERVER HOST NAME OR IP ADDRESS =
754 ======================================
756 Please enter the domain name or ip address of your computer.
758 Host name or IP Address [%s]: |;
760 $messages->{'GetOpacPort'}->{en}=qq|
761 ==========================
762 = OPAC VIRTUAL HOST PORT =
763 ==========================
765 Please enter the port for your OPAC interface. This defaults to port 80, but
766 if you are already serving web content from this server, you should change it
767 to a different port (8000 might be a good choice).
769 Enter the OPAC Port [%s]: |;
771 $messages->{'GetIntranetPort'}->{en}=qq|
772 ==============================
773 = INTRANET VIRTUAL HOST PORT =
774 ==============================
776 Please enter the port for your Intranet interface. This must be different from
779 Enter the Intranet Port [%s]: |;
782 sub getapachevhostinfo {
784 $::svr_admin = "webmaster\@$::domainname";
785 $::servername=`hostname -f`;
788 $::intranetport=8080;
790 showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
792 $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
793 $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
796 $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
797 $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
801 $messages->{'StartUpdateApache'}->{en}=qq|
802 =================================
803 = UPDATING APACHE CONFIGURATION =
804 =================================
806 Checking for modules that need to be loaded...
809 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
811 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
813 $messages->{'ApacheConfigBackupFailed'}->{en}=qq|
814 ======================================
815 = APACHE CONFIGURATION BACKUP FAILED =
816 ======================================
818 An error occurred while trying to make a backup copy of %s.
822 No changes will be made to the apache configuration file at this time.
824 Press <ENTER> to continue: |;
827 $messages->{'ApacheAlreadyConfigured'}->{en}=qq|
828 =============================
829 = APACHE ALREADY CONFIGURED =
830 =============================
832 %s appears to already have an entry for Koha
833 Virtual Hosts. You may need to edit %s
834 f anything has changed since it was last set up. This
835 script will not attempt to modify an existing Koha apache
838 Press <ENTER> to continue: |;
840 sub updateapacheconf {
841 my $logfiledir=`grep ^ErrorLog "$::realhttpdconf"`;
845 $logfiledir=~m#ErrorLog (.*)/[^/]*$#
846 or die "Can't parse ErrorLog directive\n";
850 unless ($logfiledir) {
854 showmessage(getmessage('StartUpdateApache'), 'none');
858 my $includesmodule=0;
859 open HC, "<$::realhttpdconf";
861 if (/^\s*#\s*LoadModule env_module /) {
863 showmessage(getmessage('LoadingApacheModuleModEnv'));
866 if (/^\s*#\s*LoadModule includes_module /) {
868 showmessage(getmessage('LoadingApacheModuleModInc'));
870 if (/\s*LoadModule includes_module / ) {
877 $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
879 showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
883 if ($envmodule || $includesmodule) {
884 open HC, ">$::realhttpdconf";
891 if (`grep 'VirtualHost $::servername' "$::realhttpdconf"`) {
892 showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
895 my $includesdirectives='';
896 if ($includesmodule) {
897 $includesdirectives.="Options +Includes\n";
898 $includesdirectives.=" AddHandler server-parsed .html\n";
900 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
902 if ($::opacport != 80) {
903 $opaclisten="Listen $::opacport";
905 my $intranetlisten = '';
906 if ($::intranetport != 80) {
907 $intranetlisten="Listen $::intranetport";
911 # Ports to listen to for Koha
915 # NameVirtualHost is used by one of the optional configurations detailed below
917 #NameVirtualHost 11.22.33.44
919 # KOHA's OPAC Configuration
920 <VirtualHost $::servername\:$::opacport>
921 ServerAdmin $::svr_admin
922 DocumentRoot $::opacdir/htdocs
923 ServerName $::servername
924 ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
925 ErrorLog $logfiledir/opac-error_log
926 TransferLog $logfiledir/opac-access_log
927 SetEnv PERL5LIB "$::intranetdir/modules"
931 # KOHA's INTRANET Configuration
932 <VirtualHost $::servername\:$::intranetport>
933 ServerAdmin $::svr_admin
934 DocumentRoot $::intranetdir/htdocs
935 ServerName $::servername
936 ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
937 ErrorLog $logfiledir/koha-error_log
938 TransferLog $logfiledir/koha-access_log
939 SetEnv PERL5LIB "$::intranetdir/modules"
943 # If you want to use name based Virtual Hosting:
944 # 1. remove the two Listen lines
945 # 2. replace $::servername\:$::opacport wih your.opac.domain.name
946 # 3. replace ServerName $::servername wih ServerName your.opac.domain.name
947 # 4. replace $::servername\:$::intranetport wih your intranet domain name
948 # 5. replace ServerName $::servername wih ServerName your.intranet.domain.name
950 # If you want to use NameVirtualHost'ing (using two names on one ip address):
951 # 1. Follow steps 1-5 above
952 # 2. Uncomment the NameVirtualHost line and set the correct ip address
960 $messages->{'IntranetAuthenticationQuestion'}->{en}=qq|
961 ===========================
962 = INTRANET AUTHENTICATION =
963 ===========================
965 I can set it up so that the Intranet/Librarian site is password protected using
966 Apache's Basic Authorization.
968 This is going to be phased out very soon. However, setting this up can provide
969 an extra layer of security before the new authentication system is completely
972 Would you like to do this ([Y]/N): |;
974 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
975 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
976 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
978 sub basicauthentication {
979 my $message=getmessage('IntranetAuthenticationQuestion');
980 my $answer=showmessage($message, 'yn', 'y');
982 my $apacheauthusername='librarian';
983 my $apacheauthpassword='';
984 if ($answer=~/^y/i) {
985 ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
986 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
987 while (! $apacheauthpassword) {
988 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
989 if (!$apacheauthpassword) {
990 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
993 open AUTH, ">$::etcdir/kohaintranet.pass";
994 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
995 my $salt=substr($chars, int(rand(length($chars))),1);
996 $salt.=substr($chars, int(rand(length($chars))),1);
997 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
999 open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
1002 <Directory $::intranetdir>
1003 AuthUserFile $::etcdir/kohaintranet.pass
1005 AuthName "Koha Intranet (for librarians only)"
1013 $messages->{'InstallFiles'}->{en}=qq|
1014 ====================
1015 = INSTALLING FILES =
1016 ====================
1018 Copying files to installation directories:
1023 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1030 showmessage(getmessage('InstallFiles'),'none');
1031 print getmessage('CopyingFiles', ['intranet-html', "$::intranetdir/htdocs" ]);
1032 system("cp -R intranet-html/* $::intranetdir/htdocs/");
1033 print getmessage('CopyingFiles', ['intranet-cgi', "$::intranetdir/cgi-bin" ]);
1034 system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
1035 print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
1036 system("cp -R scripts/* $::intranetdir/scripts/");
1037 print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
1038 system("cp -R modules/* $::intranetdir/modules/");
1039 print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
1040 system("cp -R opac-html/* $::opacdir/htdocs/");
1041 print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
1042 system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
1043 system("touch $::opacdir/cgi-bin/opac");
1045 system("chown -R root:$::httpduser $::opacdir");
1046 system("chown -R root:$::httpduser $::intranetdir");
1048 # Create /etc/koha.conf
1050 my $old_umask = umask(027); # make sure koha.conf is never world-readable
1051 open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1054 hostname=$::hostname
1057 includes=$::opacdir/htdocs/includes
1058 intranetdir=$::intranetdir
1060 kohalogdir=$::kohalogdir
1061 kohaversion=$::kohaversion
1062 httpduser=$::httpduser
1063 intrahtdocs=$::intranetdir/htdocs/intranet-tmpl
1064 opachtdocs=$::opacdir/htdocs/opac-tmpl
1069 chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1070 chmod 0440, "$::etcdir/koha.conf.tmp";
1072 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1073 chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1074 chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
1075 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1076 chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
1080 $messages->{'MysqlRootPassword'}->{en}=qq|
1081 ============================
1082 = MYSQL ROOT USER PASSWORD =
1083 ============================
1085 To allow us to create the koha database please supply your
1086 mysql server's root user password:
1088 Enter MySQL root user password: |;
1090 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password. Please try again.";
1092 $messages->{'CreatingDatabase'}->{en}=qq|
1093 =====================
1094 = CREATING DATABASE =
1095 =====================
1097 Creating the MySQL database for Koha...
1101 $messages->{'CreatingDatabaseError'}->{en}=qq|
1102 ===========================
1103 = ERROR CREATING DATABASE =
1104 ===========================
1106 Couldn't connect to the MySQL server for the reason given above.
1107 This is a serious problem, the database will not get installed.
\a
1109 Press <ENTER> to continue: |;
1111 $messages->{'SampleData'}->{en}=qq|
1116 If you are installing Koha for evaluation purposes, I have a batch of sample
1117 data that you can install now.
1119 If you are installing Koha with the intention of populating it with your own
1120 data, you probably don't want this sample data installed.
1122 Would you like to install the sample data? Y/[N]: |;
1124 $messages->{'SampleDataInstalled'}->{en}=qq|
1125 =========================
1126 = SAMPLE DATA INSTALLED =
1127 =========================
1129 Sample data has been installed. For some suggestions on testing Koha, please
1130 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
1131 http://bugs.koha.org/. If you need help with testing Koha, you can post a
1132 question through the koha-devel mailing list, or you can check for a developer
1133 online at +irc.katipo.co.nz:6667 channel #koha.
1135 You can find instructions for subscribing to the Koha mailing lists at:
1140 Press <ENTER> to continue: |;
1142 $messages->{'AddBranchPrinter'}->{en}=qq|
1143 ==========================
1144 = Add Branch and Printer =
1145 ==========================
1147 Would you like to install an initial branch and printer? [Y]/N: |;
1149 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1150 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1151 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1152 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1153 $messages->{'BlankMysqlPassword'}->{en}=qq|
1154 ========================
1155 = Blank MySql Password =
1156 ========================
1158 Do not leave your MySql root password blank unless you know exactly what you
1159 are doing. To change your MySql root password use the mysqladmin command:
1161 mysqladmin password NEWPASSWORDHERE
1163 Press <ENTER> to continue:
1167 $::mysqluser = 'root';
1170 foreach my $mysql (qw(/usr/local/mysql
1174 if ( -d $mysql && -f "$mysql/bin/mysqladmin") {
1179 print "I don't see mysql in the usual places.\n";
1181 print "Where have you installed mysql? ";
1182 chomp($::mysqldir = <STDIN>);
1183 last if -f "$::mysqldir/bin/mysqladmin";
1186 I can't find it there either. If you compiled mysql yourself,
1187 please give the value of --prefix when you ran configure.
1189 The file mysqladmin should be in bin/mysqladmin under the directory that you
1198 while ($needpassword) {
1199 $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1200 $::mysqlpass_quoted = $::mysqlpass;
1201 $::mysqlpass_quoted =~ s/"/\\"/g;
1202 $::mysqlpass_quoted="-p\"$::mysqlpass_quoted\"";
1203 $::mysqlpass eq '' and $::mysqlpass_quoted='';
1204 my $result=system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted proc > /dev/null 2>&1");
1206 print getmessage('InvalidMysqlRootPassword');
1208 if ($::mysqlpass eq '') {
1209 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1215 showmessage(getmessage('CreatingDatabase'),'none');
1217 my $result=system("$::mysqldir/bin/mysqladmin", "-u$::mysqluser", "-p$::mysqlpass", "create", "$::dbname");
1219 showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1221 # Populate the Koha database
1222 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname < koha.mysql");
1223 # Set up permissions
1224 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1225 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')\"");
1226 system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted reload");
1236 $messages->{'UpdateMarcTables'}->{en}=qq|
1237 =========================================
1238 = UPDATING MARC FIELD DEFINITION TABLES =
1239 =========================================
1241 You can import marc parameters for :
1247 Please choose which parameter you want to install. Note if you choose 3,
1248 nothing will be added, and it can be a BIG job to manually create those tables
1250 Choose MARC definition [1]: |;
1252 $messages->{'Language'}->{en}=qq|
1253 ====================
1254 = CHOOSE LANGUAGES =
1255 ====================
1256 This version of koha supports a few languages.
1257 Enter you languages preferences : either en, fr, es or pl.
1258 Note that the en is always choosen when the system does not finds the
1259 language you choose in a specific screen.
1260 fr : opac is translated (except pictures)
1261 es : a few intranet is translated (including pictures)
1262 pl : opac is translated (UNTESTED in this release)
1265 sub updatedatabase {
1266 # At this point, $::etcdir/koha.conf must exist, for C4::Context
1267 # We must somehow temporarily enable $::etcdir/koha.conf. A symlink can
1268 # do this & at the same time facilitate detection of aborted installs.
1269 my $result=system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1271 print "Problem updating database...\n";
1275 my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 123', '1');
1277 if ($response == 1) {
1278 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1280 if ($response == 2) {
1281 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1282 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1285 $result = system ("perl -I $::intranetdir/modules scripts/marc/updatedb2marc.pl");
1287 print "Problem updating database to MARC...\n";
1291 print "\n\nFinished updating of database. Press <ENTER> to continue...";
1295 sub populatedatabase {
1296 my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1297 if ($response =~/^y/i) {
1298 system("gunzip -d < sampledata-1.2.gz | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1299 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1300 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1301 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1302 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1303 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1306 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1308 unless ($response =~/^n/i) {
1309 my $branch='Main Library';
1310 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1311 $branch=~s/[^A-Za-z0-9\s]//g;
1313 my $branchcode=$branch;
1314 $branchcode=~s/[^A-Za-z0-9]//g;
1315 $branchcode=uc($branchcode);
1316 $branchcode=substr($branchcode,0,4);
1317 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1318 $branchcode=~s/[^A-Za-z0-9]//g;
1319 $branchcode=uc($branchcode);
1320 $branchcode=substr($branchcode,0,4);
1321 $branchcode or $branchcode='DEF';
1323 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1324 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1325 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1327 my $printername='Library Printer';
1328 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1329 $printername=~s/[^A-Za-z0-9\s]//g;
1331 my $printerqueue='lp';
1332 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1333 $printerqueue=~s/[^A-Za-z0-9]//g;
1334 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1336 my $language=showmessage(getmessage('Language'), 'free', 'en');
1337 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1341 $messages->{'RestartApache'}->{en}=qq|
1346 Apache needs to be restarted to load the new configuration for Koha.
1348 Would you like to restart Apache now? [Y]/N: |;
1352 my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1356 unless ($response=~/^n/i) {
1357 # Need to support other init structures here?
1358 if (-e "/etc/rc.d/init.d/httpd") {
1359 system('/etc/rc.d/init.d/httpd restart');
1360 } elsif (-e "/etc/init.d/apache") {
1361 system('/etc//init.d/apache restart');
1362 } elsif (-e "/etc/init.d/apache-ssl") {
1363 system('/etc/init.d/apache-ssl restart');
1370 sub loadconfigfile {
1373 open (KC, "<$::etcdir/koha.conf");
1376 (next) if (/^\s*#/);
1377 if (/(.*)\s*=\s*(.*)/) {
1380 # Clean up white space at beginning and end
1381 $variable=~s/^\s*//g;
1382 $variable=~s/\s*$//g;
1385 $configfile{$variable}=$value;
1389 $::intranetdir=$configfile{'intranetdir'};
1390 $::opacdir=$configfile{'opacdir'};
1391 $::kohaversion=$configfile{'kohaversion'};
1392 $::kohalogdir=$configfile{'kohalogdir'};
1393 $::database=$configfile{'database'};
1394 $::hostname=$configfile{'hostname'};
1395 $::user=$configfile{'user'};
1396 $::pass=$configfile{'pass'};
1399 END { } # module clean-up code here (global destructor)