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";
13 **********************************
14 * Welcome to the Koha Installer *
15 **********************************
16 Welcome to the Koha install script! This script will prompt you for some
17 basic information about your desired setup, then install Koha according to
18 your specifications. To accept the default value for any question, simply hit
21 Please be sure to read the documentation, or visit the Koha website at
22 http://www.koha.org for more information.
24 Are you ready to begin the installation? (Y/[N]):
30 if ($answer eq "Y" || $answer eq "y") {
31 print "Great! continuing setup... \n";
34 This installer currently does not support an completely automated
37 Please be sure to read the documentation, or visit the Koha website
38 at http://www.koha.org for more information.
46 # Test for Perl and Modules
55 print "\nChecking perl modules ...\n";
56 unless (eval "require 5.004") {
57 die "Sorry, you need at least Perl 5.004\n";
61 unless (eval {require DBI}) { push @missing,"DBI" };
62 unless (eval {require Date::Manip}) { push @missing,"Date::Manip" };
63 unless (eval {require DBD::mysql}) { push @missing,"DBD::mysql" };
64 unless (eval {require Set::Scalar}) { push @missing,"Set::Scalar" };
67 # Print out a list of any missing modules
71 print "You are missing some Perl modules which are required by Koha.\n";
72 print "Once these modules have been installed, rerun this installer.\n";
73 print "They can be installed by running (as root) the following:\n";
74 foreach my $module (@missing) {
75 print " perl -MCPAN -e 'install \"$module\"'\n";
78 print "All modules appear to be installed, continuing...\n";
84 my $domainname = `hostname -d`;
86 my $opacdir = '/usr/local/koha/opac';
87 my $kohadir = '/usr/local/koha/intranet';
90 # Loop until opac directory and koha directory are different
95 Please supply the directory you want Koha to store its OPAC files in. Leave off
96 the trailing slash. This directory will be auto-created for you if it doesn't
102 print "Enter directory [$opacdir]: ";
103 chomp($input = <STDIN>);
112 INTRANET/LIBRARIANS DIRECTORY
113 =============================
114 Please supply the directory you want Koha to store its Intranet/Librarians files
115 in. Leave off the trailing slash. This directory will be auto-created for you if
120 print "Enter directory [$kohadir]: ";
121 chomp($input = <STDIN>);
126 if ($kohadir eq $opacdir) {
129 You must specify different directories for the OPAC and INTRANET files!
142 my $hostname = 'localhost';
143 my $user = 'kohaadmin';
150 Koha uses a small configuration file that is usually placed in your /etc/ files
151 directory. The configuration file, will be created in this directory
155 #Get the path to the koha.conf directory
156 print "Enter the path to your configuration directory [$etcdir]: ";
157 chomp($input = <STDIN>);
164 #Get the database name
167 Please provide the name of the mysql database for your koha installation.
168 This is normally "$dbname".
172 print "Enter database name [$dbname]: ";
173 chomp($input = <STDIN>);
180 #Get the hostname for the database
183 Please provide the hostname for mysql. Unless the database is located on another
184 machine this will be "localhost".
187 print "Enter hostname [$hostname]: ";
188 chomp($input = <STDIN>);
194 #Get the username for the database
197 Please provide the name of the user, who will have full administrative rights
198 to the $dbname database, when authenticating from $hostname.
200 If no user is entered it will default to $user.
203 print "Enter username [$user]:";
204 chomp($input = <STDIN>);
210 #Get the password for the database user
213 Please provide a good password for the user $user.
216 print "Enter password:";
217 chomp($input = <STDIN>);
226 #Create the configuration file
227 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
228 at $etcdir. Must have write capability.\n";
234 includes=$kohadir/htdocs/includes
239 print "Successfully created the Koha configuration file.\n";
244 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
245 /usr/local/etc/apache/httpd.conf
246 /usr/local/etc/apache/apache.conf
247 /var/www/conf/httpd.conf
248 /etc/apache/conf/httpd.conf
249 /etc/apache/conf/apache.conf
250 /etc/httpd/conf/httpd.conf
251 /etc/httpd/httpd.conf)) {
252 if ( -f $httpdconf ) {
253 $realhttpdconf=$httpdconf;
254 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
255 while (<HTTPDCONF>) {
256 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
263 $httpduser ||= 'Undetermined';
266 # Set ownership of the koha.conf file for security
268 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
269 chmod 0440, "$etcdir/koha.conf";
274 my $svr_admin = "webmaster\@$domainname";
275 my $opac_svr_name = "opac.$domainname";
276 my $koha_svr_name = "koha.$domainname";
280 OPAC and KOHA/LIBRARIAN CONFIGURATION
281 =====================================
282 Koha needs to setup your Apache configuration file for the
285 Please enter the e-mail address for your webserver admin.
289 print "Enter e-mail address [$svr_admin]:";
290 chomp($input = <STDIN>);
299 Please enter the servername for your OPAC interface.
300 Usually $opac_svr_name
302 print "Enter servername address [$opac_svr_name]:";
303 chomp($input = <STDIN>);
306 $opac_svr_name = $input;
311 Please enter the servername for your Intranet/Librarian interface.
312 Usually $koha_svr_name
314 print "Enter servername address [$koha_svr_name]:";
315 chomp($input = <STDIN>);
318 $koha_svr_name = $input;
323 # Update Apache Conf File.
327 my $logfiledir=`grep ^ErrorLog $realhttpdconf`;
331 $logfiledir=~m#ErrorLog (.*)/[^/]*$#;
335 unless ($logfiledir) {
344 if (`grep 'VirtualHost $opac_svr_name' $realhttpdconf`) {
345 warn "$realhttpdconf appears to already have an entry for Koha\nVirtual Hosts.\n";
346 print "Press <ENTER> to continue...";
350 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
353 <VirtualHost $opac_svr_name>
354 ServerAdmin $svr_admin
355 DocumentRoot $opacdir/htdocs
356 ServerName $opac_svr_name
357 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
358 ErrorLog $logfiledir/opac-error_log
359 TransferLog $logfiledir/opac-access_log
360 SetEnv PERL5LIB "$kohadir/modules"
363 <VirtualHost $koha_svr_name>
364 ServerAdmin $svr_admin
365 DocumentRoot $kohadir/htdocs
366 ServerName $koha_svr_name
367 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
368 ErrorLog $logfiledir/koha-error_log
369 TransferLog $logfiledir/koha-access_log
370 SetEnv PERL5LIB "$kohadir/modules"
376 print "Successfully updated Apache Configuration file.\n";
380 # Setup the modules directory
384 CREATING REQUIRED DIRECTORIES
385 =============================
390 unless ( -d $kohadir ) {
391 print "Creating $kohadir...\n";
392 my $result=mkdir ($kohadir, oct(770));
394 my @dirs = split(m#/#, $kohadir);
398 unless (-e "$checkdir") {
399 mkdir($checkdir, 0775);
403 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
404 chmod (oct(770), "$kohadir");
406 unless ( -d "$kohadir/htdocs" ) {
407 print "Creating $kohadir/htdocs...\n";
408 mkdir ("$kohadir/htdocs", oct(750));
410 unless ( -d "$kohadir/cgi-bin" ) {
411 print "Creating $kohadir/cgi-bin...\n";
412 mkdir ("$kohadir/cgi-bin", oct(750));
414 unless ( -d "$kohadir/modules" ) {
415 print "Creating $kohadir/modules...\n";
416 mkdir ("$kohadir/modules", oct(750));
418 unless ( -d $opacdir ) {
419 print "Creating $opacdir...\n";
420 my $result=mkdir ($opacdir, oct(770));
422 my @dirs = split(m#/#, $opacdir);
426 unless (-e "$checkdir") {
427 mkdir($checkdir, 0775);
431 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
432 chmod (oct(770), "$opacdir");
434 unless ( -d "$opacdir/htdocs" ) {
435 print "Creating $opacdir/htdocs...\n";
436 mkdir ("$opacdir/htdocs", oct(750));
438 unless ( -d "$opacdir/cgi-bin" ) {
439 print "Creating $opacdir/cgi-bin...\n";
440 mkdir ("$opacdir/cgi-bin", oct(750));
445 print "\n\nINSTALLING KOHA...\n";
446 print "\n\n==================\n";
447 print "Copying internet-html files to $kohadir/htdocs...\n";
448 system("cp -R intranet-html/* $kohadir/htdocs/");
449 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
450 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
451 print "Copying script files to $kohadir/modules...\n";
452 system("cp -R modules/* $kohadir/modules/");
453 print "Copying opac-html files to $opacdir/htdocs...\n";
454 system("cp -R opac-html/* $opacdir/htdocs/");
455 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
456 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
458 system("chown -R root.$httpduser $opacdir");
459 system("chown -R root.$httpduser $kohadir");
468 my $mysqluser = 'root';
471 foreach my $mysql (qw(/usr/local/mysql
482 To allow us to create the koha database please supply the
483 mysql\'s root users password
486 print "Enter mysql\'s root users password: ";
487 chomp($input = <STDIN>);
499 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
501 print "\nCouldn't connect to the MySQL server for the reason given above.\n";
502 print "This is a serious problem, the database will not get installed.
\a\n";
503 print "Press <ENTER> to continue...";
507 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
508 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
509 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')\"");
510 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
512 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
517 print "\n\nWould you like to add a branch and printer? [Y]/N: ";
518 chomp($input = <STDIN>);
521 unless ($input =~/^n/i) {
522 my $branch='Main Library';
523 print "Enter a name for the library branch [$branch]: ";
524 chomp($input = <STDIN>);
528 $branch=~s/[^A-Za-z0-9\s]//g;
529 my $branchcode=$branch;
530 $branchcode=~s/[^A-Za-z0-9]//g;
531 $branchcode=uc($branchcode);
532 $branchcode=substr($branchcode,0,4);
533 print "Enter a four letter code for your branch [$branchcode]: ";
534 chomp($input = <STDIN>);
538 $branchcode=~s/[^A-Z]//g;
539 $branchcode=uc($branchcode);
540 $branchcode=substr($branchcode,0,4);
541 print "Adding branch '$branch' with code '$branchcode'.\n";
542 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass Koha -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
543 my $printername='Library Printer';
544 print "Enter a name for the printer [$printername]: ";
545 chomp($input = <STDIN>);
549 $printername=~s/[^A-Za-z0-9\s]//g;
550 my $printerqueue='lp';
551 print "Enter the queue for the printer [$printerqueue]: ";
552 chomp($input = <STDIN>);
554 $printerqueue=$input;
556 $printerqueue=~s/[^A-Za-z0-9]//g;
557 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass Koha -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
570 Congratulations ... your Koha installation is almost complete!
571 The final step is to restart your webserver.
573 Be sure to read the INSTALL, and Hints files.
575 For more information visit http://www.koha.org
577 Would you like to restart your webserver now? (Y/[N]):
580 my $restart = <STDIN>;
583 if ($answer eq "Y" || $answer eq "y") {
584 # Need to support other init structures here?
585 if (-e "/etc/rc.d/init.d/httpd") {
586 system('/etc/rc.d/init.d/httpd restart');
587 } elsif (-e "/etc/init.d/apache") {
588 system('/etc//init.d/apache restart');
589 } elsif (-e "/etc/init.d/apache-ssl") {
590 system('/etc/init.d/apache-ssl restart');
594 print "\nCongratulations ... your Koha installation is complete!\n";
595 print "\nYou will need to restart your webserver before using Koha!\n";