-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.sh
More file actions
383 lines (326 loc) · 12.1 KB
/
setup.sh
File metadata and controls
383 lines (326 loc) · 12.1 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/usr/bin/env bash
set -euo pipefail
BRANCH=master
DEV=false
DOCKER_REGISTRY="https://registry-1.docker.io"
UTILS_TAG="21.01.29"
function print_help() {
cat <<EOF
xud.sh 21.01.29
The launcher script for Exchange Union environment
USAGE:
xud.sh [OPTIONS]
OPTIONS:
-h, --help Show this help
-b, --branch <string> Git branch name
--disable-update Skip update checks and enter xud-ctl shell directly
--simnet-dir <path> Simnet environment directory path
--testnet-dir <path> Testnet environment directory path
--mainnet-dir <path> Mainnet environment directory path
--external-ip <ip> Host machine Internet IP address
--dev Use local built utils image
--use-local-images <image>[,<image>] Use other built images
Bitcoind options:
--bitcoind.mode [light|neutrino|external|native]
Bitcoind service mode (default: light)
--bitcoind.rpc-host <string> External bitcoind RPC hostname
--bitcoind.rpc-port <int> External bitcoind RPC port
--bitcoind.rpc-user <string> External bitcoind RPC username
--bitcoind.rpc-password <string> External bitcoind RPC password
--bitcoind.zmqpubrawblock <address> External bitcoind ZeroMQ raw blocks publication address
--bitcoind.zmqpubrawtx <address> External bitcoind ZeroMQ raw transactions publication address
--bitcoind.expose-ports <port>[,<port>] Expose bitcoind service ports to your host machine
Litecoind options:
--litecoind.mode [light|neutrino|external|native]
Litecoind service mode (default: light)
--litecoind.rpc-host <string> External litecoind RPC hostname
--litecoind.rpc-port <int> External litecoind RPC port
--litecoind.rpc-user <string> External litecoind RPC username
--litecoind.rpc-password <string> External litecoind RPC password
--litecoind.zmqpubrawblock <address> External litecoind ZeroMQ raw blocks publication address
--litecoind.zmqpubrawtx <address> External litecoind ZeroMQ raw transactions publication address
--litecoind.expose-ports <port>[,<port>] Expose litecoind service ports to your host machine
Geth options:
--geth.mode [light|infura|external|native] Geth service mode (default: light)
--geth.rpc-host <string> External geth RPC hostname
--geth.rpc-port <int> External geth RPC port
--geth.infura-project-id <string> Infura geth provider project ID
--geth.infura-project-secret <string> Infura geth provider project secret
--geth.expose-ports <port>[,<port>] Expose geth service ports to your host machine
--geth.cache <int> Geth cache size
Lndbtc options:
--lndbtc.expose-ports <port>[,<port>] Expose lndbtc service ports to your host machine
--lndbtc.preserve-config Preserve lndbtc lnd.conf file during updates
Lndbtc options:
--lndltc.expose-ports <port>[,<port>] Expose lndltc service ports to your host machine
--lndltc.preserve-config Preserve lndltc lnd.conf file during updates
Connext options:
--connext.expose-ports <port>[,<port>] Expose connext service ports to your host machine
Xud options:
--xud.expose-ports <port>[,<port>] Expose xud service ports to your host machine
--xud.preserve-config Preserve xud xud.conf file during updates
Arby options:
--arby.test-mode [true|false] Production/Demo mode (default: true for simnet and testnet; false for mainnet)
--arby.base-asset <string> Base asset symbol
--arby.quote-asset <string> Quote asset symbol
--arby.cex-base-asset <string> Centralized exchange base asset symbol
--arby.cex-quote-asset <string> Centralized exchange quote asset symbol
--arby.test-centralized-baseasset-balance CEX base asset balance for demo mode
--arby.test-centralized-quoteasset-balance CEX quote asset balance for demo mode
--arby.cex <string> CEX (binance/kraken)
--arby.cex-api-key <string> CEX API key
--arby.cex-api-secret <string> CEX API secret
--arby.margin <double> Trade margin
--arby.disabled [true|false] Enable/Disable arby service
Boltz options:
--boltz.disabled [true|false] Enable/Disable boltz service
Webui options:
--webui.disabled [true|false] Enable/Disable webui service
--webui.expose-ports <port>[,<port>] Expose webui service ports to your host machine
Proxy options:
--proxy.disabled [true|false] Enable/Disable proxy service
--proxy.expose-ports <port>[,<port>] Expose proxy service ports to your host machine
EOF
}
function parse_opts() {
local OPTION VALUE
while [[ $# -gt 0 ]]; do
case $1 in
"-h" | "--help" )
print_help
exit 1
;;
"-b" | "--branch")
if [[ $1 =~ = ]]; then
VALUE=$(echo "$1" | cut -d'=' -f2)
else
OPTION=$1
shift
if [[ $# -eq 0 || $1 =~ ^- ]]; then
echo >&2 "❌ Missing option value: $OPTION"
exit 1
fi
VALUE=$1
fi
BRANCH=$VALUE
;;
"--dev")
DEV=true
shift
;;
*)
shift
esac
done
}
function choose_network() {
while true; do
echo "1) Simnet"
echo "2) Testnet"
echo "3) Mainnet"
read -p "Please choose the network: " -r
shopt -s nocasematch
REPLY=$(echo "$REPLY" | awk '{$1=$1;print}') # trim whitespaces
case $REPLY in
1 | simnet)
NETWORK=simnet
break
;;
2 | testnet)
NETWORK=testnet
break
;;
3 | mainnet)
NETWORK=mainnet
break
;;
*)
continue
;;
esac
shopt -u nocasematch
done
}
function get_token() {
curl -sf "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$1:pull" | sed -E 's/^.*"token":"([^,]*)",.*$/\1/g'
}
function get_image_metadata() {
local TOKEN
local NAME
local TAG
NAME=$(echo "$1" | cut -d':' -f1)
TAG=$(echo "$1" | cut -d':' -f2)
TOKEN=$(get_token "$NAME")
curl -sf -H "Authorization: Bearer $TOKEN" "$DOCKER_REGISTRY/v2/$NAME/manifests/$TAG"
}
function get_cloud_image() {
local RESP
RESP=$(get_image_metadata "$1")
if [[ -z $RESP ]]; then
return
fi
RESP=$(echo "$RESP" | grep v1Compatibility | head -1 | sed 's/^.*v1Compatibility":/printf/g' || echo "")
if [[ -z $RESP ]]; then
return
fi
RESP=$(eval "$RESP")
echo "$RESP" | sed -E 's/.*sha256:([a-z0-9]+).*/\1/g'
echo "$RESP" | sed -E 's/.*com.exchangeunion.image.created":"([^"]*)".*/\1/g'
}
function get_local_image() {
if ! docker image inspect -f '{{.Config.Image}}' "$1" 2>/dev/null | sed -E 's/sha256://g'; then
return
fi
docker image inspect -f '{{index .Config.Labels "com.exchangeunion.image.created"}}' "$1"
}
function get_image_without_branch() {
echo "$1" | sed -E 's/__.*//g'
}
function get_pull_image() {
if ! docker image inspect "$1" >/dev/null 2>&1; then
echo "$2"
fi
}
function get_branch_image() {
if [[ $BRANCH == "master" ]]; then
echo "$1"
else
echo "${1}__${BRANCH//\//-}"
fi
}
function get_image_status() {
# possible return values: up-to-date, outdated, newer, missing
local LOCAL CLOUD
local L_SHA256 C_SHA256
local L_CREATED C_CREATED
local M_IMG # master branch image (name)
local B_IMG # branch image
local P_IMG # pulling image
local U_IMG # use image
B_IMG=$(get_branch_image "$1")
P_IMG=$B_IMG
CLOUD=$(get_cloud_image "$B_IMG")
if [[ -z $CLOUD ]]; then
if [[ $B_IMG =~ __ ]]; then
M_IMG=$(get_image_without_branch "$B_IMG")
CLOUD=$(get_cloud_image "$M_IMG")
if [[ -z $CLOUD ]]; then
echo >&2 "❌ Image not found in $DOCKER_REGISTRY: $B_IMG, $M_IMG"
exit 1
else
P_IMG=$M_IMG
fi
else
echo >&2 "❌ Image not found in $DOCKER_REGISTRY: $B_IMG"
exit 1
fi
fi
C_SHA256=$(echo "$CLOUD" | sed -n '1p')
U_IMG=$P_IMG
P_IMG=$(get_pull_image "$C_SHA256" "$P_IMG")
LOCAL=$(get_local_image "$B_IMG")
if [[ -z $LOCAL ]]; then
echo "missing $B_IMG $U_IMG $P_IMG"
return
fi
L_SHA256=$(echo "$LOCAL" | sed -n '1p')
if [[ $L_SHA256 == "$C_SHA256" ]]; then
echo "up-to-date $B_IMG $U_IMG $P_IMG"
return
fi
echo "outdated $B_IMG $U_IMG $P_IMG"
}
function pull_image() {
echo "Pulling image $1"
if ! docker pull "$1" >/dev/null 2>&1; then
echo >&2 "❌ Failed to pull image $1. This may be a Docker issue or a permissions issue. Check your Docker installation and make sure you have added your user to the docker group: https://docs.docker.com/engine/install/linux-postinstall/"
exit 1
fi
}
function ensure_utils_image() {
local STATUS
local B_IMG # branch image
local P_IMG # pulling image
local U_IMG # use image
local I_IMG # initial image
if [[ $DEV == "true" ]]; then
UTILS_IMG=$(get_branch_image "exchangeunion/utils:latest")
return
fi
if [[ $NETWORK == "mainnet" && $BRANCH == "master" ]]; then
I_IMG="exchangeunion/utils:$UTILS_TAG"
else
I_IMG="exchangeunion/utils:latest"
fi
read -r STATUS B_IMG U_IMG P_IMG <<<"$(get_image_status "$I_IMG")"
if [[ -z $U_IMG ]]; then
exit 1
fi
case $STATUS in
missing|outdated)
if [[ -n $P_IMG ]]; then
pull_image "$P_IMG"
if [[ $BRANCH != "master" && ! $P_IMG =~ __ ]]; then
echo "Warning: Branch image $B_IMG not found. Fallback to $P_IMG"
fi
fi
;;
newer)
echo "Warning: Use local $B_IMG (newer than cloud $P_IMG)"
;;
esac
UTILS_IMG=$U_IMG
}
function ensure_directory() {
if [[ -z $1 ]]; then
return
fi
if [[ ! -e $1 ]]; then
read -p "$1 does not exist, would you like to create this directory? [Y/n] " -n 1 -r
if [[ -n $REPLY ]]; then
echo
fi
if [[ $REPLY =~ ^[Yy[:space:]]$ || -z $REPLY ]]; then
mkdir -p "$1"
else
exit 1
fi
fi
if [[ ! -d $1 ]]; then
echo "❌ $1 is not a directory"
exit 1
fi
if [[ ! -r $1 ]]; then
echo "❌ $1 is not readable"
exit 1
fi
if [[ ! -w $1 ]]; then
echo "❌ $1 is not writable"
exit 1
fi
}
function get_utils_name() {
local N
N=$(docker ps -a --filter name="${NETWORK}_utils_" --format '{{.Names}}' | sed "s/${NETWORK}_utils_//" | sort -nr | head -n1)
((N++))
echo "${NETWORK}_utils_${N}"
}
################################################################################
# MAIN
################################################################################
LOG_TIMESTAMP="$(date +%F-%H-%M-%S)"
parse_opts "$@"
choose_network
ensure_utils_image
echo "🚀 Launching $NETWORK environment"
docker run --rm -it \
--name "$(get_utils_name)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /:/mnt/hostfs \
-e HOST_PWD="$PWD" \
-e HOST_HOME="$HOME" \
-e NETWORK="$NETWORK" \
-e LOG_TIMESTAMP="$LOG_TIMESTAMP" \
--entrypoint python \
"$UTILS_IMG" \
-m launcher "$@"