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`;
19 if ($kohaversion =~ /RC/) {
25 WARNING WARNING WARNING WARNING WARNING
27 You are about to install Koha version $kohaversion. This version of Koha is a
28 release candidate. It is not intended to be installed on production systems.
29 It is being released so that users can test it before we release a final
33 print "Are you sure you want to install Koha $kohaversion? (Y/[N]): ";
38 if ($answer eq "Y" || $answer eq "y") {
39 print "Great! continuing setup... \n";
43 Watch for announcements of Koha releases on the Koha mailing list or the Koha
44 web site (http://www.koha.org/).
51 if (-e "/etc/koha.conf") {
52 my $installedversion=`grep kohaversion= /etc/koha.conf`;
53 chomp $installedversion;
54 $installedversion=~m/kohaversion=(.*)/;
56 if ($installedversion) {
57 $installedversion="You currently have Koha $installedversion on your system.\n";
59 $installedversion="I am not able to determine what version of Koha is installed now.\n";
63 ==========================
64 = Koha already installed =
65 ==========================
67 It looks like Koha is already installed on your system (/etc/koha.conf exists
68 already). If you would like to upgrade your system to $kohaversion, please use
69 the koha.upgrade script in this directory.
79 **********************************
80 * Welcome to the Koha Installer *
81 **********************************
82 Welcome to the Koha install script! This script will prompt you for some
83 basic information about your desired setup, then install Koha according to
84 your specifications. To accept the default value for any question, simply hit
87 Please be sure to read the documentation, or visit the Koha website at
88 http://www.koha.org for more information.
90 Are you ready to begin the installation? (Y/[N]):
96 if ($answer eq "Y" || $answer eq "y") {
97 print "Great! continuing setup... \n";
100 This installer currently does not support a completely automated
103 Please be sure to read the documentation, or visit the Koha website
104 at http://www.koha.org for more information.
112 # Test for Perl and Modules
121 print "\nChecking perl modules ...\n";
122 unless (eval "require 5.004") {
123 die "Sorry, you need at least Perl 5.004\n";
127 unless (eval {require DBI}) { push @missing,"DBI" };
128 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
129 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
130 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
131 unless (eval {require Net::Z3950}) {
134 The Net::Z3950 module is missing. This module is necessary if you want to use
135 Koha's Z39.50 client to download bibliographic records from other libraries.
136 To install this module, you will need the yaz client installed from
137 http://www.indexdata.dk/yaz/ and then you can install the perl module with the
140 perl -MCPAN -e 'install Net::Z3950'
142 Press the <ENTER> key to continue:
148 # Print out a list of any missing modules
152 print "You are missing some Perl modules which are required by Koha.\n";
153 print "Once these modules have been installed, rerun this installer.\n";
154 print "They can be installed by running (as root) the following:\n";
155 foreach my $module (@missing) {
156 print " perl -MCPAN -e 'install \"$module\"'\n";
159 print "All modules appear to be installed, continuing...\n";
165 my $domainname = `hostname -d`;
167 my $opacdir = '/usr/local/koha/opac';
168 my $kohadir = '/usr/local/koha/intranet';
170 while ($getdirinfo) {
171 # Loop until opac directory and koha directory are different
176 Please supply the directory you want Koha to store its OPAC files in. Leave off
177 the trailing slash. This directory will be auto-created for you if it doesn't
183 print "Enter directory [$opacdir]: ";
184 chomp($input = <STDIN>);
193 INTRANET/LIBRARIANS DIRECTORY
194 =============================
195 Please supply the directory you want Koha to store its Intranet/Librarians files
196 in. Leave off the trailing slash. This directory will be auto-created for you if
201 print "Enter directory [$kohadir]: ";
202 chomp($input = <STDIN>);
207 if ($kohadir eq $opacdir) {
210 You must specify different directories for the OPAC and INTRANET files!
223 my $hostname = 'localhost';
224 my $user = 'kohaadmin';
231 Koha uses a small configuration file that is placed in your /etc/ files
232 directory. The configuration file, will be created in this directory.
236 #Get the path to the koha.conf directory
237 #print "Enter the path to your configuration directory [$etcdir]: ";
238 #chomp($input = <STDIN>);
245 #Get the database name
248 Please provide the name of the mysql database for your koha installation.
249 This is normally "$dbname".
253 print "Enter database name [$dbname]: ";
254 chomp($input = <STDIN>);
261 #Get the hostname for the database
264 Please provide the hostname for mysql. Unless the database is located on another
265 machine this will be "localhost".
268 print "Enter hostname [$hostname]: ";
269 chomp($input = <STDIN>);
275 #Get the username for the database
278 Please provide the name of the user, who will have full administrative rights
279 to the $dbname database, when authenticating from $hostname.
281 If no user is entered it will default to $user.
284 print "Enter username [$user]:";
285 chomp($input = <STDIN>);
291 #Get the password for the database user
294 Please provide a good password for the user $user.
297 print "Enter password:";
298 chomp($input = <STDIN>);
308 print "Successfully created the Koha configuration file.\n";
313 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
314 /usr/local/etc/apache/httpd.conf
315 /usr/local/etc/apache/apache.conf
316 /var/www/conf/httpd.conf
317 /etc/apache/conf/httpd.conf
318 /etc/apache/conf/apache.conf
319 /etc/apache-ssl/conf/apache.conf
320 /etc/httpd/conf/httpd.conf
321 /etc/httpd/httpd.conf)) {
322 if ( -f $httpdconf ) {
323 $realhttpdconf=$httpdconf;
324 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
325 while (<HTTPDCONF>) {
326 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
333 unless ($realhttpdconf) {
336 I was not able to find your apache configuration file. It is usually
337 called httpd.conf or apache.conf.
339 print "Where is your Apache configuratin file? ";
340 chomp($input = <STDIN>);
343 $realhttpdconf = $input;
347 if ( -f $realhttpdconf ) {
348 open (HTTPDCONF, $realhttpdconf) or warn "Insufficient privileges to open $realhttpdconf for reading.\n";
349 while (<HTTPDCONF>) {
350 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
358 unless ($httpduser) {
361 I was not able to determine the user that Apache is running as. This
362 information is necessary in order to set the access privileges correctly on
363 /etc/koha.conf. This user should be set in one of the Apache configuration
364 files using the "User" directive.
366 print "What is your Apache user? ";
367 chomp($input = <STDIN>);
372 $httpduser='Undetermined';
380 my $svr_admin = "webmaster\@$domainname";
381 my $servername=`hostname -f`;
388 OPAC and KOHA/LIBRARIAN CONFIGURATION
389 =====================================
390 Koha needs to setup your Apache configuration file for the
391 OPAC and LIBRARIAN virtual hosts. By default this installer
392 will do this by using one ip address and two different ports
393 for the virtual hosts. There are other ways to set this up,
394 and the installer will leave comments in httpd.conf detailing
395 what these other options are.
397 Please enter the e-mail address for your webserver admin.
401 print "Enter e-mail address [$svr_admin]:";
402 chomp($input = <STDIN>);
412 Please enter the domain name or ip address of your computer.
414 print "Enter server name/ip address [$servername]:";
415 chomp($input = <STDIN>);
418 $servername = $input;
423 Please enter the port for your OPAC interface.
425 print "Enter OPAC port [$opacport]:";
426 chomp($input = <STDIN>);
434 Please enter the port for your Intranet/Librarian interface.
436 print "Enter intranet port [$kohaport]:";
437 chomp($input = <STDIN>);
445 # Update Apache Conf File.
449 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
453 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
457 unless ($logfiledir) {
468 print "Checking for modules that need to be loaded...\n";
471 my $includesmodule=0;
472 open HC, $realhttpdconf;
474 if (/^\s*#\s*LoadModule env_module /) {
476 print " Loading env_module in httpd.conf\n";
479 if (/^\s*#\s*LoadModule includes_module /) {
481 print " Loading includes_module in httpd.conf\n";
483 if (/\s*LoadModule includes_module / ) {
489 my $apachebackupmade=0;
490 if ($envmodule || $includesmodule) {
491 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
493 open HC, ">$realhttpdconf";
499 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
501 $realhttpdconf appears to already have an entry for Koha
502 Virtual Hosts. You may need to edit $realhttpdconf
503 if anything has changed since it was last set up. This
504 script will not attempt to modify an existing Koha apache
508 print "Press <ENTER> to continue...";
512 unless ($apachebackupmade) {
513 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
515 my $includesdirectives='';
516 if ($includesmodule) {
517 $includesdirectives.="Options +Includes\n";
518 $includesdirectives.=" AddHandler server-parsed .html\n";
520 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
524 # Ports to listen to for Koha
528 # NameVirtualHost is used by one of the optional configurations detailed below
530 #NameVirtualHost 11.22.33.44
532 # KOHA's OPAC Configuration
533 <VirtualHost $servername\:$opacport>
534 ServerAdmin $svr_admin
535 DocumentRoot $opacdir/htdocs
536 ServerName $servername
537 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
538 ErrorLog $logfiledir/opac-error_log
539 TransferLog $logfiledir/opac-access_log
540 SetEnv PERL5LIB "$kohadir/modules"
544 # KOHA's INTRANET Configuration
545 <VirtualHost $servername\:$kohaport>
546 ServerAdmin $svr_admin
547 DocumentRoot $kohadir/htdocs
548 ServerName $servername
549 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
550 ErrorLog $logfiledir/koha-error_log
551 TransferLog $logfiledir/koha-access_log
552 SetEnv PERL5LIB "$kohadir/modules"
556 # If you want to use name based Virtual Hosting:
557 # 1. remove the two Listen lines
558 # 2. replace $servername\:$opacport wih your.opac.domain.name
559 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
560 # 4. replace $servername\:$kohaport wih your intranet domain name
561 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
563 # If you want to use NameVirtualHost'ing (using two names on one ip address):
564 # 1. Follow steps 1-5 above
565 # 2. Uncomment the NameVirtualHost line and set the correct ip address
573 Intranet Authentication
574 =======================
576 I can set it up so that the Intranet/Librarian site is password protected.
578 print "Would you like to do this? ([Y]/N): ";
579 chomp($input = <STDIN>);
581 my $apacheauthusername='librarian';
582 my $apacheauthpassword='';
583 unless ($input=~/^n/i) {
584 print "\nEnter a userid to login with [$apacheauthusername]: ";
585 chomp ($input = <STDIN>);
587 $apacheauthusername=$input;
588 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
590 while (! $apacheauthpassword) {
591 print "\nEnter a password for the $apacheauthusername user: ";
592 chomp ($input = <STDIN>);
594 $apacheauthpassword=$input;
596 if (!$apacheauthpassword) {
597 print "\nPlease enter a password.\n";
600 open AUTH, ">/etc/kohaintranet.pass";
601 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
602 my $salt=substr($chars, int(rand(length($chars))),1);
603 $salt.=substr($chars, int(rand(length($chars))),1);
604 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
609 AuthUserFile /etc/kohaintranet.pass
611 AuthName "Koha Intranet (for librarians only)"
619 print "Successfully updated Apache Configuration file.\n";
624 SETTING UP Z39.50 DAEMON
625 ========================
628 my $kohalogdir='/var/log/koha';
629 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
630 chomp($input = <STDIN>);
635 unless (-e "$kohalogdir") {
636 my $result = mkdir 0770, "$kohalogdir";
638 my @dirs = split(m#/#, $kohalogdir);
642 unless (-e "$checkdir") {
643 mkdir($checkdir, 0775);
650 # Setup the modules directory
654 CREATING REQUIRED DIRECTORIES
655 =============================
660 unless ( -d $kohadir ) {
661 print "Creating $kohadir...\n";
662 my $result=mkdir ($kohadir, oct(770));
664 my @dirs = split(m#/#, $kohadir);
668 unless (-e "$checkdir") {
669 mkdir($checkdir, 0775);
673 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
674 chmod (oct(770), "$kohadir");
676 unless ( -d "$kohadir/htdocs" ) {
677 print "Creating $kohadir/htdocs...\n";
678 mkdir ("$kohadir/htdocs", oct(750));
680 unless ( -d "$kohadir/cgi-bin" ) {
681 print "Creating $kohadir/cgi-bin...\n";
682 mkdir ("$kohadir/cgi-bin", oct(750));
684 unless ( -d "$kohadir/modules" ) {
685 print "Creating $kohadir/modules...\n";
686 mkdir ("$kohadir/modules", oct(750));
688 unless ( -d "$kohadir/scripts" ) {
689 print "Creating $kohadir/scripts...\n";
690 mkdir ("$kohadir/scripts", oct(750));
692 unless ( -d $opacdir ) {
693 print "Creating $opacdir...\n";
694 my $result=mkdir ($opacdir, oct(770));
696 my @dirs = split(m#/#, $opacdir);
700 unless (-e "$checkdir") {
701 mkdir($checkdir, 0775);
705 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
706 chmod (oct(770), "$opacdir");
708 unless ( -d "$opacdir/htdocs" ) {
709 print "Creating $opacdir/htdocs...\n";
710 mkdir ("$opacdir/htdocs", oct(750));
712 unless ( -d "$opacdir/cgi-bin" ) {
713 print "Creating $opacdir/cgi-bin...\n";
714 mkdir ("$opacdir/cgi-bin", oct(750));
719 print "\n\nINSTALLING KOHA...\n";
720 print "\n\n==================\n";
721 print "Copying internet-html files to $kohadir/htdocs...\n";
722 system("cp -R intranet-html/* $kohadir/htdocs/");
723 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
724 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
725 print "Copying script files to $kohadir/scripts...\n";
726 system("cp -R scripts/* $kohadir/scripts/");
727 print "Copying module files to $kohadir/modules...\n";
728 system("cp -R modules/* $kohadir/modules/");
729 print "Copying opac-html files to $opacdir/htdocs...\n";
730 system("cp -R opac-html/* $opacdir/htdocs/");
731 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
732 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
734 system("chown -R root.$httpduser $opacdir");
735 system("chown -R root.$httpduser $kohadir");
739 #Create the configuration file
740 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
741 at $etcdir. Must have write capability.\n";
747 includes=$kohadir/htdocs/includes
750 kohalogdir=$kohalogdir
751 kohaversion=$kohaversion
758 # Set ownership of the koha.conf file for security
760 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
761 chmod 0440, "$etcdir/koha.conf";
771 my $mysqluser = 'root';
774 foreach my $mysql (qw(/usr/local/mysql
785 To allow us to create the koha database please supply the
786 mysql\'s root users password
790 while ($needpassword) {
791 print "Enter mysql\'s root users password: ";
792 chomp($input = <STDIN>);
794 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass proc > /dev/null 2>&1");
796 print "\n\nInvalid password for the MySql root user.\n\n";
808 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
810 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
811 print "This is a serious problem, the database will not get installed.
\a\n";
812 print "Press <ENTER> to continue...";
816 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
817 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
818 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')\"");
819 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
821 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
828 If you are installing Koha for evaluation purposes, I have a batch of sample
829 data that you can install now.
831 If you are installing Koha with the intention of populating it with your own
832 data, you probably don't want this sample data installed.
834 print "\nWould you like to install the sample data? Y/[N]: ";
835 chomp($input = <STDIN>);
836 if ($input =~/^y/i) {
837 system("gunzip sampledata-1.2.gz");
838 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
839 system("gzip -9 sampledata-1.2");
840 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
841 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
844 Sample data has been installed. For some suggestions on testing Koha, please
845 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
846 http://bugs.koha.org/. If you need help with testing Koha, you can post a
847 question through the koha-devel mailing list, or you can check for a developer
848 online at +irc.katipo.co.nz:6667 channel #koha.
850 You can find instructions for subscribing to the Koha mailing lists at:
855 Press <ENTER> to continue...
859 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
860 chomp($input = <STDIN>);
863 unless ($input =~/^n/i) {
864 my $branch='Main Library';
865 print "Enter a name for the library branch [$branch]: ";
866 chomp($input = <STDIN>);
870 $branch=~s/[^A-Za-z0-9\s]//g;
871 my $branchcode=$branch;
872 $branchcode=~s/[^A-Za-z0-9]//g;
873 $branchcode=uc($branchcode);
874 $branchcode=substr($branchcode,0,4);
875 print "Enter a four letter code for your branch [$branchcode]: ";
876 chomp($input = <STDIN>);
880 $branchcode=~s/[^A-Z]//g;
881 $branchcode=uc($branchcode);
882 $branchcode=substr($branchcode,0,4);
883 print "Adding branch '$branch' with code '$branchcode'.\n";
884 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
885 my $printername='Library Printer';
886 print "Enter a name for the printer [$printername]: ";
887 chomp($input = <STDIN>);
891 $printername=~s/[^A-Za-z0-9\s]//g;
892 my $printerqueue='lp';
893 print "Enter the queue for the printer [$printerqueue]: ";
894 chomp($input = <STDIN>);
896 $printerqueue=$input;
898 $printerqueue=~s/[^A-Za-z0-9]//g;
899 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
907 chmod 0770, $kohalogdir;
908 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
911 print "Modifying Z39.50 daemon launch script...\n";
913 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
916 $newfile.="RunAsUser=$httpduser\n";
917 } elsif (/^KohaZ3950Dir=/) {
918 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
924 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
925 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
931 print "Modifying Z39.50 daemon wrapper script...\n";
933 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
935 if (/^KohaModuleDir=/) {
936 $newfile.="KohaModuleDir=$kohadir/modules\n";
937 } elsif (/^KohaZ3950Dir=/) {
938 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
939 } elsif (/^LogDir=/) {
940 $newfile.="LogDir=$kohalogdir\n";
947 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
948 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
951 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
952 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
953 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
954 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
955 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
964 Congratulations ... your Koha installation is almost complete!
965 The final step is to restart your webserver.
967 You will be able to connect to your Librarian interface at:
969 http://$servername\:$kohaport/
971 and the OPAC interface at :
973 http://$servername\:$opacport/
976 Be sure to read the INSTALL, and Hints files.
978 For more information visit http://www.koha.org
980 Would you like to restart your webserver now? (Y/[N]):
983 my $restart = <STDIN>;
986 if ($restart=~/^y/i) {
987 # Need to support other init structures here?
988 if (-e "/etc/rc.d/init.d/httpd") {
989 system('/etc/rc.d/init.d/httpd restart');
990 } elsif (-e "/etc/init.d/apache") {
991 system('/etc//init.d/apache restart');
992 } elsif (-e "/etc/init.d/apache-ssl") {
993 system('/etc/init.d/apache-ssl restart');
997 Congratulations ... your Koha installation is complete!
998 You will need to restart your webserver before using Koha!