]> git.koha-community.org Git - koha.git/blob - installer.pl
merging 1.2 and main branches. Mostly spaces and typo diffs
[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 unless ($httpduser) {
312     print qq|
313
314 I was not able to determine the user that Apache is running as.  This
315 information is necessary in order to set the access privileges correctly on
316 /etc/koha.conf.  This user should be set in one of the Apache configuration
317 files using the "User" directive.
318 |;
319     print "What is your Apache user? ";
320     chomp($input = <STDIN>);
321
322     if ($input) {
323         $httpduser = $input;
324     } else {
325         $httpduser='Undetermined';
326     }
327 }
328
329 #
330 # Set ownership of the koha.conf file for security
331 #
332 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
333 chmod 0440, "$etcdir/koha.conf";
334
335 #
336 #SETUP opac
337 #
338 my $svr_admin = "webmaster\@$domainname";
339 my $servername=`hostname -f`;
340 chomp $servername;
341 my $opacport=80;
342 my $kohaport=8080;
343
344 print qq|
345
346 OPAC and KOHA/LIBRARIAN CONFIGURATION
347 =====================================
348 Koha needs to setup your Apache configuration file for the
349 OPAC and LIBRARIAN virtual hosts.  By default this installer
350 will do this by using one ip address and two different ports
351 for the virtual hosts.  There are other ways to set this up,
352 and the installer will leave comments in httpd.conf detailing
353 what these other options are.
354
355 Please enter the e-mail address for your webserver admin.
356 Usually $svr_admin
357 |;
358
359 print "Enter e-mail address [$svr_admin]:";
360 chomp($input = <STDIN>);
361
362 if ($input) {
363   $svr_admin = $input;
364 }
365
366
367 print qq|
368
369
370 Please enter the domain name or ip address of your computer.
371 |;
372 print "Enter server name/ip address [$servername]:";
373 chomp($input = <STDIN>);
374
375 if ($input) {
376   $servername = $input;
377 }
378
379 print qq|
380
381 Please enter the port for your OPAC interface.
382 |;
383 print "Enter OPAC port [$opacport]:";
384 chomp($input = <STDIN>);
385
386 if ($input) {
387   $opacport = $input;
388 }
389
390 print qq|
391
392 Please enter the port for your Intranet/Librarian interface.
393 |;
394 print "Enter intranet port [$kohaport]:";
395 chomp($input = <STDIN>);
396
397 if ($input) {
398   $kohaport = $input;
399 }
400
401
402 #
403 # Update Apache Conf File.
404 #
405 #
406
407 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
408 chomp $logfiledir;
409
410 if ($logfiledir) {
411     $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
412     $logfiledir=$1;
413 }
414
415 unless ($logfiledir) {
416     $logfiledir='logs';
417 }
418 print qq|
419
420 UPDATING APACHE.CONF
421 ====================
422
423 |;
424
425
426 print "Checking for modules that need to be loaded...\n";
427 my $httpdconf='';
428 my $envmodule=0;
429 my $includesmodule=0;
430 open HC, $realhttpdconf;
431 while (<HC>) {
432     if (/^\s*#\s*LoadModule env_module /) {
433         s/^\s*#\s*//;
434         print "  Loading env_module in httpd.conf\n";
435         $envmodule=1;
436     }
437     if (/^\s*#\s*LoadModule includes_module /) {
438         s/^\s*#\s*//;
439         print "  Loading includes_module in httpd.conf\n";
440     }
441     if (/\s*LoadModule includes_module / ) {
442         $includesmodule=1;
443     }
444     $httpdconf.=$_;
445 }
446
447 my $apachebackupmade=0;
448 if ($envmodule || $includesmodule) {
449     system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
450     $apachebackupmade=1;
451     open HC, ">$realhttpdconf";
452     print HC $httpdconf;
453     close HC;
454 }
455
456
457 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
458     print qq|
459 $realhttpdconf appears to already have an entry for Koha
460 Virtual Hosts.  You may need to edit $realhttpdconf
461 if anything has changed since it was last set up.  This
462 script will not attempt to modify an existing Koha apache
463 configuration.
464
465 |;
466     print "Press <ENTER> to continue...";
467     <STDIN>;
468     print "\n";
469 } else {
470     unless ($apachebackupmade) {
471         system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
472     }
473     my $includesdirectives='';
474     if ($includesmodule) {
475         $includesdirectives.="Options +Includes\n";
476         $includesdirectives.="   AddHandler server-parsed .html\n";
477     }
478     open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
479     print SITE <<EOP
480
481
482 # Ports to listen to for Koha
483 Listen $opacport
484 Listen $kohaport
485
486 # NameVirtualHost is used by one of the optional configurations detailed below
487
488 #NameVirtualHost 11.22.33.44
489
490 # KOHA's OPAC Configuration
491 <VirtualHost $servername\:$opacport>
492    ServerAdmin $svr_admin
493    DocumentRoot $opacdir/htdocs
494    ServerName $servername
495    ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
496    ErrorLog $logfiledir/opac-error_log
497    TransferLog $logfiledir/opac-access_log
498    SetEnv PERL5LIB "$kohadir/modules"
499    $includesdirectives
500 </VirtualHost>
501
502 # KOHA's INTRANET Configuration
503 <VirtualHost $servername\:$kohaport>
504    ServerAdmin $svr_admin
505    DocumentRoot $kohadir/htdocs
506    ServerName $servername
507    ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
508    ErrorLog $logfiledir/koha-error_log
509    TransferLog $logfiledir/koha-access_log
510    SetEnv PERL5LIB "$kohadir/modules"
511    $includesdirectives
512 </VirtualHost>
513
514 # If you want to use name based Virtual Hosting:
515 #   1. remove the two Listen lines
516 #   2. replace $servername\:$opacport wih your.opac.domain.name
517 #   3. replace ServerName $servername wih ServerName your.opac.domain.name
518 #   4. replace $servername\:$kohaport wih your intranet domain name
519 #   5. replace ServerName $servername wih ServerName your.intranet.domain.name
520 #
521 # If you want to use NameVirtualHost'ing (using two names on one ip address):
522 #   1.  Follow steps 1-5 above
523 #   2.  Uncomment the NameVirtualHost line and set the correct ip address
524
525 EOP
526 ;
527
528
529     print qq|
530
531 Intranet Authentication
532 =======================
533
534 I can set it up so that the Intranet/Librarian site is password protected.
535 |;
536 print "Would you like to do this? ([Y]/N): ";
537 chomp($input = <STDIN>);
538
539 my $apacheauthusername='librarian';
540 my $apacheauthpassword='';
541 unless ($input=~/^n/i) {
542     print "\nEnter a userid to login with [$apacheauthusername]: ";
543     chomp ($input = <STDIN>);
544     if ($input) {
545         $apacheauthusername=$input;
546         $apacheauthusername=~s/[^a-zA-Z0-9]//g;
547     }
548     while (! $apacheauthpassword) {
549         print "\nEnter a password for the $apacheauthusername user: ";
550         chomp ($input = <STDIN>);
551         if ($input) {
552             $apacheauthpassword=$input;
553         }
554         if (!$apacheauthpassword) {
555             print "\nPlease enter a password.\n";
556         }
557     }
558     open AUTH, ">/etc/kohaintranet.pass";
559     my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
560     my $salt=substr($chars, int(rand(length($chars))),1);
561     $salt.=substr($chars, int(rand(length($chars))),1);
562     print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
563     close AUTH;
564     print SITE <<EOP
565
566 <Directory $kohadir>
567     AuthUserFile /etc/kohaintranet.pass
568     AuthType Basic
569     AuthName "Koha Intranet (for librarians only)"
570     Require  valid-user
571 </Directory>
572 EOP
573 }
574
575     close(SITE);
576
577     print "Successfully updated Apache Configuration file.\n";
578 }
579
580 #
581 # Setup the modules directory
582 #
583 print qq|
584
585 CREATING REQUIRED DIRECTORIES
586 =============================
587
588 |;
589
590
591 unless ( -d $kohadir ) {
592    print "Creating $kohadir...\n";
593    my $result=mkdir ($kohadir, oct(770));
594    if ($result==0) {
595        my @dirs = split(m#/#, $kohadir);
596         my $checkdir='';
597         foreach (@dirs) {
598             $checkdir.="$_/";
599             unless (-e "$checkdir") {
600                 mkdir($checkdir, 0775);
601             }
602         }
603    }
604    chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
605    chmod (oct(770), "$kohadir");
606 }
607 unless ( -d "$kohadir/htdocs" ) {
608    print "Creating $kohadir/htdocs...\n";
609    mkdir ("$kohadir/htdocs", oct(750));
610 }
611 unless ( -d "$kohadir/cgi-bin" ) {
612    print "Creating $kohadir/cgi-bin...\n";
613    mkdir ("$kohadir/cgi-bin", oct(750));
614 }
615 unless ( -d "$kohadir/modules" ) {
616    print "Creating $kohadir/modules...\n";
617    mkdir ("$kohadir/modules", oct(750));
618 }
619 unless ( -d "$kohadir/scripts" ) {
620    print "Creating $kohadir/scripts...\n";
621    mkdir ("$kohadir/scripts", oct(750));
622 }
623 unless ( -d $opacdir ) {
624    print "Creating $opacdir...\n";
625    my $result=mkdir ($opacdir, oct(770));
626    if ($result==0) {
627        my @dirs = split(m#/#, $opacdir);
628         my $checkdir='';
629         foreach (@dirs) {
630             $checkdir.="$_/";
631             unless (-e "$checkdir") {
632                 mkdir($checkdir, 0775);
633             }
634         }
635    }
636    chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
637    chmod (oct(770), "$opacdir");
638 }
639 unless ( -d "$opacdir/htdocs" ) {
640    print "Creating $opacdir/htdocs...\n";
641    mkdir ("$opacdir/htdocs", oct(750));
642 }
643 unless ( -d "$opacdir/cgi-bin" ) {
644    print "Creating $opacdir/cgi-bin...\n";
645    mkdir ("$opacdir/cgi-bin", oct(750));
646 }
647
648
649
650 print "\n\nINSTALLING KOHA...\n";
651 print "\n\n==================\n";
652 print "Copying internet-html files to $kohadir/htdocs...\n";
653 system("cp -R intranet-html/* $kohadir/htdocs/");
654 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
655 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
656 print "Copying script files to $kohadir/scripts...\n";
657 system("cp -R scripts/* $kohadir/scripts/");
658 print "Copying module files to $kohadir/modules...\n";
659 system("cp -R modules/* $kohadir/modules/");
660 print "Copying opac-html files to $opacdir/htdocs...\n";
661 system("cp -R opac-html/* $opacdir/htdocs/");
662 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
663 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
664
665 system("chown -R root.$httpduser $opacdir");
666 system("chown -R root.$httpduser $kohadir");
667
668 print qq|
669
670 MYSQL CONFIGURATION
671 ===================
672 |;
673 my $mysql;
674 my $mysqldir;
675 my $mysqluser = 'root';
676 my $mysqlpass = '';
677
678 foreach my $mysql (qw(/usr/local/mysql
679                       /opt/mysql
680                       )) {
681    if ( -d $mysql ) {
682             $mysqldir=$mysql;
683    }
684 }
685 if (!$mysqldir){
686     $mysqldir='/usr';
687 }
688 print qq|
689 To allow us to create the koha database please supply the 
690 mysql\'s root users password
691 |;
692
693 print "Enter mysql\'s root users password: ";
694 chomp($input = <STDIN>);
695
696 if ($input) {
697   $mysqlpass = $input;
698 }
699
700
701 print qq|
702
703 CREATING DATABASE
704 =================
705 |;
706 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
707 if ($result) {
708     print "\nCouldn't connect to the MySQL server for the reason given above.\n";
709     print "This is a serious problem, the database will not get installed.\a\n";
710     print "Press <ENTER> to continue...";
711     <STDIN>;
712     print "\n";
713 } else {
714     system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
715     system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
716     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')\"");
717     system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
718
719     system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
720
721
722     print qq|
723
724 SAMPLE DATA
725 ===========
726 If you are installing Koha for evaluation purposes,  I have a batch of sample
727 data that you can install now.
728
729 If you are installing Koha with the intention of populating it with your own
730 data, you probably don't want this sample data installed.
731 |;
732     print "\nWould you like to install the sample data? Y/[N]: ";
733     chomp($input = <STDIN>);
734     if ($input =~/^y/i) {
735         system("gunzip sampledata-1.2.gz");
736         system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
737         system("gzip -9 sampledata-1.2");
738         system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
739         system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
740         print qq|
741
742 Sample data has been installed.  For some suggestions on testing Koha, please
743 read the file doc/HOWTO-Testing.  If you find any bugs, please submit them at
744 http://bugs.koha.org/.  If you need help with testing Koha, you can post a
745 question through the koha-devel mailing list, or you can check for a developer
746 online at +irc.katipo.co.nz:6667 channel #koha.
747
748 You can find instructions for subscribing to the Koha mailing lists at:
749
750     http://www.koha.org
751
752
753 Press <ENTER> to continue...
754 |;
755         <STDIN>;
756     } else {
757         print "\n\nWould you like to add a branch and printer? [Y]/N: ";
758         chomp($input = <STDIN>);
759
760
761         unless ($input =~/^n/i) {
762             my $branch='Main Library';
763             print "Enter a name for the library branch [$branch]: ";
764             chomp($input = <STDIN>);
765             if ($input) {
766                 $branch=$input;
767             }
768             $branch=~s/[^A-Za-z0-9\s]//g;
769             my $branchcode=$branch;
770             $branchcode=~s/[^A-Za-z0-9]//g;
771             $branchcode=uc($branchcode);
772             $branchcode=substr($branchcode,0,4);
773             print "Enter a four letter code for your branch [$branchcode]: ";
774             chomp($input = <STDIN>);
775             if ($input) {
776                 $branchcode=$input;
777             }
778             $branchcode=~s/[^A-Z]//g;
779             $branchcode=uc($branchcode);
780             $branchcode=substr($branchcode,0,4);
781             print "Adding branch '$branch' with code '$branchcode'.\n";
782             system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
783             my $printername='Library Printer';
784             print "Enter a name for the printer [$printername]: ";
785             chomp($input = <STDIN>);
786             if ($input) {
787                 $printername=$input;
788             }
789             $printername=~s/[^A-Za-z0-9\s]//g;
790             my $printerqueue='lp';
791             print "Enter the queue for the printer [$printerqueue]: ";
792             chomp($input = <STDIN>);
793             if ($input) {
794                 $printerqueue=$input;
795             }
796             $printerqueue=~s/[^A-Za-z0-9]//g;
797             system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
798         }
799     }
800
801
802 }
803
804
805 print qq|
806
807 SETTING UP Z39.50 DAEMON
808 ========================
809 |;
810
811 my $kohalogdir='/var/log/koha';
812 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
813 chomp($input = <STDIN>);
814 if ($input) {
815     $kohalogdir=$input;
816 }
817
818 unless (-e "$kohalogdir") {
819     my $result = mkdir 0770, "$kohalogdir"; 
820     if ($result==0) {
821         my @dirs = split(m#/#, $kohalogdir);
822         my $checkdir='';
823         foreach (@dirs) {
824             $checkdir.="$_/";
825             unless (-e "$checkdir") {
826                 mkdir($checkdir, 0775);
827             }
828         }
829     }
830 }
831 chmod 0770, $kohalogdir;
832 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
833
834 # LAUNCH SCRIPT
835 print "Modifying Z39.50 daemon launch script...\n";
836 my $newfile='';
837 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
838 while (<L>) {
839     if (/^RunAsUser=/) {
840         $newfile.="RunAsUser=$httpduser\n";
841     } elsif (/^KohaZ3950Dir=/) {
842         $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
843     } else {
844         $newfile.=$_;
845     }
846 }
847 close L;
848 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
849 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
850 print L $newfile;
851 close L;
852
853
854 # SHELL SCRIPT
855 print "Modifying Z39.50 daemon wrapper script...\n";
856 $newfile='';
857 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
858 while (<S>) {
859     if (/^KohaModuleDir=/) {
860         $newfile.="KohaModuleDir=$kohadir/modules\n";
861     } elsif (/^KohaZ3950Dir=/) {
862         $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
863     } elsif (/^LogDir=/) {
864         $newfile.="LogDir=$kohalogdir\n";
865     } else {
866         $newfile.=$_;
867     }
868 }
869 close S;
870
871 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
872 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
873 print S $newfile;
874 close S;
875 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
876 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
877 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
878 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
879 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
880
881
882 #RESTART APACHE
883 print "\n\n";
884 print qq|
885
886 COMPLETED
887 =========
888 Congratulations ... your Koha installation is almost complete!
889 The final step is to restart your webserver.
890
891 You will be able to connect to your Librarian interface at:
892
893    http://$servername\:$kohaport/
894
895 and the OPAC interface at :
896
897    http://$servername\:$opacport/
898
899
900 Be sure to read the INSTALL, and Hints files. 
901
902 For more information visit http://www.koha.org
903
904 Would you like to restart your webserver now? (Y/[N]):
905 |;
906
907 my $restart = <STDIN>;
908 chomp $restart;
909
910 if ($restart=~/^y/i) {
911         # Need to support other init structures here?
912         if (-e "/etc/rc.d/init.d/httpd") {
913             system('/etc/rc.d/init.d/httpd restart');
914         } elsif (-e "/etc/init.d/apache") {
915             system('/etc//init.d/apache restart');
916         } elsif (-e "/etc/init.d/apache-ssl") {
917             system('/etc/init.d/apache-ssl restart');
918         }
919     } else {
920         print qq|
921 Congratulations ... your Koha installation is complete!
922 You will need to restart your webserver before using Koha!
923 |;
924     exit;
925 };