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';
85 my $opacdir = '/usr/local/www/opac';
86 my $kohadir = '/usr/local/www/koha';
91 Please supply the directory you want Koha to store its OPAC files in. Leave off
92 the trailing slash. This directory will be auto-created for you if it doesn't
98 print "Enter directory: ";
99 chomp($input = <STDIN>);
108 INTRANET/LIBRARIANS DIRECTORY
109 =============================
110 Please supply the directory you want Koha to store its Intranet/Librarians files
111 in. Leave off the trailing slash. This directory will be auto-created for you if
117 print "Enter directory: ";
118 chomp($input = <STDIN>);
129 my $hostname = 'localhost';
130 my $user = 'kohaadmin';
137 Koha uses a small configuration file that is usually placed in your /etc/ files
138 directory. The configuration file, will be created in this directory
142 #Get the path to the koha.conf directory
143 print "Enter the path to your [$etcdir]: ";
144 chomp($input = <STDIN>);
151 #Get the database name
154 Please provide the name of the mysql database for your koha installation.
155 This is normally "$dbname".
159 print "Enter database name:";
160 chomp($input = <STDIN>);
167 #Get the hostname for the database
170 Please provide the hostname for mysql. Unless the database is located on another
171 machine this will be "localhost".
174 print "Enter hostname:";
175 chomp($input = <STDIN>);
181 #Get the username for the database
184 Please provide the name of the user, who will full administrative rights to the
185 $dbname database, when authenticating from $hostname.
187 If no user is entered it will default to $user.
190 print "Enter username:";
191 chomp($input = <STDIN>);
197 #Get the password for the database user
200 Please provide a good password for the user $user.
203 print "Enter password:";
204 chomp($input = <STDIN>);
213 #Create the configuration file
214 open(SITES,">$etcdir/koha.conf") or warn "Couldn't create file
215 at $etcdir. Must have write capability.\n";
221 includes=$kohadir/htdocs/includes
226 print "Successfully created the Koha configuration file.\n";
231 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
232 /usr/local/etc/apache/httpd.conf
233 /usr/local/etc/apache/apache.conf
234 /var/www/conf/httpd.conf
235 /etc/apache/conf/httpd.conf
236 /etc/apache/conf/apache.conf
237 /etc/httpd/conf/httpd.conf
238 /etc/httpd/httpd.conf)) {
239 if ( -f $httpdconf ) {
240 $realhttpdconf=$httpdconf;
241 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
242 while (<HTTPDCONF>) {
243 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
250 $httpduser ||= 'Undetermined';
253 # Set ownership of the koha.conf file for security
255 chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf") or warn "can't chown koha.conf: $!";
260 my $svr_admin = 'webmaster@$domainname';
261 my $opac_svr_name = 'opac.$domainname';
262 my $koha_svr_name = 'koha.$domainname';
266 OPAC and KOHA/LIBRARIAN CONFIGURATION
267 =====================================
268 Koha needs to setup your Apache configuration file for the
271 Please enter the e-mail address for your webserver admin.
275 print "Enter e-mail address:";
276 chomp($input = <STDIN>);
285 Please enter the servername for your OPAC interface.
286 Usually $opac_svr_name
288 print "Enter servername address:";
289 chomp($input = <STDIN>);
292 $opac_svr_name = $input;
297 Please enter the servername for your Intranet/Librarian interface.
298 Usually $koha_svr_name
300 print "Enter servername address:";
301 chomp($input = <STDIN>);
304 $koha_svr_name = $input;
309 # Update Apache Conf File.
317 open(SITE,">>$realhttpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
320 <VirtualHost $opac_svr_name>
321 ServerAdmin $svr_admin
322 DocumentRoot $opacdir/htdocs
323 ServerName $opac_svr_name
324 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
325 ErrorLog logs/opac-error_log
326 TransferLog logs/opac-access_log common
327 SetEnv PERL5LIB "$kohadir/modules"
330 <VirtualHost $koha_svr_name>
331 ServerAdmin $svr_admin
332 DocumentRoot $kohadir/htdocs
333 ServerName $koha_svr_name
334 ScriptAlias /cgi-bin/koha/ "$kohadir/cgi-bin"
335 ErrorLog logs/koha-error_log
336 TransferLog logs/koha-access_log common
337 SetEnv PERL5LIB "$kohadir/modules"
343 print "Successfully updated Apache Configuration file.\n";
347 # Setup the modules directory
351 CREATING REQUIRED DIRECTORIES
352 =============================
356 unless ( -d $kohadir ) {
357 print "Creating $kohadir...\n";
358 mkdir ($kohadir, oct(770));
359 chown (oct(0), (getgrnam($httpduser))[2], "$kohadir");
360 chmod (oct(770), "$kohadir");
362 unless ( -d "$kohadir/htdocs" ) {
363 print "Creating $kohadir/htdocs...\n";
364 mkdir ("$kohadir/htdocs", oct(750));
366 unless ( -d "$kohadir/cgi-bin" ) {
367 print "Creating $kohadir/cgi-bin...\n";
368 mkdir ("$kohadir/cgi-bin", oct(750));
370 unless ( -d "$kohadir/modules" ) {
371 print "Creating $kohadir/modules...\n";
372 mkdir ("$kohadir/modules", oct(750));
374 unless ( -d $opacdir ) {
375 print "Creating $opacdir...\n";
376 mkdir ($opacdir, oct(770));
377 chown (oct(0), (getgrnam($httpduser))[2], "$opacdir");
378 chmod (oct(770), "$opacdir");
380 unless ( -d "$opacdir/htdocs" ) {
381 print "Creating $opacdir/htdocs...\n";
382 mkdir ("$opacdir/htdocs", oct(750));
384 unless ( -d "$opacdir/cgi-bin" ) {
385 print "Creating $opacdir/cgi-bin...\n";
386 mkdir ("$opacdir/cgi-bin", oct(750));
391 print "\n\nINSTALLING KOHA...\n";
392 print "\n\n==================\n";
393 print "Copying internet-html files to $kohadir/htdocs...\n";
394 system("cp -R intranet-html/* $kohadir/htdocs/");
395 print "Copying intranet-cgi files to $kohadir/cgi-bin...\n";
396 system("cp -R intranet-cgi/* $kohadir/cgi-bin/");
397 print "Copying script files to $kohadir/modules...\n";
398 system("cp -R modules/* $kohadir/modules/");
399 print "Copying opac-html files to $opacdir/htdocs...\n";
400 system("cp -R opac-html/* $opacdir/htdocs/");
401 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
402 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
411 my $mysqluser = 'root';
414 foreach my $mysql (qw(/usr/local/mysql
424 To allow us to create the koha database please supply the
425 mysql\'s root users password
428 print "Enter mysql\'s root users password: ";
429 chomp($input = <STDIN>);
441 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass create $dbname");
442 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass $dbname < koha.mysql");
443 system("$mysqldir/bin/mysql -u$mysqluser -p$mysqlpass mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
444 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');");
445 system("$mysqldir/bin/mysqladmin -u$mysqluser -p$mysqlpass reload");
447 system ("perl scripts/updater/updatedatabase -I $kohadir/modules");
455 Congratulations ... your Koha installation is almost complete!
456 The final step is to restart your webserver.
458 Be sure to read the INSTALL, and Hints files.
460 For more information visit http://www.koha.org
462 Would you like to restart your webserver now? (Y/[N]):
465 my $restart = <STDIN>;
468 if ($answer eq "Y" || $answer eq "y") {
469 system('/etc/rc.d/init.d/httpd restart');
472 print "\nCongratulations ... your Koha installation is complete!\n";
473 print "\nYou will need to restart your webserver before using Koha!\n";