Академический Документы
Профессиональный Документы
Культура Документы
/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
# 1-JULY-2018
#--------------------------------------------------------------------------------
# GLOBAL VARIABLES
VERSION=4.5.18
GSHHG=2.3.7
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
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
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
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# 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
#--------------------------------------------------------------------------------
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
#--------------------------------------------------------------------------------
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
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
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"`
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"`
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"`
EOF
GMT_sharedir=`get_def_answer "Enter value of GMT_SHAREDIR selection" "$GMT_share"`
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
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
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
EOF
EOF
GMT_flock=`get_def_answer "Use POSIX Advisory File Locking in GMT4 (y/n)" "y"`
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
------------------------------------------------------------------------------
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
file=`get_def_answer "Enter name of the parameter file that will now be created"
"GMT4param.txt"`
#--------------------------------------------------------------------------------
# SAVE SESSION SETTINGS TO INSTALL.PAR
#--------------------------------------------------------------------------------
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
#============================================================
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
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
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
#--------------------------------------------------------------------------------
# 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 +++"
#--------------------------------------------------------------------------------
# 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
echo "Getting GMT4 by anonymous ftp from $ftp_ip (be patient)..." >&2
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
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# GMT4 INSTALLATION PREPARATIONS
#--------------------------------------------------------------------------------
cd $topdir
cd gmt-${GMT_version}
here=`pwd`
mkdir -p $GMT_share
if [ -w $GMT_share ]; then
write_share=1
else
write_share=0
fi
mkdir -p $GMT_bin
if [ -w $GMT_bin ]; then
write_bin=1
else
write_bin=0
fi
mkdir -p $GMT_man
if [ -w $GMT_man ]; then
write_man=1
else
write_man=0
fi
mkdir -p $GMT_doc
if [ -w $GMT_doc ]; then
write_doc=1
else
write_doc=0
fi
#--------------------------------------------------------------------------------
# CONFIGURE PREPARATION
#--------------------------------------------------------------------------------
EOF
rm -f config.{cache,log,status}
if [ -f src/config.mk ]; then
echo '---> Clean out old executables, *.o, *.a, and config.mk' >&2
$GMT_make spotless || exit
fi
if [ -d $GSHHG_path/gshhg-gmt-${GSHHG} ]; then
enable_gshhg=--with-gshhg-dir=$GSHHG_path/gshhg-gmt-${GSHHG}
elif [ -d $GSHHG_path/gshhg-gmt-nc4-${GSHHG} ]; then
enable_gshhg=--with-gshhg-dir=$GSHHG_path/gshhg-gmt-nc4-${GSHHG}
elif [ -d $GSHHG_path/gshhg-gmt-nc3-${GSHHG} ]; then
enable_gshhg=--with-gshhg-dir=$GSHHG_path/gshhg-gmt-nc3-${GSHHG}
else
enable_gshhg=--with-gshhg-dir=$GSHHG_path
fi
# Echo out the exact configure command for possible reuse by the user
if [ -f .gmtconfigure ]; then
cat .gmtconfigure
rm -f .gmtconfigure
fi
#--------------------------------------------------------------------------------
# INSTALL GMT4 AND SUPPLEMENTAL PROGRAMS
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# INSTALL DATA DIRECTORY
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# INSTALL MAN PAGES
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# INSTALL WWW PAGES
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# RUN EXAMPLES
#--------------------------------------------------------------------------------
# Run examples with /src as binary path in case the user did
# not have permission to place files in GMT_bin
cd $here/src
if [ $write_bin -eq 0 ]; then
echo "Manually do the final installs as another user (root?)" >&2
echo "Go to the main GMT4 directory and say:" >&2
echo "make install install-suppl clean" >&2
fi
if [ $write_share -eq 0 ]; then
echo "Manually do the coastline install as another user (root?)" >&2
echo "Go to the main GMT4 directory and say:" >&2
echo "make install-data" >&2
fi
if [ $write_man -eq 0 ]; then
echo "Manually do the man page install as another user (root?)" >&2
echo "Go to the main GMT4 directory and say:" >&2
echo "make install-man" >&2
fi
if [ $write_doc -eq 0 ]; then
echo "Manually do the doc page install as another user (root?)" >&2
echo "Go to the main GMT4 directory and say:" >&2
echo "make install-doc" >&2
fi
cd $topdir
if [ "$GMT_delete" = "y" ]; then
rm -f gmt-*.tar.$suffix gshhg-*.tar.$suffix
fi
-----------------------------------------------------------------------
For csh or tcsh users:
set path=($GMT_bin \$path)
EOF
if [ "$GMT_sharedir" != "$GMT_share" ]; then
echo setenv GMT_SHAREDIR $GMT_sharedir >&2
fi
cat << EOF >&2
Note: if you installed netCDF as a shared library you may have to add
the path to this library to LD_LIBRARY_PATH or place the library in a
standard system path [see information on shared library for your OS].
EOF
if [ "$GMT_sharedir" != "$GMT_share" ]; then
echo export GMT_SHAREDIR=$GMT_sharedir >&2
fi
cat << EOF >&2