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/www/opac';
87 my $kohadir = '/usr/local/www/koha';
92 Please supply the directory you want Koha to store its OPAC files in. Leave off
93 the trailing slash. This directory will be auto-created for you if it doesn't
99 print "Enter directory [$opacdir]: ";
100 chomp($input = <STDIN>);
109 INTRANET/LIBRARIANS DIRECTORY
110 =============================
111 Please supply the directory you want Koha to store its Intranet/Librarians files
112 in. Leave off the trailing slash. This directory will be auto-created for you if
118 print "Enter directory [$kohadir]: ";
119 chomp($input = <STDIN>);
130 my $hostname = 'localhost';
131 my $user = 'kohaadmin';
138 Koha uses a small configuration file that is usually placed in your /etc/ files
139 directory. The configuration file, will be created in this directory
143 #Get the path to the koha.conf directory
144 print "Enter the path to your configuration directory [$etcdir]: ";
145 chomp($input = <STDIN>);
152 #Get the database name
155 Please provide the name of the mysql database for your koha installation.
156 This is normally "$dbname".
160 print "Enter database name [$dbname]: ";
161 chomp($input = <STDIN>);
168 #Get the hostname for the database
171 Please provide the hostname for mysql. Unless the database is located on another
172 machine this will be "localhost".
175 print "Enter hostname [$hostname]: ";
176 chomp($input = <STDIN>);
182 #Get the username for the database
185 Please provide the name of the user, who will have full administrative rights
186 to the $dbname database, when authenticating from $hostname.
188 If no user is entered it will default to $user.
191 print "Enter username [$user]:";
192 chomp($input = <STDIN>);
198 #Get the password for the database user
201 Please provide a good password for the user $user.
204 print "Enter password:";
205 chomp($input = <STDIN>);
214 #Create the configuration file
215 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
216 at $etcdir. Must have write capability.\n";
222 includes=$kohadir/htdocs/includes
227 print "Successfully created the Koha configuration file.\n";
232 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
233 /usr/local/etc/apache/httpd.conf
234 /usr/local/etc/apache/apache.conf
235 /var/www/conf/httpd.conf
236 /etc/apache/conf/httpd.conf
237 /etc/apache/conf/apache.conf
238 /etc/httpd/conf/httpd.conf
239 /etc/httpd/httpd.conf)) {
240 if ( -f $httpdconf ) {
241 $realhttpdconf=$httpdconf;
242 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
243 while (<HTTPDCONF>) {
244 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
251 $httpduser ||= 'Undetermined';
254 # Set ownership of the koha.conf file for security
256 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
257 chmod 0440, "$etcdir/koha.conf";
262 my $svr_admin = "webmaster\@$domainname";
263 my $opac_svr_name = "opac.$domainname";
264 my $koha_svr_name = "koha.$domainname";
268 OPAC and KOHA/LIBRARIAN CONFIGURATION
269 =====================================
270 Koha needs to setup your Apache configuration file for the
273 Please enter the e-mail address for your webserver admin.
277 print "Enter e-mail address [$svr_admin]:";
278 chomp($input = <STDIN>);
287 Please enter the servername for your OPAC interface.
288 Usually $opac_svr_name
290 print "Enter servername address [$opac_svr_name]:";
291 chomp($input = <STDIN>);
294 $opac_svr_name = $input;
299 Please enter the servername for your Intranet/Librarian interface.
300 Usually $koha_svr_name
302 print "Enter servername address [$koha_svr_name]:";
303 chomp($input = <STDIN>);
306 $koha_svr_name = $input;
311 # Update Apache Conf File.
319 if (`grep 'VirtualHost $opac_svr_name' $realhttpdconf`) {
320 warn "$realhttpdconf appears to already have an entry for Koha\nVirtual Hosts.\n";
321 print "Press <ENTER> to continue...";
325 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
328 <VirtualHost $opac_svr_name>
329 ServerAdmin $svr_admin
330 DocumentRoot $opacdir/htdocs
331 ServerName $opac_svr_name
332 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
333 ErrorLog logs/opac-error_log
334 TransferLog logs/opac-access_log common
335 SetEnv PERL5LIB "$kohadir/modules"
338 <VirtualHost $koha_svr_name>
339 ServerAdmin $svr_admin
340 DocumentRoot $kohadir/htdocs
341 ServerName $koha_svr_name
342 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin/"
343 ErrorLog logs/koha-error_log
344 TransferLog logs/koha-access_log common
345 SetEnv PERL5LIB "$kohadir/modules"
351 print "Successfully updated Apache Configuration file.\n";
356 # Setup the modules directory
360 CREATING REQUIRED DIRECTORIES
361 =============================
366 unless ( -d $kohadir ) {
367 print "Creating $kohadir...\n";
368 my $result=mkdir ($kohadir, oct(770));
370 my @dirs = split(m#/#, $kohadir);
374 unless (-e "$checkdir") {
375 mkdir($checkdir, 0775);
379 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
380 chmod (oct(770), "$kohadir");
382 unless ( -d "$kohadir/htdocs" ) {
383 print "Creating $kohadir/htdocs...\n";
384 mkdir ("$kohadir/htdocs", oct(750));
386 unless ( -d "$kohadir/cgi-bin" ) {
387 print "Creating $kohadir/cgi-bin...\n";
388 mkdir ("$kohadir/cgi-bin", oct(750));
390 unless ( -d "$kohadir/modules" ) {
391 print "Creating $kohadir/modules...\n";
392 mkdir ("$kohadir/modules", oct(750));
394 unless ( -d $opacdir ) {
395 print "Creating $opacdir...\n";
396 my $result=mkdir ($opacdir, oct(770));
398 my @dirs = split(m#/#, $opacdir);
402 unless (-e "$checkdir") {
403 mkdir($checkdir, 0775);
407 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
408 chmod (oct(770), "$opacdir");
410 unless ( -d "$opacdir/htdocs" ) {
411 print "Creating $opacdir/htdocs...\n";
412 mkdir ("$opacdir/htdocs", oct(750));
414 unless ( -d "$opacdir/cgi-bin" ) {
415 print "Creating $opacdir/cgi-bin...\n";
416 mkdir ("$opacdir/cgi-bin", oct(750));
421 print "\n\nINSTALLING KOHA...\n";
422 print "\n\n==================\n";
423 print "Copying internet-html files to $kohadir/htdocs...\n";
424 system("cp -R intranet-html/* $kohadir/htdocs/");
425 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
426 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
427 print "Copying script files to $kohadir/modules...\n";
428 system("cp -R modules/* $kohadir/modules/");
429 print "Copying opac-html files to $opacdir/htdocs...\n";
430 system("cp -R opac-html/* $opacdir/htdocs/");
431 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
432 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
434 system("chown -R root.$httpduser $opacdir");
435 system("chown -R root.$httpduser $kohadir");
444 my $mysqluser = 'root';
447 foreach my $mysql (qw(/usr/local/mysql
458 To allow us to create the koha database please supply the
459 mysql\'s root users password
462 print "Enter mysql\'s root users password: ";
463 chomp($input = <STDIN>);
475 my $result=system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
477 print "\nCouldn't connect to the MySQL server for the reason given above.";
478 print "Press <ENTER> to continue...";
482 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
483 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
484 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) values ('%','$dbname','$user','Y','Y','Y','Y','Y','Y');");
485 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
487 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
497 Congratulations ... your Koha installation is almost complete!
498 The final step is to restart your webserver.
500 Be sure to read the INSTALL, and Hints files.
502 For more information visit http://www.koha.org
504 Would you like to restart your webserver now? (Y/[N]):
507 my $restart = <STDIN>;
510 if ($answer eq "Y" || $answer eq "y") {
511 # Need to support other init structures here?
512 if (-e "/etc/rc.d/init.d/httpd") {
513 system('/etc/rc.d/init.d/httpd restart');
514 } elsif (-e "/etc/init.d/apache") {
515 system('/etc//init.d/apache restart');
516 } elsif (-e "/etc/init.d/apache-ssl") {
517 system('/etc/init.d/apache-ssl restart');
521 print "\nCongratulations ... your Koha installation is complete!\n";
522 print "\nYou will need to restart your webserver before using Koha!\n";