1 #!/usr/bin/perl -w # please develop with -w
4 use strict; # please develop with the strict pragma
7 print "\n\nYou must run koha.upgrade as root.\n\n";
11 print "You must be root to run this script.\n";
15 my $kohaversion=`cat koha.version`;
18 if (-e "/etc/koha.conf") {
19 my $installedversion=`grep kohaversion= /etc/koha.conf`;
20 chomp $installedversion;
21 $installedversion=~m/kohaversion=(.*)/;
23 if ($installedversion) {
24 $installedversion="You currently have Koha $installedversion on your system.\n";
26 $installedversion="I am not able to determine what version of Koha is installed now.\n";
30 ==========================
31 = Koha already installed =
32 ==========================
34 It looks like Koha is already installed on your system (/etc/koha.conf exists
35 already). If you would like to upgrade your system to $kohaversion, please use
36 the koha.upgrade script in this directory.
46 **********************************
47 * Welcome to the Koha Installer *
48 **********************************
49 Welcome to the Koha install script! This script will prompt you for some
50 basic information about your desired setup, then install Koha according to
51 your specifications. To accept the default value for any question, simply hit
54 Please be sure to read the documentation, or visit the Koha website at
55 http://www.koha.org for more information.
57 Are you ready to begin the installation? (Y/[N]):
63 if ($answer eq "Y" || $answer eq "y") {
64 print "Great! continuing setup... \n";
67 This installer currently does not support a completely automated
70 Please be sure to read the documentation, or visit the Koha website
71 at http://www.koha.org for more information.
79 # Test for Perl and Modules
88 print "\nChecking perl modules ...\n";
89 unless (eval "require 5.004") {
90 die "Sorry, you need at least Perl 5.004\n";
94 unless (eval {require DBI}) { push @missing,"DBI" };
95 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
96 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
97 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
98 #unless (eval {require Net::Z3950}) {
101 #The Net::Z3950 module is missing. This module is necessary if you want to use
102 #Koha's Z39.50 client to download bibliographic records from other libraries.
103 #To install this module, you will need the yaz client installed from
104 #http://www.indexdata.dk/yaz/ and then you can install the perl module with the
107 #perl -MCPAN -e 'install Net::Z3950'
109 #Press the <ENTER> key to continue:
115 # Print out a list of any missing modules
119 print "You are missing some Perl modules which are required by Koha.\n";
120 print "Once these modules have been installed, rerun this installer.\n";
121 print "They can be installed by running (as root) the following:\n";
122 foreach my $module (@missing) {
123 print " perl -MCPAN -e 'install \"$module\"'\n";
126 print "All modules appear to be installed, continuing...\n";
132 my $domainname = `hostname -d`;
134 my $opacdir = '/usr/local/koha/opac';
135 my $kohadir = '/usr/local/koha/intranet';
137 while ($getdirinfo) {
138 # Loop until opac directory and koha directory are different
143 Please supply the directory you want Koha to store its OPAC files in. Leave off
144 the trailing slash. This directory will be auto-created for you if it doesn't
150 print "Enter directory [$opacdir]: ";
151 chomp($input = <STDIN>);
160 INTRANET/LIBRARIANS DIRECTORY
161 =============================
162 Please supply the directory you want Koha to store its Intranet/Librarians files
163 in. Leave off the trailing slash. This directory will be auto-created for you if
168 print "Enter directory [$kohadir]: ";
169 chomp($input = <STDIN>);
174 if ($kohadir eq $opacdir) {
177 You must specify different directories for the OPAC and INTRANET files!
190 my $hostname = 'localhost';
191 my $user = 'kohaadmin';
198 Koha uses a small configuration file that is placed in your /etc/ files
199 directory. The configuration file, will be created in this directory.
203 #Get the path to the koha.conf directory
204 #print "Enter the path to your configuration directory [$etcdir]: ";
205 #chomp($input = <STDIN>);
212 #Get the database name
215 Please provide the name of the mysql database for your koha installation.
216 This is normally "$dbname".
220 print "Enter database name [$dbname]: ";
221 chomp($input = <STDIN>);
228 #Get the hostname for the database
231 Please provide the hostname for mysql. Unless the database is located on another
232 machine this will be "localhost".
235 print "Enter hostname [$hostname]: ";
236 chomp($input = <STDIN>);
242 #Get the username for the database
245 Please provide the name of the user, who will have full administrative rights
246 to the $dbname database, when authenticating from $hostname.
248 If no user is entered it will default to $user.
251 print "Enter username [$user]:";
252 chomp($input = <STDIN>);
258 #Get the password for the database user
261 Please provide a good password for the user $user.
264 print "Enter password:";
265 chomp($input = <STDIN>);
275 print "Successfully created the Koha configuration file.\n";
280 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
281 /usr/local/etc/apache/httpd.conf
282 /usr/local/etc/apache/apache.conf
283 /var/www/conf/httpd.conf
284 /etc/apache/conf/httpd.conf
285 /etc/apache/conf/apache.conf
286 /etc/apache-ssl/conf/apache.conf
287 /etc/httpd/conf/httpd.conf
288 /etc/httpd/httpd.conf)) {
289 if ( -f $httpdconf ) {
290 $realhttpdconf=$httpdconf;
291 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
292 while (<HTTPDCONF>) {
293 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
300 unless ($httpduser) {
303 I was not able to determine the user that Apache is running as. This
304 information is necessary in order to set the access privileges correctly on
305 /etc/koha.conf. This user should be set in one of the Apache configuration
306 files using the "User" directive.
308 print "What is your Apache user? ";
309 chomp($input = <STDIN>);
314 $httpduser='Undetermined';
319 #Create the configuration file
320 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
321 at $etcdir. Must have write capability.\n";
327 includes=$kohadir/htdocs/includes
330 kohaversion=$kohaversion
337 # Set ownership of the koha.conf file for security
339 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
340 chmod 0440, "$etcdir/koha.conf";
345 my $svr_admin = "webmaster\@$domainname";
346 my $servername=`hostname -f`;
353 OPAC and KOHA/LIBRARIAN CONFIGURATION
354 =====================================
355 Koha needs to setup your Apache configuration file for the
356 OPAC and LIBRARIAN virtual hosts. By default this installer
357 will do this by using one ip address and two different ports
358 for the virtual hosts. There are other ways to set this up,
359 and the installer will leave comments in httpd.conf detailing
360 what these other options are.
362 Please enter the e-mail address for your webserver admin.
366 print "Enter e-mail address [$svr_admin]:";
367 chomp($input = <STDIN>);
377 Please enter the domain name or ip address of your computer.
379 print "Enter server name/ip address [$servername]:";
380 chomp($input = <STDIN>);
383 $servername = $input;
388 Please enter the port for your OPAC interface.
390 print "Enter OPAC port [$opacport]:";
391 chomp($input = <STDIN>);
399 Please enter the port for your Intranet/Librarian interface.
401 print "Enter intranet port [$kohaport]:";
402 chomp($input = <STDIN>);
410 # Update Apache Conf File.
414 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
418 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
422 unless ($logfiledir) {
433 print "Checking for modules that need to be loaded...\n";
436 my $includesmodule=0;
437 open HC, $realhttpdconf;
439 if (/^\s*#\s*LoadModule env_module /) {
441 print " Loading env_module in httpd.conf\n";
444 if (/^\s*#\s*LoadModule includes_module /) {
446 print " Loading includes_module in httpd.conf\n";
448 if (/\s*LoadModule includes_module / ) {
454 my $apachebackupmade=0;
455 if ($envmodule || $includesmodule) {
456 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
458 open HC, ">$realhttpdconf";
464 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
466 $realhttpdconf appears to already have an entry for Koha
467 Virtual Hosts. You may need to edit $realhttpdconf
468 if anything has changed since it was last set up. This
469 script will not attempt to modify an existing Koha apache
473 print "Press <ENTER> to continue...";
477 unless ($apachebackupmade) {
478 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
480 my $includesdirectives='';
481 if ($includesmodule) {
482 $includesdirectives.="Options +Includes\n";
483 $includesdirectives.=" AddHandler server-parsed .html\n";
485 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
489 # Ports to listen to for Koha
493 # NameVirtualHost is used by one of the optional configurations detailed below
495 #NameVirtualHost 11.22.33.44
497 # KOHA's OPAC Configuration
498 <VirtualHost $servername\:$opacport>
499 ServerAdmin $svr_admin
500 DocumentRoot $opacdir/htdocs
501 ServerName $servername
502 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
503 ErrorLog $logfiledir/opac-error_log
504 TransferLog $logfiledir/opac-access_log
505 SetEnv PERL5LIB "$kohadir/modules"
509 # KOHA's INTRANET Configuration
510 <VirtualHost $servername\:$kohaport>
511 ServerAdmin $svr_admin
512 DocumentRoot $kohadir/htdocs
513 ServerName $servername
514 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
515 ErrorLog $logfiledir/koha-error_log
516 TransferLog $logfiledir/koha-access_log
517 SetEnv PERL5LIB "$kohadir/modules"
521 # If you want to use name based Virtual Hosting:
522 # 1. remove the two Listen lines
523 # 2. replace $servername\:$opacport wih your.opac.domain.name
524 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
525 # 4. replace $servername\:$kohaport wih your intranet domain name
526 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
528 # If you want to use NameVirtualHost'ing (using two names on one ip address):
529 # 1. Follow steps 1-5 above
530 # 2. Uncomment the NameVirtualHost line and set the correct ip address
538 Intranet Authentication
539 =======================
541 I can set it up so that the Intranet/Librarian site is password protected.
543 print "Would you like to do this? ([Y]/N): ";
544 chomp($input = <STDIN>);
546 my $apacheauthusername='librarian';
547 my $apacheauthpassword='';
548 unless ($input=~/^n/i) {
549 print "\nEnter a userid to login with [$apacheauthusername]: ";
550 chomp ($input = <STDIN>);
552 $apacheauthusername=$input;
553 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
555 while (! $apacheauthpassword) {
556 print "\nEnter a password for the $apacheauthusername user: ";
557 chomp ($input = <STDIN>);
559 $apacheauthpassword=$input;
561 if (!$apacheauthpassword) {
562 print "\nPlease enter a password.\n";
565 open AUTH, ">/etc/kohaintranet.pass";
566 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
567 my $salt=substr($chars, int(rand(length($chars))),1);
568 $salt.=substr($chars, int(rand(length($chars))),1);
569 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
574 AuthUserFile /etc/kohaintranet.pass
576 AuthName "Koha Intranet (for librarians only)"
584 print "Successfully updated Apache Configuration file.\n";
588 # Setup the modules directory
592 CREATING REQUIRED DIRECTORIES
593 =============================
598 unless ( -d $kohadir ) {
599 print "Creating $kohadir...\n";
600 my $result=mkdir ($kohadir, oct(770));
602 my @dirs = split(m#/#, $kohadir);
606 unless (-e "$checkdir") {
607 mkdir($checkdir, 0775);
611 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
612 chmod (oct(770), "$kohadir");
614 unless ( -d "$kohadir/htdocs" ) {
615 print "Creating $kohadir/htdocs...\n";
616 mkdir ("$kohadir/htdocs", oct(750));
618 unless ( -d "$kohadir/cgi-bin" ) {
619 print "Creating $kohadir/cgi-bin...\n";
620 mkdir ("$kohadir/cgi-bin", oct(750));
622 unless ( -d "$kohadir/modules" ) {
623 print "Creating $kohadir/modules...\n";
624 mkdir ("$kohadir/modules", oct(750));
626 unless ( -d "$kohadir/scripts" ) {
627 print "Creating $kohadir/scripts...\n";
628 mkdir ("$kohadir/scripts", oct(750));
630 unless ( -d $opacdir ) {
631 print "Creating $opacdir...\n";
632 my $result=mkdir ($opacdir, oct(770));
634 my @dirs = split(m#/#, $opacdir);
638 unless (-e "$checkdir") {
639 mkdir($checkdir, 0775);
643 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
644 chmod (oct(770), "$opacdir");
646 unless ( -d "$opacdir/htdocs" ) {
647 print "Creating $opacdir/htdocs...\n";
648 mkdir ("$opacdir/htdocs", oct(750));
650 unless ( -d "$opacdir/cgi-bin" ) {
651 print "Creating $opacdir/cgi-bin...\n";
652 mkdir ("$opacdir/cgi-bin", oct(750));
657 print "\n\nINSTALLING KOHA...\n";
658 print "\n\n==================\n";
659 print "Copying internet-html files to $kohadir/htdocs...\n";
660 system("cp -R intranet-html/* $kohadir/htdocs/");
661 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
662 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
663 print "Copying script files to $kohadir/scripts...\n";
664 system("cp -R scripts/* $kohadir/scripts/");
665 print "Copying module files to $kohadir/modules...\n";
666 system("cp -R modules/* $kohadir/modules/");
667 print "Copying opac-html files to $opacdir/htdocs...\n";
668 system("cp -R opac-html/* $opacdir/htdocs/");
669 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
670 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
672 system("chown -R root.$httpduser $opacdir");
673 system("chown -R root.$httpduser $kohadir");
682 my $mysqluser = 'root';
685 foreach my $mysql (qw(/usr/local/mysql
696 To allow us to create the koha database please supply the
697 mysql\'s root users password
701 while ($needpassword) {
702 print "Enter mysql\'s root users password: ";
703 chomp($input = <STDIN>);
705 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass proc > /dev/null 2>&1");
707 print "\n\nInvalid password for the MySql root user.\n\n";
719 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
721 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
722 print "This is a serious problem, the database will not get installed.
\a\n";
723 print "Press <ENTER> to continue...";
727 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
728 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
729 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')\"");
730 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
732 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
739 If you are installing Koha for evaluation purposes, I have a batch of sample
740 data that you can install now.
742 If you are installing Koha with the intention of populating it with your own
743 data, you probably don't want this sample data installed.
745 print "\nWould you like to install the sample data? Y/[N]: ";
746 chomp($input = <STDIN>);
747 if ($input =~/^y/i) {
748 system("gunzip sampledata-1.2.gz");
749 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
750 system("gzip -9 sampledata-1.2");
751 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
752 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
755 Sample data has been installed. For some suggestions on testing Koha, please
756 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
757 http://bugs.koha.org/. If you need help with testing Koha, you can post a
758 question through the koha-devel mailing list, or you can check for a developer
759 online at +irc.katipo.co.nz:6667 channel #koha.
761 You can find instructions for subscribing to the Koha mailing lists at:
766 Press <ENTER> to continue...
770 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
771 chomp($input = <STDIN>);
774 unless ($input =~/^n/i) {
775 my $branch='Main Library';
776 print "Enter a name for the library branch [$branch]: ";
777 chomp($input = <STDIN>);
781 $branch=~s/[^A-Za-z0-9\s]//g;
782 my $branchcode=$branch;
783 $branchcode=~s/[^A-Za-z0-9]//g;
784 $branchcode=uc($branchcode);
785 $branchcode=substr($branchcode,0,4);
786 print "Enter a four letter code for your branch [$branchcode]: ";
787 chomp($input = <STDIN>);
791 $branchcode=~s/[^A-Z]//g;
792 $branchcode=uc($branchcode);
793 $branchcode=substr($branchcode,0,4);
794 print "Adding branch '$branch' with code '$branchcode'.\n";
795 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
796 my $printername='Library Printer';
797 print "Enter a name for the printer [$printername]: ";
798 chomp($input = <STDIN>);
802 $printername=~s/[^A-Za-z0-9\s]//g;
803 my $printerqueue='lp';
804 print "Enter the queue for the printer [$printerqueue]: ";
805 chomp($input = <STDIN>);
807 $printerqueue=$input;
809 $printerqueue=~s/[^A-Za-z0-9]//g;
810 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
820 SETTING UP Z39.50 DAEMON
821 ========================
824 my $kohalogdir='/var/log/koha';
825 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
826 chomp($input = <STDIN>);
831 unless (-e "$kohalogdir") {
832 my $result = mkdir 0770, "$kohalogdir";
834 my @dirs = split(m#/#, $kohalogdir);
838 unless (-e "$checkdir") {
839 mkdir($checkdir, 0775);
844 chmod 0770, $kohalogdir;
845 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
848 print "Modifying Z39.50 daemon launch script...\n";
850 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
853 $newfile.="RunAsUser=$httpduser\n";
854 } elsif (/^KohaZ3950Dir=/) {
855 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
861 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
862 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
868 print "Modifying Z39.50 daemon wrapper script...\n";
870 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
872 if (/^KohaModuleDir=/) {
873 $newfile.="KohaModuleDir=$kohadir/modules\n";
874 } elsif (/^KohaZ3950Dir=/) {
875 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
876 } elsif (/^LogDir=/) {
877 $newfile.="LogDir=$kohalogdir\n";
884 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
885 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
888 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
889 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
890 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
891 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
892 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
901 Congratulations ... your Koha installation is almost complete!
902 The final step is to restart your webserver.
904 You will be able to connect to your Librarian interface at:
906 http://$servername\:$kohaport/
908 and the OPAC interface at :
910 http://$servername\:$opacport/
913 Be sure to read the INSTALL, and Hints files.
915 For more information visit http://www.koha.org
917 Would you like to restart your webserver now? (Y/[N]):
920 my $restart = <STDIN>;
923 if ($restart=~/^y/i) {
924 # Need to support other init structures here?
925 if (-e "/etc/rc.d/init.d/httpd") {
926 system('/etc/rc.d/init.d/httpd restart');
927 } elsif (-e "/etc/init.d/apache") {
928 system('/etc//init.d/apache restart');
929 } elsif (-e "/etc/init.d/apache-ssl") {
930 system('/etc/init.d/apache-ssl restart');
934 Congratulations ... your Koha installation is complete!
935 You will need to restart your webserver before using Koha!