Long is the road to MARC..
[koha.git] / installer.pl
1 #!/usr/bin/perl -w # please develop with -w
2
3 use diagnostics;
4 use strict; # please develop with the strict pragma
5
6 unless ($< == 0) {
7     print "You must be root to run this script.\n";
8     exit 1;
9 }
10
11 my $kohaversion=`cat koha.version`;
12 chomp $kohaversion;
13
14 if (-e "/etc/koha.conf") {
15     my $installedversion=`grep kohaversion= /etc/koha.conf`;
16     chomp $installedversion;
17     $installedversion=~m/kohaversion=(.*)/;
18     $installedversion=$1;
19     if ($installedversion) {
20         $installedversion="You currently have Koha $installedversion on your system.\n";
21     } else {
22         $installedversion="I am not able to determine what version of Koha is installed now.\n";
23     }
24
25     print qq|
26                         ==========================
27                         = Koha already installed =
28                         ==========================
29
30 It looks like Koha is already installed on your system (/etc/koha.conf exists
31 already).  If you would like to upgrade your system to $kohaversion, please use
32 the koha.upgrade script in this directory.
33
34 $installedversion
35
36 |;
37     exit;
38 }
39
40 system('clear');
41 print qq|
42 **********************************
43 * Welcome to the Koha Installer  *
44 **********************************
45 Welcome to the Koha install script!  This script will prompt you for some
46 basic information about your desired setup, then install Koha according to
47 your specifications.  To accept the default value for any question, simply hit
48 Enter at the prompt.
49
50 Please be sure to read the documentation, or visit the Koha website at 
51 http://www.koha.org for more information.
52
53 Are you ready to begin the installation? (Y/[N]):
54 |;
55
56 my $answer = <STDIN>;
57 chomp $answer;
58
59 if ($answer eq "Y" || $answer eq "y") {
60         print "Great! continuing setup... \n";
61     } else {
62     print qq|
63 This installer currently does not support a completely automated 
64 setup.
65
66 Please be sure to read the documentation, or visit the Koha website 
67 at http://www.koha.org for more information.
68 |;
69     exit;
70 };
71
72 print "\n";
73
74 #
75 # Test for Perl and Modules
76 #
77 print qq|
78
79 PERL & MODULES
80 ==============
81
82 |;
83
84 print "\nChecking perl modules ...\n";
85     unless (eval "require 5.004") {
86     die "Sorry, you need at least Perl 5.004\n";
87 }
88
89 my @missing = ();
90 unless (eval {require DBI})               { push @missing,"DBI" };
91 unless (eval {require Date::Manip})       { push @missing,"Date::Manip" };
92 unless (eval {require DBD::mysql})        { push @missing,"DBD::mysql" };
93 unless (eval {require Set::Scalar})       { push @missing,"Set::Scalar" };
94 #unless (eval {require Net::Z3950})        { 
95 #    print qq|
96 #
97 #The Net::Z3950 module is missing.  This module is necessary if you want to use
98 #Koha's Z39.50 client to download bibliographic records from other libraries.
99 #To install this module, you will need the yaz client installed from
100 #http://www.indexdata.dk/yaz/ and then you can install the perl module with the
101 #command:
102 #
103 #perl -MCPAN -e 'install Net::Z3950'
104 #
105 #Press the <ENTER> key to continue:
106 #|;
107 #    <STDIN>;
108 #}
109
110 #
111 # Print out a list of any missing modules
112 #
113 if (@missing > 0) {
114     print "\n\n";
115     print "You are missing some Perl modules which are required by Koha.\n";
116     print "Once these modules have been installed, rerun this installer.\n";
117     print "They can be installed by running (as root) the following:\n";
118     foreach my $module (@missing) {
119         print "   perl -MCPAN -e 'install \"$module\"'\n";
120         exit(1);
121     }} else{
122     print "All modules appear to be installed, continuing...\n";
123 };
124
125
126 print "\n";
127 my $input;
128 my $domainname = `hostname -d`;
129 chomp $domainname;
130 my $opacdir = '/usr/local/koha/opac';
131 my $kohadir = '/usr/local/koha/intranet';
132 my $getdirinfo=1;
133 while ($getdirinfo) {
134     # Loop until opac directory and koha directory are different
135     print qq|
136
137 OPAC DIRECTORY
138 ==============
139 Please supply the directory you want Koha to store its OPAC files in.  Leave off
140 the trailing slash.  This directory will be auto-created for you if it doesn't
141 exist.
142
143 Usually $opacdir
144 |;
145
146     print "Enter directory [$opacdir]: ";
147     chomp($input = <STDIN>);
148
149     if ($input) {
150       $opacdir = $input;
151     }
152
153
154     print qq|
155
156 INTRANET/LIBRARIANS DIRECTORY
157 =============================
158 Please supply the directory you want Koha to store its Intranet/Librarians files 
159 in.  Leave off the trailing slash.  This directory will be auto-created for you if 
160 it doesn't exist.
161
162 |;
163
164     print "Enter directory [$kohadir]: ";
165     chomp($input = <STDIN>);
166
167     if ($input) {
168       $kohadir = $input;
169     }
170     if ($kohadir eq $opacdir) {
171         print qq|
172
173 You must specify different directories for the OPAC and INTRANET files!
174
175 |;
176     } else {
177         $getdirinfo=0;
178     }
179 }
180
181 #
182 #KOHA conf
183 #
184 my $etcdir = '/etc';
185 my $dbname = 'Koha';
186 my $hostname = 'localhost';
187 my $user = 'kohaadmin';
188 my $pass = '';
189
190 print qq|
191
192 KOHA.CONF
193 =========
194 Koha uses a small configuration file that is placed in your /etc/ files
195 directory. The configuration file, will be created in this directory.
196
197 |;
198
199 #Get the path to the koha.conf directory
200 #print "Enter the path to your configuration directory [$etcdir]: ";
201 #chomp($input = <STDIN>);
202 #
203 #if ($input) {
204 #  $etcdir = $input;
205 #}
206
207
208 #Get the database name
209 print qq|
210
211 Please provide the name of the mysql database for your koha installation.
212 This is normally "$dbname".
213
214 |;
215
216 print "Enter database name [$dbname]: ";
217 chomp($input = <STDIN>);
218
219 if ($input) {
220   $dbname = $input;
221 }
222
223
224 #Get the hostname for the database
225 print qq|
226
227 Please provide the hostname for mysql.  Unless the database is located on another 
228 machine this will be "localhost".
229 |;
230
231 print "Enter hostname [$hostname]: ";
232 chomp($input = <STDIN>);
233
234 if ($input) {
235   $hostname = $input;
236 }
237
238 #Get the username for the database
239 print qq|
240
241 Please provide the name of the user, who will have full administrative rights
242 to the $dbname database, when authenticating from $hostname.
243
244 If no user is entered it will default to $user.
245 |;
246
247 print "Enter username [$user]:";
248 chomp($input = <STDIN>);
249
250 if ($input) {
251   $user = $input;
252 }
253
254 #Get the password for the database user
255 print qq|
256
257 Please provide a good password for the user $user.
258 |;
259
260 print "Enter password:";
261 chomp($input = <STDIN>);
262
263 if ($input) {
264   $pass = $input;
265 }
266
267 print "\n";
268
269
270 #Create the configuration file
271 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
272 at $etcdir.  Must have write capability.\n";
273 print SITES <<EOP
274 database=$dbname
275 hostname=$hostname
276 user=$user
277 pass=$pass
278 includes=$kohadir/htdocs/includes
279 intranetdir=$kohadir
280 opacdir=$opacdir
281 kohaversion=$kohaversion
282 EOP
283 ;
284 close(SITES);
285
286 print "Successfully created the Koha configuration file.\n";
287
288 my $httpduser;
289 my $realhttpdconf;
290
291 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
292                       /usr/local/etc/apache/httpd.conf
293                       /usr/local/etc/apache/apache.conf
294                       /var/www/conf/httpd.conf
295                       /etc/apache/conf/httpd.conf
296                       /etc/apache/conf/apache.conf
297                       /etc/apache-ssl/conf/apache.conf
298                       /etc/httpd/conf/httpd.conf
299                       /etc/httpd/httpd.conf)) {
300    if ( -f $httpdconf ) {
301             $realhttpdconf=$httpdconf;
302             open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
303       while (<HTTPDCONF>) {
304          if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
305             $httpduser = $1;
306          }
307       }
308       close(HTTPDCONF);
309    }
310 }
311 $httpduser ||= 'Undetermined';
312
313 #
314 # Set ownership of the koha.conf file for security
315 #
316 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
317 chmod 0440, "$etcdir/koha.conf";
318
319 #
320 #SETUP opac
321 #
322 my $svr_admin = "webmaster\@$domainname";
323 my $servername=`hostname -f`;
324 chomp $servername;
325 my $opacport=80;
326 my $kohaport=8080;
327
328 print qq|
329
330 OPAC and KOHA/LIBRARIAN CONFIGURATION
331 =====================================
332 Koha needs to setup your Apache configuration file for the
333 OPAC and LIBRARIAN virtual hosts.  By default this installer
334 will do this by using one ip address and two different ports
335 for the virtual hosts.  There are other ways to set this up,
336 and the installer will leave comments in httpd.conf detailing
337 what these other options are.
338
339 Please enter the e-mail address for your webserver admin.
340 Usually $svr_admin
341 |;
342
343 print "Enter e-mail address [$svr_admin]:";
344 chomp($input = <STDIN>);
345
346 if ($input) {
347   $svr_admin = $input;
348 }
349
350
351 print qq|
352
353
354 Please enter the domain name or ip address of your computer.
355 |;
356 print "Enter server name/ip address [$servername]:";
357 chomp($input = <STDIN>);
358
359 if ($input) {
360   $servername = $input;
361 }
362
363 print qq|
364
365 Please enter the port for your OPAC interface.
366 |;
367 print "Enter OPAC port [$opacport]:";
368 chomp($input = <STDIN>);
369
370 if ($input) {
371   $opacport = $input;
372 }
373
374 print qq|
375
376 Please enter the port for your Intranet/Librarian interface.
377 |;
378 print "Enter intranet port [$kohaport]:";
379 chomp($input = <STDIN>);
380
381 if ($input) {
382   $kohaport = $input;
383 }
384
385
386 #
387 # Update Apache Conf File.
388 #
389 #
390
391 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
392 chomp $logfiledir;
393
394 if ($logfiledir) {
395     $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
396     $logfiledir=$1;
397 }
398
399 unless ($logfiledir) {
400     $logfiledir='logs';
401 }
402 print qq|
403
404 UPDATING APACHE.CONF
405 ====================
406
407 |;
408
409
410 print "Checking for modules that need to be loaded...\n";
411 my $httpdconf='';
412 my $envmodule=0;
413 my $includesmodule=0;
414 open HC, $realhttpdconf;
415 while (<HC>) {
416     if (/^\s*#\s*LoadModule env_module /) {
417         s/^\s*#\s*//;
418         print "  Loading env_module in httpd.conf\n";
419         $envmodule=1;
420     }
421     if (/^\s*#\s*LoadModule includes_module /) {
422         s/^\s*#\s*//;
423         print "  Loading includes_module in httpd.conf\n";
424     }
425     if (/\s*LoadModule includes_module / ) {
426         $includesmodule=1;
427     }
428     $httpdconf.=$_;
429 }
430
431 my $apachebackupmade=0;
432 if ($envmodule || $includesmodule) {
433     system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
434     $apachebackupmade=1;
435     open HC, ">$realhttpdconf";
436     print HC $httpdconf;
437     close HC;
438 }
439
440
441 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
442     print qq|
443 $realhttpdconf appears to already have an entry for Koha
444 Virtual Hosts.  You may need to edit $realhttpdconf
445 if anything has changed since it was last set up.  This
446 script will not attempt to modify an existing Koha apache
447 configuration.
448
449 |;
450     print "Press <ENTER> to continue...";
451     <STDIN>;
452     print "\n";
453 } else {
454     unless ($apachebackupmade) {
455         system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
456     }
457     my $includesdirectives='';
458     if ($includesmodule) {
459         $includesdirectives.="Options +Includes\n";
460         $includesdirectives.="   AddHandler server-parsed .html\n";
461     }
462     open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
463     print SITE <<EOP
464
465
466 # Ports to listen to for Koha
467 Listen $opacport
468 Listen $kohaport
469
470 # NameVirtualHost is used by one of the optional configurations detailed below
471
472 #NameVirtualHost 11.22.33.44
473
474 # KOHA's OPAC Configuration
475 <VirtualHost $servername\:$opacport>
476    ServerAdmin $svr_admin
477    DocumentRoot $opacdir/htdocs
478    ServerName $servername
479    ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
480    ErrorLog $logfiledir/opac-error_log
481    TransferLog $logfiledir/opac-access_log
482    SetEnv PERL5LIB "$kohadir/modules"
483    $includesdirectives
484 </VirtualHost>
485
486 # KOHA's INTRANET Configuration
487 <VirtualHost $servername\:$kohaport>
488    ServerAdmin $svr_admin
489    DocumentRoot $kohadir/htdocs
490    ServerName $servername
491    ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
492    ErrorLog $logfiledir/koha-error_log
493    TransferLog $logfiledir/koha-access_log
494    SetEnv PERL5LIB "$kohadir/modules"
495    $includesdirectives
496 </VirtualHost>
497
498 # If you want to use name based Virtual Hosting:
499 #   1. remove the two Listen lines
500 #   2. replace $servername\:$opacport wih your.opac.domain.name
501 #   3. replace ServerName $servername wih ServerName your.opac.domain.name
502 #   4. replace $servername\:$kohaport wih your intranet domain name
503 #   5. replace ServerName $servername wih ServerName your.intranet.domain.name
504 #
505 # If you want to use NameVirtualHost'ing (using two names on one ip address):
506 #   1.  Follow steps 1-5 above
507 #   2.  Uncomment the NameVirtualHost line and set the correct ip address
508
509 EOP
510 ;
511
512
513     print qq|
514
515 Intranet Authentication
516 =======================
517
518 I can set it up so that the Intranet/Librarian site is password protected.
519 |;
520 print "Would you like to do this? ([Y]/N): ";
521 chomp($input = <STDIN>);
522
523 my $apacheauthusername='librarian';
524 my $apacheauthpassword='';
525 unless ($input=~/^n/i) {
526     print "\nEnter a userid to login with [$apacheauthusername]: ";
527     chomp ($input = <STDIN>);
528     if ($input) {
529         $apacheauthusername=$input;
530         $apacheauthusername=~s/[^a-zA-Z0-9]//g;
531     }
532     while (! $apacheauthpassword) {
533         print "\nEnter a password for the $apacheauthusername user: ";
534         chomp ($input = <STDIN>);
535         if ($input) {
536             $apacheauthpassword=$input;
537         }
538         if (!$apacheauthpassword) {
539             print "\nPlease enter a password.\n";
540         }
541     }
542     open AUTH, ">/etc/kohaintranet.pass";
543     my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
544     my $salt=substr($chars, int(rand(length($chars))),1);
545     $salt.=substr($chars, int(rand(length($chars))),1);
546     print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
547     close AUTH;
548     print SITE <<EOP
549
550 <Directory $kohadir>
551     AuthUserFile /etc/kohaintranet.pass
552     AuthType Basic
553     AuthName "Koha Intranet (for librarians only)"
554     Require  valid-user
555 </Directory>
556 EOP
557 }
558
559     close(SITE);
560
561     print "Successfully updated Apache Configuration file.\n";
562 }
563
564 #
565 # Setup the modules directory
566 #
567 print qq|
568
569 CREATING REQUIRED DIRECTORIES
570 =============================
571
572 |;
573
574
575 unless ( -d $kohadir ) {
576    print "Creating $kohadir...\n";
577    my $result=mkdir ($kohadir, oct(770));
578    if ($result==0) {
579        my @dirs = split(m#/#, $kohadir);
580         my $checkdir='';
581         foreach (@dirs) {
582             $checkdir.="$_/";
583             unless (-e "$checkdir") {
584                 mkdir($checkdir, 0775);
585             }
586         }
587    }
588    chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
589    chmod (oct(770), "$kohadir");
590 }
591 unless ( -d "$kohadir/htdocs" ) {
592    print "Creating $kohadir/htdocs...\n";
593    mkdir ("$kohadir/htdocs", oct(750));
594 }
595 unless ( -d "$kohadir/cgi-bin" ) {
596    print "Creating $kohadir/cgi-bin...\n";
597    mkdir ("$kohadir/cgi-bin", oct(750));
598 }
599 unless ( -d "$kohadir/modules" ) {
600    print "Creating $kohadir/modules...\n";
601    mkdir ("$kohadir/modules", oct(750));
602 }
603 unless ( -d "$kohadir/scripts" ) {
604    print "Creating $kohadir/scripts...\n";
605    mkdir ("$kohadir/scripts", oct(750));
606 }
607 unless ( -d $opacdir ) {
608    print "Creating $opacdir...\n";
609    my $result=mkdir ($opacdir, oct(770));
610    if ($result==0) {
611        my @dirs = split(m#/#, $opacdir);
612         my $checkdir='';
613         foreach (@dirs) {
614             $checkdir.="$_/";
615             unless (-e "$checkdir") {
616                 mkdir($checkdir, 0775);
617             }
618         }
619    }
620    chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
621    chmod (oct(770), "$opacdir");
622 }
623 unless ( -d "$opacdir/htdocs" ) {
624    print "Creating $opacdir/htdocs...\n";
625    mkdir ("$opacdir/htdocs", oct(750));
626 }
627 unless ( -d "$opacdir/cgi-bin" ) {
628    print "Creating $opacdir/cgi-bin...\n";
629    mkdir ("$opacdir/cgi-bin", oct(750));
630 }
631
632
633
634 print "\n\nINSTALLING KOHA...\n";
635 print "\n\n==================\n";
636 print "Copying internet-html files to $kohadir/htdocs...\n";
637 system("cp -R intranet-html/* $kohadir/htdocs/");
638 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
639 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
640 print "Copying script files to $kohadir/scripts...\n";
641 system("cp -R scripts/* $kohadir/scripts/");
642 print "Copying module files to $kohadir/modules...\n";
643 system("cp -R modules/* $kohadir/modules/");
644 print "Copying opac-html files to $opacdir/htdocs...\n";
645 system("cp -R opac-html/* $opacdir/htdocs/");
646 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
647 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
648
649 system("chown -R root.$httpduser $opacdir");
650 system("chown -R root.$httpduser $kohadir");
651
652 print qq|
653
654 MYSQL CONFIGURATION
655 ===================
656 |;
657 my $mysql;
658 my $mysqldir;
659 my $mysqluser = 'root';
660 my $mysqlpass = '';
661
662 foreach my $mysql (qw(/usr/local/mysql
663                       /opt/mysql
664                       )) {
665    if ( -d $mysql ) {
666             $mysqldir=$mysql;
667    }
668 }
669 if (!$mysqldir){
670     $mysqldir='/usr';
671 }
672 print qq|
673 To allow us to create the koha database please supply the 
674 mysql\'s root users password
675 |;
676
677 print "Enter mysql\'s root users password: ";
678 chomp($input = <STDIN>);
679
680 if ($input) {
681   $mysqlpass = $input;
682 }
683
684
685 print qq|
686
687 CREATING DATABASE
688 =================
689 |;
690 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
691 if ($result) {
692     print "\nCouldn't connect to the MySQL server for the reason given above.\n";
693     print "This is a serious problem, the database will not get installed.\a\n";
694     print "Press <ENTER> to continue...";
695     <STDIN>;
696     print "\n";
697 } else {
698     system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
699     system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
700     system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass 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')\"");
701     system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
702
703     system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
704
705
706     print qq|
707
708 SAMPLE DATA
709 ===========
710 If you are installing Koha for evaluation purposes,  I have a batch of sample
711 data that you can install now.
712
713 If you are installing Koha with the intention of populating it with your own
714 data, you probably don't want this sample data installed.
715 |;
716     print "\nWould you like to install the sample data? Y/[N]: ";
717     chomp($input = <STDIN>);
718     if ($input =~/^y/i) {
719         system("gunzip sampledata-1.2.gz");
720         system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
721         system("gzip -9 sampledata-1.2");
722         system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
723         system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
724         print qq|
725
726 Sample data has been installed.  For some suggestions on testing Koha, please
727 read the file doc/HOWTO-Testing.  If you find any bugs, please submit them at
728 http://bugs.koha.org/.  If you need help with testing Koha, you can post a
729 question through the koha-devel mailing list, or you can check for a developer
730 online at +irc.katipo.co.nz:6667 channel #koha.
731
732 You can find instructions for subscribing to the Koha mailing lists at:
733
734     http://www.koha.org
735
736
737 Press <ENTER> to continue...
738 |;
739         <STDIN>;
740     } else {
741         print "\n\nWould you like to add a branch and printer? [Y]/N: ";
742         chomp($input = <STDIN>);
743
744
745         unless ($input =~/^n/i) {
746             my $branch='Main Library';
747             print "Enter a name for the library branch [$branch]: ";
748             chomp($input = <STDIN>);
749             if ($input) {
750                 $branch=$input;
751             }
752             $branch=~s/[^A-Za-z0-9\s]//g;
753             my $branchcode=$branch;
754             $branchcode=~s/[^A-Za-z0-9]//g;
755             $branchcode=uc($branchcode);
756             $branchcode=substr($branchcode,0,4);
757             print "Enter a four letter code for your branch [$branchcode]: ";
758             chomp($input = <STDIN>);
759             if ($input) {
760                 $branchcode=$input;
761             }
762             $branchcode=~s/[^A-Z]//g;
763             $branchcode=uc($branchcode);
764             $branchcode=substr($branchcode,0,4);
765             print "Adding branch '$branch' with code '$branchcode'.\n";
766             system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
767             my $printername='Library Printer';
768             print "Enter a name for the printer [$printername]: ";
769             chomp($input = <STDIN>);
770             if ($input) {
771                 $printername=$input;
772             }
773             $printername=~s/[^A-Za-z0-9\s]//g;
774             my $printerqueue='lp';
775             print "Enter the queue for the printer [$printerqueue]: ";
776             chomp($input = <STDIN>);
777             if ($input) {
778                 $printerqueue=$input;
779             }
780             $printerqueue=~s/[^A-Za-z0-9]//g;
781             system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
782         }
783     }
784
785
786 }
787
788
789 print qq|
790
791 SETTING UP Z39.50 DAEMON
792 ========================
793 |;
794
795 my $kohalogdir='/var/log/koha';
796 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
797 chomp($input = <STDIN>);
798 if ($input) {
799     $kohalogdir=$input;
800 }
801
802 unless (-e "$kohalogdir") {
803     my $result = mkdir 0770, "$kohalogdir"; 
804     if ($result==0) {
805         my @dirs = split(m#/#, $kohalogdir);
806         my $checkdir='';
807         foreach (@dirs) {
808             $checkdir.="$_/";
809             unless (-e "$checkdir") {
810                 mkdir($checkdir, 0775);
811             }
812         }
813     }
814 }
815 chmod 0770, $kohalogdir;
816 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
817
818 # LAUNCH SCRIPT
819 print "Modifying Z39.50 daemon launch script...\n";
820 my $newfile='';
821 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
822 while (<L>) {
823     if (/^RunAsUser=/) {
824         $newfile.="RunAsUser=$httpduser\n";
825     } elsif (/^KohaZ3950Dir=/) {
826         $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
827     } else {
828         $newfile.=$_;
829     }
830 }
831 close L;
832 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
833 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
834 print L $newfile;
835 close L;
836
837
838 # SHELL SCRIPT
839 print "Modifying Z39.50 daemon wrapper script...\n";
840 $newfile='';
841 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
842 while (<S>) {
843     if (/^KohaModuleDir=/) {
844         $newfile.="KohaModuleDir=$kohadir/modules\n";
845     } elsif (/^KohaZ3950Dir=/) {
846         $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
847     } elsif (/^LogDir=/) {
848         $newfile.="LogDir=$kohalogdir\n";
849     } else {
850         $newfile.=$_;
851     }
852 }
853 close S;
854
855 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
856 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
857 print S $newfile;
858 close S;
859 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
860 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
861 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
862 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
863 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
864
865
866 #RESTART APACHE
867 print "\n\n";
868 print qq|
869
870 COMPLETED
871 =========
872 Congratulations ... your Koha installation is almost complete!
873 The final step is to restart your webserver.
874
875 You will be able to connect to your Librarian interface at:
876
877    http://$servername\:$kohaport/
878
879 and the OPAC interface at :
880
881    http://$servername\:$opacport/
882
883
884 Be sure to read the INSTALL, and Hints files. 
885
886 For more information visit http://www.koha.org
887
888 Would you like to restart your webserver now? (Y/[N]):
889 |;
890
891 my $restart = <STDIN>;
892 chomp $restart;
893
894 if ($restart=~/^y/i) {
895         # Need to support other init structures here?
896         if (-e "/etc/rc.d/init.d/httpd") {
897             system('/etc/rc.d/init.d/httpd restart');
898         } elsif (-e "/etc/init.d/apache") {
899             system('/etc//init.d/apache restart');
900         } elsif (-e "/etc/init.d/apache-ssl") {
901             system('/etc/init.d/apache-ssl restart');
902         }
903     } else {
904         print qq|
905 Congratulations ... your Koha installation is complete!
906 You will need to restart your webserver before using Koha!
907 |;
908     exit;
909 };