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 full administrative rights to the
186 $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 =============================
365 # Still need to check that all parent directories of $kohadir and $opacdir
369 unless ( -d $kohadir ) {
370 print "Creating $kohadir...\n";
371 my $result=mkdir ($kohadir, oct(770));
373 my @dirs = split(m#/#, $kohadir);
377 unless (-e "$checkdir") {
378 mkdir($checkdir, 0775);
382 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
383 chmod (oct(770), "$kohadir");
385 unless ( -d "$kohadir/htdocs" ) {
386 print "Creating $kohadir/htdocs...\n";
387 mkdir ("$kohadir/htdocs", oct(750));
389 unless ( -d "$kohadir/cgi-bin" ) {
390 print "Creating $kohadir/cgi-bin...\n";
391 mkdir ("$kohadir/cgi-bin", oct(750));
393 unless ( -d "$kohadir/modules" ) {
394 print "Creating $kohadir/modules...\n";
395 mkdir ("$kohadir/modules", oct(750));
397 unless ( -d $opacdir ) {
398 print "Creating $opacdir...\n";
399 my $result=mkdir ($opacdir, oct(770));
401 my @dirs = split(m#/#, $opacdir);
405 unless (-e "$checkdir") {
406 mkdir($checkdir, 0775);
410 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
411 chmod (oct(770), "$opacdir");
413 unless ( -d "$opacdir/htdocs" ) {
414 print "Creating $opacdir/htdocs...\n";
415 mkdir ("$opacdir/htdocs", oct(750));
417 unless ( -d "$opacdir/cgi-bin" ) {
418 print "Creating $opacdir/cgi-bin...\n";
419 mkdir ("$opacdir/cgi-bin", oct(750));
424 print "\n\nINSTALLING KOHA...\n";
425 print "\n\n==================\n";
426 print "Copying internet-html files to $kohadir/htdocs...\n";
427 system("cp -R intranet-html/* $kohadir/htdocs/");
428 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
429 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
430 print "Copying script files to $kohadir/modules...\n";
431 system("cp -R modules/* $kohadir/modules/");
432 print "Copying opac-html files to $opacdir/htdocs...\n";
433 system("cp -R opac-html/* $opacdir/htdocs/");
434 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
435 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
437 system("chown -R root.$httpduser $opacdir");
438 system("chown -R root.$httpduser $kohadir");
447 my $mysqluser = 'root';
450 foreach my $mysql (qw(/usr/local/mysql
460 To allow us to create the koha database please supply the
461 mysql\'s root users password
464 print "Enter mysql\'s root users password: ";
465 chomp($input = <STDIN>);
477 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
478 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
479 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
480 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv) values ('%','$dbname','$user','Y','Y','Y','Y');");
481 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
483 system ("perl -I $kohadir/modules scripts/updater/updatedatabase");
492 Congratulations ... your Koha installation is almost complete!
493 The final step is to restart your webserver.
495 Be sure to read the INSTALL, and Hints files.
497 For more information visit http://www.koha.org
499 Would you like to restart your webserver now? (Y/[N]):
502 my $restart = <STDIN>;
505 if ($answer eq "Y" || $answer eq "y") {
506 # Need to support other init structures here?
507 if (-e "/etc/rc.d/init.d/httpd") {
508 system('/etc/rc.d/init.d/httpd restart');
509 } elsif (-e "/etc/init.d/apache") {
510 system('/etc//init.d/apache restart');
511 } elsif (-e "/etc/init.d/apache-ssl") {
512 system('/etc/init.d/apache-ssl restart');
516 print "\nCongratulations ... your Koha installation is complete!\n";
517 print "\nYou will need to restart your webserver before using Koha!\n";