-
Notifications
You must be signed in to change notification settings - Fork 492
/
install
executable file
·1516 lines (1195 loc) · 47.1 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Socket;
use File::Copy;
my $verbose;
my $pg_only;
my $hostname;
my $gfuser;
my $gfdir;
my $mailserver;
my $yes;
my $force;
my $nogfpasswd;
my $admin_email;
my ($rez) = GetOptions(
#"length=i" => \$length, # numeric
#"file=s" => \$data, # string
"verbose" => \$verbose,
"pg_only" => \$pg_only,
"hostname=s" => \$hostname,
"gfuser=s" => \$gfuser,
"gfdir=s" => \$gfdir,
"mailserver=s" => \$mailserver,
"y|yes" => \$yes,
"f|force" => \$force,
"nogfpasswd" => \$nogfpasswd,
"admin_email=s" => \$admin_email,
);
my @CONFIG_VARIABLES;
my $postgresonly = 0;
if ($pg_only)
{
@CONFIG_VARIABLES =
( 'POSTGRES_SERVER', 'POSTGRES_PORT', 'POSTGRES_DATABASE', 'POSTGRES_USER', 'POSTGRES_PASSWORD', 'POSTGRES_ADMIN_PASSWORD' );
$postgresonly = 1;
}
else
{
@CONFIG_VARIABLES = (
'HOST_DNS_ADDRESS',
'GLASSFISH_USER',
'GLASSFISH_DIRECTORY',
'ADMIN_EMAIL',
'MAIL_SERVER',
'POSTGRES_SERVER',
'POSTGRES_PORT',
'POSTGRES_ADMIN_PASSWORD',
'POSTGRES_DATABASE',
'POSTGRES_USER',
'POSTGRES_PASSWORD',
'SOLR_LOCATION',
'TWORAVENS_LOCATION',
'RSERVE_HOST',
'RSERVE_PORT',
'RSERVE_USER',
'RSERVE_PASSWORD'
);
}
my %CONFIG_DEFAULTS = (
'HOST_DNS_ADDRESS', 'localhost',
'GLASSFISH_USER', '',
'GLASSFISH_DIRECTORY', '/usr/local/glassfish4',
'GLASSFISH_USER', '',
'ADMIN_EMAIL', '',
'MAIL_SERVER', 'mail.hmdc.harvard.edu',
'POSTGRES_ADMIN_PASSWORD', 'secret',
'POSTGRES_SERVER', '127.0.0.1',
'POSTGRES_PORT', 5432,
'POSTGRES_DATABASE', 'dvndb',
'POSTGRES_USER', 'dvnapp',
'POSTGRES_PASSWORD', 'secret',
'SOLR_LOCATION', 'LOCAL',
'TWORAVENS_LOCATION', 'NOT INSTALLED',
'RSERVE_HOST', 'localhost',
'RSERVE_PORT', 6311,
'RSERVE_USER', 'rserve',
'RSERVE_PASSWORD', 'rserve'
);
my %CONFIG_PROMPTS = (
'HOST_DNS_ADDRESS', 'Fully Qualified Domain Name of your host',
'GLASSFISH_USER', 'Glassfish service account username',
'GLASSFISH_DIRECTORY', 'Glassfish Directory',
'ADMIN_EMAIL', 'Administrator email address for this Dataverse',
'MAIL_SERVER', 'SMTP (mail) server to relay notification messages',
'POSTGRES_SERVER', 'Postgres Server Address',
'POSTGRES_PORT', 'Postgres Server Port',
'POSTGRES_ADMIN_PASSWORD', 'Postgres ADMIN password',
'POSTGRES_DATABASE', 'Name of the Postgres Database',
'POSTGRES_USER', 'Name of the Postgres User',
'POSTGRES_PASSWORD', 'Postgres user password',
'SOLR_LOCATION', 'Remote SOLR indexing service',
'TWORAVENS_LOCATION', 'Will this Dataverse be using TwoRavens application',
'RSERVE_HOST', 'Rserve Server',
'RSERVE_PORT', 'Rserve Server Port',
'RSERVE_USER', 'Rserve User Name',
'RSERVE_PASSWORD', 'Rserve User Password'
);
my %CONFIG_COMMENTS = (
'HOST_DNS_ADDRESS', ":\n(enter numeric IP address, if FQDN is unavailable) ",
'GLASSFISH_USER', ":\nThis user will be running Glassfish service on your system.\n - If this is a dev. environment, this should be your own username; \n - In production, we suggest \"glassfish\" or another unprivileged user\n: ",
'GLASSFISH_DIRECTORY', '',
'ADMIN_EMAIL', ":\n(please enter a valid email address!) ",
'MAIL_SERVER', '',
'POSTGRES_SERVER', '',
'POSTGRES_PORT', '',
'POSTGRES_ADMIN_PASSWORD', ":\n - We will need this to create the user and database that the Dataverse application will be using.\n (Hit RETURN if access control is set to \"trust\" for this connection in pg_hba.conf)\n: ",
'POSTGRES_USER', ":\n - This is the Postgres user that the Dataverse app will be using to talk to the database\n: ",
'POSTGRES_DATABASE', '',
'POSTGRES_PASSWORD', '',
'SOLR_LOCATION', "? \n - Leave this set to \"LOCAL\" if the SOLR will be running on the same (this) server.\n Otherwise, please enter the host AND THE PORT NUMBER of the remote SOLR service, colon-separated\n (for example: foo.edu:8983)\n: ",
'TWORAVENS_LOCATION', "? \n - If so, please provide the complete URL of the TwoRavens GUI under rApache,\n for example, \"https://foo.edu/dataexplore/gui.html\".\n (PLEASE NOTE, TwoRavens will need to be installed separately! - see the installation docs for more info)\n: ",
'RSERVE_HOST', '',
'RSERVE_PORT', '',
'RSERVE_USER', '',
'RSERVE_PASSWORD', ''
);
my $API_URL = "http://localhost:8080/api";
# Supported Posstgres JDBC drivers:
# (have to be configured explicitely, so that Perl "taint" (security) mode
# doesn't get paranoid)
my %POSTGRES_DRIVERS = (
# "8_4", "postgresql-8.3-603.jdbc4.jar",
"8_4", "postgresql-8.4-703.jdbc4.jar",
"9_0", "postgresql-9.0-802.jdbc4.jar",
"9_1", "postgresql-9.1-902.jdbc4.jar",
"9_2", "postgresql-9.1-902.jdbc4.jar",
"9_3", "postgresql-9.1-902.jdbc4.jar",
"9_4", "postgresql-9.1-902.jdbc4.jar",
"9_5", "postgresql-9.1-902.jdbc4.jar",
"9_6", "postgresql-9.1-902.jdbc4.jar"
);
# A few preliminary checks:
# OS:
my $uname_out = `uname -a`;
# hostname:
my $hostname_from_cmdline = `hostname`;
chop $hostname_from_cmdline;
if ($hostname) {
$CONFIG_DEFAULTS{'HOST_DNS_ADDRESS'} = $hostname;
}
else {
$CONFIG_DEFAULTS{'HOST_DNS_ADDRESS'} = $hostname_from_cmdline;
}
# read default configuration values from tab separated file "default.config" if it exists
# moved after the $hostname_from_cmdline section to avoid excessively complicating the logic
# of command line argument, automatic selection, or config file.
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
my $config_default_file = "default.config";
if ( -e $config_default_file )
{
print("loading default configuration values from $config_default_file\n");
open( my $inp_cfg, $config_default_file );
while( my $ln = <$inp_cfg> )
{
my @xs = split('\t', $ln );
if ( 2 == @xs )
{
my $k = $xs[0];
my $v = trim($xs[1]);
$CONFIG_DEFAULTS{$k}=$v;
}
}
}
else
{
print("using hard-coded default configuration values ($config_default_file not found)\n");
}
# get current user. first one wins.
my $current_user = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
if (!$CONFIG_DEFAULTS{'GLASSFISH_USER'}) {
$CONFIG_DEFAULTS{'GLASSFISH_USER'} = $current_user;
print "No pre-configured user found; using $current_user.\n";
}
# command-line argument takes precendence
if ($gfuser) {
print "Using CLI-specified user $gfuser.\n";
$CONFIG_DEFAULTS{'GLASSFISH_USER'} = $gfuser;
}
# prefer that we not install as root.
unless ( $< != 0 ) {
print "####################################################################\n";
print " It is recommended that this script not be run as root.\n";
print " Consider creating a glassfish service account, giving it ownership\n";
print " on the glassfish/domains/domain1/ and glassfish/lib/ directories,\n";
print " along with the JVM-specified files.dir location, and running\n";
print " this installer as the user who will launch Glassfish.\n";
print "####################################################################\n";
}
# ensure $gfuser exists or bail
my $gfidcmd="id $CONFIG_DEFAULTS{'GLASSFISH_USER'}";
my $gfreturncode=system($gfidcmd);
if ($gfreturncode != 0) {
die "Couldn't find user $gfuser. Please ensure the account exists and is readable by the user running this installer.\n";
}
if ($mailserver) {
$CONFIG_DEFAULTS{'MAIL_SERVER'} = $mailserver;
}
if ($gfdir) {
$CONFIG_DEFAULTS{'GLASSFISH_DIRECTORY'} = $gfdir;
}
print "\nWelcome to the Dataverse installer.\n";
unless ($postgresonly) {
print "You will be guided through the process of setting up a NEW\n";
print "instance of the dataverse application\n";
}
else {
print "You will be guided through the process of configuring the\n";
print "LOCAL instance of PostgreSQL database for use by the DVN\n";
print "application.\n";
}
my @uname_tokens = split( " ", $uname_out );
my $WORKING_OS;
if ( $uname_tokens[0] eq "Darwin" ) {
print "\nThis appears to be a MacOS X system; good.\n";
# TODO: check the OS version
$WORKING_OS = "MacOSX";
}
elsif ( $uname_tokens[0] eq "Linux" ) {
if ( -f "/etc/redhat-release" ) {
print "\nThis appears to be a RedHat system; good.\n";
$WORKING_OS = "RedHat";
# TODO: check the distro version
}
else {
print "\nThis appears to be a non-RedHat Linux system;\n";
print "this installation *may* succeed; but we're not making any promises!\n";
$WORKING_OS = "Linux";
}
}
else {
print "\nWARNING: This appears to be neither a Linux or MacOS X system!\n";
print "This installer script will most likely fail. Please refer to the\n";
print "DVN Installers Guide for more information.\n\n";
$WORKING_OS = "Unknown";
print "Do you wish to continue?\n [y/n] ";
my $yesnocont;
if ($yes) {
$yesnocont = "y";
}
else {
print "here";
exit;
$yesnocont = <>;
chop $yesnocont;
}
while ( $yesnocont ne "y" && $yesnocont ne "n" ) {
print "Please enter 'y' or 'n'!\n";
print "(or ctrl-C to exit the installer)\n";
$yesnocont = <>;
chop $yesnocont;
}
if ( $yesnocont eq "n" ) {
exit 0;
}
}
ENTERCONFIG:
print "\n";
print "Please enter the following configuration values:\n";
print "(hit [RETURN] to accept the default value)\n";
print "\n";
for my $ENTRY (@CONFIG_VARIABLES)
{
my $config_prompt = $CONFIG_PROMPTS{$ENTRY};
my $config_comment = $CONFIG_COMMENTS{$ENTRY};
if ( $config_comment eq '' )
{
print $config_prompt . ": ";
print "[" . $CONFIG_DEFAULTS{$ENTRY} . "] ";
}
else
{
print $config_prompt . $config_comment;
print "[" . $CONFIG_DEFAULTS{$ENTRY} . "] ";
}
my $user_entry = "";
unless ($yes)
{
$user_entry = <>;
chop $user_entry;
if ( $user_entry ne "" ) {
$CONFIG_DEFAULTS{$ENTRY} = $user_entry;
}
# for some values, we'll try to do some validation right here, in real time:
if ($ENTRY eq 'ADMIN_EMAIL')
{
$user_entry = $CONFIG_DEFAULTS{$ENTRY};
my $attempts = 0;
while ($user_entry !~/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/)
{
$attempts++;
print "Please enter a valid email address: ";
$user_entry = <>;
chop $user_entry;
}
if ($attempts)
{
print "OK, looks legit.\n";
$CONFIG_DEFAULTS{$ENTRY} = $user_entry;
}
}
elsif ($ENTRY eq 'GLASSFISH_DIRECTORY')
{
# 5a. CHECK IF GLASSFISH DIR LOOKS OK:
print "\nChecking your Glassfish installation...";
my $g_dir = $CONFIG_DEFAULTS{'GLASSFISH_DIRECTORY'};
unless ( -d $g_dir . "/glassfish/domains/domain1" )
{
# TODO: need better check than this
while ( !( -d $g_dir . "/glassfish/domains/domain1" ) )
{
print "\nInvalid Glassfish directory " . $g_dir . "!\n";
print "Enter the root directory of your Glassfish installation:\n";
print "(Or ctrl-C to exit the installer): ";
$g_dir = <>;
chop $g_dir;
}
# TODO:
# verify that we can write in the Glassfish directory
# (now that we are no longer requiring to run the installer as root)
my $g_testdir = $g_dir . "/glassfish/domains/domain1";
my $g_libdir = $g_dir . "/glassfish/lib";
if (!(-w $g_testdir)) {
die("$g_testdir not writable. Have you created a glassfish user, and given it write permission on $g_testdir?\n");
} elsif (!(-w $g_libdir)) {
die("$g_libdir not writable. Have you created a glassfish user, and given it write permission on $g_libdir?\n");
}
}
print "OK!\n";
$CONFIG_DEFAULTS{'GLASSFISH_DIRECTORY'} = $g_dir;
}
elsif ($ENTRY eq 'MAIL_SERVER')
{
my $smtp_server = "";
while (! &validate_smtp_server() )
{
print "Enter a valid SMTP (mail) server:\n";
print "(Or ctrl-C to exit the installer): ";
$smtp_server = <>;
chop $smtp_server;
$CONFIG_DEFAULTS{'MAIL_SERVER'} = $smtp_server unless $smtp_server eq '';
}
}
}
print "\n";
}
# CONFIRM VALUES ENTERED:
print "\nOK, please confirm what you've entered:\n\n";
for my $ENTRY (@CONFIG_VARIABLES) {
print $CONFIG_PROMPTS{$ENTRY} . ": " . $CONFIG_DEFAULTS{$ENTRY} . "\n";
}
my $yesno;
if ($yes) {
$yesno = "y";
}
else {
print "\nIs this correct? [y/n] ";
$yesno = <>;
chop $yesno;
}
while ( $yesno ne "y" && $yesno ne "n" ) {
print "Please enter 'y' or 'n'!\n";
print "(or ctrl-C to exit the installer)\n";
$yesno = <>;
chop $yesno;
}
if ( $yesno eq "n" ) {
goto ENTERCONFIG;
}
# VALIDATION/VERIFICATION OF THE CONFIGURATION VALUES:
# 1. VERIFY/VALIDATE THE MAIL SERVER THEY CONFIGURED:
# (has been moved to the top, so that it's validated in real time, when the user enters the value)
# 2. CHECK IF THE WAR FILE IS AVAILABLE:
print "\nChecking if the application .war file is available... ";
# if this installation is running out of the installer zib bundle directory,
# the war file will be sitting right here, named "dataverse.war":
my $WARFILE_LOCATION = "dataverse.war";
# but if it's not here, this is probably a personal development
# setup, so their build should be up in their source tree:
unless ( -f $WARFILE_LOCATION ) {
my $DATAVERSE_VERSION = "";
my $DATAVERSE_POM_FILE = "../../pom.xml";
if ( -f $DATAVERSE_POM_FILE )
{
open DPF, $DATAVERSE_POM_FILE;
my $pom_line;
while ($pom_line=<DPF>)
{
chop $pom_line;
if ($pom_line =~/^[ \t]*<version>([0-9\.]+)<\/version>/)
{
$DATAVERSE_VERSION=$1;
last;
}
}
close DPF;
if ($DATAVERSE_VERSION ne "") {
$WARFILE_LOCATION = "../../target/dataverse-" . $DATAVERSE_VERSION . ".war";
}
}
}
# But, if the war file cannot be found in either of the 2
# places - we'll just have to give up:
unless ( -f $WARFILE_LOCATION ) {
print "\nWARNING: Can't find the project .war file!\n";
print "\tAre you running the installer in the right directory?\n";
print "\tHave you built the war file?\n";
print "\t(if not, build the project and run the installer again)\n";
exit 0;
}
print " Yes, it is!\n";
# check the working (installer) dir:
my $cwd;
chomp( $cwd = `pwd` );
# 2b. CHECK IF THE SQL TEMPLATE IS IN PLACE AND CREATE THE SQL FILE
#my $SQL_REFERENCE_DATA = "reference_data_filtered.sql";
my $SQL_REFERENCE_TEMPLATE = "../database/reference_data.sql";
unless ( -f $SQL_REFERENCE_TEMPLATE ) {
$SQL_REFERENCE_TEMPLATE = "reference_data.sql";
}
unless ( -f $SQL_REFERENCE_TEMPLATE ) {
print "\nWARNING: Can't find .sql data template!\n";
print "(are you running the installer in the right directory?)\n";
exit 0;
}
#open DATATEMPLATEIN, $SQL_REFERENCE_TEMPLATE || die $@;
#open SQLDATAOUT, '>' . $SQL_REFERENCE_DATA || die $@;
#
#while (<DATATEMPLATEIN>) {
# s/dvnapp/$CONFIG_DEFAULTS{'POSTGRES_USER'}/g;
# print SQLDATAOUT $_;
#}
#close DATATEMPLATEIN;
#close SQLDATAOUT;
# 3. CHECK POSTGRES AND JQ AVAILABILITY:
my $pg_local_connection = 0;
my $psql_exec;
my $jq_exec = "";
my $pg_major_version = 0;
my $pg_minor_version = 0;
my $POSTGRES_SYS_UID;
if ( $CONFIG_DEFAULTS{'POSTGRES_SERVER'} eq 'localhost' || $CONFIG_DEFAULTS{'POSTGRES_SERVER'} eq '127.0.0.1' )
{
$pg_local_connection = 1;
}
elsif ($pg_only)
{
print "In the --pg_only mode the script can only be run LOCALLY,\n";
print "i.e., on the server where PostgresQL is running, with the\n";
print "Postgres server address as localhost - \"127.0.0.1\".\n";
exit 1;
}
### 3a. CHECK FOR USER postgres: (NO LONGER USED!)
###print "\nChecking system user \"postgres\"... ";
###my $POSTGRES_SYS_NAME = "postgres";
###$POSTGRES_SYS_UID = ( getpwnam("postgres") )[2];
# 3b. LOCATE THE EXECUTABLES, FOR jq AND psql:
my $sys_path = $ENV{'PATH'};
my @sys_path_dirs = split( ":", $sys_path );
for my $sys_path_dir (@sys_path_dirs) {
if ( -x $sys_path_dir . "/jq" ) {
$jq_exec = $sys_path_dir;
last;
}
}
if ( $jq_exec eq "" ) {
print STDERR "\nERROR: I haven't been able to find the jq command in your PATH! Please install it from http://stedolan.github.io/jq/\n";
exit 1;
}
$psql_exec = "";
for my $sys_path_dir (@sys_path_dirs) {
if ( -x $sys_path_dir . "/psql" ) {
$psql_exec = $sys_path_dir;
last;
}
}
my $psql_major_version = 0;
my $psql_minor_version = 0;
# 3c. IF PSQL WAS FOUND IN THE PATH, CHECK ITS VERSION:
unless ( $psql_exec eq "" ) {
open( PSQLOUT, $psql_exec . "/psql --version|" );
my $psql_version_line = <PSQLOUT>;
chop $psql_version_line;
close PSQLOUT;
my ( $postgresName, $postgresNameLong, $postgresVersion ) = split( " ", $psql_version_line );
unless ( $postgresName eq "psql" && $postgresVersion =~ /^[0-9][0-9\.]*$/ ) {
print STDERR "\nWARNING: Unexpected output from psql command!\n";
}
else {
my (@psql_version_tokens) = split( '\.', $postgresVersion );
print "\n\nFound Postgres psql command, version $postgresVersion.\n\n";
$psql_major_version = $psql_version_tokens[0];
$psql_minor_version = $psql_version_tokens[1];
$pg_major_version = $psql_major_version;
$pg_minor_version = $psql_minor_version;
}
}
# a frequent problem with MacOSX is that the copy of psql found in the PATH
# belongs to the older version of PostgresQL supplied with the OS, which happens
# to be incompatible with the newer builds from the Postgres project; which are
# recommended to be used with Dataverse. So if this is a MacOSX box, we'll
# check what other versions of PG are available, and select the highest version
# we can find:
if ( $WORKING_OS eq "MacOSX" ) {
my $macos_pg_major_version = 0;
my $macos_pg_minor_version = 0;
for $macos_pg_minor_version ( "5", "4", "3", "2", "1", "0" ) {
if ( -x "/Library/PostgreSQL/9." . $macos_pg_minor_version . "/bin/psql" ) {
$macos_pg_major_version = 9;
if ( ( $macos_pg_major_version > $psql_major_version )
|| ( $macos_pg_minor_version >= $psql_minor_version ) )
{
$psql_exec = "/Library/PostgreSQL/9." . $macos_pg_minor_version . "/bin";
$pg_major_version = $macos_pg_major_version;
$pg_minor_version = $macos_pg_minor_version;
}
last;
}
}
# And if we haven't found an 9.* version of postgresql installed, we'll also check
# for version 8.* available:
if ( $macos_pg_major_version < 9 ) {
for $macos_pg_minor_version ( "4", "3" )
# TODO:
# Do we even want to support postgres 8.3?
{
if ( -x "/Library/PostgreSQL/8." . $macos_pg_minor_version . "/bin/psql" ) {
$macos_pg_major_version = 8;
if ( $macos_pg_major_version > $psql_major_version
|| $macos_pg_minor_version > $psql_minor_version )
{
$psql_exec = "/Library/PostgreSQL/8." . $macos_pg_minor_version . "/bin";
$pg_major_version = $macos_pg_major_version;
$pg_minor_version = $macos_pg_minor_version;
}
last;
}
}
}
}
my $psql_admin_exec = "";
if ( $psql_exec eq "" )
{
if ( $pg_local_connection )
{
print STDERR "\nERROR: I haven't been able to find the psql command in your PATH!\n";
print STDERR "Please make sure PostgresQL is properly installed; if necessary, add\n";
print STDERR "the location of psql to the PATH, then try again.\n\n";
exit 1;
}
else
{
print "WARNING: I haven't been able to find the psql command in your PATH!\n";
print "But since we are configuring a Dataverse instance to use a remote Postgres server,\n";
print "we can still set up the database by running a setup script on that remote server\n";
print "(see below for instructions).\n";
}
} else {
if ( $pg_major_version == 0 ) {
# hmm?
}
print "(We'll be Using psql version " . $pg_major_version . "." . $pg_minor_version . ")\n";
$psql_admin_exec = "PGPASSWORD=" . $CONFIG_DEFAULTS{'POSTGRES_ADMIN_PASSWORD'} . "; export PGPASSWORD; " . $psql_exec;
$psql_exec = "PGPASSWORD=" . $CONFIG_DEFAULTS{'POSTGRES_PASSWORD'} . "; export PGPASSWORD; " . $psql_exec;
print "Checking if we can talk to Postgres as the admin user...\n";
}
# 4. CONFIGURE POSTGRES:
# 4a. BUT FIRST, CHECK IF WE CAN TALK TO POSTGRES AS THE ADMIN:
if ( $psql_admin_exec eq "" || system( $psql_admin_exec . "/psql -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -U postgres -d postgres -c 'SELECT * FROM pg_roles' > /dev/null 2>&1" ) )
{
# No, we can't. :(
if ($pg_local_connection)
{
# If Postgres is running locally, this is a fatal condition.
# We'll give them some (potentially) helpful pointers and exit.
print "Nope, I haven't been able to connect to the local instance of PostgresQL as the admin user.\n";
print "\nIs postgresql running? \n";
print " On a RedHat-like system, you can check the status of the daemon with\n\n";
print " service postgresql status\n\n";
print " and, if it's not running, start the daemon with\n\n";
print " service postgresql start\n\n";
print " On MacOSX, use Applications -> PostgresQL -> Start Server.\n";
print " (or, if there's no \"Start Server\" item in your PostgresQL folder, \n";
print " simply restart your MacOSX system!)\n";
print "\nAlso, please make sure that the daemon is listening to network connections!\n";
print " - at least on the localhost interface. (See \"Installing Postgres\" section\n";
print " of the installation manual).\n";
print "\nFinally, did you supply the correct admin password?\n";
print " Don't know the admin password for your Postgres installation?\n";
print " - then simply set the access level to \"trust\" temporarily (for localhost only!)\n";
print " in your pg_hba.conf file. Again, please consult the \n";
print " installation manual).\n";
exit 1;
}
else
{
# If we are configuring the Dataverse instance to use a Postgres server
# running on a remote host, it is possible to configure the database
# without opening remote access for the admin user. They will simply
# have to run this script in the "postgres-only" mode on that server, locally,
# then resume the installation here:
print "Nope, I haven't been able to connect to the remote Postgres server as the admin user.\n";
print "(Or you simply don't have psql installed on this server)\n";
print "It IS possible to configure a database for your Dataverse on a remote server,\n";
print "without having admin access to that remote Postgres installation.\n\n";
print "In order to do that, pleaes copy the installer (the entire package) to the server\n";
print "where PostgresQL is running and run the installer with the \"--pg_only\" option:\n\n";
print " ./install --pg_only\n\n";
print "Press any key to continue the installation process once that has been\n";
print "done. Or press ctrl-C to exit the installer.\n\n";
system "stty cbreak </dev/tty >/dev/tty 2>&1";
my $key = getc(STDIN);
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
print "\n";
# Find out what Postgres version is running remotely:
$pg_major_version = 9;
$pg_minor_version = 1;
print "What version of PostgresQL is installed on the remote server?\n ["
. $pg_major_version . "."
. $pg_minor_version . "] ";
my $postgresVersion = <>;
chop $postgresVersion;
while ( $postgresVersion ne "" && !( $postgresVersion =~ /^[0-9]+\.[0-9]+$/ ) ) {
print "Please enter valid Postgres version!\n";
print "(or ctrl-C to exit the installer)\n";
$postgresVersion = <>;
chop $postgresVersion;
}
unless ( $postgresVersion eq "" ) {
my (@postgres_version_tokens) = split( '\.', $postgresVersion );
unless ( ( $postgres_version_tokens[0] == 8 && $postgres_version_tokens[1] >= 4 )
|| ( $postgres_version_tokens[0] >= 9 ) )
{
print STDERR "\nERROR: PostgresQL version 8.4, or newer, is required!\n";
print STDERR "Please make sure the right version of PostgresQL is properly installed\n";
print STDERR "on the remote server, then try again.\n";
exit 1;
}
$pg_major_version = $postgres_version_tokens[0];
$pg_minor_version = $postgres_version_tokens[1];
}
}
}
else
{
print "Yes, we can!\n";
# ok, we can proceed with configuring things...
print "\nConfiguring Postgres Database:\n";
# 4c. CHECK IF THIS DB ALREADY EXISTS:
my $psql_command_dbcheck =
$psql_admin_exec . "/psql -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -U postgres -c \"\" -d " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . ">/dev/null 2>&1";
if ( ( my $exitcode = system($psql_command_dbcheck) ) == 0 )
{
if ($force)
{
print "WARNING! Database "
. $CONFIG_DEFAULTS{'POSTGRES_DATABASE'}
. " already exists but --force given... continuing.\n";
}
else
{
print "WARNING! Database " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . " already exists!\n";
print "\nPlease note that you can only use this installer to create a blank, \n";
print "new and shiny Dataverse database. I.e., you cannot install on top of an \n";
print "existing one. Please enter a different name for the DVN database.\n";
print "\nPress any key to continue, or ctrl-C to exit the installer...\n\n";
system "stty cbreak </dev/tty >/dev/tty 2>&1";
my $key = getc(STDIN);
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
print "\n";
goto ENTERCONFIG;
}
}
# 4d. CHECK IF THIS USER ALREADY EXISTS:
my $psql_command_rolecheck =
$psql_exec . "/psql -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -c \"\" -d postgres " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . " >/dev/null 2>&1";
if ( ( my $exitcode = system($psql_command_rolecheck) ) == 0 )
{
print "User (role) " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . " already exists;\n";
print "Proceeding.";
}
else
{
# 4e. CREATE DVN DB USER:
print "\nCreating Postgres user (role) for the DVN:\n";
open TMPCMD, ">/tmp/pgcmd.$$.tmp";
# with md5-encrypted password:
my $pg_password_md5 =
&create_pg_hash( $CONFIG_DEFAULTS{'POSTGRES_USER'}, $CONFIG_DEFAULTS{'POSTGRES_PASSWORD'} );
my $sql_command =
"CREATE ROLE \""
. $CONFIG_DEFAULTS{'POSTGRES_USER'}
. "\" PASSWORD 'md5"
. $pg_password_md5
. "' NOSUPERUSER CREATEDB CREATEROLE INHERIT LOGIN";
print TMPCMD $sql_command;
close TMPCMD;
my $psql_commandline = $psql_admin_exec . "/psql -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -U postgres -d postgres -f /tmp/pgcmd.$$.tmp >/dev/null 2>&1";
my $out = qx($psql_commandline 2>&1);
my $exitcode = $?;
unless ( $exitcode == 0 )
{
print STDERR "Could not create the DVN Postgres user role!\n";
print STDERR "(SQL: " . $sql_command . ")\n";
print STDERR "(psql exit code: " . $exitcode . ")\n";
print STDERR "(STDERR and STDOUT was: " . $out . ")\n";
exit 1;
}
unlink "/tmp/pgcmd.$$.tmp";
print "done.\n";
}
# 4f. CREATE DVN DB:
print "\nCreating Postgres database:\n";
my $psql_command =
$psql_exec
. "/createdb -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -U $CONFIG_DEFAULTS{'POSTGRES_USER'} "
. $CONFIG_DEFAULTS{'POSTGRES_DATABASE'}
. " --owner="
. $CONFIG_DEFAULTS{'POSTGRES_USER'};
my $out = qx($psql_command 2>&1);
my $exitcode = $?;
unless ( $exitcode == 0 )
{
print STDERR "Could not create Postgres database for the Dataverse app!\n";
print STDERR "(command: " . $psql_command . ")\n";
print STDERR "(psql exit code: " . $exitcode . ")\n";
print STDERR "(STDOUT and STDERR: " . $out . ")\n";
if ($force)
{
print STDERR "\n--force called, continuing\n";
}
else
{
print STDERR "\naborting the installation (sorry!)\n\n";
exit 1;
}
}
}
if ($postgresonly) {
print "\nOK, done.\n";
print "You can now resume the installation on the main Dataverse host.\n\n";
exit 0;
}
# Whether the user and the database were created locally or remotely, we'll now
# verify that we can talk to that database, with the credentials of the database
# user that we want the Dataverse application to be using:
if ( system( $psql_exec . "/psql -h " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . " -U " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . " -d " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . " -c 'SELECT * FROM pg_roles' > /dev/null 2>&1" ) )
{
print STDERR "Oops, haven't been able to connect to the database " . $CONFIG_DEFAULTS{'POSTGRES_DATABASE'} . ",\n";
print STDERR "running on " . $CONFIG_DEFAULTS{'POSTGRES_SERVER'} . ", as user " . $CONFIG_DEFAULTS{'POSTGRES_USER'} . ".\n\n";
print STDERR "Aborting the installation (sorry!)\n";
exit 1;
}
# 5. CONFIGURE GLASSFISH
my $glassfish_dir = $CONFIG_DEFAULTS{'GLASSFISH_DIRECTORY'};
print "\nProceeding with the Glassfish setup.\n";
# 5b. DETERMINE HOW MUCH MEMORY TO GIVE TO GLASSFISH AS HEAP:
my $gf_heap_default = "2048m";
my $sys_mem_total = 0;
if ( -e "/proc/meminfo" && open MEMINFO, "/proc/meminfo" ) {
# Linux
while ( my $mline = <MEMINFO> ) {
if ( $mline =~ /MemTotal:[ \t]*([0-9]*) kB/ ) {
$sys_mem_total = $1;
}
}
close MEMINFO;
}
elsif ( -x "/usr/sbin/sysctl" ) {
# MacOS X, probably...
$sys_mem_total = `/usr/sbin/sysctl -n hw.memsize`;
chop $sys_mem_total;
if ( $sys_mem_total > 0 ) {
$sys_mem_total = int( $sys_mem_total / 1024 );
# size in kb
}
}
if ( $sys_mem_total > 0 ) {
# setting the default heap size limit to 3/8 of the available
# amount of memory:
$gf_heap_default = ( int( $sys_mem_total / ( 8 / 3 * 1024 ) ) );
print "\nSetting the heap limit for Glassfish to " . $gf_heap_default . "MB. \n";
print "You may need to adjust this setting to better suit \n";
print "your system.\n\n";
#$gf_heap_default .= "m";
}
else {
print "\nCould not determine the amount of memory on your system.\n";
print "Setting the heap limit for Glassfish to 2GB. You may need \n";
print "to adjust the value to better suit your system.\n\n";
}
push @CONFIG_VARIABLES, "DEF_MEM_SIZE";