Updated Changelog, and INSTALL should now reflect the new directory
[koha.git] / installer.pl
1 #!/usr/bin/perl -w # please develop with -w
2
3 use diagnostics;
4 use strict; # please develop with the strict pragma
5
6 system('clear');
7 print qq|
8 **********************************
9 * Welcome to the Koha Installer  *
10 **********************************
11
12 This installer will prompt you with a series of questions.
13 It assumes you (or your system administrator) has installed:
14   * Apache (http://httpd.apache.org/)
15   * Perl (http://www.perl.org)
16
17 and one of the following database applications:
18   * MySql (http://www.mysql.org)
19
20 on some type of Unix or Unix-like operating system
21
22
23 Are Apache, Perl, and a database from the list above installed 
24 on this system? (Y/[N]):
25 |;
26
27 my $answer = <STDIN>;
28 chomp $answer;
29
30 if ($answer eq "Y" || $answer eq "y") {
31         print "Great! continuing setup... \n";
32     } else {
33     print qq|
34 This installer currently does not support an completely automated 
35 setup.
36
37 Please be sure to read the documentation, or visit the Koha website 
38 at http://www.koha.org for more information.
39 |;
40     exit;
41 };
42
43 print "\n";
44
45
46 #
47 # Test for Perl - Do we need to explicity check versions?
48 #
49 print "\nChecking perl modules ...\n";
50     unless (eval "require 5.004") {
51     die "Sorry, you need at least Perl 5.004\n";
52 }
53
54 #
55 # Test for Perl Dependancies
56 #
57 my @missing = ();
58 unless (eval require DBI)               { push @missing,"DBI" };
59 unless (eval require Date::Manip)       { push @missing,"Date::Manip" };
60 unless (eval require DBD::mysql)        { push @missing,"DBD::mysql" };
61 unless (eval require Set::Scalar)       { push @missing,"Set::Scalar" };
62
63 #
64 # Print out a list of any missing modules
65 #
66 if (@missing > 0) {
67     print "\n\n";
68     print "You are missing some Perl modules which are required by Koha.\n";
69     print "Once these modules have been installed, rerun this installery.\n";
70     print "They can be installed by running (as root) the following:\n";
71     foreach my $module (@missing) {
72         print "   perl -MCPAN -e 'install \"$module\"'\n";
73         exit(1);
74     }} else{
75     print "All modules appear to be installed, continuing...\n";
76 };
77
78
79 print "\n";
80 print "Testing for mysql - still to be done\n";
81 #test for MySQL?
82 #print "Are you using MySql?(Y/[N]): ";
83 #$answer = $_;                      
84 #chomp $answer
85 #if ($answer eq "Y" || $answer eq "y") {
86     # FIXME
87     # there is no $password or $KohaDBNAME yet
88 #    system("mysqladmin -uroot -p$password create $KohaDBNAME ");
89 #    system("mysql -u$root -p$password ");
90     #need to get to mysql prompt  HOW DO I DO THIS?
91     
92     # FIXME 
93     # you could pipe this into mysql in the shell that system generates
94     # can this be done from dbi?
95 #    system("grant all privileges on Koha.* to koha@localhost identified by 'kohapassword'; ");
96 #} else {
97 #    print qq|
98 #You will need to use the MySQL database system for your application.
99 #The installer currently does not support an automated setup with this database.
100 #|;
101 #  };
102
103 print "\n";
104 #
105 # FIXME
106 # there is no updatedatabase program yet
107 #
108 #system ("perl updatedatabase -I /pathtoC4 ");
109
110 #
111 #KOHA conf
112 #
113 print qq|
114 Koha uses a small configuration file that is usually placed in your
115 /etc/ files directory (although you can technically place
116 it anywhere you wish).
117
118 Please enter the full path to your configuration files
119 directory (the default Koha conf file is "koha.conf").
120 The path is usually something like /etc/ by default.  The
121 configuration file, will be created here.
122 |;
123
124 #Get the path to the koha.conf directory
125 my $conf_path;
126 my $dbname;
127 my $hostname;
128 my $user;
129 my $pass;
130 my $inc_path;
131 do {
132         print "Enter path:";
133         chomp($conf_path = <STDIN>);
134         print "$conf_path is not a directory.\n" if !-d $conf_path;
135 } until -d $conf_path;
136
137
138 print "\n";
139 print "\n";
140 print qq|
141 Please provide the name of the mysql database for koha. 
142 This is normally "Koha".
143 |;
144
145 #Get the database name
146 do {
147         print "Enter database name:";
148         chomp($dbname = <STDIN>);
149 };
150
151
152 print "\n";
153 print "\n";
154 print qq|
155 Please provide the hostname for mysql.  Unless the database is located 
156 on another machine this is likely to be "localhost".
157 |;
158
159 #Get the hostname for the database
160 do {
161         print "Enter hostname:";
162         chomp($hostname = <STDIN>);
163 };
164
165
166 print "\n";
167 print "\n";
168 print qq|
169 Please provide the name of the user, who has full administrative 
170 rights to the $dbname database, when authenicating from $hostname.
171 |;
172
173 #Get the username for the database
174 do {
175         print "Enter username:";
176         chomp($user = <STDIN>);
177 };
178
179
180 print "\n";
181 print "\n";
182 print qq|
183 Please provide the password for the user $user.
184 |;
185
186 #Get the password for the database user
187 do {
188         print "Enter password:";
189         chomp($pass = <STDIN>);
190 };
191
192
193 print "\n";
194 print "\n";
195 print qq|
196 Please provide the full path to your Koha OPAC installation.
197 Usually /usr/local/www/koha/htdocs
198 |;
199
200 #Get the password for the database user
201 do {
202         print "Enter installation path:";
203         chomp($inc_path = <STDIN>);
204 };
205
206
207 #Create the configuration file
208 open(SITES,">$conf_path/koha.conf") or die "Couldn't create file
209 at $conf_path.  Must have write capability.\n";
210 print SITES <<EOP
211 database=$dbname
212 hostname=$hostname
213 user=$user
214 password=$pass
215 includes=$inc_path/includes
216 EOP
217 ;
218 close(SITES);
219
220 print "Successfully created the Koha configuration file.\n";
221
222 print "\n";
223 print "\n";
224 my $apache_owner;
225 print qq|
226 The permissions on the koha.conf file should also be strict, 
227 since they contain the database password.
228 Please supply the username that your apache webserver runs under. 
229 |;
230 do {
231         print "Enter apache user:";
232         chomp($apache_owner = <STDIN>);
233 };
234
235
236 #
237 # Set ownership of the koha.conf file for security
238 # FIXME - this will only work if run as work.
239 #
240
241 chown((getpwnam($apache_owner)) [2,3], "$conf_path/koha.conf") or die "can't chown koha.conf: $!";
242
243 print "\n";
244 print "\n";
245
246 #
247 #SETUP opac
248 #
249 my $apache_conf_path;
250 my $svr_admin;
251 my $docu_root;
252 my $svr_name;
253
254 print qq|
255 Koha needs to setup your Apache configuration file for the
256 OPAC virtual host.
257
258 Please enter the filename and path to your Apache Configuration file 
259 usually located in \"/usr/local/apache/conf/httpd.conf\".
260 |;
261 do {
262         print "Enter path:";
263         chomp($apache_conf_path = <STDIN>);
264         print "$conf_path is not a valid file.\n" if !-f $apache_conf_path;
265 } until -f $apache_conf_path;
266
267
268 print qq|
269 Please enter the servername for your OPAC.
270 Usually opac.your.domain
271 |;
272 do {
273         print "Enter servername address:";
274         chomp($svr_name = <STDIN>);
275 };
276
277
278 print qq|
279 Please enter the e-mail address for your webserver admin.
280 Usually webmaster\@your.domain
281 |;
282 do {
283         print "Enter e-mail address:";
284         chomp($svr_admin = <STDIN>);
285 };
286
287
288 print qq|
289 Please enter the full path to your OPAC\'s document root.
290 usually something like \"/usr/local/www/opac/htdocs\".
291 |;
292 do {
293         print "Enter Document Roots Path:";
294         chomp($docu_root = <STDIN>);
295 };
296
297
298 #
299 # Update Apache Conf File.
300 #
301 open(SITES,">>$apache_conf_path") or die "Couldn't write to file 
302 $conf_path.  Must have write capability.\n";
303 print SITES <<EOP
304
305 <VirtualHost $svr_name>
306     ServerAdmin $svr_admin
307     DocumentRoot $docu_root
308     ServerName $svr_name
309     ErrorLog logs/opac-error_log
310     TransferLog logs/opac-access_log common
311 </VirtualHost>
312
313 EOP
314 ;
315 close(SITES);
316
317 print "Successfully updated Apache Configuration file.\n";
318
319
320
321 ###RESTART APACHE
322 # FIXME
323 # this is a pretty rude thing to do on a system ...
324 # perhaps asking the user first would be better.
325 #
326 #system('/etc/rc.d/init.d/httpd restart');
327
328 #
329 # It is completed
330 #
331 print "\nCongratulations ... your Koha installation is complete!\n";
332 print "\nYou will need to restart your webserver before using Koha!\n";