forked from EthVM/EthVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh
executable file
·149 lines (107 loc) · 4.25 KB
/
env.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
#!/usr/bin/env bash
# Give script sane defaults
set -o errexit
# set -o nounset
if [ "${TRACE:-}" == "true" ]; then
set -o xtrace
set -o verbose
fi
# Export common vars
ORG="${ORG:-ethvm}"
ROOT_DIR=$(cd ${SCRIPT_DIR}/..; pwd)
APPS_PATH="${ROOT_DIR}/apps"
DOCKER_IMAGES_PATH="${ROOT_DIR}/docker/images"
DOCKER_RUN_META_PATH="${SCRIPT_DIR}/docker-run-envs/docker-run.meta.json"
DOCKER_BUILD_META_PATH="${SCRIPT_DIR}/docker-build.meta.json"
# ---------------------------------------------------------
# Helper Functions
# ---------------------------------------------------------
# prop - read .properties files and search elements by key
prop() {
local path=${1}
local key=${2:-'version'}
grep ${key} ${path} | cut -d '=' -f2 | sed "s/'/ /g"
}
# to_version - tries to find the version, depending on the extension name
to_version() {
if [[ "$1" =~ \.properties$ ]]; then
echo $(prop "$1")
else
echo $(jq -r '.version' "$1")
fi
}
read_version() {
local raw_version_path=$(jq -car ".projects[] | select(.id==\"${1}\") | .version" ${DOCKER_BUILD_META_PATH})
local version_path=$(eval "echo -e ${raw_version_path}")
echo $(to_version "${version_path}")
}
# invalid - prints section type message
section() {
local green=`tput setaf 2`
local reset=`tput sgr0`
echo -e "${green}"
echo -e "-------------------------------------------------------------------------------------"
echo -e " $1"
echo -e "-------------------------------------------------------------------------------------"
echo -e "${reset}"
}
# invalid - prints invalid message
invalid() {
local bold=`tput bold`
local red=`tput setaf 1`
local reset=`tput sgr0`
>&2 echo -e "${red}${bold}ERROR:${reset} ${1}"
}
# warning - prints a warning message
warning() {
local bold=`tput bold`
local yellow=`tput setaf 3`
local reset=`tput sgr0`
>&2 echo -e "${yellow}${bold}WARNING:${reset} ${1}"
}
# info - prints an info message
info() {
local bold=`tput bold`
local green=`tput setaf 2`
local reset=`tput sgr0`
>&2 echo -e "${green}${bold}INFO:${reset} ${1}"
}
# ---------------------------------------------------------
# Checks
# ---------------------------------------------------------
# ensure checks that we have corresponding utilities installed
ensure() {
if ! [ -x "$(command -v jq)" ]; then
>&2 invalid "jq is necessary to be installed to run this script!\n\tFor installation instructions, please visit: https://stedolan.github.io/jq/download/"
exit 1
fi
if ! [ -x "$(command -v docker)" ]; then
>&2 invalid "docker is necessary to be installed to run this script!\n\tFor installation instructions, please visit: https://docs.docker.com/install/"
exit 1
fi
if ! [ -x "$(command -v docker-compose)" ]; then
>&2 invalid "docker-compose is necessary to be installed to run this script!\n\tFor installation instructions, please visit: https://docs.docker.com/compose/install/"
exit 1
fi
if ! [ -x "$(command -v javac)" ]; then
>&2 invalid "JAVA is necessary to be installed to run this script!\n\tFor installation instructions, please use your OS package manager"
exit 1
fi
local version=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*"/\1\2/p;')
[[ $version != "18" ]] && >&2 invalid "It looks like your JAVA version is not 1.8.\n\tWe recommend you to switch to version 1.8 in order to avoid issues while executing some Kafka commands!" && exit 1
if ! [ -x "$(command -v yarn)" ]; then
>&2 warning "yarn is not installed on the system! Although not completely necessary, it's recommended its installation.\n\tFor installation instructions, please visit: https://yarnpkg.com/lang/en/docs/install/"
fi
if ! [ -x "$(command -v curl)" ]; then
>&2 invalid "curl is necessary to be installed to run this script!\n\tFor installation instructions, please visit: https://curl.haxx.se/"
exit 1
fi
if ! [ -x "$(command -v grep)" ]; then
>&2 invalid "grep is necessary to be installed to run this script!\n\tFor installation instructions, please use your OS package manager"
exit 1
fi
if ! [ -x "$(command -v md5sum)" ]; then
>&2 invalid "md5sum is necessary to be installed to run this script!\n\tFor installation instructions, please use your OS package manager"
exit 1
fi
}