summaryrefslogtreecommitdiff
path: root/setup.sh
blob: 5976e46a783fa905e2e4597f9505d03de42e7182 (plain)
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
#!/bin/bash -norc

PERL=perl
case "`uname -s`" in
Darwin )
  PERL=/usr/bin/perl
  ;;
esac

DIR="$( cd "$( dirname "$0" )" && pwd )"

cat <<EOF

Trying to establish local installations of any missing Perl modules
(as logged in $DIR/setup-deps.log).
Please be patient, as this step may take a little while.
EOF

cd "$DIR"

if ! "${PERL}" -Iaux/lib/perl5 -MMozilla::CA -e '1;' 2>/dev/null
then
  gzip -cd Mozilla-CA.tar.gz | tar xvf -
fi

mkdir -p _cpan/CPAN
echo '1;' >> _cpan/CPAN/MyConfig.pm
if ! "${PERL}" -I_cpan -Iaux/lib/perl5 setup-deps.pl </dev/null >setup-deps.log 2>&1
then
  if grep '^read timeout.*HTTP' setup-deps.log >/dev/null
  then
    cat <<EOF
Unable to access the Comprehensive Perl Archive Network.  You might
need to set http_proxy and/or ftp_proxy in your user environment.
Please consult your network administrator for suitable values.
EOF
  elif grep '^SSLeay\.xs:.*[Ee]rror:' setup-deps.log >/dev/null
  then
    cat <<EOF
Unable to build Net::SSLeay.  Please install either a prebuilt version
of this module or OpenSSL development files to build it against.
EOF
  fi
fi
rm -rf _cpan

osname=`uname -s`
cputype=`uname -m`
case "$osname-$cputype" in
  Linux-x86_64 )           platform=Linux ;;
  Darwin-x86_64 )          platform=Darwin ;;
  Darwin-*arm* )           platform=Darwin ;;
  CYGWIN_NT-* | MINGW*-* ) platform=CYGWIN_NT ;;
  Linux-*arm* )            platform=ARM ;;
  * )                      platform=UNSUPPORTED ;;
esac

if [ -n "$platform" ]
then
  ./nquire -dwn ftp.ncbi.nlm.nih.gov /entrez/entrezdirect xtract."$platform".gz
  gunzip -f xtract."$platform".gz
fi

if [ -f xtract."$platform" ]
then
  chmod +x xtract."$platform"
else
  echo "Unable to download xtract executable."
fi

if [ -n "$platform" ]
then
  ./nquire -dwn ftp.ncbi.nlm.nih.gov /entrez/entrezdirect transmute."$platform".gz
  gunzip -f transmute."$platform".gz
fi

if [ -f transmute."$platform" ]
then
  chmod +x transmute."$platform"
else
  echo "Unable to download transmute executable."
fi

if [ -n "$platform" ]
then
  ./nquire -dwn ftp.ncbi.nlm.nih.gov /entrez/entrezdirect rchive."$platform".gz
  gunzip -f rchive."$platform".gz
fi

if [ -f rchive."$platform" ]
then
  chmod +x rchive."$platform"
else
  echo "Unable to download rchive executable."
fi

echo ""
echo "Entrez Direct has been successfully downloaded and installed."
echo ""

prfx="In order to complete the configuration process, please execute the following:\n"
advice=`mktemp`

target=bash_profile
if ! grep "$target" "$HOME/.bashrc" >/dev/null 2>&1
then
  if [ ! -f $HOME/.$target ] || grep 'bashrc' "$HOME/.$target" >/dev/null 2>&1
  then
    target=bashrc
  else
    if [ -n "$prfx" ]
    then
      echo -e "$prfx"
      prfx=""
    fi
    echo "  echo \"source ~/.bash_profile\" >>" "\$HOME/.bashrc" | tee $advice
  fi
fi
if ! grep "PATH.*edirect" "$HOME/.$target" >/dev/null 2>&1
then
  if [ -n "$prfx" ]
  then
    echo -e "$prfx"
    prfx=""
  fi
  echo "  echo \"export PATH=\\\${PATH}:$DIR\" >>" "\$HOME/.$target" \
    | tee $advice
fi

if [ -z "$prfx" ]
then
echo ""
echo "or manually edit the PATH variable assignment in your .bash_profile file."
echo ""
echo "Would you like to do that automatically now? [y/N]"
read response
case "$response" in
  [Yy]*      ) . $advice; echo "OK, done." ;;
  [Nn]* | '' ) echo "Holding off, then." ;;
  *          ) echo "Conservatively taking that as a no." ;;
esac
fi
rm $advice