-
Notifications
You must be signed in to change notification settings - Fork 5
/
installer
269 lines (216 loc) · 6.13 KB
/
installer
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ###############################################################
# CCTL Installation Script
# ###############################################################
# ---------------------------------------------------------------
# SECTION: HELPER VARIABLES
# ---------------------------------------------------------------
# GitHub repos.
declare _GH_URL_OF_CCTL=https://github.com/casper-network/cctl.git
declare _GH_URL_OF_CLI=https://github.com/casper-ecosystem/casper-client-rs.git
declare _GH_URL_OF_NODE=https://github.com/casper-network/casper-node.git
declare _GH_URL_OF_NODE_LAUNCHER=https://github.com/casper-network/casper-node-launcher.git
# OS types.
declare _OS_LINUX="linux"
declare _OS_LINUX_REDHAT="$_OS_LINUX-redhat"
declare _OS_LINUX_SUSE="$_OS_LINUX-suse"
declare _OS_LINUX_ARCH="$_OS_LINUX-arch"
declare _OS_LINUX_DEBIAN="$_OS_LINUX-debian"
declare _OS_MACOSX="macosx"
declare _OS_UNKNOWN="unknown"
# ---------------------------------------------------------------
# SECTION: HELPER FUNCTIONS
# ---------------------------------------------------------------
# Wraps standard echo.
function _log()
{
local NOW=`date +%Y-%m-%dT%H:%M:%S`
echo -e $NOW" [INFO] :: CCTL > "$1
}
# Outputs a line to split up _logging.
function _log_banner()
{
echo "-------------------------------------------------------------------------------"
}
# Returns OS type.
function _get_os()
{
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ -f /etc/redhat-release ]; then
echo $_OS_LINUX_REDHAT
elif [ -f /etc/SuSE-release ]; then
echo $_OS_LINUX_SUSE
elif [ -f /etc/arch-release ]; then
echo $_OS_LINUX_ARCH
elif [ -f /etc/debian_version ]; then
echo $_OS_LINUX_DEBIAN
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo $_OS_MACOSX
else
echo $_OS_UNKNOWN
fi
}
# Returns directory in which application will be installed.
function _get_install_dir()
{
echo "$(_get_root_dir)"/cctl
}
# Returns directory in which repo will be installed.
function _get_repo_dir()
{
echo "$(_get_root_dir)"/cctl
}
# Returns directory in which application will be installed.
function _get_root_dir()
{
echo "$HOME"/cspr
}
# Returns file path of bash terminal session initiliser.
function _get_bashrc_filepath()
{
local OS_TYPE="$(_get_os)"
if [[ $OS_TYPE == $_OS_MACOSX ]]; then
echo "$HOME/.bash_profile"
else
echo "$HOME/.bashrc"
fi
}
# Wraps pushd command to suppress stdout.
function _pushd () {
command pushd "$@" > /dev/null
}
# Wraps popd command to suppress stdout.
function _popd () {
command popd "$@" > /dev/null
}
# Reset terminal.
function _tidyup()
{
unset _GH_URL_OF_CCTL
unset _GH_URL_OF_CLI
unset _GH_URL_OF_NODE
unset _GH_URL_OF_NODE_LAUNCHER
unset _OS_LINUX
unset _OS_LINUX_REDHAT
unset _OS_LINUX_SUSE
unset _OS_LINUX_ARCH
unset _OS_LINUX_DEBIAN
unset _OS_MACOSX
unset _OS_UNKNOWN
}
# Notify user upon installation.
function _notify_user()
{
_log_banner
echo "1. CCTL has been successfully installed."
echo ""
echo "2. To spin up a network:"
echo " cctl-infra-net-setup && cctl-infra-net-start"
echo ""
echo "3. To tear down a network"
echo " cctl-infra-net-teardown"
_log_banner
}
# ---------------------------------------------------------------
# SECTION: VERIFY INSTALLATION
# ---------------------------------------------------------------
function _verify {
_log_banner
_log 'verifying system:'
_verify_previous
_verify_prequisites
}
function _verify_prequisites {
_log '... prequisites'
# Curl.
command -v curl >/dev/null 2>&1 || { echo >&2 "Please install curl. https://curl.se"; exit 1; }
# Git.
command -v git >/dev/null 2>&1 || { echo >&2 "Please install git. https://www.atlassian.com/git/tutorials/install-git"; exit 1; }
# Python3.
command -v python3 >/dev/null 2>&1 || { echo >&2 "Please install python3. https://www.python.org/downloads"; exit 1; }
# Cargo.
command -v cargo >/dev/null 2>&1 || { echo >&2 "Please install cargo. https://doc.rust-lang.org/cargo/getting-started/installation.html"; exit 1; }
# Make.
command -v make >/dev/null 2>&1 || { echo >&2 "Please install cargo. https://www.geeksforgeeks.org/how-to-install-make-on-ubuntu"; exit 1; }
# jq.
command -v jq >/dev/null 2>&1 || { echo >&2 "Please install jq. https://jqlang.github.io/jq"; exit 1; }
}
function _verify_previous {
_log '... previous installation'
local REPO_DIR="$(_get_install_dir)"
if [ -d $REPO_DIR ]; then
_log "... CCTL IS ALREADY INSTALLED !"
_log_banner
exit 1
fi
}
# ---------------------------------------------------------------
# SECTION: INSTALL FUNCTIONS
# ---------------------------------------------------------------
# Install entry point.
function _install()
{
_log_banner
_log 'installing:'
_log "... repos"
_install_repos
_log '... environment activator'
_install_environment_activator
_log '... python dependencies'
_install_python_dependencies
_log '... rust toolchain'
_install_rust_toolchain
}
function _install_repos()
{
_install_repo $_GH_URL_OF_CCTL
_install_repo $_GH_URL_OF_CLI
_install_repo $_GH_URL_OF_NODE
_install_repo $_GH_URL_OF_NODE_LAUNCHER
}
function _install_repo()
{
local REPO_URL=${1}
local ROOT_DIR="$(_get_root_dir)"
_log "... ... $REPO_URL"
mkdir -p $ROOT_DIR
_pushd $ROOT_DIR
git clone -q $REPO_URL
_popd
}
function _install_environment_activator()
{
local PATH_TO_INSTALL_DIR="$(_get_install_dir)"
local PATH_TO_BASHRC_FILE="$(_get_bashrc_filepath)"
cat >> $PATH_TO_BASHRC_FILE <<- EOM
# ----------------------------------------------------------------------
# CCTL
# ----------------------------------------------------------------------
source ${PATH_TO_INSTALL_DIR}/activate
EOM
source $PATH_TO_BASHRC_FILE
source ${PATH_TO_INSTALL_DIR}/activate
}
function _install_python_dependencies()
{
python3 -m pip -q install supervisor toml tomlkit
}
function _install_rust_toolchain()
{
local ROOT_DIR="$(_get_root_dir)"
_pushd $ROOT_DIR/casper-node
make setup-rs
_popd
}
# ---------------------------------------------------------------
# SECTION: MAIN ENTRY POINT
# ---------------------------------------------------------------
# Main entry point.
function _main()
{
_verify
_install
_tidyup
_notify_user
}
_main