3a3077815980a801f65b21b8db514012d227d9e8
[koha.git] / misc / Install.pm
1 package Install; #assumes Install.pm
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20
21 use strict;
22 use POSIX;
23 require Exporter;
24
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
26
27 =head1 NAME
28
29 Install.pm - Perl module containing the bulk of the installation logic
30
31 =head1 DESCRIPTION
32
33 The Install.pm module contains the bulk
34 of the code to do installation;
35 this code is used by installer.pl
36 to perform an actual installation.
37
38 =head2 Internal functions (not meant to be used outside of Install.pm)
39
40 =over 4
41
42 =cut
43
44 # set the version for version checking
45 $VERSION = 0.01;
46
47 @ISA = qw(Exporter);
48 @EXPORT = qw(   &checkperlmodules
49                 &checkabortedinstall
50                 &getmessage
51                 &showmessage
52                 &releasecandidatewarning
53                 &getinstallationdirectories
54                 &getdatabaseinfo
55                 &getapacheinfo
56                 &getapachevhostinfo
57                 &updateapacheconf
58                 &basicauthentication
59                 &installfiles
60                 &databasesetup
61                 &updatedatabase
62                 &populatedatabase
63                 &restartapache
64                 &loadconfigfile
65                 );
66
67
68 =item heading
69
70     $messages->{'WelcomeToKohaInstaller'
71         = heading('Welcome to the Koha Installer') . qq|...|;
72
73 The heading function takes one string, the text to be displayed as
74 the heading, and returns a formatted heading (currently formatted
75 in the "traditional Koha installer" style, i.e., surrounded by a
76 box of equal signs).
77
78 This reduces the likelihood of pod2man(1) etc. misinterpreting
79 a line of equal signs as POD directives.
80
81 =cut
82
83 sub heading ($) {
84    my($s) = @_;
85    my $n = length($s) + 4;
86    my $line = ('=' x $n) . "\n";
87    "\n$line= $s =\n$line\n";
88 }
89
90 my $messages;
91 $messages->{'continuing'}->{en}="Great!  Continuing setup.\n\n";
92 $messages->{'WelcomeToKohaInstaller'}->{en} =
93    heading('Welcome to the Koha Installer') . qq|
94 Welcome to the Koha install script!  This script will prompt you for some
95 basic information about your desired setup, then install Koha according to
96 your specifications.  To accept the default value for any question, simply hit
97 Enter at the prompt.
98
99 Please be sure to read the documentation, or visit the Koha website at
100 http://www.koha.org for more information.
101
102 Are you ready to begin the installation? (Y/[N]): |;
103 $messages->{'ReleaseCandidateWarning'}->{en} =
104    heading('RELEASE CANDIDATE') . qq|
105 WARNING WARNING WARNING WARNING WARNING
106
107 You are about to install Koha version %s.  This version of Koha is a
108 release candidate.  It is not intended to be installed on production systems.
109 It is being released so that users can test it before we release a final
110 version.
111
112 Are you sure you want to install Koha %s? (Y/[N]): |;
113 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
114
115 Watch for announcements of Koha releases on the Koha mailing list or the Koha
116 web site (http://www.koha.org/).
117
118 |;
119
120 $messages->{'NETZ3950Missing'}->{en}=qq|
121
122 The Net::Z3950 module is missing.  This module is necessary if you want to use
123 Koha's Z39.50 client to download bibliographic records from other libraries.
124 To install this module, you will need the yaz client installed from
125 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
126 command:
127
128 perl -MCPAN -e 'install Net::Z3950'
129
130 Press the <ENTER> key to continue: |;
131
132 $messages->{'CheckingPerlModules'}->{en} = heading('PERL & MODULES') . qq|
133 Checking perl modules ...
134 |;
135
136 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
137
138 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
139 You are missing some Perl modules which are required by Koha.
140 Once these modules have been installed, rerun this installer.
141 They can be installed by running (as root) the following:
142
143 %s
144 |;
145
146 $messages->{'AllPerlModulesInstalled'}->{en} =
147    heading('ALL PERL MODULES INSTALLED') . qq|
148 All mandatory perl modules are installed.
149
150 Press <ENTER> to continue: |;
151 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
152 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
153 $messages->{'KohaAlreadyInstalled'}->{en} =
154    heading('Koha already installed') . qq|
155 It looks like Koha is already installed on your system (%s/koha.conf exists
156 already).  If you would like to upgrade your system to %s, please use
157 the koha.upgrade script in this directory.
158
159 %s
160
161 |;
162 $messages->{'GetOpacDir'}->{en} = heading('OPAC DIRECTORY') . qq|
163 Please supply the directory you want Koha to store its OPAC files in.  This
164 directory will be auto-created for you if it doesn't exist.
165
166 OPAC Directory [%s]: |;
167
168 $messages->{'GetIntranetDir'}->{en} =
169    heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
170 Please supply the directory you want Koha to store its Intranet/Librarians
171 files in.  This directory will be auto-created for you if it doesn't exist.
172
173 Intranet Directory [%s]: |;
174
175 $messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
176 Specify a log directory where any Koha daemons can create log files.
177
178 Koha Log Directory [%s]: |;
179
180 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
181 This release of Koha has a new authentication module.  If you are not already
182 using basic authentication on your intranet, you will be required to log in to
183 access some of the features of the intranet.  You can log in using the userid
184 and password from the %s/koha.conf configuration file at any time.  Use the
185 "Members" module to add passwords for other accounts and set their permissions.
186
187 Press the <ENTER> key to continue: |;
188
189 $messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
190 Congratulations ... your Koha installation is complete!
191
192 You will be able to connect to your Librarian interface at:
193
194    http://%s\:%s/
195
196 and the OPAC interface at :
197
198    http://%s\:%s/
199
200 Be sure to read the INSTALL, and Hints files.
201
202 For more information visit http://www.koha.org
203
204 Press <ENTER> to exit the installer: |;
205
206 sub releasecandidatewarning {
207     my $message=getmessage('ReleaseCandidateWarning', [$::newversion, $::newversion]);
208     my $answer=showmessage($message, 'yn', 'n');
209
210     if ($answer =~ /y/i) {
211         print getmessage('continuing');
212     } else {
213         my $message=getmessage('WatchForReleaseAnnouncements');
214         print $message;
215         exit;
216     };
217 }
218
219
220 =back
221
222 =head2 Miscellaneous utility functions
223
224 =over 4
225
226 =cut
227
228 =item dirname
229
230     dirname $path;
231
232 Does the equivalent of dirname(1). Given a path $path, return the
233 parent directory of $path (best guess), except when $path seems to
234 be the same as /, in which case $path itself is returned unchanged.
235
236 =cut
237
238 sub dirname ($;$) {
239     my($path) = @_;
240     if ($path =~ /[^\/]/s) {
241         if ($path =~ /\//) {
242             $path =~ s/\/+[^\/]+\/*$//s;
243         } else {
244             $path = '.';
245         }
246     }
247     return $path;
248 }
249
250 =item mkdir_parents
251
252     mkdir_parents $path;
253     mkdir_parents $path, $mode;
254
255 Does the equivalent of mkdir -p. Given a path $path, create the path
256 $path, recursively creating any intermediate directories. If $mode
257 is given, the directory will be created with mode $mode.
258
259 WARNING: If $path already exists, mkdir_parents will just return
260 successfully (just like mkdir -p), whether the mode of $path conforms
261 to $mode or not.
262
263 =cut
264
265 sub mkdir_parents ($;$) {
266     my($path, $mode) = @_;
267     my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
268
269     if (!$ok && $! == ENOENT) {
270         my $parent = dirname($path);
271         $ok = mkdir_parents($parent, $mode);
272
273         # retry and at the same time make sure that $! is set correctly
274         $ok = defined $mode? mkdir($path, $mode): mkdir($path);
275     }
276     return $ok;
277 }
278
279 =back
280
281 =head2 Subtasks of doing an installation
282
283 =over 4
284
285 =cut
286
287 =item checkabortedinstall
288
289     checkabortedinstall;
290
291 Assuming that Koha will be installed on a modern Unix with symlinks,
292 it is possible to code the installer so that aborted installs can be
293 detected. In case of such an event we can do our best to "roll back"
294 the aborted install.
295
296 FIXME: The "roll back" is not complete!
297
298 =cut
299
300 sub checkabortedinstall () {
301     if (-l("$::etcdir/koha.conf")
302         && readlink("$::etcdir/koha.conf") =~ /\.tmp$/
303     ) {
304         print qq|
305 I have detected that you tried to install Koha before, but the installation
306 was aborted.  I will try to continue, but there might be problems if the
307 database is already created.
308
309 |;
310         print "Please press <ENTER> to continue: ";
311         <STDIN>;
312
313         # Remove the symlink after the <STDIN>, so the user can back out
314         unlink "$::etcdir/koha.conf"
315             || die "Failed to remove incomplete $::etcdir/koha.conf: $!\n";
316     }
317 }
318
319 #
320 # Test for Perl and Modules
321 #
322 #
323 sub checkperlmodules {
324     my $message = getmessage('CheckingPerlModules');
325     showmessage($message, 'none');
326
327     unless (eval "require 5.006_000") {
328         die getmessage('PerlVersionFailure', ['5.6.0']);
329     }
330
331     my @missing = ();
332     unless (eval {require DBI})               { push @missing,"DBI" };
333     unless (eval {require Date::Manip})       { push @missing,"Date::Manip" };
334     unless (eval {require DBD::mysql})        { push @missing,"DBD::mysql" };
335     unless (eval {require HTML::Template})          { push @missing,"HTML::Template" };
336     unless (eval {require Set::Scalar})       { push @missing,"Set::Scalar" };
337     unless (eval {require Digest::MD5})       { push @missing,"Digest::MD5" };
338     unless (eval {require MARC::Record})       { push @missing,"MARC::Record" };
339     unless (eval {require Net::Z3950})        {
340         my $message = getmessage('NETZ3950Missing');
341         showmessage($message, 'PressEnter', '', 1);
342         if ($#missing>=0) {
343             push @missing, "Net::Z3950";
344         }
345     }
346
347 #
348 # Print out a list of any missing modules
349 #
350
351     if (@missing > 0) {
352         my $missing='';
353         foreach my $module (@missing) {
354             $missing.="   perl -MCPAN -e 'install \"$module\"'\n";
355         }
356         my $message=getmessage('MissingPerlModules', [$missing]);
357         showmessage($message, 'none');
358         exit;
359     } else {
360         showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
361     }
362
363
364     unless (-x "/usr/bin/perl") {
365         my $realperl=`which perl`;
366         chomp $realperl;
367         $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
368         until (-x $realperl) {
369             $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
370         }
371         my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
372         unless ($response eq 'n') {
373             system("ln -s $realperl /usr/bin/perl");
374         }
375     }
376
377
378 }
379
380 $messages->{'NoUsrBinPerl'}->{en} =
381    heading('Perl is not located in /usr/bin/perl') . qq|
382 The Koha perl scripts expect to find the perl executable in the /usr/bin
383 directory.  It is not there on your system.
384
385 |;
386
387 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
388 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
389 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
390
391 May I create this symlink? ([Y]/N):
392 : |;
393
394 sub getmessage {
395     my $messagename=shift;
396     my $variables=shift;
397     my $message=$messages->{$messagename}->{$::language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
398     if (defined($variables)) {
399         $message=sprintf $message, @$variables;
400     }
401     return $message;
402 }
403
404
405 sub showmessage {
406     my $message=shift;
407     my $responsetype=shift;
408     my $defaultresponse=shift;
409     my $noclear=shift;
410     ($noclear) || (system('clear'));
411     if ($responsetype =~ /^yn$/) {
412         $responsetype='restrictchar yn';
413     }
414     print $message;
415     SWITCH: {
416         if ($responsetype =~/^restrictchar (.*)/i) {
417             my $response='\0';
418             my $options=$1;
419             until ($options=~/$response/) {
420                 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
421                 $response=<STDIN>;
422                 chomp $response;
423                 (length($response)) || ($response=$defaultresponse);
424                 unless ($options=~/$response/) {
425                     ($noclear) || (system('clear'));
426                     print "Invalid Response.  Choose from [$options].\n\n";
427                     print $message;
428                 }
429             }
430             return $response;
431         }
432         if ($responsetype =~/^free$/i) {
433             (defined($defaultresponse)) || ($defaultresponse='');
434             my $response=<STDIN>;
435             chomp $response;
436             ($response) || ($response=$defaultresponse);
437             return $response;
438         }
439         if ($responsetype =~/^numerical$/i) {
440             (defined($defaultresponse)) || ($defaultresponse='');
441             my $response='';
442             until ($response=~/^\d+$/) {
443                 $response=<STDIN>;
444                 chomp $response;
445                 ($response) || ($response=$defaultresponse);
446                 unless ($response=~/^\d+$/) {
447                     ($noclear) || (system('clear'));
448                     print "Invalid Response ($response).  Response must be a number.\n\n";
449                     print $message;
450                 }
451             }
452             return $response;
453         }
454         if ($responsetype =~/^email$/i) {
455             (defined($defaultresponse)) || ($defaultresponse='');
456             my $response='';
457             until ($response=~/.*\@.*\..*/) {
458                 $response=<STDIN>;
459                 chomp $response;
460                 ($response) || ($response=$defaultresponse);
461                 unless ($response=~/.*\@.*\..*/) {
462                     ($noclear) || (system('clear'));
463                     print "Invalid Response ($response).  Response must be a valid email address.\n\n";
464                     print $message;
465                 }
466             }
467             return $response;
468         }
469         if ($responsetype =~/^PressEnter$/i) {
470             <STDIN>;
471             return;
472         }
473         if ($responsetype =~/^none$/i) {
474             return;
475         }
476     }
477 }
478
479 sub getinstallationdirectories {
480     $::opacdir = '/usr/local/koha/opac';
481     $::intranetdir = '/usr/local/koha/intranet';
482     my $getdirinfo=1;
483     while ($getdirinfo) {
484         # Loop until opac directory and koha directory are different
485         my $message=getmessage('GetOpacDir', [$::opacdir]);
486         $::opacdir=showmessage($message, 'free', $::opacdir);
487
488         $message=getmessage('GetIntranetDir', [$::intranetdir]);
489         $::intranetdir=showmessage($message, 'free', $::intranetdir);
490
491         if ($::intranetdir eq $::opacdir) {
492             print qq|
493
494 You must specify different directories for the OPAC and INTRANET files!
495  :: $::intranetdir :: $::opacdir ::
496 |;
497 <STDIN>
498         } else {
499             $getdirinfo=0;
500         }
501     }
502     $::kohalogdir='/var/log/koha';
503     my $message=getmessage('GetKohaLogDir', [$::kohalogdir]);
504     $::kohalogdir=showmessage($message, 'free', $::kohalogdir);
505
506
507     # FIXME: Missing error handling for all mkdir calls here
508     unless ( -d $::intranetdir ) {
509        mkdir_parents (dirname($::intranetdir), 0775);
510        mkdir ($::intranetdir,                  0770);
511        chown (oct(0), (getgrnam($::httpduser))[2], "$::intranetdir");
512        chmod (oct(770), "$::intranetdir");
513     }
514     mkdir_parents ("$::intranetdir/htdocs",    0750);
515     mkdir_parents ("$::intranetdir/cgi-bin",   0750);
516     mkdir_parents ("$::intranetdir/modules",   0750);
517     mkdir_parents ("$::intranetdir/scripts",   0750);
518     unless ( -d $::opacdir ) {
519        mkdir_parents (dirname($::opacdir),     0775);
520        mkdir ($::opacdir,                      0770);
521        chown (oct(0), (getgrnam($::httpduser))[2], "$::opacdir");
522        chmod (oct(770), "$::opacdir");
523     }
524     mkdir_parents ("$::opacdir/htdocs",        0750);
525     mkdir_parents ("$::opacdir/cgi-bin",       0750);
526
527
528     unless ( -d $::kohalogdir ) {
529        mkdir_parents (dirname($::kohalogdir),  0775);
530        mkdir ($::kohalogdir,                   0770);
531        chown (oct(0), (getgrnam($::httpduser))[2,3], "$::kohalogdir");
532        chmod (oct(770), "$::kohalogdir");
533     }
534 }
535
536
537
538 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
539 Please provide the name of the mysql database for your koha installation.
540
541 Database name [%s]: |;
542
543 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
544 Please provide the hostname for mysql.  Unless the database is located on
545 another machine this will be "localhost".
546
547 Database host [%s]: |;
548
549 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
550 Please provide the name of the user, who will have full administrative rights
551 to the %s database, when authenticating from %s.
552
553 This user will also be used to access Koha's INTRANET interface.
554
555 Database user [%s]: |;
556
557 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
558 Please provide a good password for the user %s.
559
560 Database Password: |;
561
562 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
563 You must not use a blank password for your MySQL user!
564
565 Press <ENTER> to try again: 
566 |;
567
568 sub getdatabaseinfo {
569
570     $::dbname = 'Koha';
571     $::hostname = 'localhost';
572     $::user = 'kohaadmin';
573     $::pass = '';
574
575 #Get the database name
576
577     my $message=getmessage('DatabaseName', [$::dbname]);
578     $::dbname=showmessage($message, 'free', $::dbname);
579
580 #Get the hostname for the database
581     
582     $message=getmessage('DatabaseHost', [$::hostname]);
583     $::hostname=showmessage($message, 'free', $::hostname);
584
585 #Get the username for the database
586
587     $message=getmessage('DatabaseUser', [$::dbname, $::hostname, $::user]);
588     $::user=showmessage($message, 'free', $::user);
589
590 #Get the password for the database user
591
592     while ($::pass eq '') {
593         my $message=getmessage('DatabasePassword', [$::user]);
594         $::pass=showmessage($message, 'free', $::pass);
595         if ($::pass eq '') {
596             my $message=getmessage('BlankPassword');
597             showmessage($message,'PressEnter');
598         }
599     }
600 }
601
602
603
604 $messages->{'FoundMultipleApacheConfFiles'}->{en} = 
605    heading('MULTIPLE APACHE CONFIG FILES') . qq|
606 I found more than one possible Apache configuration file:
607
608 %s
609
610 Choose the correct file [1]: |;
611
612 $messages->{'NoApacheConfFiles'}->{en} =
613    heading('NO APACHE CONFIG FILE FOUND') . qq|
614 I was not able to find your Apache configuration file.
615
616 The file is usually called httpd.conf or apache.conf.
617
618 Please specify the location of your config file: |;
619
620 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
621 The file %s does not exist.
622
623 Please press <ENTER> to continue: |;
624
625 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
626 I was not able to determine the user that Apache is running as.  This
627 information is necessary in order to set the access privileges correctly on
628 %s/koha.conf.  This user should be set in one of the Apache configuration
629 files using the "User" directive.
630
631 Enter the Apache userid: |;
632
633 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
634 The userid %s is not a valid userid on this system.
635
636 Press <ENTER> to continue: |;
637
638 sub getapacheinfo {
639     my @confpossibilities;
640
641     foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
642                           /usr/local/etc/apache/httpd.conf
643                           /usr/local/etc/apache/apache.conf
644                           /var/www/conf/httpd.conf
645                           /etc/apache/conf/httpd.conf
646                           /etc/apache/conf/apache.conf
647                           /etc/apache-ssl/conf/apache.conf
648                           /etc/apache-ssl/httpd.conf
649                           /etc/httpd/conf/httpd.conf
650                           /etc/httpd/httpd.conf)) {
651         if ( -f $httpdconf ) {
652             push @confpossibilities, $httpdconf;
653         }
654     }
655
656     if ($#confpossibilities==-1) {
657         my $message=getmessage('NoApacheConfFiles');
658         my $choice='';
659         until (-f $::realhttpdconf) {
660             $choice=showmessage($message, "free", 1);
661             if (-f $choice) {
662                 $::realhttpdconf=$choice;
663             } else {
664                 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
665             }
666         }
667     } elsif ($#confpossibilities>0) {
668         my $conffiles='';
669         my $counter=1;
670         my $options='';
671         foreach (@confpossibilities) {
672             $conffiles.="   $counter: $_\n";
673             $options.="$counter";
674             $counter++;
675         }
676         my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
677         my $choice=showmessage($message, "restrictchar $options", 1);
678         $::realhttpdconf=$confpossibilities[$choice-1];
679     } else {
680         $::realhttpdconf=$confpossibilities[0];
681     }
682     unless (open (HTTPDCONF, "<$::realhttpdconf")) {
683         warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
684         sleep 4;
685     }
686
687     while (<HTTPDCONF>) {
688         if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
689             $::httpduser = $1;
690         }
691     }
692     close(HTTPDCONF);
693
694
695
696
697     unless ($::httpduser) {
698         my $message=getmessage('EnterApacheUser', [$::etcdir]);
699         until (length($::httpduser) && getpwnam($::httpduser)) {
700             $::httpduser=showmessage($message, "free", '');
701             if (length($::httpduser)>0) {
702                 unless (getpwnam($::httpduser)) {
703                     my $message=getmessage('InvalidUserid', [$::httpduser]);
704                     showmessage($message,'PressEnter');
705                 }
706             } else {
707             }
708         }
709         print "AU: $::httpduser\n";
710     }
711 }
712
713
714 $messages->{'ApacheConfigIntroduction'}->{en} =
715    heading('APACHE CONFIGURATION') . qq|
716 Koha needs to setup your Apache configuration file for the
717 OPAC and LIBRARIAN virtual hosts.  By default this installer
718 will do this by using one ip address and two different ports
719 for the virtual hosts.  There are other ways to set this up,
720 and the installer will leave comments in httpd.conf detailing
721 what these other options are.
722
723
724 Press <ENTER> to continue: |;
725
726 $messages->{'GetVirtualHostEmail'}->{en} =
727    heading('WEB SERVER E-MAIL CONTACT') . qq|
728 Enter the e-mail address to be used as a contact for the virtual hosts (this
729 address is displayed if any errors are encountered).
730
731 E-mail contact [%s]: |;
732
733 $messages->{'GetServerName'}->{en} =
734    heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
735 Please enter the domain name or ip address of your computer.
736
737 Host name or IP Address [%s]: |;
738
739 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
740 Please enter the port for your OPAC interface.  This defaults to port 80, but
741 if you are already serving web content from this server, you should change it
742 to a different port (8000 might be a good choice).
743
744 Enter the OPAC Port [%s]: |;
745
746 $messages->{'GetIntranetPort'}->{en} =
747    heading('INTRANET VIRTUAL HOST PORT') . qq|
748 Please enter the port for your Intranet interface.  This must be different from
749 the OPAC port (%s).
750
751 Enter the Intranet Port [%s]: |;
752
753
754 sub getapachevhostinfo {
755
756     $::svr_admin = "webmaster\@$::domainname";
757     $::servername=`hostname`;
758     chomp $::servername;
759     $::opacport=80;
760     $::intranetport=8080;
761
762     showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
763
764     $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
765     $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
766
767
768     $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
769     $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
770
771 }
772
773 $messages->{'StartUpdateApache'}->{en} =
774    heading('UPDATING APACHE CONFIGURATION') . qq|
775 Checking for modules that need to be loaded...
776 |;
777
778 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
779
780 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
781
782 $messages->{'ApacheConfigBackupFailed'}->{en} =
783    heading('APACHE CONFIGURATION BACKUP FAILED') . qq|
784 An error occurred while trying to make a backup copy of %s.
785
786   %s
787
788 No changes will be made to the apache configuration file at this time.
789
790 Press <ENTER> to continue: |;
791
792
793 $messages->{'ApacheAlreadyConfigured'}->{en} =
794    heading('APACHE ALREADY CONFIGURED') . qq|
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
799 configuration.
800
801 Press <ENTER> to continue: |;
802
803 sub updateapacheconf {
804     my $logfiledir=`grep ^ErrorLog "$::realhttpdconf"`;
805     chomp $logfiledir;
806
807     if ($logfiledir) {
808         $logfiledir=~m#ErrorLog (.*)/[^/]*$#
809             or die "Can't parse ErrorLog directive\n";
810         $logfiledir=$1;
811     }
812
813     unless ($logfiledir) {
814         $logfiledir='logs';
815     }
816
817     showmessage(getmessage('StartUpdateApache'), 'none');
818
819     my $httpdconf;
820     my $envmodule=0;
821     my $includesmodule=0;
822     open HC, "<$::realhttpdconf";
823     while (<HC>) {
824         if (/^\s*#\s*LoadModule env_module /) {
825             s/^\s*#\s*//;
826             showmessage(getmessage('LoadingApacheModuleModEnv'));
827             $envmodule=1;
828         }
829         if (/^\s*#\s*LoadModule includes_module /) {
830             s/^\s*#\s*//;
831             showmessage(getmessage('LoadingApacheModuleModInc'));
832         }
833         if (/\s*LoadModule includes_module / ) {
834             $includesmodule=1;
835         }
836         $httpdconf.=$_;
837     }
838
839     my $backupfailed=0;
840     $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
841     if ($backupfailed) {
842         showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
843         return;
844     }
845
846     if ($envmodule || $includesmodule) {
847         open HC, ">$::realhttpdconf";
848         print HC $httpdconf;
849         close HC;
850     }
851
852
853     
854     if (`grep 'VirtualHost $::servername' "$::realhttpdconf"`) {
855         showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
856         return;
857     } else {
858         my $includesdirectives='';
859         if ($includesmodule) {
860             $includesdirectives.="Options +Includes\n";
861             $includesdirectives.="   AddHandler server-parsed .html\n";
862         }
863         open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
864         my $opaclisten = '';
865         if ($::opacport != 80) {
866             $opaclisten="Listen $::opacport";
867         }
868         my $intranetlisten = '';
869         if ($::intranetport != 80) {
870             $intranetlisten="Listen $::intranetport";
871         }
872         print SITE <<EOP
873
874 # Ports to listen to for Koha
875 $opaclisten
876 $intranetlisten
877
878 # NameVirtualHost is used by one of the optional configurations detailed below
879
880 #NameVirtualHost 11.22.33.44
881
882 # KOHA's OPAC Configuration
883 <VirtualHost $::servername\:$::opacport>
884    ServerAdmin $::svr_admin
885    DocumentRoot $::opacdir/htdocs
886    ServerName $::servername
887    ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
888    ErrorLog $logfiledir/opac-error_log
889    TransferLog $logfiledir/opac-access_log
890    SetEnv PERL5LIB "$::intranetdir/modules"
891    $includesdirectives
892 </VirtualHost>
893
894 # KOHA's INTRANET Configuration
895 <VirtualHost $::servername\:$::intranetport>
896    ServerAdmin $::svr_admin
897    DocumentRoot $::intranetdir/htdocs
898    ServerName $::servername
899    ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
900    ErrorLog $logfiledir/koha-error_log
901    TransferLog $logfiledir/koha-access_log
902    SetEnv PERL5LIB "$::intranetdir/modules"
903    $includesdirectives
904 </VirtualHost>
905
906 # If you want to use name based Virtual Hosting:
907 #   1. remove the two Listen lines
908 #   2. replace $::servername\:$::opacport wih your.opac.domain.name
909 #   3. replace ServerName $::servername wih ServerName your.opac.domain.name
910 #   4. replace $::servername\:$::intranetport wih your intranet domain name
911 #   5. replace ServerName $::servername wih ServerName your.intranet.domain.name
912 #
913 # If you want to use NameVirtualHost'ing (using two names on one ip address):
914 #   1.  Follow steps 1-5 above
915 #   2.  Uncomment the NameVirtualHost line and set the correct ip address
916
917 EOP
918
919
920     }
921 }
922
923 $messages->{'IntranetAuthenticationQuestion'}->{en} =
924    heading('INTRANET AUTHENTICATION') . qq|
925 I can set it up so that the Intranet/Librarian site is password protected using
926 Apache's Basic Authorization.
927
928 This is going to be phased out very soon. However, setting this up can provide
929 an extra layer of security before the new authentication system is completely
930 in place.
931
932 Would you like to do this ([Y]/N): |;
933
934 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
935 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
936 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
937
938 sub basicauthentication {
939     my $message=getmessage('IntranetAuthenticationQuestion');
940     my $answer=showmessage($message, 'yn', 'y');
941
942     my $apacheauthusername='librarian';
943     my $apacheauthpassword='';
944     if ($answer=~/^y/i) {
945         ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
946         $apacheauthusername=~s/[^a-zA-Z0-9]//g;
947         while (! $apacheauthpassword) {
948             ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
949             if (!$apacheauthpassword) {
950                 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
951             }
952         }
953         open AUTH, ">$::etcdir/kohaintranet.pass";
954         my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
955         my $salt=substr($chars, int(rand(length($chars))),1);
956         $salt.=substr($chars, int(rand(length($chars))),1);
957         print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
958         close AUTH;
959         open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
960         print SITE <<EOP
961
962 <Directory $::intranetdir>
963     AuthUserFile $::etcdir/kohaintranet.pass
964     AuthType Basic
965     AuthName "Koha Intranet (for librarians only)"
966     Require  valid-user
967 </Directory>
968 EOP
969     }
970     close(SITE);
971 }
972
973 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
974 Copying files to installation directories:
975
976 |;
977
978
979 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
980
981
982
983 sub installfiles {
984
985
986     showmessage(getmessage('InstallFiles'),'none');
987     print getmessage('CopyingFiles', ['intranet-html', "$::intranetdir/htdocs" ]);
988     system("cp -R intranet-html/* $::intranetdir/htdocs/");
989     print getmessage('CopyingFiles', ['intranet-cgi', "$::intranetdir/cgi-bin" ]);
990     system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
991     print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
992     system("cp -R scripts/* $::intranetdir/scripts/");
993     print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
994     system("cp -R modules/* $::intranetdir/modules/");
995     print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
996     system("cp -R opac-html/* $::opacdir/htdocs/");
997     print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
998     system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
999     system("touch $::opacdir/cgi-bin/opac");
1000
1001     system("chown -R root:$::httpduser $::opacdir");
1002     system("chown -R root:$::httpduser $::intranetdir");
1003
1004     # Create /etc/koha.conf
1005
1006     my $old_umask = umask(027); # make sure koha.conf is never world-readable
1007     open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1008     print SITES qq|
1009 database=$::dbname
1010 hostname=$::hostname
1011 user=$::user
1012 pass=$::pass
1013 includes=$::opacdir/htdocs/includes
1014 intranetdir=$::intranetdir
1015 opacdir=$::opacdir
1016 kohalogdir=$::kohalogdir
1017 kohaversion=$::kohaversion
1018 httpduser=$::httpduser
1019 intrahtdocs=$::intranetdir/htdocs/intranet-tmpl
1020 opachtdocs=$::opacdir/htdocs/opac-tmpl
1021 |;
1022     close(SITES);
1023     umask($old_umask);
1024
1025     chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1026     chmod 0440, "$::etcdir/koha.conf.tmp";
1027
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: $!";
1033
1034 }
1035
1036 $messages->{'MysqlRootPassword'}->{en} =
1037    heading('MYSQL ROOT USER PASSWORD') . qq|
1038 To allow us to create the koha database please supply your
1039 mysql server's root user password:
1040
1041 Enter MySQL root user password: |;
1042
1043 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password.  Please try again.";
1044
1045 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1046 Creating the MySQL database for Koha...
1047
1048 |;
1049
1050 $messages->{'CreatingDatabaseError'}->{en} =
1051    heading('ERROR CREATING DATABASE') . qq|
1052 Couldn't connect to the MySQL server for the reason given above.
1053 This is a serious problem, the database will not get installed.\a
1054
1055 Press <ENTER> to continue: |;
1056
1057 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1058 If you are installing Koha for evaluation purposes,  I have a batch of sample
1059 data that you can install now.
1060
1061 If you are installing Koha with the intention of populating it with your own
1062 data, you probably don't want this sample data installed.
1063
1064 Would you like to install the sample data? Y/[N]: |;
1065
1066 $messages->{'SampleDataInstalled'}->{en} =
1067    heading('SAMPLE DATA INSTALLED') . qq|
1068 Sample data has been installed.  For some suggestions on testing Koha, please
1069 read the file doc/HOWTO-Testing.  If you find any bugs, please submit them at
1070 http://bugs.koha.org/.  If you need help with testing Koha, you can post a
1071 question through the koha-devel mailing list, or you can check for a developer
1072 online at +irc.katipo.co.nz:6667 channel #koha.
1073
1074 You can find instructions for subscribing to the Koha mailing lists at:
1075
1076     http://www.koha.org
1077
1078
1079 Press <ENTER> to continue: |;
1080
1081 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1082 Would you like to install an initial branch and printer? [Y]/N: |;
1083
1084 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1085 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1086 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1087 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1088 $messages->{'BlankMysqlPassword'}->{en} = heading('Blank MySQL Password') . qq|
1089 Do not leave your MySQL root password blank unless you know exactly what you
1090 are doing.  To change your MySQL root password use the mysqladmin command:
1091
1092 mysqladmin password NEWPASSWORDHERE
1093
1094 Press <ENTER> to continue:
1095 |;
1096
1097 sub databasesetup {
1098     $::mysqluser = 'root';
1099     $::mysqlpass = '';
1100
1101     foreach my $mysql (qw(/usr/local/mysql
1102                           /opt/mysql
1103                           /usr
1104                           )) {
1105        if ( -d $mysql  && -f "$mysql/bin/mysqladmin") {
1106             $::mysqldir=$mysql;
1107        }
1108     }
1109     if (!$::mysqldir){
1110         print "I don't see mysql in the usual places.\n";
1111         for (;;) {
1112             print "Where have you installed mysql? ";
1113             chomp($::mysqldir = <STDIN>);
1114             last if -f "$::mysqldir/bin/mysqladmin";
1115         print <<EOP;
1116
1117 I can't find it there either. If you compiled mysql yourself,
1118 please give the value of --prefix when you ran configure.
1119
1120 The file mysqladmin should be in bin/mysqladmin under the directory that you
1121 provide here.
1122
1123 EOP
1124         }
1125     }
1126
1127
1128     my $needpassword=1;
1129     while ($needpassword) {
1130         $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1131         $::mysqlpass_quoted = $::mysqlpass;
1132         $::mysqlpass_quoted =~ s/"/\\"/g;
1133         $::mysqlpass_quoted="-p\"$::mysqlpass_quoted\"";
1134         $::mysqlpass eq '' and $::mysqlpass_quoted='';
1135         my $result=system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted proc > /dev/null 2>&1");
1136         if ($result) {
1137             print getmessage('InvalidMysqlRootPassword');
1138         } else {
1139             if ($::mysqlpass eq '') {
1140                 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1141             }
1142             $needpassword=0;
1143         }
1144     }
1145
1146     showmessage(getmessage('CreatingDatabase'),'none');
1147
1148     my $result=system("$::mysqldir/bin/mysqladmin", "-u$::mysqluser", "-p$::mysqlpass", "create", "$::dbname");
1149     if ($result) {
1150         showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1151     } else {
1152         # Populate the Koha database
1153         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname < koha.mysql");
1154         # Set up permissions
1155         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1156         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')\"");
1157         system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted reload");
1158
1159
1160
1161
1162
1163     }
1164
1165 }
1166
1167 $messages->{'UpdateMarcTables'}->{en} =
1168    heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1169 You can import marc parameters for :
1170
1171   1 MARC21
1172   2 UNIMARC
1173   3 none
1174
1175 Please choose which parameter you want to install. Note if you choose 3,
1176 nothing will be added, and it can be a BIG job to manually create those tables
1177
1178 Choose MARC definition [1]: |;
1179
1180 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1181 This version of koha supports a few languages.
1182 Enter you languages preferences : either en, fr, es or pl.
1183 Note that the en is always choosen when the system does not finds the
1184 language you choose in a specific screen.
1185 fr : opac is translated (except pictures)
1186 es : a few intranet is translated (including pictures)
1187 pl : opac is translated (UNTESTED in this release)
1188 |;
1189
1190 sub updatedatabase {
1191     # At this point, $::etcdir/koha.conf must exist, for C4::Context
1192     # We must somehow temporarily enable $::etcdir/koha.conf. A symlink can
1193     # do this & at the same time facilitate detection of aborted installs.
1194         my $result=system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1195         if ($result) {
1196                 print "Problem updating database...\n";
1197                 exit;
1198         }
1199
1200         my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 123', '1');
1201
1202         if ($response == 1) {
1203                 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1204         }
1205         if ($response == 2) {
1206                 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1207                 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1208         }
1209
1210         $result = system ("perl -I $::intranetdir/modules scripts/marc/updatedb2marc.pl");
1211         if ($result) {
1212                 print "Problem updating database to MARC...\n";
1213                 exit;
1214         }
1215
1216         print "\n\nFinished updating of database. Press <ENTER> to continue...";
1217         <STDIN>;
1218 }
1219
1220 sub populatedatabase {
1221         my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1222         if ($response =~/^y/i) {
1223                 system("gunzip -d < sampledata-1.2.gz | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1224                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1225                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1226                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1227                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1228                 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1229         } else {
1230                 my $input;
1231                 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1232
1233                 unless ($response =~/^n/i) {
1234                 my $branch='Main Library';
1235                 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1236                 $branch=~s/[^A-Za-z0-9\s]//g;
1237
1238                 my $branchcode=$branch;
1239                 $branchcode=~s/[^A-Za-z0-9]//g;
1240                 $branchcode=uc($branchcode);
1241                 $branchcode=substr($branchcode,0,4);
1242                 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1243                 $branchcode=~s/[^A-Za-z0-9]//g;
1244                 $branchcode=uc($branchcode);
1245                 $branchcode=substr($branchcode,0,4);
1246                 $branchcode or $branchcode='DEF';
1247
1248                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1249                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1250                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1251
1252                 my $printername='Library Printer';
1253                 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1254                 $printername=~s/[^A-Za-z0-9\s]//g;
1255
1256                 my $printerqueue='lp';
1257                 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1258                 $printerqueue=~s/[^A-Za-z0-9]//g;
1259                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1260                 }
1261         my $language=showmessage(getmessage('Language'), 'free', 'en');
1262         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1263         }
1264 }
1265
1266 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1267 Apache needs to be restarted to load the new configuration for Koha.
1268
1269 Would you like to restart Apache now?  [Y]/N: |;
1270
1271 sub restartapache {
1272
1273     my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1274
1275
1276
1277     unless ($response=~/^n/i) {
1278         # Need to support other init structures here?
1279         if (-e "/etc/rc.d/init.d/httpd") {
1280             system('/etc/rc.d/init.d/httpd restart');
1281         } elsif (-e "/etc/init.d/apache") {
1282             system('/etc//init.d/apache restart');
1283         } elsif (-e "/etc/init.d/apache-ssl") {
1284             system('/etc/init.d/apache-ssl restart');
1285         }
1286     }
1287
1288 }
1289
1290
1291 sub loadconfigfile {
1292     my %configfile;
1293
1294     open (KC, "<$::etcdir/koha.conf");
1295     while (<KC>) {
1296      chomp;
1297      (next) if (/^\s*#/);
1298      if (/(.*)\s*=\s*(.*)/) {
1299        my $variable=$1;
1300        my $value=$2;
1301        # Clean up white space at beginning and end
1302        $variable=~s/^\s*//g;
1303        $variable=~s/\s*$//g;
1304        $value=~s/^\s*//g;
1305        $value=~s/\s*$//g;
1306        $configfile{$variable}=$value;
1307      }
1308     }
1309
1310     $::intranetdir=$configfile{'intranetdir'};
1311     $::opacdir=$configfile{'opacdir'};
1312     $::kohaversion=$configfile{'kohaversion'};
1313     $::kohalogdir=$configfile{'kohalogdir'};
1314     $::database=$configfile{'database'};
1315     $::hostname=$configfile{'hostname'};
1316     $::user=$configfile{'user'};
1317     $::pass=$configfile{'pass'};
1318 }
1319
1320 END { }       # module clean-up code here (global destructor)
1321
1322 =back
1323
1324 =head1 SEE ALSO
1325
1326 buildrelease.pl,
1327 installer.pl
1328
1329 =cut
1330
1331 1;