1 #!/usr/bin/perl -w # please develop with -w
6 use strict; # please develop with the strict pragma
12 print "\n\nYou must run koha.upgrade as root.\n\n";
16 print "You must be root to run this script.\n";
20 my $kohaversion=`cat koha.version`;
24 if ($kohaversion =~ /RC/) {
25 releasecandidatewarning($language, $kohaversion);
28 if (-e "/etc/koha.conf") {
29 my $installedversion=`grep kohaversion= /etc/koha.conf`;
30 chomp $installedversion;
31 $installedversion=~m/kohaversion=(.*)/;
33 if ($installedversion) {
34 $installedversion=getmessage('KohaVersionInstalled', $language, [$installedversion]);
36 $installedversion=getmessage('KohaUnknownVersionInstalled', $language);
39 my $message=getmessage('KohaAlreadyInstalled', $language, [$kohaversion, $installedversion]);
40 showmessage($message, 'none');
44 my $continuingmsg=getmessage('continuing', $language);
46 my $message=getmessage('WelcomeToKohaInstaller', $language);
47 my $answer=showmessage($message, 'yn');
49 if ($answer eq "Y" || $answer eq "y") {
53 This installer currently does not support a completely automated
56 Please be sure to read the documentation, or visit the Koha website
57 at http://www.koha.org for more information.
63 my $domainname = `hostname -d`;
67 # Check for missing Perl Modules
69 checkperlmodules($language);
72 # Ask for installation directories
74 my ($opacdir, $intranetdir) = getinstallationdirectories($language);
84 my $hostname = 'localhost';
85 my $user = 'kohaadmin';
89 ($dbname, $hostname,$user, $pass) = getdatabaseinfo($language,$dbname,$hostname,$user,$pass);
105 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
106 /usr/local/etc/apache/httpd.conf
107 /usr/local/etc/apache/apache.conf
108 /var/www/conf/httpd.conf
109 /etc/apache/conf/httpd.conf
110 /etc/apache/conf/apache.conf
111 /etc/apache-ssl/conf/apache.conf
112 /etc/httpd/conf/httpd.conf
113 /etc/httpd/httpd.conf)) {
114 if ( -f $httpdconf ) {
115 $realhttpdconf=$httpdconf;
116 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
117 while (<HTTPDCONF>) {
118 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
125 unless ($realhttpdconf) {
128 I was not able to find your apache configuration file. It is usually
129 called httpd.conf or apache.conf.
131 print "Where is your Apache configuratin file? ";
132 chomp($input = <STDIN>);
135 $realhttpdconf = $input;
139 if ( -f $realhttpdconf ) {
140 open (HTTPDCONF, $realhttpdconf) or warn "Insufficient privileges to open $realhttpdconf for reading.\n";
141 while (<HTTPDCONF>) {
142 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
150 unless ($httpduser) {
153 I was not able to determine the user that Apache is running as. This
154 information is necessary in order to set the access privileges correctly on
155 /etc/koha.conf. This user should be set in one of the Apache configuration
156 files using the "User" directive.
158 print "What is your Apache user? ";
159 chomp($input = <STDIN>);
164 $httpduser='Undetermined';
172 my $svr_admin = "webmaster\@$domainname";
173 my $servername=`hostname -f`;
180 OPAC and KOHA/LIBRARIAN CONFIGURATION
181 =====================================
182 Koha needs to setup your Apache configuration file for the
183 OPAC and LIBRARIAN virtual hosts. By default this installer
184 will do this by using one ip address and two different ports
185 for the virtual hosts. There are other ways to set this up,
186 and the installer will leave comments in httpd.conf detailing
187 what these other options are.
189 Please enter the e-mail address for your webserver admin.
193 print "Enter e-mail address [$svr_admin]:";
194 chomp($input = <STDIN>);
204 Please enter the domain name or ip address of your computer.
206 print "Enter server name/ip address [$servername]:";
207 chomp($input = <STDIN>);
210 $servername = $input;
215 Please enter the port for your OPAC interface.
217 print "Enter OPAC port [$opacport]:";
218 chomp($input = <STDIN>);
226 Please enter the port for your Intranet/Librarian interface.
228 print "Enter intranet port [$kohaport]:";
229 chomp($input = <STDIN>);
237 # Update Apache Conf File.
241 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
245 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
249 unless ($logfiledir) {
260 print "Checking for modules that need to be loaded...\n";
263 my $includesmodule=0;
264 open HC, $realhttpdconf;
266 if (/^\s*#\s*LoadModule env_module /) {
268 print " Loading env_module in httpd.conf\n";
271 if (/^\s*#\s*LoadModule includes_module /) {
273 print " Loading includes_module in httpd.conf\n";
275 if (/\s*LoadModule includes_module / ) {
281 my $apachebackupmade=0;
282 if ($envmodule || $includesmodule) {
283 system("mv -f $realhttpdconf $realhttpdconf\.prekoha");
285 open HC, ">$realhttpdconf";
291 if (`grep 'VirtualHost $servername' $realhttpdconf`) {
293 $realhttpdconf appears to already have an entry for Koha
294 Virtual Hosts. You may need to edit $realhttpdconf
295 if anything has changed since it was last set up. This
296 script will not attempt to modify an existing Koha apache
300 print "Press <ENTER> to continue...";
304 unless ($apachebackupmade) {
305 system("cp -f $realhttpdconf $realhttpdconf\.prekoha");
307 my $includesdirectives='';
308 if ($includesmodule) {
309 $includesdirectives.="Options +Includes\n";
310 $includesdirectives.=" AddHandler server-parsed .html\n";
312 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
316 # Ports to listen to for Koha
320 # NameVirtualHost is used by one of the optional configurations detailed below
322 #NameVirtualHost 11.22.33.44
324 # KOHA's OPAC Configuration
325 <VirtualHost $servername\:$opacport>
326 ServerAdmin $svr_admin
327 DocumentRoot $opacdir/htdocs
328 ServerName $servername
329 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
330 ErrorLog $logfiledir/opac-error_log
331 TransferLog $logfiledir/opac-access_log
332 SetEnv PERL5LIB "$intranetdir/modules"
336 # KOHA's INTRANET Configuration
337 <VirtualHost $servername\:$kohaport>
338 ServerAdmin $svr_admin
339 DocumentRoot $intranetdir/htdocs
340 ServerName $servername
341 ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
342 ErrorLog $logfiledir/koha-error_log
343 TransferLog $logfiledir/koha-access_log
344 SetEnv PERL5LIB "$intranetdir/modules"
348 # If you want to use name based Virtual Hosting:
349 # 1. remove the two Listen lines
350 # 2. replace $servername\:$opacport wih your.opac.domain.name
351 # 3. replace ServerName $servername wih ServerName your.opac.domain.name
352 # 4. replace $servername\:$kohaport wih your intranet domain name
353 # 5. replace ServerName $servername wih ServerName your.intranet.domain.name
355 # If you want to use NameVirtualHost'ing (using two names on one ip address):
356 # 1. Follow steps 1-5 above
357 # 2. Uncomment the NameVirtualHost line and set the correct ip address
365 Intranet Authentication
366 =======================
368 I can set it up so that the Intranet/Librarian site is password protected.
370 print "Would you like to do this? ([Y]/N): ";
371 chomp($input = <STDIN>);
373 my $apacheauthusername='librarian';
374 my $apacheauthpassword='';
375 unless ($input=~/^n/i) {
376 print "\nEnter a userid to login with [$apacheauthusername]: ";
377 chomp ($input = <STDIN>);
379 $apacheauthusername=$input;
380 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
382 while (! $apacheauthpassword) {
383 print "\nEnter a password for the $apacheauthusername user: ";
384 chomp ($input = <STDIN>);
386 $apacheauthpassword=$input;
388 if (!$apacheauthpassword) {
389 print "\nPlease enter a password.\n";
392 open AUTH, ">/etc/kohaintranet.pass";
393 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
394 my $salt=substr($chars, int(rand(length($chars))),1);
395 $salt.=substr($chars, int(rand(length($chars))),1);
396 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
400 <Directory $intranetdir>
401 AuthUserFile /etc/kohaintranet.pass
403 AuthName "Koha Intranet (for librarians only)"
411 print "Successfully updated Apache Configuration file.\n";
416 SETTING UP Z39.50 DAEMON
417 ========================
420 my $kohalogdir='/var/log/koha';
421 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
422 chomp($input = <STDIN>);
427 unless (-e "$kohalogdir") {
428 my $result = mkdir 0770, "$kohalogdir";
430 my @dirs = split(m#/#, $kohalogdir);
434 unless (-e "$checkdir") {
435 mkdir($checkdir, 0775);
442 # Setup the modules directory
446 CREATING REQUIRED DIRECTORIES
447 =============================
452 unless ( -d $intranetdir ) {
453 print "Creating $intranetdir...\n";
454 my $result=mkdir ($intranetdir, oct(770));
456 my @dirs = split(m#/#, $intranetdir);
460 unless (-e "$checkdir") {
461 mkdir($checkdir, 0775);
465 chown (oct(0), (getgrnam($httpduser))[2], "$intranetdir");
466 chmod (oct(770), "$intranetdir");
468 unless ( -d "$intranetdir/htdocs" ) {
469 print "Creating $intranetdir/htdocs...\n";
470 mkdir ("$intranetdir/htdocs", oct(750));
472 unless ( -d "$intranetdir/cgi-bin" ) {
473 print "Creating $intranetdir/cgi-bin...\n";
474 mkdir ("$intranetdir/cgi-bin", oct(750));
476 unless ( -d "$intranetdir/modules" ) {
477 print "Creating $intranetdir/modules...\n";
478 mkdir ("$intranetdir/modules", oct(750));
480 unless ( -d "$intranetdir/scripts" ) {
481 print "Creating $intranetdir/scripts...\n";
482 mkdir ("$intranetdir/scripts", oct(750));
484 unless ( -d $opacdir ) {
485 print "Creating $opacdir...\n";
486 my $result=mkdir ($opacdir, oct(770));
488 my @dirs = split(m#/#, $opacdir);
492 unless (-e "$checkdir") {
493 mkdir($checkdir, 0775);
497 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
498 chmod (oct(770), "$opacdir");
500 unless ( -d "$opacdir/htdocs" ) {
501 print "Creating $opacdir/htdocs...\n";
502 mkdir ("$opacdir/htdocs", oct(750));
504 unless ( -d "$opacdir/cgi-bin" ) {
505 print "Creating $opacdir/cgi-bin...\n";
506 mkdir ("$opacdir/cgi-bin", oct(750));
511 print "\n\nINSTALLING KOHA...\n";
512 print "\n\n==================\n";
513 print "Copying internet-html files to $intranetdir/htdocs...\n";
514 system("cp -R intranet-html/* $intranetdir/htdocs/");
515 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
516 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
517 print "Copying script files to $intranetdir/scripts...\n";
518 system("cp -R scripts/* $intranetdir/scripts/");
519 print "Copying module files to $intranetdir/modules...\n";
520 system("cp -R modules/* $intranetdir/modules/");
521 print "Copying opac-html files to $opacdir/htdocs...\n";
522 system("cp -R opac-html/* $opacdir/htdocs/");
523 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
524 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
526 system("chown -R root.$httpduser $opacdir");
527 system("chown -R root.$httpduser $intranetdir");
534 Koha uses a small configuration file that is placed in your /etc/ files
535 directory. The configuration file, will be created in this directory.
539 #Create the configuration file
540 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
541 at $etcdir. Must have write capability.\n";
547 includes=$intranetdir/htdocs/includes
548 intranetdir=$intranetdir
550 kohalogdir=$kohalogdir
551 kohaversion=$kohaversion
558 # Set ownership of the koha.conf file for security
560 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
561 chmod 0440, "$etcdir/koha.conf";
564 print "Successfully created the Koha configuration file.\n";
573 my $mysqluser = 'root';
576 foreach my $mysql (qw(/usr/local/mysql
587 To allow us to create the koha database please supply the
588 mysql\'s root users password
592 while ($needpassword) {
593 print "Enter mysql\'s root users password: ";
594 chomp($input = <STDIN>);
596 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass proc > /dev/null 2>&1");
598 print "\n\nInvalid password for the MySql root user.\n\n";
610 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
612 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
613 print "This is a serious problem, the database will not get installed.
\a\n";
614 print "Press <ENTER> to continue...";
618 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
619 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
620 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')\"");
621 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
623 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
630 If you are installing Koha for evaluation purposes, I have a batch of sample
631 data that you can install now.
633 If you are installing Koha with the intention of populating it with your own
634 data, you probably don't want this sample data installed.
636 print "\nWould you like to install the sample data? Y/[N]: ";
637 chomp($input = <STDIN>);
638 if ($input =~/^y/i) {
639 system("gunzip sampledata-1.2.gz");
640 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname");
641 system("gzip -9 sampledata-1.2");
642 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
643 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
646 Sample data has been installed. For some suggestions on testing Koha, please
647 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
648 http://bugs.koha.org/. If you need help with testing Koha, you can post a
649 question through the koha-devel mailing list, or you can check for a developer
650 online at +irc.katipo.co.nz:6667 channel #koha.
652 You can find instructions for subscribing to the Koha mailing lists at:
657 Press <ENTER> to continue...
661 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
662 chomp($input = <STDIN>);
665 unless ($input =~/^n/i) {
666 my $branch='Main Library';
667 print "Enter a name for the library branch [$branch]: ";
668 chomp($input = <STDIN>);
672 $branch=~s/[^A-Za-z0-9\s]//g;
673 my $branchcode=$branch;
674 $branchcode=~s/[^A-Za-z0-9]//g;
675 $branchcode=uc($branchcode);
676 $branchcode=substr($branchcode,0,4);
677 print "Enter a four letter code for your branch [$branchcode]: ";
678 chomp($input = <STDIN>);
682 $branchcode=~s/[^A-Z]//g;
683 $branchcode=uc($branchcode);
684 $branchcode=substr($branchcode,0,4);
685 print "Adding branch '$branch' with code '$branchcode'.\n";
686 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
687 my $printername='Library Printer';
688 print "Enter a name for the printer [$printername]: ";
689 chomp($input = <STDIN>);
693 $printername=~s/[^A-Za-z0-9\s]//g;
694 my $printerqueue='lp';
695 print "Enter the queue for the printer [$printerqueue]: ";
696 chomp($input = <STDIN>);
698 $printerqueue=$input;
700 $printerqueue=~s/[^A-Za-z0-9]//g;
701 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
709 chmod 0770, $kohalogdir;
710 chown((getpwnam($httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
713 print "Modifying Z39.50 daemon launch script...\n";
715 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
718 $newfile.="RunAsUser=$httpduser\n";
719 } elsif (/^KohaZ3950Dir=/) {
720 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
726 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
727 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
733 print "Modifying Z39.50 daemon wrapper script...\n";
735 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
737 if (/^KohaModuleDir=/) {
738 $newfile.="KohaModuleDir=$intranetdir/modules\n";
739 } elsif (/^KohaZ3950Dir=/) {
740 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
741 } elsif (/^LogDir=/) {
742 $newfile.="LogDir=$kohalogdir\n";
749 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
750 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
753 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
754 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
755 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
756 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
757 chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
765 This release of Koha has a new authentication module. If you are not already
766 using basic authentication on your intranet, you will be required to log in to
767 access some of the features of the intranet. You can log in using the userid
768 and password from the /etc/koha.conf configuration file at any time. Use the
769 "Members" module to add passwords for other accounts and set their permissions.
771 [NOTE PERMISSIONS ARE NOT COMPLETED AS OF 1.2.3RC1. Do not give passwords to
772 any patrons unless you want them to have full access to your intranet.]
774 print "Press the <ENTER> key to continue: ";
784 Congratulations ... your Koha installation is almost complete!
785 The final step is to restart your webserver.
787 You will be able to connect to your Librarian interface at:
789 http://$servername\:$kohaport/
791 and the OPAC interface at :
793 http://$servername\:$opacport/
796 Be sure to read the INSTALL, and Hints files.
798 For more information visit http://www.koha.org
800 Would you like to restart your webserver now? (Y/[N]):
803 my $restart = <STDIN>;
806 if ($restart=~/^y/i) {
807 # Need to support other init structures here?
808 if (-e "/etc/rc.d/init.d/httpd") {
809 system('/etc/rc.d/init.d/httpd restart');
810 } elsif (-e "/etc/init.d/apache") {
811 system('/etc//init.d/apache restart');
812 } elsif (-e "/etc/init.d/apache-ssl") {
813 system('/etc/init.d/apache-ssl restart');
817 Congratulations ... your Koha installation is complete!
818 You will need to restart your webserver before using Koha!