-
Notifications
You must be signed in to change notification settings - Fork 2
/
dockstore
251 lines (208 loc) · 8.04 KB
/
dockstore
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
#!/usr/bin/env bash
set -o errexit
# Ensure this file is executable via `chmod a+x dockstore`, then place it
# somewhere on your $PATH, like ~/bin. The rest of SeqWare will be
# installed upon first run into the ~/.dockstore directory.
# Encase variables inside brackets to prevent issues.
# $DOCKSTORE_VERSION would cause problems if $DOCKSTORE exists. ${DOCKSTORE_VERSION} would be better.
DEFAULT_DOCKSTORE_VERSION="1.3.6"
export DOCKSTORE_VERSION="${DOCKSTORE_VERSION:-"$DEFAULT_DOCKSTORE_VERSION"}"
case ${DOCKSTORE_VERSION} in
*SNAPSHOT) SNAPSHOT="YES" ;;
*) SNAPSHOT="NO" ;;
esac
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
delimiter=";"
else
delimiter=":"
fi
if [[ "$OSTYPE" == "cygwin" ]]; then
cygwin=true
else
cygwin=false
fi
if [ `id -u` -eq 0 ] && [ "$DOCKSTORE_ROOT" = "" ]; then
echo "WARNING: You're currently running as root; probably by accident."
echo "Press control-C to abort or Enter to continue as root."
echo "Set DOCKSTORE_ROOT to disable this warning."
read _
fi
export DOCKSTORE_HOME="${DOCKSTORE_HOME:-"$HOME/.dockstore"}"
# export DOCKSTORE_HOME="${DOCKSTORE_HOME:-"$HOME/dockstore"}"
if ${cygwin}; then
export DOCKSTORE_HOME=`cygpath -w "$DOCKSTORE_HOME"`
fi
export DOCKSTORE_JAR="$DOCKSTORE_HOME/self-installs/dockstore-client-$DOCKSTORE_VERSION.jar"
export DOCKSTORE_SETTINGS="${DOCKSTORE_SETTINGS:-"$DOCKSTORE_HOME/config"}"
# normalize $0 on certain BSDs
if [ "$(dirname "$0")" = "." ]; then
if ! SCRIPT="$(which $(basename "$0"))"; then
if [[ "$@" != *"--script"* ]]; then
(>&2 echo "dockstore needs to be on PATH for certain commands to work (like --upgrade)")
fi
fi
else
SCRIPT="$0"
fi
# resolve symlinks to the script itself portably
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT="$(dirname "$SCRIPT"$)/$link"
fi
done
function make_native_path {
# ensure we have native paths
if ${cygwin} && [[ "$1" == /* ]]; then
echo -n "$(cygpath -wp "$1")"
elif [[ "$OSTYPE" == "msys" && "$1" == /* ]]; then
echo -n "$(sh -c "(cd $1 2</dev/null && pwd -W) || echo $1 | sed 's/^\\/\([a-z]\)/\\1:/g'")"
else
echo -n "$1"
fi
}
# usage : add_path PATH_VAR [PATH]...
function add_path {
local path_var="$1"
shift
while [ -n "$1" ];do
# http://bashify.com/?Useful_Techniques:Indirect_Variables:Indirect_Assignment
export ${path_var}="${!path_var}${delimiter}$(make_native_path "$1")"
shift
done
}
add_path CLASSPATH "$DOCKSTORE_JAR"
BOOTCLASSPATH="-Xbootclasspath/a:$DOCKSTORE_JAR"
if [ ! -r "$DOCKSTORE_JAR" -a "$1" != "self-install" -a "$1" != "self-check-install" -a "$1" != "init" ]; then
"$0" self-install
if [ $? != 0 ]; then
exit $?
fi
fi
if [ ! -r "$DOCKSTORE_SETTINGS" -a "$1" != "self-install" -a "$1" != "self-check-install" -a "$1" != "init" ]; then
"$0" init
exit $?
fi
if [ "$HTTP_CLIENT" = "" ]; then
if type -p curl >/dev/null 2>&1; then
if [ "$https_proxy" != "" ]; then
CURL_PROXY="-x $https_proxy"
fi
HTTP_CLIENT="curl --retry 20 $CURL_PROXY -f -L -o"
else
HTTP_CLIENT="wget -O"
fi
fi
# TODO: explain what to do when Java is missing
export JAVA_CMD="${JAVA_CMD:-"java"}"
# Support $JAVA_OPTS for backwards-compatibility.
export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"
# Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62
cygterm=false
if ${cygwin}; then
case "$TERM" in
rxvt* | xterm* | vt*) cygterm=true ;;
esac
fi
if ${cygterm}; then
JVM_OPTS="$JVM_OPTS -Djline.terminal=jline.UnixTerminal"
stty -icanon min 1 -echo > /dev/null 2>&1
fi
function download_failed_message {
echo "Failed to download $1"
echo "It's possible your HTTP client's certificate store does not have the"
echo "correct certificate authority needed. This is often caused by an"
echo "out-of-date version of libssl. Either upgrade it or set HTTP_CLIENT"
echo "to turn off certificate checks:"
echo " export HTTP_CLIENT=\"wget --no-check-certificate -O\" # or"
echo " export HTTP_CLIENT=\"curl --insecure -f -L -o\""
echo "It's also possible that you're behind a firewall haven't yet"
echo "set HTTP_PROXY and HTTPS_PROXY."
}
if [ "$1" = "self-install" ]; then
if [ -r "$DOCKSTORE_JAR" ]; then
echo "The self-install jar already exists at $DOCKSTORE_JAR."
echo "If you wish to re-download, delete it and rerun \"$0 self-install\"."
exit 1
fi
(>&2 echo "Downloading Dockstore to $DOCKSTORE_JAR now...")
mkdir -p "$(dirname "$DOCKSTORE_JAR")"
if [ ${SNAPSHOT} = "YES" ]; then
DOCKSTORE_URL="file:///$HOME/.m2/repository/io/dockstore/dockstore-client/$DOCKSTORE_VERSION/dockstore-client-$DOCKSTORE_VERSION-shaded.jar"
elif [ -r "/$HOME/.m2/repository/io/dockstore/dockstore-client/$DOCKSTORE_VERSION/dockstore-client-$DOCKSTORE_VERSION-shaded.jar" ]; then
# for testing, if you have a local release version, just use it
DOCKSTORE_URL="file:///$HOME/.m2/repository/io/dockstore/dockstore-client/$DOCKSTORE_VERSION/dockstore-client-$DOCKSTORE_VERSION-shaded.jar"
else
# DOCKSTORE_URL="https://artifacts.oicr.on.ca/artifactory/collab-release/io/dockstore/dockstore-client/$DOCKSTORE_VERSION/dockstore-client-$DOCKSTORE_VERSION-shaded.jar"
DOCKSTORE_URL="https://github.com/ga4gh/dockstore/releases/download/$DOCKSTORE_VERSION/dockstore-client-$DOCKSTORE_VERSION-shaded.jar"
fi
(>&2 echo "$DOCKSTORE_URL")
${HTTP_CLIENT} "$DOCKSTORE_JAR.pending" "$DOCKSTORE_URL"
if [ $? == 0 ]; then
# TODO: checksum
mv -f "$DOCKSTORE_JAR.pending" "$DOCKSTORE_JAR"
else
rm "$DOCKSTORE_JAR.pending" 2> /dev/null
download_failed_message "$DOCKSTORE_URL"
exit 1
fi
elif [ "$1" = "init" ]; then
if [ -r "$DOCKSTORE_SETTINGS" ]; then
echo "The Dockstore settings file already exists at $DOCKSTORE_SETTINGS."
echo "If you wish to re-initialize, delete it and rerun \"$0 init\"."
exit 1
fi
echo "DOCKSTORE COMMAND LINE"
echo "----------------------"
echo "Welcome to the command line tool for the Dockstore. This bootstrap process will"
echo "ask you a few questions, download, and configure the command line tool."
echo
echo
echo "Have you setup an account at http://www.dockstore.org/?"
echo -n "Y/N> "
read HASACCOUNT
if [ "$HASACCOUNT" = "Y" ] || [ "$HASACCOUNT" = "y" ]; then
mkdir -p "$(dirname "$DOCKSTORE_SETTINGS")"
touch ${DOCKSTORE_SETTINGS}
chmod 600 ${DOCKSTORE_SETTINGS}
echo
echo "What is your token?"
read TOKEN
echo "token: $TOKEN" >> ${DOCKSTORE_SETTINGS}
echo "What is your server-url?"
read SERVER_URL
echo "server-url: $SERVER_URL" >> ${DOCKSTORE_SETTINGS}
echo
echo "Created Dockstore settings file at $DOCKSTORE_SETTINGS"
echo
echo "Downloading default file-provisioning plugins"
${JAVA_CMD} ${DOCKSTORE_JVM_OPTS} io.dockstore.client.cli.Client plugin download
echo "Dockstore is ready to use!"
else
echo "Please setup an account at http://www.dockstore.org/"
fi
else
# from https://stackoverflow.com/questions/7334754/correct-way-to-check-java-version-from-bash-script
if type -p java > /dev/null; then
_java=java
else
echo "Java was not installed or is not on your PATH."
exit -100;
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
if [[ "$version" < "1.8" ]]; then
echo "Dockstore requires Java version 1.8 and above."
exit -100;
fi
fi
${JAVA_CMD} ${DOCKSTORE_JVM_OPTS} io.dockstore.client.cli.Client "$@"
EXIT_CODE=$?
if ${cygterm} ; then
stty icanon echo > /dev/null 2>&1
fi
exit $EXIT_CODE
fi