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