1 #!/usr/bin/perl -w # please develop with -w
4 use strict; # please develop with the strict pragma
7 print "You must be root to run this script.\n";
11 my $kohaversion=`cat koha.version`;
14 if (-e "/etc/koha.conf") {
15 my $installedversion=`grep kohaversion= /etc/koha.conf`;
16 chomp $installedversion;
17 $installedversion=~m/kohaversion=(.*)/;
19 if ($installedversion) {
20 $installedversion="You currently have Koha $installedversion on your system.\n";
22 $installedversion="I am not able to determine what version of Koha is installed now.\n";
26 ==========================
27 = Koha already installed =
28 ==========================
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.
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
50 Please be sure to read the documentation, or visit the Koha website at
51 http://www.koha.org for more information.
53 Are you ready to begin the installation? (Y/[N]):
59 if ($answer eq "Y" || $answer eq "y") {
60 print "Great! continuing setup... \n";
63 This installer currently does not support a completely automated
66 Please be sure to read the documentation, or visit the Koha website
67 at http://www.koha.org for more information.
75 # Test for Perl and Modules
84 print "\nChecking perl modules ...\n";
85 unless (eval "require 5.004") {
86 die "Sorry, you need at least Perl 5.004\n";
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}) {
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
103 #perl -MCPAN -e 'install Net::Z3950'
105 #Press the <ENTER> key to continue:
111 # Print out a list of any missing modules
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";
122 print "All modules appear to be installed, continuing...\n";
128 my $domainname = `hostname -d`;
130 my $opacdir = '/usr/local/koha/opac';
131 my $kohadir = '/usr/local/koha/intranet';
133 while ($getdirinfo) {
134 # Loop until opac directory and koha directory are different
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
146 print "Enter directory [$opacdir]: ";
147 chomp($input = <STDIN>);
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
164 print "Enter directory [$kohadir]: ";
165 chomp($input = <STDIN>);
170 if ($kohadir eq $opacdir) {
173 You must specify different directories for the OPAC and INTRANET files!
186 my $hostname = 'localhost';
187 my $user = 'kohaadmin';
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.
199 #Get the path to the koha.conf directory
200 #print "Enter the path to your configuration directory [$etcdir]: ";
201 #chomp($input = <STDIN>);
208 #Get the database name
211 Please provide the name of the mysql database for your koha installation.
212 This is normally "$dbname".
216 print "Enter database name [$dbname]: ";
217 chomp($input = <STDIN>);
224 #Get the hostname for the database
227 Please provide the hostname for mysql. Unless the database is located on another
228 machine this will be "localhost".
231 print "Enter hostname [$hostname]: ";
232 chomp($input = <STDIN>);
238 #Get the username for the database
241 Please provide the name of the user, who will have full administrative rights
242 to the $dbname database, when authenticating from $hostname.
244 If no user is entered it will default to $user.
247 print "Enter username [$user]:";
248 chomp($input = <STDIN>);
254 #Get the password for the database user
257 Please provide a good password for the user $user.
260 print "Enter password:";
261 chomp($input = <STDIN>);
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";
278 includes=$kohadir/htdocs/includes
281 kohaversion=$kohaversion
286 print "Successfully created the Koha configuration file.\n";
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*$/) {
311 unless ($httpduser) {
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.
319 print "What is your Apache user? ";
320 chomp($input = <STDIN>);
325 $httpduser='Undetermined';
330 # Set ownership of the koha.conf file for security
332 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
333 chmod 0440, "$etcdir/koha.conf";
338 my $svr_admin = "webmaster\@$domainname";
339 my $servername=`hostname -f`;
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.
355 Please enter the e-mail address for your webserver admin.
359 print "Enter e-mail address [$svr_admin]:";
360 chomp($input = <STDIN>);
370 Please enter the domain name or ip address of your computer.
372 print "Enter server name/ip address [$servername]:";
373 chomp($input = <STDIN>);
376 $servername = $input;
381 Please enter the port for your OPAC interface.
383 print "Enter OPAC port [$opacport]:";
384 chomp($input = <STDIN>);
392 Please enter the port for your Intranet/Librarian interface.
394 print "Enter intranet port [$kohaport]:";
395 chomp($input = <STDIN>);
403 # Update Apache Conf File.
407 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
411 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
415 unless ($logfiledir) {
426 print "Checking for modules that need to be loaded...\n";
429 my $includesmodule=0;
430 open HC, $realhttpdconf;
432 if (/^\s*#\s*LoadModule env_module /) {
434 print " Loading env_module in httpd.conf\n";
437 if (/^\s*#\s*LoadModule includes_module /) {
439 print " Loading includes_module in httpd.conf\n";
441 if (/\s*LoadModule includes_module / ) {
447 my $apachebackupmade=0;
448 if ($envmodule || $includesmodule) {
449 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
451 open HC, ">$realhttpdconf";
457 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
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
466 print "Press <ENTER> to continue...";
470 unless ($apachebackupmade) {
471 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
473 my $includesdirectives='';
474 if ($includesmodule) {
475 $includesdirectives.="Options +Includes\n";
476 $includesdirectives.=" AddHandler server-parsed .html\n";
478 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
482 # Ports to listen to for Koha
486 # NameVirtualHost is used by one of the optional configurations detailed below
488 #NameVirtualHost 11.22.33.44
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"
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"
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
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
531 Intranet Authentication
532 =======================
534 I can set it up so that the Intranet/Librarian site is password protected.
536 print "Would you like to do this? ([Y]/N): ";
537 chomp($input = <STDIN>);
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>);
545 $apacheauthusername=$input;
546 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
548 while (! $apacheauthpassword) {
549 print "\nEnter a password for the $apacheauthusername user: ";
550 chomp ($input = <STDIN>);
552 $apacheauthpassword=$input;
554 if (!$apacheauthpassword) {
555 print "\nPlease enter a password.\n";
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";
567 AuthUserFile /etc/kohaintranet.pass
569 AuthName "Koha Intranet (for librarians only)"
577 print "Successfully updated Apache Configuration file.\n";
581 # Setup the modules directory
585 CREATING REQUIRED DIRECTORIES
586 =============================
591 unless ( -d $kohadir ) {
592 print "Creating $kohadir...\n";
593 my $result=mkdir ($kohadir, oct(770));
595 my @dirs = split(m#/#, $kohadir);
599 unless (-e "$checkdir") {
600 mkdir($checkdir, 0775);
604 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
605 chmod (oct(770), "$kohadir");
607 unless ( -d "$kohadir/htdocs" ) {
608 print "Creating $kohadir/htdocs...\n";
609 mkdir ("$kohadir/htdocs", oct(750));
611 unless ( -d "$kohadir/cgi-bin" ) {
612 print "Creating $kohadir/cgi-bin...\n";
613 mkdir ("$kohadir/cgi-bin", oct(750));
615 unless ( -d "$kohadir/modules" ) {
616 print "Creating $kohadir/modules...\n";
617 mkdir ("$kohadir/modules", oct(750));
619 unless ( -d "$kohadir/scripts" ) {
620 print "Creating $kohadir/scripts...\n";
621 mkdir ("$kohadir/scripts", oct(750));
623 unless ( -d $opacdir ) {
624 print "Creating $opacdir...\n";
625 my $result=mkdir ($opacdir, oct(770));
627 my @dirs = split(m#/#, $opacdir);
631 unless (-e "$checkdir") {
632 mkdir($checkdir, 0775);
636 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
637 chmod (oct(770), "$opacdir");
639 unless ( -d "$opacdir/htdocs" ) {
640 print "Creating $opacdir/htdocs...\n";
641 mkdir ("$opacdir/htdocs", oct(750));
643 unless ( -d "$opacdir/cgi-bin" ) {
644 print "Creating $opacdir/cgi-bin...\n";
645 mkdir ("$opacdir/cgi-bin", oct(750));
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/");
665 system("chown -R root.$httpduser $opacdir");
666 system("chown -R root.$httpduser $kohadir");
675 my $mysqluser = 'root';
678 foreach my $mysql (qw(/usr/local/mysql
689 To allow us to create the koha database please supply the
690 mysql\'s root users password
693 print "Enter mysql\'s root users password: ";
694 chomp($input = <STDIN>);
706 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
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...";
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");
719 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
726 If you are installing Koha for evaluation purposes, I have a batch of sample
727 data that you can install now.
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.
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')\"");
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.
748 You can find instructions for subscribing to the Koha mailing lists at:
753 Press <ENTER> to continue...
757 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
758 chomp($input = <STDIN>);
761 unless ($input =~/^n/i) {
762 my $branch='Main Library';
763 print "Enter a name for the library branch [$branch]: ";
764 chomp($input = <STDIN>);
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>);
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>);
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>);
794 $printerqueue=$input;
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', '')\"");
807 SETTING UP Z39.50 DAEMON
808 ========================
811 my $kohalogdir='/var/log/koha';
812 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
813 chomp($input = <STDIN>);
818 unless (-e "$kohalogdir") {
819 my $result = mkdir 0770, "$kohalogdir";
821 my @dirs = split(m#/#, $kohalogdir);
825 unless (-e "$checkdir") {
826 mkdir($checkdir, 0775);
831 chmod 0770, $kohalogdir;
832 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
835 print "Modifying Z39.50 daemon launch script...\n";
837 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
840 $newfile.="RunAsUser=$httpduser\n";
841 } elsif (/^KohaZ3950Dir=/) {
842 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
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";
855 print "Modifying Z39.50 daemon wrapper script...\n";
857 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
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";
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";
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: $!";
888 Congratulations ... your Koha installation is almost complete!
889 The final step is to restart your webserver.
891 You will be able to connect to your Librarian interface at:
893 http://$servername\:$kohaport/
895 and the OPAC interface at :
897 http://$servername\:$opacport/
900 Be sure to read the INSTALL, and Hints files.
902 For more information visit http://www.koha.org
904 Would you like to restart your webserver now? (Y/[N]):
907 my $restart = <STDIN>;
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');
921 Congratulations ... your Koha installation is complete!
922 You will need to restart your webserver before using Koha!