Added more POD
[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, or mkdir --parents. Given a path $path,
256 create the directory $path, recursively creating any intermediate
257 directories. If $mode is given, the directory will be created with
258 mode $mode.
259
260 WARNING: If $path already exists, mkdir_parents will just return
261 successfully (just like mkdir -p), whether the mode of $path conforms
262 to $mode or not. (This is the behaviour of the mkdir -p command.)
263
264 =cut
265
266 sub mkdir_parents ($;$) {
267     my($path, $mode) = @_;
268     my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
269
270     if (!$ok && $! == ENOENT) {
271         my $parent = dirname($path);
272         $ok = mkdir_parents($parent, $mode);
273
274         # retry and at the same time make sure that $! is set correctly
275         $ok = defined $mode? mkdir($path, $mode): mkdir($path);
276     }
277     return $ok;
278 }
279
280 =back
281
282 =head2 Subtasks of doing an installation
283
284 =over 4
285
286 =cut
287
288 =item checkabortedinstall
289
290     checkabortedinstall;
291
292 Checks whether a previous installation process has been abnormally
293 aborted, by checking whether $::etcidr/koha.conf is a symlink or not.
294 If an aborted installation is detected, gives the user a chance to
295 abort, before trying to recover the aborted installation.
296
297 Assuming that Koha will be installed on a modern Unix with symlinks,
298 it is possible to code the installer so that aborted installs can be
299 detected. In case of such an event we can do our best to "roll back"
300 the aborted install.
301
302 FIXME: The "roll back" is not complete!
303
304 =cut
305
306 sub checkabortedinstall () {
307     if (-l("$::etcdir/koha.conf")
308         && readlink("$::etcdir/koha.conf") =~ /\.tmp$/
309     ) {
310         print qq|
311 I have detected that you tried to install Koha before, but the installation
312 was aborted.  I will try to continue, but there might be problems if the
313 database is already created.
314
315 |;
316         print "Please press <ENTER> to continue: ";
317         <STDIN>;
318
319         # Remove the symlink after the <STDIN>, so the user can back out
320         unlink "$::etcdir/koha.conf"
321             || die "Failed to remove incomplete $::etcdir/koha.conf: $!\n";
322     }
323 }
324
325
326 =item checkperlmodules
327
328     checkperlmodules;
329
330 Test whether the version of Perl is new enough, whether Perl is
331 found at the expected location, and whether all required modules
332 have been installed.
333
334 =cut
335
336 sub checkperlmodules {
337 #
338 # Test for Perl and Modules
339 #
340
341     my $message = getmessage('CheckingPerlModules');
342     showmessage($message, 'none');
343
344     # FIXME: Perl 5.6 is BUGGY!!! IT SHOULD NOT BE USED in production!!!
345     unless (eval "require 5.006_000") {
346         die getmessage('PerlVersionFailure', ['5.6.0']);
347     }
348
349     my @missing = ();
350     unless (eval {require DBI})               { push @missing,"DBI" };
351     unless (eval {require Date::Manip})       { push @missing,"Date::Manip" };
352     unless (eval {require DBD::mysql})        { push @missing,"DBD::mysql" };
353     unless (eval {require HTML::Template})          { push @missing,"HTML::Template" };
354     unless (eval {require Set::Scalar})       { push @missing,"Set::Scalar" };
355     unless (eval {require Digest::MD5})       { push @missing,"Digest::MD5" };
356     unless (eval {require MARC::Record})       { push @missing,"MARC::Record" };
357     unless (eval {require Net::Z3950})        {
358         my $message = getmessage('NETZ3950Missing');
359         showmessage($message, 'PressEnter', '', 1);
360         if ($#missing>=0) {
361             push @missing, "Net::Z3950";
362         }
363     }
364
365 #
366 # Print out a list of any missing modules
367 #
368
369     if (@missing > 0) {
370         my $missing='';
371         foreach my $module (@missing) {
372             $missing.="   perl -MCPAN -e 'install \"$module\"'\n";
373         }
374         my $message=getmessage('MissingPerlModules', [$missing]);
375         showmessage($message, 'none');
376         exit;
377     } else {
378         showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
379     }
380
381
382     unless (-x "/usr/bin/perl") {
383         my $realperl=`which perl`;
384         chomp $realperl;
385         $realperl = showmessage(getmessage('NoUsrBinPerl'), 'none');
386         until (-x $realperl) {
387             $realperl=showmessage(getmessage('AskLocationOfPerlExecutable', $realperl), 'free', $realperl, 1);
388         }
389         my $response=showmessage(getmessage('ConfirmPerlExecutableSymlink', $realperl), 'yn', 'y', 1);
390         unless ($response eq 'n') {
391             system("ln -s $realperl /usr/bin/perl");
392         }
393     }
394
395
396 }
397
398 $messages->{'NoUsrBinPerl'}->{en} =
399    heading('Perl is not located in /usr/bin/perl') . qq|
400 The Koha perl scripts expect to find the perl executable in the /usr/bin
401 directory.  It is not there on your system.
402
403 |;
404
405 $messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
406 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
407 The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
408
409 May I create this symlink? ([Y]/N):
410 : |;
411
412
413 =item getmessage
414
415     getmessage($msgid);
416     getmessage($msgid, $variables);
417
418 Gets a localized message (format string) with message id $msgid,
419 and, if an array reference of variables $variables is given,
420 substitutes variables in the format string with @$variables.
421 Returns the found message string, with variable substitutions
422 if specified.
423
424 $msgid must be the message identifier corresponding to a defined
425 message string (a valid key to the $messages hash in the Installer
426 package). getmessage throws an exception if the message cannot be
427 found.
428
429 =cut
430
431 sub getmessage {
432     my $messagename=shift;
433     my $variables=shift;
434     my $message=$messages->{$messagename}->{$::language} || $messages->{$messagename}->{en} || "Error: No message named $messagename in Install.pm\n";
435     if (defined($variables)) {
436         $message=sprintf $message, @$variables;
437     }
438     return $message;
439 }
440
441
442 =item showmessage
443
444     showmessage($message, 'none');
445     showmessage($message, 'none', undef, $noclear);
446
447     $result = showmessage($message, 'yn');
448     $result = showmessage($message, 'yn', $defaultresponse);
449     $result = showmessage($message, 'yn', $defaultresponse, $noclear);
450
451     $result = showmessage($message, 'restrictchar CHARS');
452     $result = showmessage($message, 'free');
453     $result = showmessage($message, 'numerical');
454     $result = showmessage($message, 'email');
455     $result = showmessage($message, 'PressEnter');
456
457 Shows a message and optionally gets a response from the user.
458
459 The first two arguments, the message and the response type,
460 are mandatory.  The message must be the actual string to
461 display. The caller is responsible for calling getmessage if
462 required.
463
464 If a response type other than 'none' is specified, a third
465 argument, specifying the default value, is optional.
466
467 The screen is normally cleared before the message is displayed;
468 if a fourth argument is specified and is nonzero, this
469 screen-clearing is not done.
470
471 FIXME: If $noclear is not specified or specified as undef, we
472 just test it for a non-zero value without testing it for being
473 undef first.
474
475 =cut
476
477 sub showmessage {
478     my $message=shift;
479     my $responsetype=shift;
480     my $defaultresponse=shift;
481     my $noclear=shift;
482     ($noclear) || (system('clear'));
483     if ($responsetype =~ /^yn$/) {
484         $responsetype='restrictchar yn';
485     }
486     print $message;
487     SWITCH: {
488         if ($responsetype =~/^restrictchar (.*)/i) {
489             my $response='\0';
490             my $options=$1;
491             until ($options=~/$response/) {
492                 ($defaultresponse) || ($defaultresponse=substr($options,0,1));
493                 $response=<STDIN>;
494                 chomp $response;
495                 (length($response)) || ($response=$defaultresponse);
496                 unless ($options=~/$response/) {
497                     ($noclear) || (system('clear'));
498                     print "Invalid Response.  Choose from [$options].\n\n";
499                     print $message;
500                 }
501             }
502             return $response;
503         }
504         if ($responsetype =~/^free$/i) {
505             (defined($defaultresponse)) || ($defaultresponse='');
506             my $response=<STDIN>;
507             chomp $response;
508             ($response) || ($response=$defaultresponse);
509             return $response;
510         }
511         if ($responsetype =~/^numerical$/i) {
512             (defined($defaultresponse)) || ($defaultresponse='');
513             my $response='';
514             until ($response=~/^\d+$/) {
515                 $response=<STDIN>;
516                 chomp $response;
517                 ($response) || ($response=$defaultresponse);
518                 unless ($response=~/^\d+$/) {
519                     ($noclear) || (system('clear'));
520                     print "Invalid Response ($response).  Response must be a number.\n\n";
521                     print $message;
522                 }
523             }
524             return $response;
525         }
526         if ($responsetype =~/^email$/i) {
527             (defined($defaultresponse)) || ($defaultresponse='');
528             my $response='';
529             until ($response=~/.*\@.*\..*/) {
530                 $response=<STDIN>;
531                 chomp $response;
532                 ($response) || ($response=$defaultresponse);
533                 unless ($response=~/.*\@.*\..*/) {
534                     ($noclear) || (system('clear'));
535                     print "Invalid Response ($response).  Response must be a valid email address.\n\n";
536                     print $message;
537                 }
538             }
539             return $response;
540         }
541         if ($responsetype =~/^PressEnter$/i) {
542             <STDIN>;
543             return;
544         }
545         if ($responsetype =~/^none$/i) {
546             return;
547         }
548     }
549 }
550
551
552 =item getinstallationdirectories
553
554     getinstallationdirectories;
555
556 Get the various installation directories from the user, and then
557 create those directories (if they do not already exist).
558
559 These pieces of information are saved to global variables; the
560 function does not return any values.
561
562 =cut
563
564 sub getinstallationdirectories {
565     $::opacdir = '/usr/local/koha/opac';
566     $::intranetdir = '/usr/local/koha/intranet';
567     my $getdirinfo=1;
568     while ($getdirinfo) {
569         # Loop until opac directory and koha directory are different
570         my $message=getmessage('GetOpacDir', [$::opacdir]);
571         $::opacdir=showmessage($message, 'free', $::opacdir);
572
573         $message=getmessage('GetIntranetDir', [$::intranetdir]);
574         $::intranetdir=showmessage($message, 'free', $::intranetdir);
575
576         if ($::intranetdir eq $::opacdir) {
577             print qq|
578
579 You must specify different directories for the OPAC and INTRANET files!
580  :: $::intranetdir :: $::opacdir ::
581 |;
582 <STDIN>
583         } else {
584             $getdirinfo=0;
585         }
586     }
587     $::kohalogdir='/var/log/koha';
588     my $message=getmessage('GetKohaLogDir', [$::kohalogdir]);
589     $::kohalogdir=showmessage($message, 'free', $::kohalogdir);
590
591
592     # FIXME: Missing error handling for all mkdir calls here
593     unless ( -d $::intranetdir ) {
594        mkdir_parents (dirname($::intranetdir), 0775);
595        mkdir ($::intranetdir,                  0770);
596        chown (oct(0), (getgrnam($::httpduser))[2], "$::intranetdir");
597        chmod (oct(770), "$::intranetdir");
598     }
599     mkdir_parents ("$::intranetdir/htdocs",    0750);
600     mkdir_parents ("$::intranetdir/cgi-bin",   0750);
601     mkdir_parents ("$::intranetdir/modules",   0750);
602     mkdir_parents ("$::intranetdir/scripts",   0750);
603     unless ( -d $::opacdir ) {
604        mkdir_parents (dirname($::opacdir),     0775);
605        mkdir ($::opacdir,                      0770);
606        chown (oct(0), (getgrnam($::httpduser))[2], "$::opacdir");
607        chmod (oct(770), "$::opacdir");
608     }
609     mkdir_parents ("$::opacdir/htdocs",        0750);
610     mkdir_parents ("$::opacdir/cgi-bin",       0750);
611
612
613     unless ( -d $::kohalogdir ) {
614        mkdir_parents (dirname($::kohalogdir),  0775);
615        mkdir ($::kohalogdir,                   0770);
616        chown (oct(0), (getgrnam($::httpduser))[2,3], "$::kohalogdir");
617        chmod (oct(770), "$::kohalogdir");
618     }
619 }
620
621
622
623 =item getdatabaseinfo
624
625     getdatabaseinfo;
626
627 Get various pieces of information related to the Koha database:
628 the name of the database, the host on which the SQL server is
629 running, and the database user name.
630
631 These pieces of information are saved to global variables; the
632 function does not return any values.
633
634 =cut
635
636 $messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
637 Please provide the name of the mysql database for your koha installation.
638
639 Database name [%s]: |;
640
641 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
642 Please provide the hostname for mysql.  Unless the database is located on
643 another machine this will be "localhost".
644
645 Database host [%s]: |;
646
647 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
648 Please provide the name of the user, who will have full administrative rights
649 to the %s database, when authenticating from %s.
650
651 This user will also be used to access Koha's INTRANET interface.
652
653 Database user [%s]: |;
654
655 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
656 Please provide a good password for the user %s.
657
658 Database Password: |;
659
660 $messages->{'BlankPassword'}->{en} = heading('BLANK PASSWORD') . qq|
661 You must not use a blank password for your MySQL user!
662
663 Press <ENTER> to try again: 
664 |;
665
666 sub getdatabaseinfo {
667
668     $::dbname = 'Koha';
669     $::hostname = 'localhost';
670     $::user = 'kohaadmin';
671     $::pass = '';
672
673 #Get the database name
674
675     my $message=getmessage('DatabaseName', [$::dbname]);
676     $::dbname=showmessage($message, 'free', $::dbname);
677
678 #Get the hostname for the database
679     
680     $message=getmessage('DatabaseHost', [$::hostname]);
681     $::hostname=showmessage($message, 'free', $::hostname);
682
683 #Get the username for the database
684
685     $message=getmessage('DatabaseUser', [$::dbname, $::hostname, $::user]);
686     $::user=showmessage($message, 'free', $::user);
687
688 #Get the password for the database user
689
690     while ($::pass eq '') {
691         my $message=getmessage('DatabasePassword', [$::user]);
692         $::pass=showmessage($message, 'free', $::pass);
693         if ($::pass eq '') {
694             my $message=getmessage('BlankPassword');
695             showmessage($message,'PressEnter');
696         }
697     }
698 }
699
700
701
702 =item getapacheinfo
703
704     getapacheinfo;
705
706 Get various pieces of information related to the Apache server:
707 the location of the configuration file and, if needed, the Unix
708 user that the Koha CGI will be run under.
709
710 These pieces of information are saved to global variables; the
711 function does not return any values.
712
713 =cut
714
715 $messages->{'FoundMultipleApacheConfFiles'}->{en} = 
716    heading('MULTIPLE APACHE CONFIG FILES') . qq|
717 I found more than one possible Apache configuration file:
718
719 %s
720
721 Choose the correct file [1]: |;
722
723 $messages->{'NoApacheConfFiles'}->{en} =
724    heading('NO APACHE CONFIG FILE FOUND') . qq|
725 I was not able to find your Apache configuration file.
726
727 The file is usually called httpd.conf or apache.conf.
728
729 Please specify the location of your config file: |;
730
731 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
732 The file %s does not exist.
733
734 Please press <ENTER> to continue: |;
735
736 $messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
737 I was not able to determine the user that Apache is running as.  This
738 information is necessary in order to set the access privileges correctly on
739 %s/koha.conf.  This user should be set in one of the Apache configuration
740 files using the "User" directive.
741
742 Enter the Apache userid: |;
743
744 $messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
745 The userid %s is not a valid userid on this system.
746
747 Press <ENTER> to continue: |;
748
749 sub getapacheinfo {
750     my @confpossibilities;
751
752     foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
753                           /usr/local/etc/apache/httpd.conf
754                           /usr/local/etc/apache/apache.conf
755                           /var/www/conf/httpd.conf
756                           /etc/apache/conf/httpd.conf
757                           /etc/apache/conf/apache.conf
758                           /etc/apache-ssl/conf/apache.conf
759                           /etc/apache-ssl/httpd.conf
760                           /etc/httpd/conf/httpd.conf
761                           /etc/httpd/httpd.conf)) {
762         if ( -f $httpdconf ) {
763             push @confpossibilities, $httpdconf;
764         }
765     }
766
767     if ($#confpossibilities==-1) {
768         my $message=getmessage('NoApacheConfFiles');
769         my $choice='';
770         until (-f $::realhttpdconf) {
771             $choice=showmessage($message, "free", 1);
772             if (-f $choice) {
773                 $::realhttpdconf=$choice;
774             } else {
775                 showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
776             }
777         }
778     } elsif ($#confpossibilities>0) {
779         my $conffiles='';
780         my $counter=1;
781         my $options='';
782         foreach (@confpossibilities) {
783             $conffiles.="   $counter: $_\n";
784             $options.="$counter";
785             $counter++;
786         }
787         my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
788         my $choice=showmessage($message, "restrictchar $options", 1);
789         $::realhttpdconf=$confpossibilities[$choice-1];
790     } else {
791         $::realhttpdconf=$confpossibilities[0];
792     }
793     unless (open (HTTPDCONF, "<$::realhttpdconf")) {
794         warn "Insufficient privileges to open $::realhttpdconf for reading.\n";
795         sleep 4;
796     }
797
798     while (<HTTPDCONF>) {
799         if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
800             $::httpduser = $1;
801         }
802     }
803     close(HTTPDCONF);
804
805
806
807
808     unless ($::httpduser) {
809         my $message=getmessage('EnterApacheUser', [$::etcdir]);
810         until (length($::httpduser) && getpwnam($::httpduser)) {
811             $::httpduser=showmessage($message, "free", '');
812             if (length($::httpduser)>0) {
813                 unless (getpwnam($::httpduser)) {
814                     my $message=getmessage('InvalidUserid', [$::httpduser]);
815                     showmessage($message,'PressEnter');
816                 }
817             } else {
818             }
819         }
820         print "AU: $::httpduser\n";
821     }
822 }
823
824
825 $messages->{'ApacheConfigIntroduction'}->{en} =
826    heading('APACHE CONFIGURATION') . qq|
827 Koha needs to setup your Apache configuration file for the
828 OPAC and LIBRARIAN virtual hosts.  By default this installer
829 will do this by using one ip address and two different ports
830 for the virtual hosts.  There are other ways to set this up,
831 and the installer will leave comments in httpd.conf detailing
832 what these other options are.
833
834
835 Press <ENTER> to continue: |;
836
837 $messages->{'GetVirtualHostEmail'}->{en} =
838    heading('WEB SERVER E-MAIL CONTACT') . qq|
839 Enter the e-mail address to be used as a contact for the virtual hosts (this
840 address is displayed if any errors are encountered).
841
842 E-mail contact [%s]: |;
843
844 $messages->{'GetServerName'}->{en} =
845    heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
846 Please enter the domain name or ip address of your computer.
847
848 Host name or IP Address [%s]: |;
849
850 $messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
851 Please enter the port for your OPAC interface.  This defaults to port 80, but
852 if you are already serving web content from this server, you should change it
853 to a different port (8000 might be a good choice).
854
855 Enter the OPAC Port [%s]: |;
856
857 $messages->{'GetIntranetPort'}->{en} =
858    heading('INTRANET VIRTUAL HOST PORT') . qq|
859 Please enter the port for your Intranet interface.  This must be different from
860 the OPAC port (%s).
861
862 Enter the Intranet Port [%s]: |;
863
864
865 sub getapachevhostinfo {
866
867     $::svr_admin = "webmaster\@$::domainname";
868     $::servername=`hostname`;
869     chomp $::servername;
870     $::opacport=80;
871     $::intranetport=8080;
872
873     showmessage(getmessage('ApacheConfigIntroduction'), 'PressEnter');
874
875     $::svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$::svr_admin]), 'email', $::svr_admin);
876     $::servername=showmessage(getmessage('GetServerName', [$::servername]), 'free', $::servername);
877
878
879     $::opacport=showmessage(getmessage('GetOpacPort', [$::opacport]), 'numerical', $::opacport);
880     $::intranetport=showmessage(getmessage('GetIntranetPort', [$::opacport, $::intranetport]), 'numerical', $::intranetport);
881
882 }
883
884 $messages->{'StartUpdateApache'}->{en} =
885    heading('UPDATING APACHE CONFIGURATION') . qq|
886 Checking for modules that need to be loaded...
887 |;
888
889 $messages->{'LoadingApacheModuleModEnv'}->{en}="Loading SetEnv Apache module.\n";
890
891 $messages->{'LoadingApacheModuleModInc'}->{en}="Loading Includes Apache module.\n";
892
893 $messages->{'ApacheConfigBackupFailed'}->{en} =
894    heading('APACHE CONFIGURATION BACKUP FAILED') . qq|
895 An error occurred while trying to make a backup copy of %s.
896
897   %s
898
899 No changes will be made to the apache configuration file at this time.
900
901 Press <ENTER> to continue: |;
902
903
904 $messages->{'ApacheAlreadyConfigured'}->{en} =
905    heading('APACHE ALREADY CONFIGURED') . qq|
906 %s appears to already have an entry for Koha
907 Virtual Hosts.  You may need to edit %s
908 f anything has changed since it was last set up.  This
909 script will not attempt to modify an existing Koha apache
910 configuration.
911
912 Press <ENTER> to continue: |;
913
914 sub updateapacheconf {
915     my $logfiledir=`grep ^ErrorLog "$::realhttpdconf"`;
916     chomp $logfiledir;
917
918     if ($logfiledir) {
919         $logfiledir=~m#ErrorLog (.*)/[^/]*$#
920             or die "Can't parse ErrorLog directive\n";
921         $logfiledir=$1;
922     }
923
924     unless ($logfiledir) {
925         $logfiledir='logs';
926     }
927
928     showmessage(getmessage('StartUpdateApache'), 'none');
929
930     my $httpdconf;
931     my $envmodule=0;
932     my $includesmodule=0;
933     open HC, "<$::realhttpdconf";
934     while (<HC>) {
935         if (/^\s*#\s*LoadModule env_module /) {
936             s/^\s*#\s*//;
937             showmessage(getmessage('LoadingApacheModuleModEnv'));
938             $envmodule=1;
939         }
940         if (/^\s*#\s*LoadModule includes_module /) {
941             s/^\s*#\s*//;
942             showmessage(getmessage('LoadingApacheModuleModInc'));
943         }
944         if (/\s*LoadModule includes_module / ) {
945             $includesmodule=1;
946         }
947         $httpdconf.=$_;
948     }
949
950     my $backupfailed=0;
951     $backupfailed=`cp -f $::realhttpdconf $::realhttpdconf\.prekoha`;
952     if ($backupfailed) {
953         showmessage(getmessage('ApacheConfigBackupFailed', [$::realhttpdconf,$backupfailed ]), 'PressEnter');
954         return;
955     }
956
957     if ($envmodule || $includesmodule) {
958         open HC, ">$::realhttpdconf";
959         print HC $httpdconf;
960         close HC;
961     }
962
963
964     
965     if (`grep 'VirtualHost $::servername' "$::realhttpdconf"`) {
966         showmessage(getmessage('ApacheAlreadyConfigured', [$::realhttpdconf, $::realhttpdconf]), 'PressEnter');
967         return;
968     } else {
969         my $includesdirectives='';
970         if ($includesmodule) {
971             $includesdirectives.="Options +Includes\n";
972             $includesdirectives.="   AddHandler server-parsed .html\n";
973         }
974         open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
975         my $opaclisten = '';
976         if ($::opacport != 80) {
977             $opaclisten="Listen $::opacport";
978         }
979         my $intranetlisten = '';
980         if ($::intranetport != 80) {
981             $intranetlisten="Listen $::intranetport";
982         }
983         print SITE <<EOP
984
985 # Ports to listen to for Koha
986 $opaclisten
987 $intranetlisten
988
989 # NameVirtualHost is used by one of the optional configurations detailed below
990
991 #NameVirtualHost 11.22.33.44
992
993 # KOHA's OPAC Configuration
994 <VirtualHost $::servername\:$::opacport>
995    ServerAdmin $::svr_admin
996    DocumentRoot $::opacdir/htdocs
997    ServerName $::servername
998    ScriptAlias /cgi-bin/koha/ $::opacdir/cgi-bin/
999    ErrorLog $logfiledir/opac-error_log
1000    TransferLog $logfiledir/opac-access_log
1001    SetEnv PERL5LIB "$::intranetdir/modules"
1002    $includesdirectives
1003 </VirtualHost>
1004
1005 # KOHA's INTRANET Configuration
1006 <VirtualHost $::servername\:$::intranetport>
1007    ServerAdmin $::svr_admin
1008    DocumentRoot $::intranetdir/htdocs
1009    ServerName $::servername
1010    ScriptAlias /cgi-bin/koha/ "$::intranetdir/cgi-bin/"
1011    ErrorLog $logfiledir/koha-error_log
1012    TransferLog $logfiledir/koha-access_log
1013    SetEnv PERL5LIB "$::intranetdir/modules"
1014    $includesdirectives
1015 </VirtualHost>
1016
1017 # If you want to use name based Virtual Hosting:
1018 #   1. remove the two Listen lines
1019 #   2. replace $::servername\:$::opacport wih your.opac.domain.name
1020 #   3. replace ServerName $::servername wih ServerName your.opac.domain.name
1021 #   4. replace $::servername\:$::intranetport wih your intranet domain name
1022 #   5. replace ServerName $::servername wih ServerName your.intranet.domain.name
1023 #
1024 # If you want to use NameVirtualHost'ing (using two names on one ip address):
1025 #   1.  Follow steps 1-5 above
1026 #   2.  Uncomment the NameVirtualHost line and set the correct ip address
1027
1028 EOP
1029
1030
1031     }
1032 }
1033
1034 $messages->{'IntranetAuthenticationQuestion'}->{en} =
1035    heading('INTRANET AUTHENTICATION') . qq|
1036 I can set it up so that the Intranet/Librarian site is password protected using
1037 Apache's Basic Authorization.
1038
1039 This is going to be phased out very soon. However, setting this up can provide
1040 an extra layer of security before the new authentication system is completely
1041 in place.
1042
1043 Would you like to do this ([Y]/N): |;
1044
1045 $messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
1046 $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
1047 $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
1048
1049 sub basicauthentication {
1050     my $message=getmessage('IntranetAuthenticationQuestion');
1051     my $answer=showmessage($message, 'yn', 'y');
1052
1053     my $apacheauthusername='librarian';
1054     my $apacheauthpassword='';
1055     if ($answer=~/^y/i) {
1056         ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
1057         $apacheauthusername=~s/[^a-zA-Z0-9]//g;
1058         while (! $apacheauthpassword) {
1059             ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
1060             if (!$apacheauthpassword) {
1061                 ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
1062             }
1063         }
1064         open AUTH, ">$::etcdir/kohaintranet.pass";
1065         my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1066         my $salt=substr($chars, int(rand(length($chars))),1);
1067         $salt.=substr($chars, int(rand(length($chars))),1);
1068         print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
1069         close AUTH;
1070         open(SITE,">>$::realhttpdconf") or warn "Insufficient priveleges to open $::realhttpdconf for writing.\n";
1071         print SITE <<EOP
1072
1073 <Directory $::intranetdir>
1074     AuthUserFile $::etcdir/kohaintranet.pass
1075     AuthType Basic
1076     AuthName "Koha Intranet (for librarians only)"
1077     Require  valid-user
1078 </Directory>
1079 EOP
1080     }
1081     close(SITE);
1082 }
1083
1084 $messages->{'InstallFiles'}->{en} = heading('INSTALLING FILES') . qq|
1085 Copying files to installation directories:
1086
1087 |;
1088
1089
1090 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
1091
1092
1093
1094 sub installfiles {
1095
1096
1097     showmessage(getmessage('InstallFiles'),'none');
1098     print getmessage('CopyingFiles', ['intranet-html', "$::intranetdir/htdocs" ]);
1099     system("cp -R intranet-html/* $::intranetdir/htdocs/");
1100     print getmessage('CopyingFiles', ['intranet-cgi', "$::intranetdir/cgi-bin" ]);
1101     system("cp -R intranet-cgi/* $::intranetdir/cgi-bin/");
1102     print getmessage('CopyingFiles', ['stand-alone scripts', "$::intranetdir/scripts" ]);
1103     system("cp -R scripts/* $::intranetdir/scripts/");
1104     print getmessage('CopyingFiles', ['perl modules', "$::intranetdir/modules" ]);
1105     system("cp -R modules/* $::intranetdir/modules/");
1106     print getmessage('CopyingFiles', ['opac-html', "$::opacdir/htdocs" ]);
1107     system("cp -R opac-html/* $::opacdir/htdocs/");
1108     print getmessage('CopyingFiles', ['opac-cgi', "$::opacdir/cgi-bin" ]);
1109     system("cp -R opac-cgi/* $::opacdir/cgi-bin/");
1110     system("touch $::opacdir/cgi-bin/opac");
1111
1112     system("chown -R root:$::httpduser $::opacdir");
1113     system("chown -R root:$::httpduser $::intranetdir");
1114
1115     # Create /etc/koha.conf
1116
1117     my $old_umask = umask(027); # make sure koha.conf is never world-readable
1118     open(SITES,">$::etcdir/koha.conf.tmp") or warn "Couldn't create file at $::etcdir. Must have write capability.\n";
1119     print SITES qq|
1120 database=$::dbname
1121 hostname=$::hostname
1122 user=$::user
1123 pass=$::pass
1124 includes=$::opacdir/htdocs/includes
1125 intranetdir=$::intranetdir
1126 opacdir=$::opacdir
1127 kohalogdir=$::kohalogdir
1128 kohaversion=$::kohaversion
1129 httpduser=$::httpduser
1130 intrahtdocs=$::intranetdir/htdocs/intranet-tmpl
1131 opachtdocs=$::opacdir/htdocs/opac-tmpl
1132 |;
1133     close(SITES);
1134     umask($old_umask);
1135
1136     chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
1137     chmod 0440, "$::etcdir/koha.conf.tmp";
1138
1139     chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
1140     chmod 0750, "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
1141     chmod 0750, "$::intranetdir/scripts/z3950daemon/processz3950queue";
1142     chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $::intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
1143     chown(0, (getpwnam($::httpduser)) [3], "$::intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $::intranetdir/scripts/z3950daemon/processz3950queue: $!";
1144
1145 }
1146
1147 $messages->{'MysqlRootPassword'}->{en} =
1148    heading('MYSQL ROOT USER PASSWORD') . qq|
1149 To allow us to create the koha database please supply your
1150 mysql server's root user password:
1151
1152 Enter MySQL root user password: |;
1153
1154 $messages->{'InvalidMysqlRootPassword'}->{en}="Invalid Password.  Please try again.";
1155
1156 $messages->{'CreatingDatabase'}->{en} = heading('CREATING DATABASE') . qq|
1157 Creating the MySQL database for Koha...
1158
1159 |;
1160
1161 $messages->{'CreatingDatabaseError'}->{en} =
1162    heading('ERROR CREATING DATABASE') . qq|
1163 Couldn't connect to the MySQL server for the reason given above.
1164 This is a serious problem, the database will not get installed.\a
1165
1166 Press <ENTER> to continue: |;
1167
1168 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
1169 If you are installing Koha for evaluation purposes,  I have a batch of sample
1170 data that you can install now.
1171
1172 If you are installing Koha with the intention of populating it with your own
1173 data, you probably don't want this sample data installed.
1174
1175 Would you like to install the sample data? Y/[N]: |;
1176
1177 $messages->{'SampleDataInstalled'}->{en} =
1178    heading('SAMPLE DATA INSTALLED') . qq|
1179 Sample data has been installed.  For some suggestions on testing Koha, please
1180 read the file doc/HOWTO-Testing.  If you find any bugs, please submit them at
1181 http://bugs.koha.org/.  If you need help with testing Koha, you can post a
1182 question through the koha-devel mailing list, or you can check for a developer
1183 online at +irc.katipo.co.nz:6667 channel #koha.
1184
1185 You can find instructions for subscribing to the Koha mailing lists at:
1186
1187     http://www.koha.org
1188
1189
1190 Press <ENTER> to continue: |;
1191
1192 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
1193 Would you like to install an initial branch and printer? [Y]/N: |;
1194
1195 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
1196 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
1197 $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
1198 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
1199 $messages->{'BlankMysqlPassword'}->{en} = heading('Blank MySQL Password') . qq|
1200 Do not leave your MySQL root password blank unless you know exactly what you
1201 are doing.  To change your MySQL root password use the mysqladmin command:
1202
1203 mysqladmin password NEWPASSWORDHERE
1204
1205 Press <ENTER> to continue:
1206 |;
1207
1208 sub databasesetup {
1209     $::mysqluser = 'root';
1210     $::mysqlpass = '';
1211
1212     foreach my $mysql (qw(/usr/local/mysql
1213                           /opt/mysql
1214                           /usr
1215                           )) {
1216        if ( -d $mysql  && -f "$mysql/bin/mysqladmin") {
1217             $::mysqldir=$mysql;
1218        }
1219     }
1220     if (!$::mysqldir){
1221         print "I don't see mysql in the usual places.\n";
1222         for (;;) {
1223             print "Where have you installed mysql? ";
1224             chomp($::mysqldir = <STDIN>);
1225             last if -f "$::mysqldir/bin/mysqladmin";
1226         print <<EOP;
1227
1228 I can't find it there either. If you compiled mysql yourself,
1229 please give the value of --prefix when you ran configure.
1230
1231 The file mysqladmin should be in bin/mysqladmin under the directory that you
1232 provide here.
1233
1234 EOP
1235         }
1236     }
1237
1238
1239     my $needpassword=1;
1240     while ($needpassword) {
1241         $::mysqlpass=showmessage(getmessage('MysqlRootPassword'), 'free');
1242         $::mysqlpass_quoted = $::mysqlpass;
1243         $::mysqlpass_quoted =~ s/"/\\"/g;
1244         $::mysqlpass_quoted="-p\"$::mysqlpass_quoted\"";
1245         $::mysqlpass eq '' and $::mysqlpass_quoted='';
1246         my $result=system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted proc > /dev/null 2>&1");
1247         if ($result) {
1248             print getmessage('InvalidMysqlRootPassword');
1249         } else {
1250             if ($::mysqlpass eq '') {
1251                 showmessage(getmessage('BlankMysqlPassword'), 'PressEnter');
1252             }
1253             $needpassword=0;
1254         }
1255     }
1256
1257     showmessage(getmessage('CreatingDatabase'),'none');
1258
1259     my $result=system("$::mysqldir/bin/mysqladmin", "-u$::mysqluser", "-p$::mysqlpass", "create", "$::dbname");
1260     if ($result) {
1261         showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
1262     } else {
1263         # Populate the Koha database
1264         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname < koha.mysql");
1265         # Set up permissions
1266         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
1267         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')\"");
1268         system("$::mysqldir/bin/mysqladmin -u$::mysqluser $::mysqlpass_quoted reload");
1269
1270
1271
1272
1273
1274     }
1275
1276 }
1277
1278 $messages->{'UpdateMarcTables'}->{en} =
1279    heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
1280 You can import marc parameters for :
1281
1282   1 MARC21
1283   2 UNIMARC
1284   3 none
1285
1286 Please choose which parameter you want to install. Note if you choose 3,
1287 nothing will be added, and it can be a BIG job to manually create those tables
1288
1289 Choose MARC definition [1]: |;
1290
1291 $messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
1292 This version of koha supports a few languages.
1293 Enter you languages preferences : either en, fr, es or pl.
1294 Note that the en is always choosen when the system does not finds the
1295 language you choose in a specific screen.
1296 fr : opac is translated (except pictures)
1297 es : a few intranet is translated (including pictures)
1298 pl : opac is translated (UNTESTED in this release)
1299 |;
1300
1301 sub updatedatabase {
1302     # At this point, $::etcdir/koha.conf must exist, for C4::Context
1303     # We must somehow temporarily enable $::etcdir/koha.conf. A symlink can
1304     # do this & at the same time facilitate detection of aborted installs.
1305         my $result=system ("perl -I $::intranetdir/modules scripts/updater/updatedatabase");
1306         if ($result) {
1307                 print "Problem updating database...\n";
1308                 exit;
1309         }
1310
1311         my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 123', '1');
1312
1313         if ($response == 1) {
1314                 system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1315         }
1316         if ($response == 2) {
1317                 system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1318                 system("cat scripts/misc/lang-datas/fr/stopwords.sql | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1319         }
1320
1321         $result = system ("perl -I $::intranetdir/modules scripts/marc/updatedb2marc.pl");
1322         if ($result) {
1323                 print "Problem updating database to MARC...\n";
1324                 exit;
1325         }
1326
1327         print "\n\nFinished updating of database. Press <ENTER> to continue...";
1328         <STDIN>;
1329 }
1330
1331 sub populatedatabase {
1332         my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
1333         if ($response =~/^y/i) {
1334                 system("gunzip -d < sampledata-1.2.gz | $::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname");
1335                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
1336                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1337                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1338                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
1339                 showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
1340         } else {
1341                 my $input;
1342                 my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
1343
1344                 unless ($response =~/^n/i) {
1345                 my $branch='Main Library';
1346                 $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
1347                 $branch=~s/[^A-Za-z0-9\s]//g;
1348
1349                 my $branchcode=$branch;
1350                 $branchcode=~s/[^A-Za-z0-9]//g;
1351                 $branchcode=uc($branchcode);
1352                 $branchcode=substr($branchcode,0,4);
1353                 $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
1354                 $branchcode=~s/[^A-Za-z0-9]//g;
1355                 $branchcode=uc($branchcode);
1356                 $branchcode=substr($branchcode,0,4);
1357                 $branchcode or $branchcode='DEF';
1358
1359                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
1360                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
1361                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
1362
1363                 my $printername='Library Printer';
1364                 $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
1365                 $printername=~s/[^A-Za-z0-9\s]//g;
1366
1367                 my $printerqueue='lp';
1368                 $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
1369                 $printerqueue=~s/[^A-Za-z0-9]//g;
1370                 system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
1371                 }
1372         my $language=showmessage(getmessage('Language'), 'free', 'en');
1373         system("$::mysqldir/bin/mysql -u$::mysqluser $::mysqlpass_quoted $::dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
1374         }
1375 }
1376
1377 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
1378 Apache needs to be restarted to load the new configuration for Koha.
1379
1380 Would you like to restart Apache now?  [Y]/N: |;
1381
1382 sub restartapache {
1383
1384     my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
1385
1386
1387
1388     unless ($response=~/^n/i) {
1389         # Need to support other init structures here?
1390         if (-e "/etc/rc.d/init.d/httpd") {
1391             system('/etc/rc.d/init.d/httpd restart');
1392         } elsif (-e "/etc/init.d/apache") {
1393             system('/etc//init.d/apache restart');
1394         } elsif (-e "/etc/init.d/apache-ssl") {
1395             system('/etc/init.d/apache-ssl restart');
1396         }
1397     }
1398
1399 }
1400
1401
1402 sub loadconfigfile {
1403     my %configfile;
1404
1405     open (KC, "<$::etcdir/koha.conf");
1406     while (<KC>) {
1407      chomp;
1408      (next) if (/^\s*#/);
1409      if (/(.*)\s*=\s*(.*)/) {
1410        my $variable=$1;
1411        my $value=$2;
1412        # Clean up white space at beginning and end
1413        $variable=~s/^\s*//g;
1414        $variable=~s/\s*$//g;
1415        $value=~s/^\s*//g;
1416        $value=~s/\s*$//g;
1417        $configfile{$variable}=$value;
1418      }
1419     }
1420
1421     $::intranetdir=$configfile{'intranetdir'};
1422     $::opacdir=$configfile{'opacdir'};
1423     $::kohaversion=$configfile{'kohaversion'};
1424     $::kohalogdir=$configfile{'kohalogdir'};
1425     $::database=$configfile{'database'};
1426     $::hostname=$configfile{'hostname'};
1427     $::user=$configfile{'user'};
1428     $::pass=$configfile{'pass'};
1429 }
1430
1431 END { }       # module clean-up code here (global destructor)
1432
1433 =back
1434
1435 =head1 BUGS
1436
1437 A lot of variables like $::opacdir. Because Perl does not check
1438 for strictness when a package name is explicitly specified,
1439 using such variables defeats the purpose of "use strict".
1440
1441 =head1 SEE ALSO
1442
1443 buildrelease.pl,
1444 installer.pl
1445
1446 =cut
1447
1448 1;