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 $::kohaversion=`cat koha.version`;
24 if ($::kohaversion =~ /RC/) {
25 releasecandidatewarning();
28 if (-e "/etc/koha.conf") {
29 $::installedversion=`grep kohaversion= /etc/koha.conf`;
30 chomp $::installedversion;
31 $::installedversion=~m/kohaversion=(.*)/;
32 $::installedversion=$1;
33 my $installedversionmsg;
34 if ($::installedversion) {
35 $installedversionmsg=getmessage('KohaVersionInstalled', [$::installedversion]);
37 $installedversionmsg=getmessage('KohaUnknownVersionInstalled');
40 my $message=getmessage('KohaAlreadyInstalled', [$::kohaversion, $installedversionmsg]);
41 showmessage($message, 'none');
45 my $continuingmsg=getmessage('continuing');
47 my $message=getmessage('WelcomeToKohaInstaller');
48 my $answer=showmessage($message, 'yn');
50 if ($answer eq "Y" || $answer eq "y") {
54 This installer currently does not support a completely automated
57 Please be sure to read the documentation, or visit the Koha website
58 at http://www.koha.org for more information.
64 $::domainname = `hostname -d`;
68 # Check for missing Perl Modules
73 # Ask for installation directories
75 my ($opacdir, $intranetdir) = getinstallationdirectories();
85 $::hostname = 'localhost';
86 $::user = 'kohaadmin';
97 print "user: $::httpduser\n";
98 print "conf: $::realhttpdconf\n";
101 getapachevhostinfo();
104 # Update Apache Conf File.
108 my $logfiledir=`grep ^ErrorLog $$::realhttpdconf`;
112 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
116 unless ($logfiledir) {
127 print "Checking for modules that need to be loaded...\n";
130 my $includesmodule=0;
131 open HC, $$::realhttpdconf;
133 if (/^\s*#\s*LoadModule env_module /) {
135 print " Loading env_module in httpd.conf\n";
138 if (/^\s*#\s*LoadModule includes_module /) {
140 print " Loading includes_module in httpd.conf\n";
142 if (/\s*LoadModule includes_module / ) {
148 my $apachebackupmade=0;
149 if ($envmodule || $includesmodule) {
150 system("mv -f $$::realhttpdconf $$::realhttpdconf\.prekoha");
152 open HC, ">$$::realhttpdconf";
159 #if (`grep 'VirtualHost $servername' $$::realhttpdconf`) {
161 #$$::realhttpdconf appears to already have an entry for Koha
162 #Virtual Hosts. You may need to edit $$::realhttpdconf
163 #if anything has changed since it was last set up. This
164 #script will not attempt to modify an existing Koha apache
168 print "Press <ENTER> to continue...";
172 unless ($apachebackupmade) {
173 system("cp -f $$::realhttpdconf $$::realhttpdconf\.prekoha");
175 my $includesdirectives='';
176 if ($includesmodule) {
177 $includesdirectives.="Options +Includes\n";
178 $includesdirectives.=" AddHandler server-parsed .html\n";
180 open(SITE,">>$$::realhttpdconf") or warn "Insufficient priveleges to open $$::realhttpdconf for writing.\n";
184 ## Ports to listen to for Koha
188 ## NameVirtualHost is used by one of the optional configurations detailed below
190 ##NameVirtualHost 11.22.33.44
192 ## KOHA's OPAC Configuration
193 #<VirtualHost $servername\:$opacport>
194 # ServerAdmin $svr_admin
195 # DocumentRoot $opacdir/htdocs
196 # ServerName $servername
197 # ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
198 # ErrorLog $logfiledir/opac-error_log
199 # TransferLog $logfiledir/opac-access_log
200 # SetEnv PERL5LIB "$intranetdir/modules"
201 # $includesdirectives
204 ## KOHA's INTRANET Configuration
205 #<VirtualHost $servername\:$kohaport>
206 # ServerAdmin $svr_admin
207 # DocumentRoot $intranetdir/htdocs
208 # ServerName $servername
209 # ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
210 # ErrorLog $logfiledir/koha-error_log
211 # TransferLog $logfiledir/koha-access_log
212 # SetEnv PERL5LIB "$intranetdir/modules"
213 # $includesdirectives
216 ## If you want to use name based Virtual Hosting:
217 ## 1. remove the two Listen lines
218 ## 2. replace $servername\:$opacport wih your.opac.domain.name
219 ## 3. replace ServerName $servername wih ServerName your.opac.domain.name
220 ## 4. replace $servername\:$kohaport wih your intranet domain name
221 ## 5. replace ServerName $servername wih ServerName your.intranet.domain.name
223 ## If you want to use NameVirtualHost'ing (using two names on one ip address):
224 ## 1. Follow steps 1-5 above
225 ## 2. Uncomment the NameVirtualHost line and set the correct ip address
233 Intranet Authentication
234 =======================
236 I can set it up so that the Intranet/Librarian site is password protected.
238 print "Would you like to do this? ([Y]/N): ";
239 chomp($input = <STDIN>);
241 my $apacheauthusername='librarian';
242 my $apacheauthpassword='';
243 unless ($input=~/^n/i) {
244 print "\nEnter a userid to login with [$apacheauthusername]: ";
245 chomp ($input = <STDIN>);
247 $apacheauthusername=$input;
248 $apacheauthusername=~s/[^a-zA-Z0-9]//g;
250 while (! $apacheauthpassword) {
251 print "\nEnter a password for the $apacheauthusername user: ";
252 chomp ($input = <STDIN>);
254 $apacheauthpassword=$input;
256 if (!$apacheauthpassword) {
257 print "\nPlease enter a password.\n";
260 open AUTH, ">/etc/kohaintranet.pass";
261 my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
262 my $salt=substr($chars, int(rand(length($chars))),1);
263 $salt.=substr($chars, int(rand(length($chars))),1);
264 print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
268 <Directory $intranetdir>
269 AuthUserFile /etc/kohaintranet.pass
271 AuthName "Koha Intranet (for librarians only)"
279 print "Successfully updated Apache Configuration file.\n";
284 SETTING UP Z39.50 DAEMON
285 ========================
288 my $kohalogdir='/var/log/koha';
289 print "Directory for logging by Z39.50 daemon [$kohalogdir]: ";
290 chomp($input = <STDIN>);
295 unless (-e "$kohalogdir") {
296 my $result = mkdir 0770, "$kohalogdir";
298 my @dirs = split(m#/#, $kohalogdir);
302 unless (-e "$checkdir") {
303 mkdir($checkdir, 0775);
310 # Setup the modules directory
314 CREATING REQUIRED DIRECTORIES
315 =============================
320 unless ( -d $intranetdir ) {
321 print "Creating $intranetdir...\n";
322 my $result=mkdir ($intranetdir, oct(770));
324 my @dirs = split(m#/#, $intranetdir);
328 unless (-e "$checkdir") {
329 mkdir($checkdir, 0775);
333 chown (oct(0), (getgrnam($::httpduser))[2], "$intranetdir");
334 chmod (oct(770), "$intranetdir");
336 unless ( -d "$intranetdir/htdocs" ) {
337 print "Creating $intranetdir/htdocs...\n";
338 mkdir ("$intranetdir/htdocs", oct(750));
340 unless ( -d "$intranetdir/cgi-bin" ) {
341 print "Creating $intranetdir/cgi-bin...\n";
342 mkdir ("$intranetdir/cgi-bin", oct(750));
344 unless ( -d "$intranetdir/modules" ) {
345 print "Creating $intranetdir/modules...\n";
346 mkdir ("$intranetdir/modules", oct(750));
348 unless ( -d "$intranetdir/scripts" ) {
349 print "Creating $intranetdir/scripts...\n";
350 mkdir ("$intranetdir/scripts", oct(750));
352 unless ( -d $opacdir ) {
353 print "Creating $opacdir...\n";
354 my $result=mkdir ($opacdir, oct(770));
356 my @dirs = split(m#/#, $opacdir);
360 unless (-e "$checkdir") {
361 mkdir($checkdir, 0775);
365 chown (oct(0), (getgrnam($::httpduser))[2], "$opacdir");
366 chmod (oct(770), "$opacdir");
368 unless ( -d "$opacdir/htdocs" ) {
369 print "Creating $opacdir/htdocs...\n";
370 mkdir ("$opacdir/htdocs", oct(750));
372 unless ( -d "$opacdir/cgi-bin" ) {
373 print "Creating $opacdir/cgi-bin...\n";
374 mkdir ("$opacdir/cgi-bin", oct(750));
379 print "\n\nINSTALLING KOHA...\n";
380 print "\n\n==================\n";
381 print "Copying internet-html files to $intranetdir/htdocs...\n";
382 system("cp -R intranet-html/* $intranetdir/htdocs/");
383 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
384 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
385 print "Copying script files to $intranetdir/scripts...\n";
386 system("cp -R scripts/* $intranetdir/scripts/");
387 print "Copying module files to $intranetdir/modules...\n";
388 system("cp -R modules/* $intranetdir/modules/");
389 print "Copying opac-html files to $opacdir/htdocs...\n";
390 system("cp -R opac-html/* $opacdir/htdocs/");
391 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
392 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
394 system("chown -R root.$::httpduser $opacdir");
395 system("chown -R root.$::httpduser $intranetdir");
402 Koha uses a small configuration file that is placed in your /etc/ files
403 directory. The configuration file, will be created in this directory.
407 #Create the configuration file
408 open(SITES,">$::etcdir/koha.conf") or warn "Couldn't create file
409 at $::etcdir. Must have write capability.\n";
415 includes=$intranetdir/htdocs/includes
416 intranetdir=$intranetdir
418 kohalogdir=$kohalogdir
419 kohaversion=$::kohaversion
420 httpduser=$::httpduser
426 # Set ownership of the koha.conf file for security
428 chown((getpwnam($::httpduser)) [2,3], "$::etcdir/koha.conf") or warn "can't chown koha.conf: $!";
429 chmod 0440, "$::etcdir/koha.conf";
432 print "Successfully created the Koha configuration file.\n";
441 my $mysqluser = 'root';
444 foreach my $mysql (qw(/usr/local/mysql
455 To allow us to create the koha database please supply the
456 mysql\'s root users password
460 while ($needpassword) {
461 print "Enter mysql\'s root users password: ";
462 chomp($input = <STDIN>);
464 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass proc > /dev/null 2>&1");
466 print "\n\nInvalid password for the MySql root user.\n\n";
478 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $::dbname");
480 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
481 print "This is a serious problem, the database will not get installed.
\a\n";
482 print "Press <ENTER> to continue...";
486 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname < koha.mysql");
487 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$::hostname','$::user',password('$::pass'))\"\;");
488 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')\"");
489 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
491 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
498 If you are installing Koha for evaluation purposes, I have a batch of sample
499 data that you can install now.
501 If you are installing Koha with the intention of populating it with your own
502 data, you probably don't want this sample data installed.
504 print "\nWould you like to install the sample data? Y/[N]: ";
505 chomp($input = <STDIN>);
506 if ($input =~/^y/i) {
507 system("gunzip sampledata-1.2.gz");
508 system("cat sampledata-1.2 | $mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname");
509 system("gzip -9 sampledata-1.2");
510 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
511 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
514 Sample data has been installed. For some suggestions on testing Koha, please
515 read the file doc/HOWTO-Testing. If you find any bugs, please submit them at
516 http://bugs.koha.org/. If you need help with testing Koha, you can post a
517 question through the koha-devel mailing list, or you can check for a developer
518 online at +irc.katipo.co.nz:6667 channel #koha.
520 You can find instructions for subscribing to the Koha mailing lists at:
525 Press <ENTER> to continue...
529 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
530 chomp($input = <STDIN>);
533 unless ($input =~/^n/i) {
534 my $branch='Main Library';
535 print "Enter a name for the library branch [$branch]: ";
536 chomp($input = <STDIN>);
540 $branch=~s/[^A-Za-z0-9\s]//g;
541 my $branchcode=$branch;
542 $branchcode=~s/[^A-Za-z0-9]//g;
543 $branchcode=uc($branchcode);
544 $branchcode=substr($branchcode,0,4);
545 print "Enter a four letter code for your branch [$branchcode]: ";
546 chomp($input = <STDIN>);
550 $branchcode=~s/[^A-Z]//g;
551 $branchcode=uc($branchcode);
552 $branchcode=substr($branchcode,0,4);
553 print "Adding branch '$branch' with code '$branchcode'.\n";
554 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
555 my $printername='Library Printer';
556 print "Enter a name for the printer [$printername]: ";
557 chomp($input = <STDIN>);
561 $printername=~s/[^A-Za-z0-9\s]//g;
562 my $printerqueue='lp';
563 print "Enter the queue for the printer [$printerqueue]: ";
564 chomp($input = <STDIN>);
566 $printerqueue=$input;
568 $printerqueue=~s/[^A-Za-z0-9]//g;
569 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $::dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
577 chmod 0770, $kohalogdir;
578 chown((getpwnam($::httpduser)) [2,3], $kohalogdir) or warn "can't chown $kohalogdir: $!";
581 print "Modifying Z39.50 daemon launch script...\n";
583 open (L, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh");
586 $newfile.="RunAsUser=$::httpduser\n";
587 } elsif (/^KohaZ3950Dir=/) {
588 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
594 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh $intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh.orig");
595 open L, ">$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
601 print "Modifying Z39.50 daemon wrapper script...\n";
603 open (S, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh");
605 if (/^KohaModuleDir=/) {
606 $newfile.="KohaModuleDir=$intranetdir/modules\n";
607 } elsif (/^KohaZ3950Dir=/) {
608 $newfile.="KohaZ3950Dir=$intranetdir/scripts/z3950daemon\n";
609 } elsif (/^LogDir=/) {
610 $newfile.="LogDir=$kohalogdir\n";
617 system("mv $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh.orig");
618 open S, ">$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
621 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh";
622 chmod 0750, "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh";
623 chmod 0750, "$intranetdir/scripts/z3950daemon/processz3950queue";
624 chown(0, (getpwnam($::httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
625 chown(0, (getpwnam($::httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
633 This release of Koha has a new authentication module. If you are not already
634 using basic authentication on your intranet, you will be required to log in to
635 access some of the features of the intranet. You can log in using the userid
636 and password from the /etc/koha.conf configuration file at any time. Use the
637 "Members" module to add passwords for other accounts and set their permissions.
639 [NOTE PERMISSIONS ARE NOT COMPLETED AS OF 1.2.3RC1. Do not give passwords to
640 any patrons unless you want them to have full access to your intranet.]
642 print "Press the <ENTER> key to continue: ";
652 #Congratulations ... your Koha installation is almost complete!
653 #The final step is to restart your webserver.
655 #You will be able to connect to your Librarian interface at:
657 # http://$servername\:$kohaport/
659 #and the OPAC interface at :
661 # http://$servername\:$opacport/
664 #Be sure to read the INSTALL, and Hints files.
666 #For more information visit http://www.koha.org
668 #Would you like to restart your webserver now? (Y/[N]):
671 my $restart = <STDIN>;
674 if ($restart=~/^y/i) {
675 # Need to support other init structures here?
676 if (-e "/etc/rc.d/init.d/httpd") {
677 system('/etc/rc.d/init.d/httpd restart');
678 } elsif (-e "/etc/init.d/apache") {
679 system('/etc//init.d/apache restart');
680 } elsif (-e "/etc/init.d/apache-ssl") {
681 system('/etc/init.d/apache-ssl restart');
685 Congratulations ... your Koha installation is complete!
686 You will need to restart your webserver before using Koha!