generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 29
/
morphirw
executable file
·93 lines (71 loc) · 2.03 KB
/
morphirw
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
#!/usr/bin/env bash
# Download and run the Morphir launcher jar.
#
# The launcher jar downloads the other jars that are required for Morphir development.
#
# The version of the launcher jar can be set from MORPHIR_VERSION or the .morphir-version file.
#
# Order of precedence for launcher jar version is
# - MORPHIR_VERSION env variable
# - contents of version file .morphir-version
# - the default from this file
set -euo pipefail
#set -x
FALLBACK_MORPHIR_VERSION=0.2.1
MORPHIR_VERSION_FILE=.morphir-version
CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}/morphir/launcher"
URL_FMT=https://repo1.maven.org/maven2/org/finos/morphir/morphir-tools-launcher_2.13/%s/morphir-tools-launcher_2.13-%s-assembly.jar
_log() {
echo $* >/dev/stderr
echo >/dev/stderr
}
_advise_version_is_from() {
local ver="$1"
local src="$2"
_log Using Morphir launcher version $ver set from $src...
}
_version_from_env() {
if [[ -n "${MORPHIR_VERSION+x}" ]]; then
_advise_version_is_from $MORPHIR_VERSION "MORPHIR_VERSION environment variable"
echo $MORPHIR_VERSION
else
return 1
fi
}
_version_from_file() {
if [[ -r "$MORPHIR_VERSION_FILE" ]]; then
local ver="$(cat "$MORPHIR_VERSION_FILE")"
_advise_version_is_from $ver "file $MORPHIR_VERSION_FILE"
echo $ver
else
return 1
fi
}
_version_fallback() {
_advise_version_is_from $FALLBACK_MORPHIR_VERSION "hard-coded default"
echo $FALLBACK_MORPHIR_VERSION
}
morphir_version() {
_version_from_env || _version_from_file || _version_fallback
}
curl_download() {
local url="$1"
local target="$2"
mkdir -p "$(dirname $target)"
_log Downloading $url to $target...
curl -Sf -o "$target" "$url"
_log
}
launcher_jar_url() {
local ver="$1"
printf $URL_FMT $ver $ver
}
main() {
local ver="$(morphir_version)"
local url="$(launcher_jar_url "$ver")"
local jar="$CACHE_HOME/$ver.jar"
[[ ! -r "$jar" ]] && curl_download "$url" "$jar"
_log Running $jar...
java -jar "$jar"
}
main