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 $httpduser ||= 'Undetermined';
314 # Set ownership of the koha.conf file for security
316 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
317 chmod 0440, "$etcdir/koha.conf";
322 my $svr_admin = "webmaster\@$domainname";
323 my $servername=`hostname -f`;
330 OPAC and KOHA/LIBRARIAN CONFIGURATION
331 =====================================
332 Koha needs to setup your Apache configuration file for the
333 OPAC and LIBRARIAN virtual hosts. By default this installer
334 will do this by using one ip address and two different ports
335 for the virtual hosts. There are other ways to set this up,
336 and the installer will leave comments in httpd.conf detailing
337 what these other options are.
339 Please enter the e-mail address for your webserver admin.
343 print "Enter e-mail address [$svr_admin]:";
344 chomp($input = <STDIN>);
354 Please enter the domain name or ip address of your computer.
356 print "Enter server name/ip address [$servername]:";
357 chomp($input = <STDIN>);
360 $servername = $input;
365 Please enter the port for your OPAC interface.
367 print "Enter OPAC port [$opacport]:";
368 chomp($input = <STDIN>);
376 Please enter the port for your Intranet/Librarian interface.
378 print "Enter intranet port [$kohaport]:";
379 chomp($input = <STDIN>);
387 # Update Apache Conf File.
391 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
395 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
399 unless ($logfiledir) {
410 print "Checking for modules that need to be loaded...\n";
413 my $includesmodule=0;
414 open HC, $realhttpdconf;
416 if (/^\s*#\s*LoadModule env_module /) {
418 print " Loading env_module in httpd.conf\n";
421 if (/^\s*#\s*LoadModule includes_module /) {
423 print " Loading includes_module in httpd.conf\n";
425 if (/\s*LoadModule includes_module / ) {
431 my $apachebackupmade=0;
432 if ($envmodule || $includesmodule) {
433 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
435 open HC, ">$realhttpdconf";
441 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
443 $realhttpdconf appears to already have an entry for Koha
444 Virtual Hosts. You may need to edit $realhttpdconf
445 if anything has changed since it was last set up. This
446 script will not attempt to modify an existing Koha apache
450 print "Press <ENTER> to continue...";
454 unless ($apachebackupmade) {
455 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
457 my $includesdirectives='';
458 if ($includesmodule) {
459 $includesdirectives.="Options +Includes\n";
460 $includesdirectives.=" AddHandler server-parsed .html\n";
462 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
466 # Ports to listen to for Koha
470 # NameVirtualHost is used by one of the optional configurations detailed below
472 #NameVirtualHost 11.22.33.44
474 # KOHA's OPAC Configuration
475 <VirtualHost $servername\:$opacport>
476 ServerAdmin $svr_admin
477 DocumentRoot $opacdir/htdocs
478 ServerName $servername
479 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
480 ErrorLog $logfiledir/opac-error_log
481 TransferLog $logfiledir/opac-access_log
482 SetEnv PERL5LIB "$kohadir/modules"
486 # KOHA's INTRANET Configuration
487 <VirtualHost $servername\:$kohaport>
488 ServerAdmin $svr_admin
489 DocumentRoot $kohadir/htdocs
490 ServerName $servername
491 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
492 ErrorLog $logfiledir/koha-error_log
493 TransferLog $logfiledir/koha-access_log
494 SetEnv PERL5LIB "$kohadir/modules"
498 # If you want to use name based Virtual Hosting:
499 # 1. remove the two Listen lines
500 # 2. replace $servername\:$opacport wih your.opac.domain.name
501 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
502 # 4. replace $servername\:$kohaport wih your intranet domain name
503 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
505 # If you want to use NameVirtualHost'ing (using two names on one ip address):
506 # 1. Follow steps 1-5 above
507 # 2. Uncomment the NameVirtualHost line and set the correct ip address
515 Intranet Authentication
516 =======================
518 I can set it up so that the Intranet/Librarian site is password protected.
520 print "Would you like to do this? ([Y]/N): ";
521 chomp($input = <STDIN>);
523 my $apacheauthusername='librarian';
524 my $apacheauthpassword='';
525 unless ($input=~/^n/i) {
526 print "\nEnter a userid to login with [$apacheauthusername]: ";
527 chomp ($input = <STDIN>);
529 $apacheauthusername=$input;
530 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
532 while (! $apacheauthpassword) {
533 print "\nEnter a password for the $apacheauthusername user: ";
534 chomp ($input = <STDIN>);
536 $apacheauthpassword=$input;
538 if (!$apacheauthpassword) {
539 print "\nPlease enter a password.\n";
542 open AUTH, ">/etc/kohaintranet.pass";
543 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
544 my $salt=substr($chars, int(rand(length($chars))),1);
545 $salt.=substr($chars, int(rand(length($chars))),1);
546 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
551 AuthUserFile /etc/kohaintranet.pass
553 AuthName "Koha Intranet (for librarians only)"
561 print "Successfully updated Apache Configuration file.\n";
565 # Setup the modules directory
569 CREATING REQUIRED DIRECTORIES
570 =============================
575 unless ( -d $kohadir ) {
576 print "Creating $kohadir...\n";
577 my $result=mkdir ($kohadir, oct(770));
579 my @dirs = split(m#/#, $kohadir);
583 unless (-e "$checkdir") {
584 mkdir($checkdir, 0775);
588 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
589 chmod (oct(770), "$kohadir");
591 unless ( -d "$kohadir/htdocs" ) {
592 print "Creating $kohadir/htdocs...\n";
593 mkdir ("$kohadir/htdocs", oct(750));
595 unless ( -d "$kohadir/cgi-bin" ) {
596 print "Creating $kohadir/cgi-bin...\n";
597 mkdir ("$kohadir/cgi-bin", oct(750));
599 unless ( -d "$kohadir/modules" ) {
600 print "Creating $kohadir/modules...\n";
601 mkdir ("$kohadir/modules", oct(750));
603 unless ( -d "$kohadir/scripts" ) {
604 print "Creating $kohadir/scripts...\n";
605 mkdir ("$kohadir/scripts", oct(750));
607 unless ( -d $opacdir ) {
608 print "Creating $opacdir...\n";
609 my $result=mkdir ($opacdir, oct(770));
611 my @dirs = split(m#/#, $opacdir);
615 unless (-e "$checkdir") {
616 mkdir($checkdir, 0775);
620 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
621 chmod (oct(770), "$opacdir");
623 unless ( -d "$opacdir/htdocs" ) {
624 print "Creating $opacdir/htdocs...\n";
625 mkdir ("$opacdir/htdocs", oct(750));
627 unless ( -d "$opacdir/cgi-bin" ) {
628 print "Creating $opacdir/cgi-bin...\n";
629 mkdir ("$opacdir/cgi-bin", oct(750));
634 print "\n\nINSTALLING KOHA...\n";
635 print "\n\n==================\n";
636 print "Copying internet-html files to $kohadir/htdocs...\n";
637 system("cp -R intranet-html/* $kohadir/htdocs/");
638 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
639 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
640 print "Copying script files to $kohadir/scripts...\n";
641 system("cp -R scripts/* $kohadir/scripts/");
642 print "Copying module files to $kohadir/modules...\n";
643 system("cp -R modules/* $kohadir/modules/");
644 print "Copying opac-html files to $opacdir/htdocs...\n";
645 system("cp -R opac-html/* $opacdir/htdocs/");
646 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
647 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
649 system("chown -R root.$httpduser $opacdir");
650 system("chown -R root.$httpduser $kohadir");
659 my $mysqluser = 'root';
662 foreach my $mysql (qw(/usr/local/mysql
673 To allow us to create the koha database please supply the
674 mysql\'s root users password
677 print "Enter mysql\'s root users password: ";
678 chomp($input = <STDIN>);
690 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
692 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
693 print "This is a serious problem, the database will not get installed.
\a\n";
694 print "Press <ENTER> to continue...";
698 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
699 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
700 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')\"");
701 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
703 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
710 If you are installing Koha for evaluation purposes, I have a batch of sample
711 data that you can install now.
713 If you are installing Koha with the intention of populating it with your own
714 data, you probably don't want this sample data installed.
716 print "\nWould you like to install the sample data? Y/[N]: ";
717 chomp($input = <STDIN>);
718 if ($input =~/^y/i) {
719 system("gunzip sampledata-1.2.gz");
720 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
721 system("gzip -9 sampledata-1.2");
722 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
723 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
726 Sample data has been installed. For some suggestions on testing Koha, please
727 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
728 http://bugs.koha.org/. If you need help with testing Koha, you can post a
729 question through the koha-devel mailing list, or you can check for a developer
730 online at +irc.katipo.co.nz:6667 channel #koha.
732 You can find instructions for subscribing to the Koha mailing lists at:
737 Press <ENTER> to continue...
741 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
742 chomp($input = <STDIN>);
745 unless ($input =~/^n/i) {
746 my $branch='Main Library';
747 print "Enter a name for the library branch [$branch]: ";
748 chomp($input = <STDIN>);
752 $branch=~s/[^A-Za-z0-9\s]//g;
753 my $branchcode=$branch;
754 $branchcode=~s/[^A-Za-z0-9]//g;
755 $branchcode=uc($branchcode);
756 $branchcode=substr($branchcode,0,4);
757 print "Enter a four letter code for your branch [$branchcode]: ";
758 chomp($input = <STDIN>);
762 $branchcode=~s/[^A-Z]//g;
763 $branchcode=uc($branchcode);
764 $branchcode=substr($branchcode,0,4);
765 print "Adding branch '$branch' with code '$branchcode'.\n";
766 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
767 my $printername='Library Printer';
768 print "Enter a name for the printer [$printername]: ";
769 chomp($input = <STDIN>);
773 $printername=~s/[^A-Za-z0-9\s]//g;
774 my $printerqueue='lp';
775 print "Enter the queue for the printer [$printerqueue]: ";
776 chomp($input = <STDIN>);
778 $printerqueue=$input;
780 $printerqueue=~s/[^A-Za-z0-9]//g;
781 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
791 SETTING UP Z39.50 DAEMON
792 ========================
795 my $kohalogdir='/var/log/koha';
796 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
797 chomp($input = <STDIN>);
802 unless (-e "$kohalogdir") {
803 my $result = mkdir 0770, "$kohalogdir";
805 my @dirs = split(m#/#, $kohalogdir);
809 unless (-e "$checkdir") {
810 mkdir($checkdir, 0775);
815 chmod 0770, $kohalogdir;
816 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
819 print "Modifying Z39.50 daemon launch script...\n";
821 open (L, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh");
824 $newfile.="RunAsUser=$httpduser\n";
825 } elsif (/^KohaZ3950Dir=/) {
826 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
832 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh $kohadir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
833 open L, ">$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
839 print "Modifying Z39.50 daemon wrapper script...\n";
841 open (S, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh");
843 if (/^KohaModuleDir=/) {
844 $newfile.="KohaModuleDir=$kohadir/modules\n";
845 } elsif (/^KohaZ3950Dir=/) {
846 $newfile.="KohaZ3950Dir=$kohadir/scripts/z3950daemon\n";
847 } elsif (/^LogDir=/) {
848 $newfile.="LogDir=$kohalogdir\n";
855 system("mv $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
856 open S, ">$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
859 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-launch.sh";
860 chmod 0750, "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh";
861 chmod 0750, "$kohadir/scripts/z3950daemon/processz3950queue";
862 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $kohadir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
863 chown(0, (getpwnam($httpduser)) [3], "$kohadir/scripts/z3950daemon/processz3950queue") or warn "can't chown $kohadir/scripts/z3950daemon/processz3950queue: $!";
872 Congratulations ... your Koha installation is almost complete!
873 The final step is to restart your webserver.
875 You will be able to connect to your Librarian interface at:
877 http://$servername\:$kohaport/
879 and the OPAC interface at :
881 http://$servername\:$opacport/
884 Be sure to read the INSTALL, and Hints files.
886 For more information visit http://www.koha.org
888 Would you like to restart your webserver now? (Y/[N]):
891 my $restart = <STDIN>;
894 if ($restart=~/^y/i) {
895 # Need to support other init structures here?
896 if (-e "/etc/rc.d/init.d/httpd") {
897 system('/etc/rc.d/init.d/httpd restart');
898 } elsif (-e "/etc/init.d/apache") {
899 system('/etc//init.d/apache restart');
900 } elsif (-e "/etc/init.d/apache-ssl") {
901 system('/etc/init.d/apache-ssl restart');
905 Congratulations ... your Koha installation is complete!
906 You will need to restart your webserver before using Koha!