comparison DVN-web/installer/dvninstall/install~ @ 6:1b2188262ae9

adding the installer.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Wed, 13 May 2015 11:50:21 +0200
parents
children
comparison
equal deleted inserted replaced
5:dd9adfc73390 6:1b2188262ae9
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Socket;
5 use File::Copy;
6
7 my( %opts ) = ( );
8 my( $rez ) = GetOptions( \%opts, "pg_only!");
9
10 my $postgresonly = 0;
11
12 my @CONFIG_VARIABLES = ();
13
14 unless ($opts{pg_only})
15 {
16 @CONFIG_VARIABLES = (
17 'HOST_DNS_ADDRESS',
18 'GLASSFISH_DIRECTORY',
19 'MAIL_SERVER',
20
21 'POSTGRES_SERVER',
22 'POSTGRES_PORT',
23 'POSTGRES_DATABASE',
24 'POSTGRES_USER',
25 'POSTGRES_PASSWORD',
26
27 'RSERVE_HOST',
28 'RSERVE_PORT',
29 'RSERVE_USER',
30 'RSERVE_PASSWORD'
31
32 );
33 }
34 else
35 {
36 @CONFIG_VARIABLES = (
37 'POSTGRES_SERVER',
38 'POSTGRES_PORT',
39 'POSTGRES_DATABASE',
40 'POSTGRES_USER',
41 'POSTGRES_PASSWORD'
42 );
43
44 $postgresonly = 1;
45 }
46
47 my %CONFIG_DEFAULTS =
48 (
49 'HOST_DNS_ADDRESS', '',
50 'GLASSFISH_DIRECTORY', '/home/glassfish/glassfish',
51 'MAIL_SERVER', 'localhost',
52
53 'POSTGRES_SERVER', 'localhost',
54 'POSTGRES_PORT', 5432,
55 'POSTGRES_DATABASE','dvnDb',
56 'POSTGRES_USER', 'postgres',
57 'POSTGRES_PASSWORD','admin',
58
59 'RSERVE_HOST', 'localhost',
60 'RSERVE_PORT', 6311,
61 'RSERVE_USER', 'rserve',
62 'RSERVE_PASSWORD', 'rserve'
63
64 );
65
66
67 my %CONFIG_PROMPTS =
68 (
69 'HOST_DNS_ADDRESS', 'Internet Address of your host',
70 'GLASSFISH_DIRECTORY', 'Glassfish Directory',
71 'MAIL_SERVER', 'SMTP (mail) server to relay notification messages',
72
73 'POSTGRES_SERVER', 'Postgres Server',
74 'POSTGRES_PORT', 'Postgres Server Port',
75 'POSTGRES_DATABASE','Name of the Postgres Database',
76 'POSTGRES_USER', 'Name of the Postgres User',
77 'POSTGRES_PASSWORD','Postgres user password',
78
79 'RSERVE_HOST', 'Rserve Server',
80 'RSERVE_PORT', 'Rserve Server Port',
81 'RSERVE_USER', 'Rserve User Name',
82 'RSERVE_PASSWORD', 'Rserve User Password'
83
84 );
85
86 # Supported Posstgres JDBC drivers:
87 # (have to be configured explicitely, so that Perl "taint" (security) mode
88 # doesn't get paranoid)
89
90 my $POSTGRES_DRIVER_8_3 = "postgresql-8.3-603.jdbc4.jar";
91 #my $POSTGRES_DRIVER_8_4 = "postgresql-8.4-703.jdbc4.jar";
92 my $POSTGRES_DRIVER_8_4 = "postgresql-8.3-603.jdbc4.jar";
93 my $POSTGRES_DRIVER_9_0 = "postgresql-9.0-802.jdbc4.jar";
94 my $POSTGRES_DRIVER_9_1 = "postgresql-9.1-902.jdbc4.jar";
95
96
97 # A few preliminary checks:
98
99 # user -- must be root:
100
101 $user_real = `who am i`;
102 chop $user_real;
103 $user_real =~s/ .*$//;
104
105 if ( $< != 0 )
106 {
107 print STDERR "\nERROR: You must be logged in as root to run the installer.\n\n";
108 exit 1;
109 }
110
111 # OS:
112
113 my $uname_out = `uname -a`;
114
115 # hostname:
116
117 my $hostname_from_cmdline = `hostname`;
118 chop $hostname_from_cmdline;
119
120 $CONFIG_DEFAULTS{'HOST_DNS_ADDRESS'} = $hostname_from_cmdline;
121
122
123 print "\nWelcome to the DVN installer.\n";
124 unless ($opts{pg_only})
125 {
126 print "You will be guided through the process of setting up a NEW\n";
127 print "instance of the DVN application\n";
128 }
129 else
130 {
131 print "You will be guided through the process of configuring the\n";
132 print "LOCAL instance of PostgreSQL database for use by the DVN\n";
133 print "application.\n";
134 }
135
136 my @uname_tokens = split (" ", $uname_out);
137
138 if ( $uname_tokens[0] eq "Darwin" )
139 {
140 print "\nThis appears to be a MacOS X system; good.\n";
141 # TODO: check the OS version
142
143 $WORKING_OS = "MacOSX";
144 }
145 elsif ( $uname_tokens[0] eq "Linux" )
146 {
147 if ( -f "/etc/redhat-release" )
148 {
149 print "\nThis appears to be a RedHat system; good.\n";
150 $WORKING_OS = "RedHat";
151 # TODO: check the distro version
152 }
153 else
154 {
155 print "\nThis appears to be a non-RedHat Linux system;\n";
156 print "this installation *may* succeed; but we're not making any promises!\n";
157 $WORKING_OS = "Linux";
158 }
159 }
160 else
161 {
162 print "\nWARNING: This appears to be neither a Linux or MacOS X system!\n";
163 print "This installer script will most likely fail. Please refer to the\n";
164 print "DVN Installers Guide for more information.\n\n";
165
166 $WORKING_OS = "Unknown";
167
168 print "Do you wish to continue?\n [y/n] ";
169
170
171 my $yesnocont = <>; chop $yesnocont;
172
173 while ( $yesnocont ne "y" && $yesnocont ne "n" )
174 {
175 print "Please enter 'y' or 'n'!\n";
176 print "(or ctrl-C to exit the installer)\n";
177 $yesnocont = <>; chop $yesnocont;
178 }
179
180 if ( $yesnocont eq "n" )
181 {
182 exit 0;
183 }
184
185 }
186
187 ENTERCONFIG:
188
189 print "\n";
190 print "Please enter the following configuration values:\n";
191 print "(hit [RETURN] to accept the default value)\n";
192 print "\n";
193
194 for $ENTRY (@CONFIG_VARIABLES)
195 {
196 print $CONFIG_PROMPTS{$ENTRY} . ": ";
197 print "[" . $CONFIG_DEFAULTS{$ENTRY} . "] ";
198
199 $user_entry = <>;
200 chop $user_entry;
201
202 if ($user_entry ne "")
203 {
204 $CONFIG_DEFAULTS{$ENTRY} = $user_entry;
205 }
206
207 print "\n";
208 }
209
210 # CONFIRM VALUES ENTERED:
211
212
213 print "\nOK, please confirm what you've entered:\n\n";
214
215 for $ENTRY (@CONFIG_VARIABLES)
216 {
217 print $CONFIG_PROMPTS{$ENTRY} . ": " . $CONFIG_DEFAULTS{$ENTRY} . "\n";
218 }
219
220 print "\nIs this correct? [y/n] ";
221
222
223 my $yesno = <>; chop $yesno;
224
225 while ( $yesno ne "y" && $yesno ne "n" )
226 {
227 print "Please enter 'y' or 'n'!\n";
228 print "(or ctrl-C to exit the installer)\n";
229 $yesno = <>; chop $yesno;
230 }
231
232 if ( $yesno eq "n" )
233 {
234 goto ENTERCONFIG;
235 }
236
237 # VALIDATION/VERIFICATION OF THE CONFIGURATION VALUES:
238 # 1. VERIFY MAIL SERVER THEY CONFIGURED:
239
240 =pod
241
242 unless ( $postgresonly )
243 {
244
245 my ( $mail_server_iaddr, $mail_server__paddr, $mail_server_proto, $mail_server_status );
246
247 $mail_server_status = 1;
248
249 unless ( $mail_server_iaddr = inet_aton($CONFIG_DEFAULTS{'MAIL_SERVER'}) )
250 {
251 print STDERR "Could not look up $CONFIG_DEFAULTS{'MAIL_SERVER'},\n";
252 print STDERR "the host you specified as your mail server.\n";
253 $mail_server_status = 0;
254 }
255
256 if ($mail_server_status) {
257 $mail_server_paddr = sockaddr_in(25, $mail_server_iaddr);
258 $mail_server_proto = getprotobyname('tcp');
259
260 unless ( socket(SOCK, PF_INET, SOCK_STREAM, $mail_server_proto) &&
261 connect(SOCK, $mail_server_paddr) )
262 {
263 print STDERR "Could not establish connection to $CONFIG_DEFAULTS{'MAIL_SERVER'},\n";
264 print STDERR "the address you provided for your Mail server.\n";
265 print STDERR "Please select a valid mail server, and try again.\n\n";
266
267 $mail_server_status = 0;
268 }
269
270 }
271
272 close (SOCK);
273
274 unless ($mail_server_status)
275 {
276 goto ENTERCONFIG;
277 }
278 }
279 =cut
280
281 # 2. CHECK IF THE WAR FILE IS AVAILABLE:
282 unless ( -f "appdeploy/dist/DVN-web.war" )
283 {
284 print "\nWARNING: Can't find the project .war file in appdeploy/dist/!\n";
285 print "\tAre you running the installer in the right directory?\n";
286 print "\tHave you built the war file?\n";
287 print "\t(if not, build the project and run the installer again)\n";
288
289 exit 0;
290 }
291
292 # check the working (installer) dir:
293 my $cwd;
294 chomp($cwd = `pwd`);
295
296 # 2b. CHECK IF THE SQL TEMPLATE IS IN PLACE AND CREATE THE SQL FILE
297
298 $SQL_REFERENCE_DATA = "referenceData.sql";
299 $SQL_REFERENCE_TEMPLATE = "referenceData.sql.TEMPLATE";
300
301 unless ( -f $SQL_REFERENCE_TEMPLATE )
302 {
303 print "\nWARNING: Can't find .sql data template!\n";
304 print "(are you running the installer in the right directory?)\n";
305
306 exit 0;
307 }
308
309 open DATATEMPLATEIN, $SQL_REFERENCE_TEMPLATE || die $@;
310 open SQLDATAOUT, '>'.$SQL_REFERENCE_DATA || die $@;
311
312 while( <DATATEMPLATEIN> )
313 {
314 s/%POSTGRES_USER%/$CONFIG_DEFAULTS{'POSTGRES_USER'}/g;
315 print SQLDATAOUT $_;
316 }
317
318
319 close DATATEMPLATEIN;
320 close SQLDATAOUT;
321
322 # 3. CHECK POSTGRES AVAILABILITY:
323
324 my $pg_local_connection = 0;
325
326 if ( $CONFIG_DEFAULTS{'POSTGRES_SERVER'} eq 'localhost' )
327 {
328 $pg_local_connection = 1;
329
330 # 3a. CHECK FOR USER postgres:
331
332 print "\nChecking system user \"postgres\"... ";
333
334 $POSTGRES_SYS_NAME = "postgres";
335 $POSTGRES_SYS_UID = (getpwnam ("postgres"))[2];
336
337 if ($POSTGRES_SYS_UID == undef) {
338 print STDERR "\nERROR: I haven't been able to find user \"postgres\" on the system!\n";
339 print STDERR "(TODO: prompt the user instead to supply an alternative username, if\n";
340 print STDERR "available)\n";
341
342 exit 1;
343 }
344
345 print "OK.\n";
346
347 # 3b. LOCATE THE EXECUTABLE:
348
349 $sys_path = $ENV{'PATH'};
350 @sys_path_dirs = split ( ":", $sys_path );
351
352 $psql_exec = "";
353
354 for $sys_path_dir ( @sys_path_dirs )
355 {
356 if ( -x $sys_path_dir . "/psql" )
357 {
358 $psql_exec = $sys_path_dir;
359 last;
360 }
361 }
362
363 $pg_major_version = 0;
364 $pg_minor_version = 0;
365
366 if ( $psql_exec eq "" && $WORKING_OS eq "MacOSX" )
367 {
368 for $pg_minor_version ( "1", "0" )
369 {
370 if ( -x "/Library/PostgreSQL/9." . $pg_minor_version . "/bin/psql" )
371 {
372 $pg_major_version = 9;
373 $psql_exec = "/Library/PostgreSQL/9." . $pg_minor_version . "/bin";
374 last;
375 }
376 }
377 if (!$pg_major_version)
378 {
379 for $pg_minor_version ( "4", "3" )
380 {
381 if ( -x "/Library/PostgreSQL/8." . $pg_minor_version . "/bin/psql" )
382 {
383 $pg_major_version = 8;
384 $psql_exec = "/Library/PostgreSQL/8." . $pg_minor_version . "/bin";
385 last;
386 }
387 }
388 }
389 }
390
391 if ( $psql_exec eq "" )
392 {
393 print STDERR "\nERROR: I haven't been able to find the psql command in your PATH!\n";
394 print STDERR "Please make sure PostgresQL is properly installed and try again.\n\n";
395
396 exit 1;
397 }
398
399
400
401 # 3c. CHECK POSTGRES VERSION:
402
403 open (PSQLOUT, $psql_exec . "/psql --version|");
404
405 $psql_version_line = <PSQLOUT>;
406 chop $psql_version_line;
407 close PSQLOUT;
408
409 my ($postgresName, $postgresNameLong, $postgresVersion) = split ( " ", $psql_version_line );
410
411 unless ( $postgresName eq "psql" && $postgresVersion =~ /^[0-9][0-9\.]*$/ )
412 {
413 print STDERR "\nERROR: Unexpected output from psql command!\n";
414 print STDERR "Please make sure PostgresQL is properly installed and try again.\n\n";
415
416 exit 1;
417 }
418
419
420 my (@postgres_version_tokens) = split ( '\.', $postgresVersion );
421
422 unless ( ($postgres_version_tokens[0] == 8 && $postgres_version_tokens[1] >= 3) || ($postgres_version_tokens[0] >= 9) )
423 {
424 print STDERR "\nERROR: PostgresQL version 8.3, or newer, is required!\n";
425 print STDERR "Found a copy of psql ($psql_exec/psql) that belongs to version $postgresVersion.\n\n";
426 print STDERR "Please make sure the right version of PostgresQL is properly installed,\n";
427 print STDERR "and the right version of psql comes first in the PATH,\n";
428 print STDERR "then try again.\n";
429
430 exit 1;
431 }
432
433 print "\n\nFound Postgres psql command, version $postgresVersion. Good.\n\n";
434
435 $pg_major_version = $postgres_version_tokens[0];
436 $pg_minor_version = $postgres_version_tokens[1];
437
438 # 4. CONFIGURE POSTGRES:
439
440 print "\nConfiguring Postgres Database:\n";
441
442
443
444 $< = $POSTGRES_SYS_UID;
445 $> = $POSTGRES_SYS_UID;
446
447 # 4a. CHECK IF POSTGRES IS RUNNING:
448 print "Checking if a local instance of Postgres is running and accessible...\n";
449
450 # (change to /tmp before executing the command below -
451 # we are trying to do it as user postgres, and it may not have
452 # access to the current, installer directory; the command would still
453 # work, but there would be an error message from the shell init on screen
454 # - potentially confusing)
455 chdir ("/tmp");
456
457 if (!system ($psql_exec . "/psql -c 'SELECT * FROM pg_roles' > /dev/null 2>&1"))
458 {
459 print "Yes, it is.\n";
460 }
461 else
462 {
463 print "Nope, I haven't been able to connect to the local instance of PostgresQL.\n";
464 print "daemon. Is postgresql running? \n";
465 print "On a RedHat system, you can check the status of the daemon with\n\n";
466 print " service postgresql status\n\n";
467 print "and, if it's not running, start the daemon with\n\n";
468 print " service postgresql start\n\n";
469 print "On MacOSX, use Applications -> PostgresQL -> Start Server.\n";
470 print "Also, please make sure that the daemon is listening to network connections,\n";
471 print "at leaset on the localhost interface. (See \"Installing Postgres\" section\n";
472 print "of the installation manual).\n";
473 print "Finally, please make sure that the postgres user can make localhost \n";
474 print "connections without supplying a password. (That's controlled by the \n";
475 print "\"localhost ... ident\" line in pg_hba.conf; again, please consult the \n";
476 print "installation manual).\n";
477
478
479 exit 1;
480 }
481
482
483 # 4c. CHECK IF THIS DB ALREADY EXISTS:
484
485 $psql_command_dbcheck = $psql_exec . "/psql -c \"\" -d " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . ">/dev/null 2>&1";
486 if ( ($exitcode = system($psql_command_dbcheck)) == 0 )
487 {
488 # switch back to root uid:
489 $> = 0;
490 $< = 0;
491 chdir ($cwd);
492
493 print "WARNING! Database " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . " already exists!\n";
494 print "\nPlease note that you can only use this installer to create a blank, \n";
495 print "new and shiny DVN database. I.e., you cannot install on top of an \n";
496 print "existing database. Please enter a different name for the DVN database.\n";
497 print "\nPress any key to continue, or ctrl-C to exit the installer...\n\n";
498
499 system "stty cbreak </dev/tty >/dev/tty 2>&1";
500 my $key = getc(STDIN);
501 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
502 print "\n";
503
504 goto ENTERCONFIG;
505
506 }
507
508 # 4d. CHECK IF THIS USER ALREADY EXISTS:
509
510 $psql_command_rolecheck = $psql_exec . "/psql -c \"\" -d postgres " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . " >/dev/null 2>&1";
511 if ( ($exitcode = system($psql_command_rolecheck)) == 0 )
512 {
513 print "User (role) . " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . " already exists;\n";
514 print "Proceeding.";
515 }
516 else
517 {
518 # 4e. CREATE DVN DB USER:
519
520 print "\nCreating Postgres user (role) for the DVN:\n";
521
522 open TMPCMD, ">/tmp/pgcmd.$$.tmp";
523
524 # with unencrypted password:
525 #print TMPCMD "CREATE ROLE ".$CONFIG_DEFAULTS{'POSTGRES_USER'}." UNENCRYPTED PASSWORD '".$CONFIG_DEFAULTS{'POSTGRES_PASSWORD'}."' NOSUPERUSER CREATEDB CREATEROLE NOINHERIT LOGIN";
526
527 # with md5-encrypted password:
528 $pg_password_md5 = &create_pg_hash ($CONFIG_DEFAULTS{'POSTGRES_USER'},$CONFIG_DEFAULTS{'POSTGRES_PASSWORD'});
529 my $sql_command = "CREATE ROLE \"".$CONFIG_DEFAULTS{'POSTGRES_USER'}."\" PASSWORD 'md5". $pg_password_md5 ."' NOSUPERUSER CREATEDB CREATEROLE INHERIT LOGIN";
530
531 print TMPCMD $sql_command;
532 close TMPCMD;
533
534 my $psql_commandline = $psql_exec . "/psql -f /tmp/pgcmd.$$.tmp";
535
536 unless ( ($exitcode = system($psql_commandline)) == 0 )
537 {
538 print STDERR "Could not create the DVN Postgres user role!\n";
539 print STDERR "(SQL: " . $sql_command . ")\n";
540 print STDERR "(psql exit code: " . $exitcode . ")\n";
541 exit 1;
542 }
543
544 unlink "/tmp/pgcmd.$$.tmp";
545 print "done.\n";
546 }
547
548 # 4f. CREATE DVN DB:
549
550 print "\nCreating Postgres database:\n";
551
552 $psql_command = $psql_exec . "/createdb ".$CONFIG_DEFAULTS{'POSTGRES_DATABASE'}." --owner=".$CONFIG_DEFAULTS{'POSTGRES_USER'};
553
554 unless ( ($exitcode = system("$psql_command")) == 0 )
555 {
556 print STDERR "Could not create Postgres database for the DVN app!\n";
557 print STDERR "(command: " . $psql_command . ")\n";
558 print STDERR "(psql exit code: " . $exitcode . ")\n";
559 print STDERR "\naborting the installation (sorry!)\n\n";
560 exit 1;
561 }
562
563
564 # Changing back to root UID:
565
566 $> = 0;
567 $< = 0;
568
569 chdir ($cwd);
570
571 }
572 else
573 {
574 if (0) # DEV. INSTALLER ONLY:
575 {
576 print "\nIt is strongly recommended that you use a local PostgresQL server,\n";
577 print "running on localhost, in your development environment!\n\n";
578
579 print "Do you wish to continue?\n [y/n] ";
580
581
582 my $yesnocont = <>; chop $yesnocont;
583
584 while ( $yesnocont ne "y" && $yesnocont ne "n" )
585 {
586 print "Please enter 'y' or 'n'!\n";
587 print "(or ctrl-C to exit the installer)\n";
588 $yesnocont = <>; chop $yesnocont;
589 }
590
591 if ( $yesnocont eq "n" )
592 {
593 print "(aborting the installation)\n".
594 exit 0;
595 }
596 }
597
598 if ( $opts{$pg_only} )
599 {
600 print "The script must be run in the --pg_only mode ONLY locally,\n";
601 print "i.e., on the server where PostgresQL is running.\n";
602
603 exit 1;
604 }
605
606 print "In order to use a PostgresQL database running on a remote server,\n";
607 print "Please run this installer on that host with the \"--pg_only\" option:\n\n";
608 print "./install --pg_only\n\n";
609
610 print "Press any key to continue the installation process once that has been\n";
611 print "done. Or press ctrl-C to exit the installer.\n\n";
612
613 chdir ("/tmp");
614 system "stty cbreak </dev/tty >/dev/tty 2>&1";
615 my $key = getc(STDIN);
616 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
617 print "\n";
618 chdir ($cwd);
619
620 # Check if the role and database have been created on the remote server:
621 # -- TODO;
622
623 # Find out what Postgres version is running remotely:
624
625 $pg_major_version = 9;
626 $pg_minor_version = 1;
627
628 print "What version of PostgresQL is installed on the remote server?\n [" . $pg_major_version . "." . $pg_minor_version . "] ";
629
630
631 my $postgresVersion = <>; chop $postgresVersion;
632
633 while ( $postgresVersion ne "" && !($postgresVersion =~/^[0-9]+\.[0-9]+$/) )
634 {
635 print "Please enter valid Postgres version!\n";
636 print "(or ctrl-C to exit the installer)\n";
637 $postgresVersion = <>; chop $postgresVersion;
638 }
639
640 unless ( $postgresVersion eq "" )
641 {
642 my (@postgres_version_tokens) = split ( '\.', $postgresVersion );
643
644 unless ( ($postgres_version_tokens[0] == 8 && $postgres_version_tokens[1] >= 3) || ($postgres_version_tokens[0] >= 9) )
645 {
646 print STDERR "\nERROR: PostgresQL version 8.3, or newer, is required!\n";
647 print STDERR "Please make sure the right version of PostgresQL is properly installed\n";
648 print STDERR "on the remote server, then try again.\n";
649
650 exit 1;
651 }
652
653 $pg_major_version = $postgres_version_tokens[0];
654 $pg_minor_version = $postgres_version_tokens[1];
655 }
656
657 }
658
659
660 if ( $postgresonly )
661 {
662 print "\nOK, done.\n";
663 print "You can now resume the installation on the main DVN host.\n\n";
664
665 exit 0;
666 }
667
668
669 # 5. CONFIGURE GLASSFISH
670
671 print "\nProceeding with the Glassfish setup.\n";
672 print "\nChecking your Glassfish installation...";
673
674 my $glassfish_dir = $CONFIG_DEFAULTS{'GLASSFISH_DIRECTORY'};
675
676 # 5a. CHECK IF GLASSFISH DIR LOOKS OK:
677
678 print $glassfish_dir."/glassfish/domains/domain1";
679
680 unless ( -d $glassfish_dir."/glassfish/domains/domain1" )
681 {
682 # TODO: need better check than this
683
684 while ( ! ( -d $glassfish_dir."/glassfish/domains/domain1" ) )
685 {
686 print "\nInvalid Glassfish directory " . $glassfish_dir . "!\n";
687 print "Enter the root directory of your Glassfish installation:\n";
688 print "(Or ctrl-C to exit the installer): ";
689
690 $glassfish_dir = <>;
691 chop $glassfish_dir;
692 }
693 }
694
695 print "OK!\n";
696
697 # 5b. DETERMINE HOW MUCH MEMORY TO GIVE TO GLASSFISH AS HEAP:
698
699 $gf_heap_default = "2048m";
700 $sys_mem_total = 0;
701
702 if ( -e "/proc/meminfo" && open MEMINFO, "/proc/meminfo" )
703 {
704 # Linux
705
706 while ( $mline = <MEMINFO> )
707 {
708 if ( $mline =~ /MemTotal:[ \t]*([0-9]*) kB/ )
709 {
710 $sys_mem_total = $1;
711 }
712 }
713
714 close MEMINFO;
715
716 }
717 elsif ( -x "/usr/sbin/sysctl" )
718 {
719 # MacOS X, probably...
720
721 $sys_mem_total = `/usr/sbin/sysctl -n hw.memsize`;
722 chop $sys_mem_total;
723 if ($sys_mem_total > 0)
724 {
725 $sys_mem_total = int ($sys_mem_total / 1024);
726 # size in kb
727 }
728 }
729
730 if ( $sys_mem_total > 0 )
731 {
732 # setting the default heap size limit to 3/8 of the available
733 # amount of memory:
734 $gf_heap_default = ( int ($sys_mem_total / (8 / 3 * 1024) ) );
735
736 print "\nSetting the heap limit for Glassfish to " . $gf_heap_default . "MB. \n";
737 print "You may need to adjust this setting to better suit \n";
738 print "your system.\n\n";
739
740 $gf_heap_default .= "m";
741
742 }
743 else
744 {
745 print "\nCould not determine the amount of memory on your system.\n";
746 print "Setting the heap limit for Glassfish to 2GB. You may need \n";
747 print "to adjust the value to better suit your system.\n\n";
748 }
749
750 push @CONFIG_VARIABLES, "DEF_MEM_SIZE";
751 $CONFIG_DEFAULTS{"DEF_MEM_SIZE"} = $gf_heap_default;
752
753 print "\nPress any key to continue...\n\n";
754
755 system "stty cbreak </dev/tty >/dev/tty 2>&1";
756 my $key = getc(STDIN);
757 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
758 print "\n";
759
760 # 5c. GENERATE GLASSFISH CONFIGURATION FILE:
761
762 print "\nWriting glassfish configuration file (domain.xml)... ";
763
764 # 5cc. FIND THE "special-admin-indicator" IN THE ORIGINAL GLASSFISH CONFIG:
765
766 open ( GFCNFG, $glassfish_dir."/glassfish/domains/domain1/config/domain.xml") || die $@;
767
768 while ( <GFCNFG> )
769 {
770 if (/<secure-admin special-admin-indicator=\"([^\"]*)\"/)
771 {
772 $CONFIG_DEFAULTS{'GF_SPEC_INDICATOR'} = $1;
773 }
774 }
775
776 # (is it really a problem if we haven't found it?)
777
778 close GFCNFG;
779
780 open TEMPLATEIN, 'domain.xml.TEMPLATE';
781 open CONFIGOUT, '>domain.xml';
782
783 while( <TEMPLATEIN> )
784 {
785 for $ENTRY (@CONFIG_VARIABLES)
786 {
787 $patin = '%' . $ENTRY . '%';
788 $patout = $CONFIG_DEFAULTS{$ENTRY};
789
790 s/$patin/$patout/g;
791 }
792
793 print CONFIGOUT $_;
794
795 }
796
797 close TEMPLATEIN;
798 close CONFIGOUT;
799
800 print "done.\n";
801
802 system ("/bin/cp -f domain.xml ".$glassfish_dir."/glassfish/domains/domain1/config");
803 #diagnostics needed!
804
805 # check if the supllied config files are in the right place:
806
807 unless ( -f "config/logging.properties" )
808 {
809 print "\nERROR! Configuration files not found in config dir!\n";
810 print "(are you running the installer in the right directory?\n";
811 print "Aborting...\n";
812 exit 1;
813 }
814
815 print "\nCopying additional configuration files... ";
816
817 system ( "/bin/cp -Rf config/* ".$glassfish_dir."/glassfish/domains/domain1/config");
818 #diagnostics needed!
819
820 # install pre-configured robots.txt blocking bot crawlers:
821 system ( "/bin/cp -f robots.txt ".$glassfish_dir."/glassfish/domains/domain1/docroot");
822
823 # install the DVN guides (HTML) into the application docroot:
824 system ( "/bin/cp -Rf doc/guides/* ".$glassfish_dir."/glassfish/domains/domain1/docroot/guides");
825
826
827 print "done!\n";
828
829 print "\nInstalling the Glassfish PostgresQL driver... ";
830
831 my $install_driver_jar = "";
832
833 if ( $pg_major_version == 8 )
834 {
835 if ( $pg_minor_version == 3 )
836 {
837 $install_driver_jar = $POSTGRES_DRIVER_8_3;
838 }
839 elsif ( $pg_minor_version == 4 )
840 {
841 $install_driver_jar = $POSTGRES_DRIVER_8_4;
842 }
843 }
844 elsif ( $pg_major_version == 9 )
845 {
846 if ( $pg_minor_version == 0 )
847 {
848 $install_driver_jar = $POSTGRES_DRIVER_9_0;
849 }
850 elsif ( $pg_minor_version == 1 )
851 {
852 $install_driver_jar = $POSTGRES_DRIVER_9_1;
853 }
854 }
855
856 =poc
857 unless ( $install_driver_jar )
858 {
859 die "Installer could not find POSTGRES JDBC driver for your version of PostgresQL!\n";
860
861 }
862 =cut
863
864 system ( "/bin/cp", "pgdriver/" . $install_driver_jar, $glassfish_dir."/glassfish/lib");
865 #diagnostics needed!
866
867 print "done!\n";
868
869 # 5d. STOP GLASSFISH (OK IF NOT RUNNING):
870 print "\nStopping glassfish...\n";
871
872 unless ( ($exit_code=system ($glassfish_dir."/bin/asadmin stop-domain domain1")) == 0 )
873 {
874 print STDERR "(that's OK!)\n";
875 }
876
877 # 5dd. INSTALL PATCHED WEBCORE GLASSFISH MODULE:
878
879 $gf_webcore_jar = $glassfish_dir."/glassfish/modules/web-core.jar";
880
881 system ("/bin/mv -f ".$gf_webcore_jar . " " . $gf_webcore_jar.".PRESERVED");
882 system ("/bin/cp web-core.jar ".$gf_webcore_jar);
883
884 # 5ddd. DELETE EJB TIMER APP LOCK FILE, if exists (just in case!):
885
886 system ( "/bin/rm -f ".$glassfish_dir."/glassfish/domains/domain1/generated/ejb-timer-service-app" );
887
888 # 5e. START GLASSFISH:
889 print "\nStarting glassfish.\n";
890
891 unless ( ($exit_code=system ($glassfish_dir."/bin/asadmin start-domain domain1")) == 0 )
892 {
893 print STDERR "Could not start glassfish!\n";
894 print STDERR "(exit code: " . $exitcode . ")\n";
895 exit 1;
896 }
897
898
899 # check if glassfish is running:
900 # TODO.
901
902 # 6. DEPLOY APPLICATION:
903 # 6a. DO WE HAVE ANT?
904 # (we are no longer using ant to deply -- L.A.)
905 #
906 #$sys_path = $ENV{'PATH'};
907 #@sys_path_dirs = split ( ":", $sys_path );
908
909 #$ant_exec = "";
910 #
911 #for $sys_path_dir ( @sys_path_dirs )
912 #{
913 # if ( -x $sys_path_dir . "/ant" )
914 # {
915 # $ant_exec = $sys_path_dir . "/ant";
916 # last;
917 # }
918 #}
919 #
920 #if ( $ant_exec eq "" )
921 #{
922 # print STDERR "\nERROR: I haven't been able to find ant command in your PATH!\n";
923 # print STDERR "Please make sure and is installed and in your PATH; then try again.\n\n";
924 #
925 # exit 1;
926 #}
927 # 6b. TRY TO DEPLOY:
928
929 print "\nAttempting to deploy the application:\n\n";
930
931 $CONFIG_DEFAULTS{'GLASSFISH_ADMIN_PASSWORD'} = 'adminadmin';
932 # TODO: ask for password! -- in case they have already changed it
933 # (update: chances are we don't even need the password anymore, as
934 # long as we are deploying locally (?))
935
936 my $glassfish_password = $CONFIG_DEFAULTS{'GLASSFISH_ADMIN_PASSWORD'};
937
938 # create deployment properties files:
939 # (these properties files are no longer used, because we are no longer
940 # using ant to deploy the app. -- L.A.)
941
942 #for $prop_file ('AS', 'glassfish')
943 #{
944 # open ( TEMPLIN, "appdeploy/" . $prop_file . ".properties.TEMPLATE" )
945 # || die "failed to open appdeploy/" . $prop_file . ".properties.TEMPLATE";
946 # open ( PROPOUT, ">appdeploy/" . $prop_file . ".properties" )
947 # || die "failed to open appdeploy/" . $prop_file . ".properties for writing";
948 #
949 # while( <TEMPLIN> )
950 # {
951 # s/%GF_ADMIN_PASSWORD%/$glassfish_password/g;
952 # s/%GF_ROOT_DIR%/$glassfish_dir/g;
953 # print PROPOUT $_;
954 # }
955 #
956 # close TEMPLIN;
957 # close PROPOUT;
958 #}
959
960 # Create the .asadminpass file, or replace it, if exists:
961
962 $asadminpass_file = $ENV{'HOME'} . "/.asadminpass";
963
964 if ( -e $asadminpass_file )
965 {
966 system ("/bin/mv -f " . $asadminpass_file . " " . $asadminpass_file . ".PRESERVED");
967 }
968
969 system ("echo 'asadmin://admin@localhost:4848 ' > " . $asadminpass_file);
970
971 $deploy_command = $glassfish_dir."/bin/asadmin deploy --force=true --name=DVN-web dist/DVN-web.war";
972
973 unless ( ($exit_code = system ("cd appdeploy; " . $deploy_command)) == 0 )
974 {
975 print STDERR "Could not deploy DVN application!\n";
976 print STDERR "(exit code: " . $exitcode . ")\n";
977 exit 1;
978 }
979
980 if ( $pg_local_connection )
981 {
982 print "\nOK; now we are going to stop glassfish and populate the database with\n";
983 print "some initial content, then start glassfish again.\n";
984 }
985 else
986 {
987 print "\nOK; stopping glasfish.\n";
988 }
989
990
991 # 6c. SHUT DOWN:
992
993 $gf_stop_command = $glassfish_dir."/bin/asadmin stop-domain domain1";
994
995 unless ( ($exit_code = system ($gf_stop_command)) == 0 )
996 {
997 print STDERR "Could not stop glassfish!\n";
998 print STDERR "(command line: " . $gf_stop_command . ")\n";
999 print STDERR "(exit code: " . $exitcode . ")\n";
1000 print STDERR "\nPlease finish the installation process manually: \n";
1001 print STDERR "stop/kill glassfish; then populate the database with \n";
1002 print STDERR "the supplied initial content, by executing the following \n";
1003 print STDERR "command, *as Unix user postgres*: \n\n";
1004
1005 $psql_command = $psql_exec . "/psql -d $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} -f " . $SQL_REFERENCE_DATA;
1006
1007 print STDERR $psql_command . "\n\n";
1008 print STDERR "Then start glassfish again... Voila, you should then have \n";
1009 print STDERR "a running DVN instance at the following URL:\n\n";
1010 print STDERR " http://" . $CONFIG_DEFAULTS{'HOST_DNS_ADDRESS'} . "/dvn\n";
1011
1012 print STDERR "\naborting the installer... (sorry!)\n";
1013
1014 exit 1;
1015 }
1016
1017 # 7. POPULATE DATABASE:
1018
1019 if ( $pg_local_connection )
1020 {
1021 # 7a. POPULATE LOCALLY:
1022 print "\nPopulating the database (local PostgresQL instance):\n\n";
1023
1024 # Copy the SQL file to /tmp, where user postgres will definitely
1025 # have read access to it:
1026
1027 copy("referenceData.sql","/tmp") or die "Could not copy referenceData.sql to /tmp: $!";
1028
1029 $< = $POSTGRES_SYS_UID;
1030 $> = $POSTGRES_SYS_UID;
1031 chdir ("/tmp");
1032 $psql_command = $psql_exec . "/psql -d $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} -f referenceData.sql";
1033
1034 unless ( ($exitcode = system("$psql_command")) == 0 )
1035 {
1036 print STDERR "Could not populate Postgres database for the DVN app!\n";
1037 print STDERR "(command: " . $psql_command . ")\n";
1038 print STDERR "(psql exit code: " . $exitcode . ")\n";
1039 print STDERR "\nYou must populate the database before you can use your new\n";
1040 print STDERR "DVN instance. Please consult the installation manual and/or\n";
1041 print STDERR "seek support from the DVN team.\n\n";
1042 exit 1;
1043
1044 }
1045
1046 chdir ($cwd);
1047 print "\nOK, done!\n";
1048
1049 }
1050 else
1051 {
1052 # 7b. INSTRUCT THE USER TO POPULATE THE DB ON THE REMOTE SERVER:
1053 # NOT SUPPORTED YET -- TODO
1054 print "The database needs to be populated with some intial content \n";
1055 print "before we restart the DVN one last time. \n";
1056 print "However, populating a database on a remote PostgresQL server ";
1057 print "is not supported yet!\n";
1058 print "Please copy the file referenceData.sql (found in this directory)\n";
1059 print "onto the remote server and populate the database manually,\n";
1060 print "as user postgres, with the following command:\n\n";
1061 print " psql -d $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} -f referenceData.sql\n";
1062 print "then start glassfish again on this server with \n\n";
1063 print " " . $glassfish_dir."/bin/asadmin start-domain domain1\n\n";
1064
1065 $> = 0;
1066 $< = 0;
1067
1068 exit 0;
1069
1070 }
1071
1072 # back to root:
1073
1074 $> = 0;
1075 $< = 0;
1076
1077 # 8. START GLASSFISH AGAIN:
1078 print "\nStarting glassfish, again:\n\n";
1079
1080 $gf_start_command = $glassfish_dir."/bin/asadmin start-domain domain1";
1081
1082 # delete the EJB TIMER app lock file, if exists (just in case!):
1083 system ( "/bin/rm -f ".$glassfish_dir."/glassfish/domains/domain1/generated/ejb-timer-service-app" );
1084
1085 unless ( ($exit_code = system ($gf_start_command)) == 0 )
1086 {
1087 print STDERR "Could not start glassfish!\n";
1088 print STDERR "(command line: " . $gf_start_command . ")\n";
1089 print STDERR "(exit code: " . $exit_code . ")\n";
1090 exit 1;
1091 }
1092
1093
1094 print "\nYou should now have a running DVN instance;\n";
1095 print "Please go to the application at the following URL:\n\n";
1096 print " http://" . $CONFIG_DEFAULTS{'HOST_DNS_ADDRESS'} . "/dvn\n";
1097 print "\nand log in by using \"networkAdmin\" as both the user name\n";
1098 print "and password. Click the \"networkAdmin\" link on the right side\n";
1099 print "Of the main screen, then click \"Update Account\". Change this\n";
1100 print "default password and default e-mail address.\n";
1101
1102 # 9. FINALLY, CHECK IF RSERVE IS RUNNING:
1103 print "\n\nFinally, checking if Rserve is running and accessible...\n";
1104
1105 unless ( $CONFIG_DEFAULTS{'RSERVE_PORT'}=~/^[0-9][0-9]*$/ )
1106 {
1107 print $CONFIG_DEFAULTS{'RSERVE_HOST'} . " does not look like a valid port number,\n";
1108 print "defaulting to 6311.\n\n";
1109
1110 $CONFIG_DEFAULTS{'RSERVE_PORT'} = 6311;
1111 }
1112
1113 my ( $rserve_iaddr, $rserve_paddr, $rserve_proto );
1114
1115 unless ( $rserve_iaddr = inet_aton($CONFIG_DEFAULTS{'RSERVE_HOST'}) )
1116 {
1117 print STDERR "Could not look up $CONFIG_DEFAULTS{'RSERVE_HOST'},\n";
1118 print STDERR "the host you specified as your R server.\n";
1119 print STDERR "\nDVN can function without a working R server, but\n";
1120 print STDERR "much of the functionality concerning running statistics\n";
1121 print STDERR "and analysis on quantitative data will not be available.\n";
1122 print STDERR "Please consult the Installers guide for more info.\n";
1123
1124 exit 0;
1125 }
1126
1127 $rserve_paddr = sockaddr_in($CONFIG_DEFAULTS{'RSERVE_PORT'}, $rserve_iaddr);
1128 $rserve_proto = getprotobyname('tcp');
1129
1130 unless ( socket(SOCK, PF_INET, SOCK_STREAM, $rserve_proto) &&
1131 connect(SOCK, $rserve_paddr) )
1132 {
1133 print STDERR "Could not establish connection to $CONFIG_DEFAULTS{'RSERVE_HOST'}\n";
1134 print STDERR "on port $CONFIG_DEFAULTS{'RSERVE_PORT'}, the address you provided\n";
1135 print STDERR "for your R server.\n";
1136 print STDERR "DVN can function without a working R server, but\n";
1137 print STDERR "much of the functionality concerning running statistics\n";
1138 print STDERR "and analysis on quantitative data will not be available.\n";
1139 print STDERR "Please consult the \"Installing R\" section in the Installers guide\n";
1140 print STDERR "for more info.\n";
1141
1142 exit 0;
1143
1144 }
1145
1146 close (SOCK);
1147 print "\nOK!\n";
1148
1149 exit 0;
1150
1151
1152 sub create_pg_hash {
1153 local $pg_username = shift @_;
1154 local $pg_password = shift @_;
1155
1156 $encode_line = $pg_password . $pg_username;
1157
1158 # for Redhat:
1159
1160 ##print STDERR "executing /bin/echo -n $encode_line | md5sum\n";
1161
1162 if ( $WORKING_OS eq "MacOSX" )
1163 {
1164 $hash = `/bin/echo -n $encode_line | md5`;
1165 }
1166 else
1167 {
1168 $hash = `/bin/echo -n $encode_line | md5sum`;
1169 }
1170
1171 chop $hash;
1172
1173 $hash =~s/ \-$//;
1174
1175 if ( (length($hash) != 32) || ($hash !~ /^[0-9a-f]*$/) )
1176 {
1177 print STDERR "Failed to generate a MD5-encrypted password hash for the Postgres database.\n";
1178 exit 1;
1179 }
1180
1181
1182 return $hash;
1183 }