-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_gmt4.sh
executable file
·1168 lines (1005 loc) · 35.5 KB
/
install_gmt4.sh
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
#!/bin/sh
# $Id: install_gmt.sh 10118 2013-11-01 22:13:06Z pwessel $
#
# Automatic installation of GMT4
# Suitable for the Bourne shell (or compatible)
#
# Paul Wessel
# 28-OCT-2016
#--------------------------------------------------------------------------------
# GLOBAL VARIABLES
VERSION=4.5.14
GSHHG=2.2.4
GMT_FTP_TEST=0
GMT_SIZE=38
GSHHG_SIZE=45
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# FUNCTIONS
#--------------------------------------------------------------------------------
# Get the functionality of echo -n
#--------------------------------------------------------------------------------
if [ x`echo -n` = x ]; then # echo -n works
echon()
{
echo -n "$*"
}
elif [ x`echo -e` = x ]; then # echo -e works
echon()
{
echo -e "$*"'\c'
}
else # echo with escapes better work
echon()
{
echo "$*"'\c'
}
fi
# Question poser, return answer
#--------------------------------------------------------------------------------
get_answer()
{
# Arg1 is question
echon "==> $1: " >&2
read answer
echo $answer
}
#--------------------------------------------------------------------------------
# Question poser with default answer, return answer
#--------------------------------------------------------------------------------
get_def_answer()
{
# Arg1 is question, Argv2 is default answer
echon "==> $1 [$2]: " >&2
read answer
echo $answer $2 | awk '{print $1}'
}
check_for_bzip2()
{
if [ `bzip2 -h 2>&1 | wc -l` -lt 10 ]; then # Dont have bzip2
echo "ERROR: bzip2 not installed - exits" >&2
exit
fi
}
#--------------------------------------------------------------------------------
# INTERACTIVE GMT4 PARAMETER REQUEST SESSION
#--------------------------------------------------------------------------------
prep_gmt()
{
#--------------------------------------------------------------------------------
cat << EOF > gmt_install.ftp_site
1. SOEST, U of Hawaii [GMT Home], Honolulu, Hawaii, USA
2. NOAA, Lab for Satellite Altimetry, College Park, Maryland, USA
3. IRIS, Incorporated Research Institutions for Seismology, Seattle, Washington, USA
4. IAG-USP, Dept of Geophysics, U. of Sao Paulo, BRAZIL
5. Dept of Geosciences, U of Oslo, NORWAY
6. Goodie Domain Service, Vienna U of Techology, AUSTRIA
7. Tokai U, Shimizu, JAPAN
8. TENET, Tertiary Education & Research Networks of South Africa, SOUTH AFRICA
EOF
cat << EOF >&2
====>>>> Interactive installation of GMT4 <<<<====
We first need a questions and answer session to determine how
and where GMT4 is to be installed. Then, when all parameters
have been assembled, we will run the installation (unless you
chose -n when starting this script).
This script will install the latest version of GMT $VERSION.
EOF
GMT_version=$VERSION
N_EXAMPLES=30
topdir=`pwd`
os=`uname -s`
if [ "$os" = "Darwin" ]; then # Set default paths for OSX
if [ -d /sw/lib ]; then
# fink
LIBINC_DEF=/sw
else
# macports
LIBINC_DEF=/opt/local
fi
else
LIBINC_DEF=/usr/local
fi
#--------------------------------------------------------------------------------
# See if user has defined NETCDFHOME, if so use it as default path
#--------------------------------------------------------------------------------
netcdf_path=${NETCDFHOME:-}
check_for_bzip2
suffix="bz2"
expand="bzip2 -dc"
#--------------------------------------------------------------------------------
# MAKE UTILITY
#--------------------------------------------------------------------------------
GMT_make=`get_def_answer "Enter make utility to use" "make"`
#--------------------------------------------------------------------------------
# FTP MODE
#--------------------------------------------------------------------------------
passive_ftp=n
if [ $do_ftp_qa -eq 1 ]; then
cat << EOF >&2
If you are behind a firewall you will need to use a passive ftp session.
Only if you have some very old ftp client, you may have to resort to active ftp
(which involves the server connecting back to the client).
EOF
passive_ftp=`get_def_answer "Do you want passive ftp transmission (y/n)" "y"`
fi
#--------------------------------------------------------------------------------
# NETCDF SETUP
#--------------------------------------------------------------------------------
def=${NETCDFHOME:-$LIBINC_DEF}
netcdf_path=`get_def_answer "Enter directory with netcdf lib and include" "$def"`
#--------------------------------------------------------------------------------
# GDAL SETUP
#--------------------------------------------------------------------------------
cat << EOF >&2
GMT4 offers experimental and optional support for other grid formats
and plotting of geotiffs via GDAL. To use this option you must already
have the GDAL library and include files installed.
EOF
use_gdal=`get_def_answer "Use experimental GDAL grid input in GMT4 (y/n)" "y"`
if [ "$use_gdal" = "y" ]; then # Must get the path
cat <<- EOF >&2
If the dirs include and lib both reside in the same parent directory,
you can specify that below. If not, leave blank and manually set
the two environmental parameters GDAL_INC and GDAL_LIB.
EOF
def=${GDALHOME:-$LIBINC_DEF}
gdal_path=`get_def_answer "Enter directory with GDAL lib and include" "$def"`
else
gdal_path=
fi
#--------------------------------------------------------------------------------
# GSHHG SETUP
#--------------------------------------------------------------------------------
cat << EOF >&2
GMT4 requires the GSHHG coastlines, borders, and rivers netCDF file to operate.
GSHHG is a separate installation as it does not change as often as GMT4 itself.
If you already have GSHHG version $GSHHG then you just need to specify its
directory; otherwise say yes to obtain GSHHG via ftp and install it.
EOF
GSHHG_install=d
GSHHG_ftp=n
GSHHG_install=`get_def_answer "Install GSHHG version $GSHHG? (y/n)" "y"`
if [ $do_ftp_qa -eq 1 ]; then
GSHHG_ftp=`get_def_answer "Get the GSHHG version $GSHHG archive ($GSHHG_SIZE Mb) via ftp? (y/n)" "y"`
fi
if [ "$GSHHG_install" = "n" ]; then
GSHHG_path=`get_def_answer "Enter directory where GSHHG version $GSHHG can be found" "$topdir"`
else
GSHHG_path=`get_def_answer "Enter directory where GSHHG version $GSHHG should be placed" "$topdir"`
fi
#--------------------------------------------------------------------------------
# GMT4 FTP SECTION
#--------------------------------------------------------------------------------
GMT_ftpsite=1
GMT_ftp=n
GMT_inst_gmt=`get_def_answer "Install GMT version $GMT_version? (y/n)" "y"`
if [ $do_ftp_qa -eq 1 ]; then
GMT_ftp=`get_def_answer "Get the GMT version $GMT_version archive ($GMT_SIZE Mb) via ftp? (y/n)" "y"`
fi
if [ "$GMT_ftp" = "y" ] || [ "$GSHHG_ftp" = "y" ]; then
cat << EOF >&2
We offer $N_FTP_SITES different ftp sites. Choose the one nearest
you in order to minimize net traffic and transmission times.
The sites are:
EOF
cat gmt_install.ftp_site >&2
echo " " >&2
GMT_ftpsite=`get_def_answer "Enter your choice" "1"`
if [ $GMT_ftpsite -eq 0 ]; then
echo " [Special GMT4 guru testing site selected]" >&2
GMT_ftpsite=1
GMT_FTP_TEST=1
elif [ $GMT_ftpsite -lt 0 ] || [ $GMT_ftpsite -gt $N_FTP_SITES ]; then
GMT_ftpsite=1
echo " Error in assigning site, using default site." >&2
else
echo " You selected site number $GMT_ftpsite:" >&2
sed -n ${GMT_ftpsite}p gmt_install.ftp_site >&2
fi
echo " " >&2
ftp_ip=`sed -n ${GMT_ftpsite}p gmt_install.ftp_ip`
is_dns=`sed -n ${GMT_ftpsite}p gmt_install.ftp_dns`
if [ $is_dns -eq 1 ]; then
cat << EOF >&2
This anonymous ftp server $ftp_ip only accepts
connections from computers on the Internet that are registered
in the Domain Name System (DNS). If you encounter a problem
connecting because your computer is not registered, please
either use a different computer that is registered or see your
computer systems administrator (or your site DNS coordinator)
to register your computer.
EOF
fi
else
echo " " >&2
echo "Since ftp mode is not selected, the install procedure will" >&2
echo "assume the compressed archives are in the current directory." >&2
fi
echo "GMT4 can use two different algorithms for Delauney triangulation." >&2
echo " " >&2
echo " Shewchuk [1996]: Modern and very fast, copyrighted." >&2
echo " Watson [1982] : Older and slower, public domain." >&2
echo " " >&2
echo "Because of the copyright, GMT4 uses Watson's routine by default." >&2
echo "However, most will want to use the optional Shewchuk routine." >&2
GMT_triangle=`get_def_answer "Use optional Shewchuk's triangulation routine (y/n)?" "y"`
cat << EOF >&2
The installation will install all GMT4 components in several subdirectories
under one root directory. On most Unix systems this root directory will be
something like /usr/local or /sw, under which the installation will add
bin, lib, share, etc. Below you are asked to select to location of each
of the subdirectories.
EOF
GMT_bin=`get_def_answer "Directory for GMT4 executables?" "$topdir/gmt-${GMT_version}/bin"`
GMT_prefix=`echo $GMT_bin | sed 's!/bin!!'`
GMT_lib=`get_def_answer "Directory for GMT4 linkable libraries?" "$GMT_prefix/lib"`
GMT_include=`get_def_answer "Directory for GMT4 include files?" "$GMT_prefix/include"`
GMT_share=`get_def_answer "Directory for GMT4 data resources?" "$GMT_prefix/share"`
cat << EOF >&2
Unix man pages are usually stored in /usr/man/manX, where X is
the relevant man section. Below, you will be asked for the /usr/man part;
the /manX will be appended automatically, so do not answer /usr/man/man1.
EOF
GMT_man=`get_def_answer "Directory for GMT4 man pages?" "$GMT_prefix/man"`
GMT_doc=`get_def_answer "Directory for GMT4 doc pages?" "$GMT_prefix/share/doc/gmt"`
cat << EOF >&2
At run-time GMT4 will look in the directory $GMT_share to find configuration
and data files. That directory may appear with a different name to remote users
if a different mount point or a symbolic link is set.
GMT4 can use the environment variable \$GMT_SHAREDIR to point to the right place.
If users see a different location for the shared data files, specify it here.
(It will be used only to remind you at the end of the installation to set
the enronment variable \$GMT_SHAREDIR).
EOF
GMT_sharedir=`get_def_answer "Enter value of GMT_SHAREDIR selection" "$GMT_share"`
cat << EOF >&2
The answer to the following question will modify the GMT4 defaults.
(You can always change your mind by editing share/gmt.conf)
EOF
answer=`get_def_answer "Do you prefer SI or US default values for GMT4 (s/u)" "s"`
if [ "$answer" = "s" ]; then
GMT_si=y
else
GMT_si=n
fi
cat << EOF >&2
The answer to the following question will modify the GMT4 defaults.
(You can always change your mind later by using gmtset)
PostScript (PS) files may contain commands to set paper size, pick
a specific paper tray, or ask for manual feed. Encapsulated PS
files (EPS) are not intended for printers (but will print ok) and
can be included in other documents. Both formats will preview
on most previwers (out-of-date Sun pageview is an exception).
EOF
answer=`get_def_answer "Do you prefer PS or EPS as default PostScript output (p/e)" "p"`
if [ "$answer" = "p" ]; then
GMT_ps=y
else
GMT_ps=n
fi
cat << EOF >&2
Building the GMT4 libraries as shared instead of static will
reduce executable sizes considerably. GMT4 supports shared
libraries under Linux, Mac OS X, SunOS, Solaris, IRIX, HPUX,
and FreeBSD. Under other systems you may have to manually
configure macros and determine what specific options to use
with ld.
EOF
GMT_sharedlib=`get_def_answer "Try to make and use shared libraries? (y/n)" "n"`
cat << EOF >&2
If you have more than one C compiler you need to specify which,
otherwise just hit return to use the default compiler.
EOF
GMT_cc=`get_answer "Enter name of C compiler (include path if not in search path)"`
cat << EOF >&2
GMT4 can be built as 32-bit or 64-bit. We do not recommend to
explicitly choose 32-bit or 64-bit, as the netCDF install is
not set up to honor either of these settings. The default is
to compile without sending any 32-bit or 64-bit options to the
compiler, which generally create 32-bit versions on older systems,
and 64-bit versions on newer systems, like OS X Snow Leopard.
EOF
answer=`get_def_answer "Explicitly select 32- or 64-bit executables? (y/n)" "n"`
if [ $answer = y ]; then
GMT_64=`get_def_answer "Force 64-bit? (y/n) " "y"`
else
GMT_64=
fi
cat << EOF >&2
GMT4 passes information about previous GMT4 commands onto later
GMT4 commands via a hidden file (.gmtcommands). To avoid that
this file is updated by more than one program at the same time
(e.g., when connecting two or more GMT4 programs with pipes) we
use POSIX advisory file locking on the file. Apparently, some
versions of the Network File System (NFS) have not implemented
file locking properly. Although the behavior may be undefined
in this case, it should be safe to activate this option.
EOF
GMT_flock=`get_def_answer "Use POSIX Advisory File Locking in GMT4 (y/n)" "y"`
GMT_run_examples=`get_def_answer "Want to test GMT4 by running the $N_EXAMPLES examples? (y/n)" "y"`
GMT_delete=`get_def_answer "Delete all tar files after install? (y/n)" "n"`
# export CONFIG_SHELL=`type sh | awk '{print $NF}'`
GMT_suppl_mex=d
GMT_suppl_xgrid=d
if [ ! "X$MATLAB" = "X" ]; then
MATDIR=$MATLAB
elif [ "$os" = "Darwin" ]; then # Pick one from Applications folder
(echo /Applications/MATLAB* | grep -v '\*' | head -1 > /tmp/$$.matlab) 2> /dev/null
if [ ! -s /tmp/$$.matlab ]; then
MATDIR=`cat /tmp/$$.matlab`
else
MATDIR=/usr/local/matlab
fi
rm -f /tmp/$$.matlab
else
MATDIR=/usr/local/matlab
fi
if [ ! $GMT_get_suppl = "n" ]; then
cat << EOF >&2
Several supplemental packages are included in the archive:
------------------------------------------------------------------------------
dbase: Extracting data from NGDC DEM and other grids
gshhg: Global Self-consistent Hierarchical High-resolution Geography extractor
imgsrc: Extracting grids from global altimeter files (Sandwell/Smith)
meca: Plotting special symbols in seismology and geodesy
mex: Interface for reading/writing GMT grdfiles (REQUIRES MATLAB or OCTAVE)
mgd77: Programs for handling MGD77 data files
mgg: Programs for making, managing, and plotting .gmt files
misc: Digitize or stitch line segments, read netCDF 1-D tables, and more
EOF
if [ $SERIES -eq 5 ]; then
cat <<- EOF >&2
potential: Geopotential tools
EOF
fi
cat << EOF >&2
segyprogs: Plot SEGY seismic data files
sph: Spherical triangulation, Voronoi construction and interpolation
spotter: Plate tectonic backtracking and hotspotting
x2sys: New (Generic) Track intersection (crossover) tools
x_system: Old (MGG-specific) Track intersection (crossover) tools
xgrid: An X11-based graphical editor for netCDF-based .nc files
------------------------------------------------------------------------------
Supplements that only depend on GMT4 will be installed. Because others depend on
libraries outside GMT4 we ask if you want to install these supplements separately.
EOF
GMT_suppl_mex=`get_def_answer "Install the mex supplemental package? (y/n)?" "y"`
GMT_suppl_xgrid=`get_def_answer "Install the xgrid supplemental package? (y/n)?" "y"`
if [ "$GMT_suppl_mex" = "y" ]; then
echo " " >&2
echo "The mex supplement requires Matlab or Octave." >&2
GMT_mex_type=`get_def_answer "Specify matlab or octave" "octave"`
if [ "$GMT_mex_type" = "matlab" ];then
MATDIR=`get_def_answer "Enter MATLAB system directory" "$MATDIR"`
fi
echo "Hit return for default paths or provide the alternative paths for matlab/Octave files:" >&2
mex_mdir=`get_def_answer "Enter Install directory for .m functions" ""`
mex_xdir=`get_def_answer "Enter Install directory for .mex functions" ""`
fi
fi
file=`get_def_answer "Enter name of the parameter file that will now be created" "GMT4param.txt"`
if [ $GMT_FTP_TEST -eq 1 ]; then
GMT_ftpsite=0
fi
#--------------------------------------------------------------------------------
# SAVE SESSION SETTINGS TO INSTALL.PAR
#--------------------------------------------------------------------------------
cat << EOF > $file
# This file contains parameters needed by the install script
# for GMT4 Version ${GMT_version}. Give this parameter file
# as the argument to the install_gmt.sh script and the whole
# installation process can be placed in the background.
# Default answers will be selected where none is given.
# You can edit the values, but do not remove definitions!
#
# This script was created by install_gmt.sh on
#
EOF
date | awk '{printf "#\t%s\n", $0}' >> $file
cat << EOF >> $file
#
# Do NOT add any spaces around the = signs. The
# file MUST conform to Bourne shell syntax
#---------------------------------------------
# GMT4 VERSION TO INSTALL
#---------------------------------------------
VERSION=$GMT_version
#---------------------------------------------
# SYSTEM UTILITIES AND FTP SETTING
#---------------------------------------------
GMT_make=$GMT_make
passive_ftp=$passive_ftp
#---------------------------------------------
# NETCDF SECTION
#---------------------------------------------
netcdf_path=$netcdf_path
#---------------------------------------------
# GSHHG SECTION
#---------------------------------------------
GSHHG_install=$GSHHG_install
GSHHG_ftp=$GSHHG_ftp
GSHHG_path=$GSHHG_path
#---------------------------------------------
# GDAL SECTION
#---------------------------------------------
use_gdal=$use_gdal
gdal_path=$gdal_path
#---------------------------------------------
# GMT4 & GSHHG FTP SECTION
#---------------------------------------------
GMT_ftp=$GMT_ftp
GMT_inst_gmt=$GMT_inst_gmt
GMT_ftpsite=$GMT_ftpsite
#---------------------------------------------
# GMT4 SUPPLEMENTS SELECT SECTION
#---------------------------------------------
GMT_suppl_mex=$GMT_suppl_mex
GMT_suppl_xgrid=$GMT_suppl_xgrid
#---------------------------------------------
# GMT4 ENVIRONMENT SECTION
#---------------------------------------------
GMT_si=$GMT_si
GMT_ps=$GMT_ps
GMT_prefix=$GMT_prefix
GMT_bin=$GMT_bin
GMT_lib=$GMT_lib
GMT_share=$GMT_share
GMT_include=$GMT_include
GMT_man=$GMT_man
GMT_doc=$GMT_doc
GMT_sharedir=$GMT_sharedir
#---------------------------------------------
# COMPILING & LINKING SECTION
#---------------------------------------------
GMT_sharedlib=$GMT_sharedlib
GMT_cc=$GMT_cc
GMT_64=$GMT_64
GMT_triangle=$GMT_triangle
GMT_flock=$GMT_flock
#---------------------------------------------
# TEST & PRINT SECTION
#---------------------------------------------
GMT_run_examples=$GMT_run_examples
GMT_delete=$GMT_delete
#---------------------------------------------
# MEX SECTION
#---------------------------------------------
MATDIR=$MATDIR
mex_mdir=$mex_mdir
mex_xdir=$mex_xdir
EOF
echo "Session parameters written to file $file" >&2
echo $file
}
#--------------------------------------------------------------------------------
# BACKGROUND INSTALLATION OF GMT4 FUNCTIONS
#--------------------------------------------------------------------------------
install_this_gmt()
# Get? File
{
ok=1
if [ -f gmt-${GMT_version}-src.tar.$suffix ]; then
this=gmt-${GMT_version}-src.tar.$suffix
else
ok=0
fi
if [ $ok -eq 1 ]; then # File exists and we have not said no
$expand $this | tar xvf -
fi
ok=1
if [ -f gmt-${GMT_version}-non-gpl-src.tar.$suffix ]; then
this=gmt-${GMT_version}-non-gpl-src.tar.$suffix
else
ok=0
fi
if [ $ok -eq 1 ]; then # File exists and we have not said no
$expand $this | tar xvf -
fi
}
install_gshhg()
{
# Get? dir
dir=$1
here=`pwd`
ok=1
done=0
if [ -f gshhg-gmt-${GSHHG}.tar.gz ]; then
this=gshhg-gmt-${GSHHG}.tar.gz
expander="gzip -dc"
elif [ -f gshhg-gmt-nc4-${GSHHG}.tar.gz ]; then
this=gshhg-gmt-nc4-${GSHHG}.tar.gz
expander="gzip -dc"
elif [ -f gshhg-gmt-nc3-${GSHHG}.tar.$suffix ]; then
this=gshhg-gmt-nc3-${GSHHG}.tar.$suffix
expander=$expand
else
ok=0
fi
if [ $ok -eq 1 ]; then # File is present and wanted
if [ ! -d $dir ]; then
mkdir -p $dir
fi
if [ ! -d $dir ]; then
echo "Could not make the directory $dir - $this not untarred"
else
cd $dir
$expander $here/$this | tar xvf -
done=1
cd $here
fi
fi
}
make_ftp_list()
{
# arg1=get arg2=prefix
get_this=$1
pre=$2
if [ "$get_this" = "y" ]; then
echo "get ${pre}.tar.$suffix" >> gmt_install.ftp_list
fi
}
#============================================================
# START OF MAIN SCRIPT - INITIALIZATION OF PARAMETERS
#============================================================
trap "rm -f gmt_install.ftp_*; exit" 0 2 15
DIR=pub/gmt
#--------------------------------------------------------------------------------
# LISTING OF CURRENT FTP MIRROR SITES
#--------------------------------------------------------------------------------
N_FTP_SITES=8
cat << EOF > gmt_install.ftp_ip
ftp.soest.hawaii.edu
ftp.star.nesdis.noaa.gov
ftp.iris.washington.edu
ftp.iag.usp.br
ftp.geologi.uio.no
gd.tuwien.ac.at
ftp.scc.u-tokai.ac.jp
gmt.mirror.ac.za
EOF
cat << EOF > gmt_install.ftp_dns
1
1
0
0
0
0
1
0
0
EOF
#--------------------------------------------------------------------------------
give_help=0
if [ $# -gt 0 ]; then
if [ "X$1" = "X-h" ] || [ "X$1" = "X-help" ] || [ "X$1" = "X--help" ]; then
give_help=1
fi
fi
if [ $give_help -eq 1 ]; then
cat << EOF >&2
install_gmt.sh - Automatic installation of GMT4
GMT4 is installed in the background following the gathering
of installation parameters. These parameters are obtained
in one of two ways:
(1) Via Internet: You may compose a parameter file using
the form on the GMT4 home page (see the installation
link under gmt.soest.hawaii.edu) and save the result
of your request to a parameter file on your hard disk.
2) Interactively: You may direct this script to start an
interactive session which gathers information from you
via a question-and-answer dialog and then saves your
answers to a parameter file on your hard disk.
The parameter file is then passed on to the next stage which
carries out the installation without further interruptions.
Thus, two forms of the command are recognized:
install_gmt.sh [ -c ] parameterfile [ &> logfile] (for background install)
install_gmt.sh [ -c ] [ -n ] [ &> logfile] (for interactive install)
The option -n means do NOT install, just gather the parameters.
The option -c means all tar archices are already in current directory
and there is no need to ask questions regarding ftp transfers.
Of course, there is also
install_gmt.sh -h (to display this message)
EOF
exit
fi
do_install=1
do_ftp_qa=1
if [ $# -ge 1 ] && [ "$1" = "-n" ]; then # Do not want to install yet
do_install=0
shift
fi
if [ $# -ge 1 ] && [ "$1" = "-c" ]; then # Local install from cwd - turn off ftp questions
do_ftp_qa=0
shift
fi
if [ $# -eq 1 ] && [ "$1" != "-h" ]; then # User gave a parameter file
parfile=$1
if [ ! -f $parfile ]; then
echo "install_gmt.sh: Parameter file $parfile not found" >&2
exit
fi
else # We must run an interactive session first
parfile=`prep_gmt`
if [ $do_install -eq 0 ]; then # Did not want to install yet
exit
fi
answer=`get_answer "Hit return to start the install"`
fi
#--------------------------------------------------------------------------------
# INITIATE SETTINGS FROM PARAMETER FILE
#--------------------------------------------------------------------------------
#
# Because arguments to the . command MUST be in the users PATH
# we must prepend ./ if the file is in the local directory since
# the user may not have . in his PATH
first=`echo $parfile | awk '{print substr($1,1,1)}'`
if [ "$first" = "/" ]; then # absolute path OK
. $parfile
else # Local file, prepend ./
. ./$parfile
fi
GMT_version=$VERSION
SERIES=`echo $GMT_version | awk '{print substr($1,1,1)}'`
topdir=`pwd`
os=`uname -s`
check_for_bzip2
suffix="bz2"
expand="bzip2 -dc"
echo "+++ Will expand *.bz2 files made with bzip2 +++"
CONFIG_SHELL=`type sh | awk '{print $NF}'`
export CONFIG_SHELL
#--------------------------------------------------------------------------------
# NETCDF SECTION
#--------------------------------------------------------------------------------
if [ ! x"$NETCDF_INC" = x ] && [ ! x"$NETCDF_LIB" = x ]; then # Only set up path if these are not set
echo "install_gmt.sh: Using NETCDF_INC=$NETCDF_INC and NETCDF_LIB=$NETCDF_LIB to find netcdf support"
elif [ x"$netcdf_path" = x ]; then # Not explicitly set, must assign it
echo "install_gmt.sh: Let configure determine netcdf support"
else
echo "install_gmt.sh: Use $netcdf_path for netcdf support"
fi
#--------------------------------------------------------------------------------
# GMT4 FTP SECTION
#--------------------------------------------------------------------------------
cd $topdir
if [ "$GMT_ftp" = "y" ] || [ "$GSHHG_ftp" = "y" ]; then
if [ $GMT_ftpsite -eq 0 ]; then
GMT_ftpsite=1
echo " [Special GMT4 guru ftp site selected]" >&2
GMT_FTP_TEST=1
fi
if [ $GMT_ftpsite -lt 0 ] || [ $GMT_ftpsite -gt $N_FTP_SITES ]; then
GMT_ftpsite=1
echo " Error in assigning site, use default site $GMT_ftpsite" >&2
fi
if [ $GMT_ftpsite -eq 1 ]; then # SOEST's server starts at / and there is no pub
if [ $GMT_FTP_TEST -eq 1 ]; then # Special dir for guru testing
DIR=gmttest/4
else
DIR=gmt
fi
elif [ $GMT_ftpsite -eq 2 ]; then # NOAA's server uses different subdir
DIR=pub/sod/lsa/gmt
fi
ftp_ip=`sed -n ${GMT_ftpsite}p gmt_install.ftp_ip`
is_dns=`sed -n ${GMT_ftpsite}p gmt_install.ftp_dns`
# Determine if client's ftp is set to active or passive mode by default
echo passive | \ftp | grep off > /dev/null
active=$?
# Set-up ftp command; active above will be 0 if passive is off
echo "user anonymous $USER@" > gmt_install.ftp_list
if [ "$passive_ftp" = "y" ] && [ $active -eq 0 ]; then
echo "passive" >> gmt_install.ftp_list
echo "quote pasv" >> gmt_install.ftp_list
if [ "$os" = "Darwin" ]; then # Seems to need this now
echo "epsv" >> gmt_install.ftp_list
fi
fi
echo "cd $DIR" >> gmt_install.ftp_list
echo "binary" >> gmt_install.ftp_list
make_ftp_list $GMT_ftp gmt-${GMT_version}-src
make_ftp_list $GMT_triangle gmt-${GMT_version}-non-gpl-src
if [ $GSHHG_ftp = y ]; then
echo "get gshhg-gmt-${GSHHG}.tar.gz" >> gmt_install.ftp_list
fi
echo "quit" >> gmt_install.ftp_list
echo " " >> gmt_install.ftp_list
# Get the files
echo "Getting GMT4 by anonymous ftp from $ftp_ip (be patient)..." >&2
before=`du -sk . | cut -f1`
ftp -dn $ftp_ip < gmt_install.ftp_list || ( echo "fpt failed - try again later >&2"; exit )
after=`du -sk . | cut -f1`
rm -f gmt_install.ftp_list
newstuff=`echo $before $after | awk '{print $2 - $1}'`
echo "Got $newstuff kb ... done" >&2
fi
# If we got here via a parameter file that had blank answers
# we need to provide the default values here
GMT_prefix=${GMT_prefix:-$topdir/gmt-${GMT_version}}
GMT_bin=${GMT_bin:-$GMT_prefix/bin}
GMT_lib=${GMT_lib:-$GMT_prefix/lib}
GMT_share=${GMT_share:-$GMT_prefix/share}
GMT_include=${GMT_include:-$GMT_prefix/include}
GMT_man=${GMT_man:-$GMT_prefix/man}
GMT_doc=${GMT_doc:-$GMT_prefix/share/doc/gmt}
GMT_sharedir=${GMT_sharedir:-$GMT_share}
GSHHG_path=${GSHHG_path:-$topdir}
#--------------------------------------------------------------------------------
# First install source code and documentation
#--------------------------------------------------------------------------------
if [ "$GMT_inst_gmt" = "y" ]; then
install_this_gmt
fi
#--------------------------------------------------------------------------------
# Now do coastline archives
#--------------------------------------------------------------------------------
if [ "$GSHHG_install" = "y" ]; then
install_gshhg $GSHHG_path
fi
echo " " >&2
echo "Set write privileges on all files in gmt-${GMT_version} ..." >&2
cd gmt-${GMT_version}
chmod -R +w .
cd ..
echo "Done" >&2
echo " " >&2
#--------------------------------------------------------------------------------
# GMT4 INSTALLATION PREPARATIONS
#--------------------------------------------------------------------------------
cd $topdir
cd gmt-${GMT_version}
here=`pwd`
# Are we allowed to write in $GMT_share?
mkdir -p $GMT_share
if [ -w $GMT_share ]; then
write_share=1
else
write_share=0
fi
# Are we allowed to write in $GMT_bin?
mkdir -p $GMT_bin
if [ -w $GMT_bin ]; then
write_bin=1
else
write_bin=0
fi
# Are we allowed to write in $GMT_man?
mkdir -p $GMT_man
if [ -w $GMT_man ]; then
write_man=1
else
write_man=0
fi
# Are we allowed to write in $GMT_doc?
mkdir -p $GMT_doc
if [ -w $GMT_doc ]; then
write_doc=1
else
write_doc=0
fi
#--------------------------------------------------------------------------------
# CONFIGURE PREPARATION
#--------------------------------------------------------------------------------
if [ "$GMT_si" = "y" ]; then
enable_us=
else
enable_us=--enable-US
fi
if [ "$GMT_ps" = "y" ]; then
enable_eps=
else
enable_eps=--enable-eps
fi
if [ "$GMT_flock" = "y" ]; then
disable_flock=
else
disable_flock=--disable-flock
fi
if [ "$GMT_triangle" = "y" ]; then
enable_triangle=--enable-triangle
else
enable_triangle=
fi
if [ "$GMT_suppl_mex" = "y" ]; then
disable_mex=
else
disable_mex=--disable-mex
fi
if [ "$GMT_suppl_xgrid" = "y" ]; then
disable_xgrid=
else
disable_xgrid=--disable-xgrid
fi
if [ "$GMT_sharedlib" = "y" ]; then
enable_shared=--enable-shared
else
enable_shared=
fi
if [ "$GMT_64" = "y" ]; then
enable_64=--enable-64
elif [ "$GMT_64" = "n" ]; then
enable_64=--disable-64
else
enable_64=
fi
if [ ! x"$MATDIR" = x ]; then # MATDIR is set
if [ "X$GMT_mex_type" = "Xmatlab" ]; then
enable_matlab=--enable-matlab=$MATDIR
else
enable_matlab=--enable-octave=yes
fi
else
enable_matlab=
fi
if [ ! x"$mex_mdir" = x ]; then # mex_mdir is set
enable_mex_mdir=--enable-mex-mdir=$mex_mdir
else
enable_mex_mdir=
fi
if [ ! x"$mex_xdir" = x ]; then # mex_xdir is set
enable_mex_xdir=--enable-mex-xdir=$mex_xdir
else
enable_mex_xdir=
fi
# Experimental GDAL support
if [ "$use_gdal" = "y" ]; then # Try to include GDAL support
if [ ! "x$gdal_path" = "x" ]; then # GDAL parent dir specified
enable_gdal=--enable-gdal=$gdal_path
else
enable_gdal=--enable-gdal
fi
else
enable_gdal=
fi
#--------------------------------------------------------------------------------
# GMT4 installation commences here
#--------------------------------------------------------------------------------
cat << EOF >&2
---> Begin GMT $GMT_version installation <---
---> Run configure to create config.mk and gmt_notposix.h
EOF
# Clean out old cached values
rm -f config.{cache,log,status}
# Clean out old config.mk etc if present