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