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>);
271 print "Successfully created the Koha configuration file.\n";
276 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
277 /usr/local/etc/apache/httpd.conf
278 /usr/local/etc/apache/apache.conf
279 /var/www/conf/httpd.conf
280 /etc/apache/conf/httpd.conf
281 /etc/apache/conf/apache.conf
282 /etc/apache-ssl/conf/apache.conf
283 /etc/httpd/conf/httpd.conf
284 /etc/httpd/httpd.conf)) {
285 if ( -f $httpdconf ) {
286 $realhttpdconf=$httpdconf;
287 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
288 while (<HTTPDCONF>) {
289 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
296 unless ($httpduser) {
299 I was not able to determine the user that Apache is running as. This
300 information is necessary in order to set the access privileges correctly on
301 /etc/koha.conf. This user should be set in one of the Apache configuration
302 files using the "User" directive.
304 print "What is your Apache user? ";
305 chomp($input = <STDIN>);
310 $httpduser='Undetermined';
315 #Create the configuration file
316 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
317 at $etcdir. Must have write capability.\n";
323 includes=$kohadir/htdocs/includes
326 kohaversion=$kohaversion
333 # Set ownership of the koha.conf file for security
335 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
336 chmod 0440, "$etcdir/koha.conf";
341 my $svr_admin = "webmaster\@$domainname";
342 my $servername=`hostname -f`;
349 OPAC and KOHA/LIBRARIAN CONFIGURATION
350 =====================================
351 Koha needs to setup your Apache configuration file for the
352 OPAC and LIBRARIAN virtual hosts. By default this installer
353 will do this by using one ip address and two different ports
354 for the virtual hosts. There are other ways to set this up,
355 and the installer will leave comments in httpd.conf detailing
356 what these other options are.
358 Please enter the e-mail address for your webserver admin.
362 print "Enter e-mail address [$svr_admin]:";
363 chomp($input = <STDIN>);
373 Please enter the domain name or ip address of your computer.
375 print "Enter server name/ip address [$servername]:";
376 chomp($input = <STDIN>);
379 $servername = $input;
384 Please enter the port for your OPAC interface.
386 print "Enter OPAC port [$opacport]:";
387 chomp($input = <STDIN>);
395 Please enter the port for your Intranet/Librarian interface.
397 print "Enter intranet port [$kohaport]:";
398 chomp($input = <STDIN>);
406 # Update Apache Conf File.
410 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
414 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
418 unless ($logfiledir) {
429 print "Checking for modules that need to be loaded...\n";
432 my $includesmodule=0;
433 open HC, $realhttpdconf;
435 if (/^\s*#\s*LoadModule env_module /) {
437 print " Loading env_module in httpd.conf\n";
440 if (/^\s*#\s*LoadModule includes_module /) {
442 print " Loading includes_module in httpd.conf\n";
444 if (/\s*LoadModule includes_module / ) {
450 my $apachebackupmade=0;
451 if ($envmodule || $includesmodule) {
452 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
454 open HC, ">$realhttpdconf";
460 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
462 $realhttpdconf appears to already have an entry for Koha
463 Virtual Hosts. You may need to edit $realhttpdconf
464 if anything has changed since it was last set up. This
465 script will not attempt to modify an existing Koha apache
469 print "Press <ENTER> to continue...";
473 unless ($apachebackupmade) {
474 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
476 my $includesdirectives='';
477 if ($includesmodule) {
478 $includesdirectives.="Options +Includes\n";
479 $includesdirectives.=" AddHandler server-parsed .html\n";
481 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
485 # Ports to listen to for Koha
489 # NameVirtualHost is used by one of the optional configurations detailed below
491 #NameVirtualHost 11.22.33.44
493 # KOHA's OPAC Configuration
494 <VirtualHost $servername\:$opacport>
495 ServerAdmin $svr_admin
496 DocumentRoot $opacdir/htdocs
497 ServerName $servername
498 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
499 ErrorLog $logfiledir/opac-error_log
500 TransferLog $logfiledir/opac-access_log
501 SetEnv PERL5LIB "$kohadir/modules"
505 # KOHA's INTRANET Configuration
506 <VirtualHost $servername\:$kohaport>
507 ServerAdmin $svr_admin
508 DocumentRoot $kohadir/htdocs
509 ServerName $servername
510 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
511 ErrorLog $logfiledir/koha-error_log
512 TransferLog $logfiledir/koha-access_log
513 SetEnv PERL5LIB "$kohadir/modules"
517 # If you want to use name based Virtual Hosting:
518 # 1. remove the two Listen lines
519 # 2. replace $servername\:$opacport wih your.opac.domain.name
520 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
521 # 4. replace $servername\:$kohaport wih your intranet domain name
522 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
524 # If you want to use NameVirtualHost'ing (using two names on one ip address):
525 # 1. Follow steps 1-5 above
526 # 2. Uncomment the NameVirtualHost line and set the correct ip address
534 Intranet Authentication
535 =======================
537 I can set it up so that the Intranet/Librarian site is password protected.
539 print "Would you like to do this? ([Y]/N): ";
540 chomp($input = <STDIN>);
542 my $apacheauthusername='librarian';
543 my $apacheauthpassword='';
544 unless ($input=~/^n/i) {
545 print "\nEnter a userid to login with [$apacheauthusername]: ";
546 chomp ($input = <STDIN>);
548 $apacheauthusername=$input;
549 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
551 while (! $apacheauthpassword) {
552 print "\nEnter a password for the $apacheauthusername user: ";
553 chomp ($input = <STDIN>);
555 $apacheauthpassword=$input;
557 if (!$apacheauthpassword) {
558 print "\nPlease enter a password.\n";
561 open AUTH, ">/etc/kohaintranet.pass";
562 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
563 my $salt=substr($chars, int(rand(length($chars))),1);
564 $salt.=substr($chars, int(rand(length($chars))),1);
565 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
570 AuthUserFile /etc/kohaintranet.pass
572 AuthName "Koha Intranet (for librarians only)"
580 print "Successfully updated Apache Configuration file.\n";
584 # Setup the modules directory
588 CREATING REQUIRED DIRECTORIES
589 =============================
594 unless ( -d $kohadir ) {
595 print "Creating $kohadir...\n";
596 my $result=mkdir ($kohadir, oct(770));
598 my @dirs = split(m#/#, $kohadir);
602 unless (-e "$checkdir") {
603 mkdir($checkdir, 0775);
607 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
608 chmod (oct(770), "$kohadir");
610 unless ( -d "$kohadir/htdocs" ) {
611 print "Creating $kohadir/htdocs...\n";
612 mkdir ("$kohadir/htdocs", oct(750));
614 unless ( -d "$kohadir/cgi-bin" ) {
615 print "Creating $kohadir/cgi-bin...\n";
616 mkdir ("$kohadir/cgi-bin", oct(750));
618 unless ( -d "$kohadir/modules" ) {
619 print "Creating $kohadir/modules...\n";
620 mkdir ("$kohadir/modules", oct(750));
622 unless ( -d "$kohadir/scripts" ) {
623 print "Creating $kohadir/scripts...\n";
624 mkdir ("$kohadir/scripts", oct(750));
626 unless ( -d $opacdir ) {
627 print "Creating $opacdir...\n";
628 my $result=mkdir ($opacdir, oct(770));
630 my @dirs = split(m#/#, $opacdir);
634 unless (-e "$checkdir") {
635 mkdir($checkdir, 0775);
639 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
640 chmod (oct(770), "$opacdir");
642 unless ( -d "$opacdir/htdocs" ) {
643 print "Creating $opacdir/htdocs...\n";
644 mkdir ("$opacdir/htdocs", oct(750));
646 unless ( -d "$opacdir/cgi-bin" ) {
647 print "Creating $opacdir/cgi-bin...\n";
648 mkdir ("$opacdir/cgi-bin", oct(750));
653 print "\n\nINSTALLING KOHA...\n";
654 print "\n\n==================\n";
655 print "Copying internet-html files to $kohadir/htdocs...\n";
656 system("cp -R intranet-html/* $kohadir/htdocs/");
657 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
658 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
659 print "Copying script files to $kohadir/scripts...\n";
660 system("cp -R scripts/* $kohadir/scripts/");
661 print "Copying module files to $kohadir/modules...\n";
662 system("cp -R modules/* $kohadir/modules/");
663 print "Copying opac-html files to $opacdir/htdocs...\n";
664 system("cp -R opac-html/* $opacdir/htdocs/");
665 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
666 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
668 system("chown -R root.$httpduser $opacdir");
669 system("chown -R root.$httpduser $kohadir");
678 my $mysqluser = 'root';
681 foreach my $mysql (qw(/usr/local/mysql
692 To allow us to create the koha database please supply the
693 mysql\'s root users password
696 print "Enter mysql\'s root users password: ";
697 chomp($input = <STDIN>);
709 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
711 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
712 print "This is a serious problem, the database will not get installed.
\a\n";
713 print "Press <ENTER> to continue...";
717 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
718 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
719 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')\"");
720 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
722 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
729 If you are installing Koha for evaluation purposes, I have a batch of sample
730 data that you can install now.
732 If you are installing Koha with the intention of populating it with your own
733 data, you probably don't want this sample data installed.
735 print "\nWould you like to install the sample data? Y/[N]: ";
736 chomp($input = <STDIN>);
737 if ($input =~/^y/i) {
738 system("gunzip sampledata-1.2.gz");
739 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
740 system("gzip -9 sampledata-1.2");
741 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
742 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
745 Sample data has been installed. For some suggestions on testing Koha, please
746 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
747 http://bugs.koha.org/. If you need help with testing Koha, you can post a
748 question through the koha-devel mailing list, or you can check for a developer
749 online at +irc.katipo.co.nz:6667 channel #koha.
751 You can find instructions for subscribing to the Koha mailing lists at:
756 Press <ENTER> to continue...
760 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
761 chomp($input = <STDIN>);
764 unless ($input =~/^n/i) {
765 my $branch='Main Library';
766 print "Enter a name for the library branch [$branch]: ";
767 chomp($input = <STDIN>);
771 $branch=~s/[^A-Za-z0-9\s]//g;
772 my $branchcode=$branch;
773 $branchcode=~s/[^A-Za-z0-9]//g;
774 $branchcode=uc($branchcode);
775 $branchcode=substr($branchcode,0,4);
776 print "Enter a four letter code for your branch [$branchcode]: ";
777 chomp($input = <STDIN>);
781 $branchcode=~s/[^A-Z]//g;
782 $branchcode=uc($branchcode);
783 $branchcode=substr($branchcode,0,4);
784 print "Adding branch '$branch' with code '$branchcode'.\n";
785 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
786 my $printername='Library Printer';
787 print "Enter a name for the printer [$printername]: ";
788 chomp($input = <STDIN>);
792 $printername=~s/[^A-Za-z0-9\s]//g;
793 my $printerqueue='lp';
794 print "Enter the queue for the printer [$printerqueue]: ";
795 chomp($input = <STDIN>);
797 $printerqueue=$input;
799 $printerqueue=~s/[^A-Za-z0-9]//g;
800 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
810 SETTING UP Z39.50 DAEMON
811 ========================
814 my $kohalogdir='/var/log/koha';
815 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
816 chomp($input = <STDIN>);
821 unless (-e "$kohalogdir") {
822 my $result = mkdir 0770, "$kohalogdir";
824 my @dirs = split(m#/#, $kohalogdir);
828 unless (-e "$checkdir") {
829 mkdir($checkdir, 0775);
834 chmod 0770, $kohalogdir;
835 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
838 print "Modifying Z39.50 daemon launch script...\n";
840 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
843 $newfile.="RunAsUser=$httpduser\n";
844 } elsif (/^KohaZ3950Dir=/) {
845 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
851 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
852 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
858 print "Modifying Z39.50 daemon wrapper script...\n";
860 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
862 if (/^KohaModuleDir=/) {
863 $newfile.="KohaModuleDir=$kohadir/modules\n";
864 } elsif (/^KohaZ3950Dir=/) {
865 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
866 } elsif (/^LogDir=/) {
867 $newfile.="LogDir=$kohalogdir\n";
874 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
875 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
878 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
879 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
880 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
881 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
882 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
891 Congratulations ... your Koha installation is almost complete!
892 The final step is to restart your webserver.
894 You will be able to connect to your Librarian interface at:
896 http://$servername\:$kohaport/
898 and the OPAC interface at :
900 http://$servername\:$opacport/
903 Be sure to read the INSTALL, and Hints files.
905 For more information visit http://www.koha.org
907 Would you like to restart your webserver now? (Y/[N]):
910 my $restart = <STDIN>;
913 if ($restart=~/^y/i) {
914 # Need to support other init structures here?
915 if (-e "/etc/rc.d/init.d/httpd") {
916 system('/etc/rc.d/init.d/httpd restart');
917 } elsif (-e "/etc/init.d/apache") {
918 system('/etc//init.d/apache restart');
919 } elsif (-e "/etc/init.d/apache-ssl") {
920 system('/etc/init.d/apache-ssl restart');
924 Congratulations ... your Koha installation is complete!
925 You will need to restart your webserver before using Koha!