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';
378 # Set ownership of the koha.conf file for security
380 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
381 chmod 0440, "$etcdir/koha.conf";
386 my $svr_admin = "webmaster\@$domainname";
387 my $servername=`hostname -f`;
394 OPAC and KOHA/LIBRARIAN CONFIGURATION
395 =====================================
396 Koha needs to setup your Apache configuration file for the
397 OPAC and LIBRARIAN virtual hosts. By default this installer
398 will do this by using one ip address and two different ports
399 for the virtual hosts. There are other ways to set this up,
400 and the installer will leave comments in httpd.conf detailing
401 what these other options are.
403 Please enter the e-mail address for your webserver admin.
407 print "Enter e-mail address [$svr_admin]:";
408 chomp($input = <STDIN>);
418 Please enter the domain name or ip address of your computer.
420 print "Enter server name/ip address [$servername]:";
421 chomp($input = <STDIN>);
424 $servername = $input;
429 Please enter the port for your OPAC interface.
431 print "Enter OPAC port [$opacport]:";
432 chomp($input = <STDIN>);
440 Please enter the port for your Intranet/Librarian interface.
442 print "Enter intranet port [$kohaport]:";
443 chomp($input = <STDIN>);
451 # Update Apache Conf File.
455 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
459 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
463 unless ($logfiledir) {
474 print "Checking for modules that need to be loaded...\n";
477 my $includesmodule=0;
478 open HC, $realhttpdconf;
480 if (/^\s*#\s*LoadModule env_module /) {
482 print " Loading env_module in httpd.conf\n";
485 if (/^\s*#\s*LoadModule includes_module /) {
487 print " Loading includes_module in httpd.conf\n";
489 if (/\s*LoadModule includes_module / ) {
495 my $apachebackupmade=0;
496 if ($envmodule || $includesmodule) {
497 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
499 open HC, ">$realhttpdconf";
505 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
507 $realhttpdconf appears to already have an entry for Koha
508 Virtual Hosts. You may need to edit $realhttpdconf
509 if anything has changed since it was last set up. This
510 script will not attempt to modify an existing Koha apache
514 print "Press <ENTER> to continue...";
518 unless ($apachebackupmade) {
519 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
521 my $includesdirectives='';
522 if ($includesmodule) {
523 $includesdirectives.="Options +Includes\n";
524 $includesdirectives.=" AddHandler server-parsed .html\n";
526 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
530 # Ports to listen to for Koha
534 # NameVirtualHost is used by one of the optional configurations detailed below
536 #NameVirtualHost 11.22.33.44
538 # KOHA's OPAC Configuration
539 <VirtualHost $servername\:$opacport>
540 ServerAdmin $svr_admin
541 DocumentRoot $opacdir/htdocs
542 ServerName $servername
543 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
544 ErrorLog $logfiledir/opac-error_log
545 TransferLog $logfiledir/opac-access_log
546 SetEnv PERL5LIB "$kohadir/modules"
550 # KOHA's INTRANET Configuration
551 <VirtualHost $servername\:$kohaport>
552 ServerAdmin $svr_admin
553 DocumentRoot $kohadir/htdocs
554 ServerName $servername
555 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
556 ErrorLog $logfiledir/koha-error_log
557 TransferLog $logfiledir/koha-access_log
558 SetEnv PERL5LIB "$kohadir/modules"
562 # If you want to use name based Virtual Hosting:
563 # 1. remove the two Listen lines
564 # 2. replace $servername\:$opacport wih your.opac.domain.name
565 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
566 # 4. replace $servername\:$kohaport wih your intranet domain name
567 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
569 # If you want to use NameVirtualHost'ing (using two names on one ip address):
570 # 1. Follow steps 1-5 above
571 # 2. Uncomment the NameVirtualHost line and set the correct ip address
579 Intranet Authentication
580 =======================
582 I can set it up so that the Intranet/Librarian site is password protected.
584 print "Would you like to do this? ([Y]/N): ";
585 chomp($input = <STDIN>);
587 my $apacheauthusername='librarian';
588 my $apacheauthpassword='';
589 unless ($input=~/^n/i) {
590 print "\nEnter a userid to login with [$apacheauthusername]: ";
591 chomp ($input = <STDIN>);
593 $apacheauthusername=$input;
594 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
596 while (! $apacheauthpassword) {
597 print "\nEnter a password for the $apacheauthusername user: ";
598 chomp ($input = <STDIN>);
600 $apacheauthpassword=$input;
602 if (!$apacheauthpassword) {
603 print "\nPlease enter a password.\n";
606 open AUTH, ">/etc/kohaintranet.pass";
607 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
608 my $salt=substr($chars, int(rand(length($chars))),1);
609 $salt.=substr($chars, int(rand(length($chars))),1);
610 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
615 AuthUserFile /etc/kohaintranet.pass
617 AuthName "Koha Intranet (for librarians only)"
625 print "Successfully updated Apache Configuration file.\n";
630 SETTING UP Z39.50 DAEMON
631 ========================
634 my $kohalogdir='/var/log/koha';
635 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
636 chomp($input = <STDIN>);
641 unless (-e "$kohalogdir") {
642 my $result = mkdir 0770, "$kohalogdir";
644 my @dirs = split(m#/#, $kohalogdir);
648 unless (-e "$checkdir") {
649 mkdir($checkdir, 0775);
656 # Setup the modules directory
660 CREATING REQUIRED DIRECTORIES
661 =============================
666 unless ( -d $kohadir ) {
667 print "Creating $kohadir...\n";
668 my $result=mkdir ($kohadir, oct(770));
670 my @dirs = split(m#/#, $kohadir);
674 unless (-e "$checkdir") {
675 mkdir($checkdir, 0775);
679 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
680 chmod (oct(770), "$kohadir");
682 unless ( -d "$kohadir/htdocs" ) {
683 print "Creating $kohadir/htdocs...\n";
684 mkdir ("$kohadir/htdocs", oct(750));
686 unless ( -d "$kohadir/cgi-bin" ) {
687 print "Creating $kohadir/cgi-bin...\n";
688 mkdir ("$kohadir/cgi-bin", oct(750));
690 unless ( -d "$kohadir/modules" ) {
691 print "Creating $kohadir/modules...\n";
692 mkdir ("$kohadir/modules", oct(750));
694 unless ( -d "$kohadir/scripts" ) {
695 print "Creating $kohadir/scripts...\n";
696 mkdir ("$kohadir/scripts", oct(750));
698 unless ( -d $opacdir ) {
699 print "Creating $opacdir...\n";
700 my $result=mkdir ($opacdir, oct(770));
702 my @dirs = split(m#/#, $opacdir);
706 unless (-e "$checkdir") {
707 mkdir($checkdir, 0775);
711 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
712 chmod (oct(770), "$opacdir");
714 unless ( -d "$opacdir/htdocs" ) {
715 print "Creating $opacdir/htdocs...\n";
716 mkdir ("$opacdir/htdocs", oct(750));
718 unless ( -d "$opacdir/cgi-bin" ) {
719 print "Creating $opacdir/cgi-bin...\n";
720 mkdir ("$opacdir/cgi-bin", oct(750));
725 print "\n\nINSTALLING KOHA...\n";
726 print "\n\n==================\n";
727 print "Copying internet-html files to $kohadir/htdocs...\n";
728 system("cp -R intranet-html/* $kohadir/htdocs/");
729 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
730 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
731 print "Copying script files to $kohadir/scripts...\n";
732 system("cp -R scripts/* $kohadir/scripts/");
733 print "Copying module files to $kohadir/modules...\n";
734 system("cp -R modules/* $kohadir/modules/");
735 print "Copying opac-html files to $opacdir/htdocs...\n";
736 system("cp -R opac-html/* $opacdir/htdocs/");
737 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
738 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
740 system("chown -R root.$httpduser $opacdir");
741 system("chown -R root.$httpduser $kohadir");
745 #Create the configuration file
746 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
747 at $etcdir. Must have write capability.\n";
753 includes=$kohadir/htdocs/includes
756 kohalogdir=$kohalogdir
757 kohaversion=$kohaversion
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!