forked from hummingbot/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgateway-setup.sh
More file actions
executable file
·420 lines (352 loc) · 12 KB
/
Copy pathgateway-setup.sh
File metadata and controls
executable file
·420 lines (352 loc) · 12 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/bin/bash
# init
# Get the gateway directory path (this script's location)
GATEWAY_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Since gateway is a submodule in hummingbot, go up one level to get hummingbot root
HUMMINGBOT_ROOT="$(dirname "$GATEWAY_DIR")"
HOST_CONF_PATH="$GATEWAY_DIR/conf"
TEMPLATE_DIR="$GATEWAY_DIR/src/templates"
CERTS_TO_PATH="$GATEWAY_DIR/certs"
# Default Hummingbot certs path (one level up from gateway)
HUMMINGBOT_CERTS_PATH="$HUMMINGBOT_ROOT/certs"
# Check for --with-defaults flag
WITH_DEFAULTS=false
for arg in "$@"; do
if [ "$arg" = "--with-defaults" ]; then
WITH_DEFAULTS=true
break
fi
done
prompt_proceed () {
if [ "$WITH_DEFAULTS" = true ]; then
PROCEED="Y"
else
read -p "Do you want to proceed? [Y/N] >>> " PROCEED
if [ "$PROCEED" == "" ]
then
prompt_proceed
else
if [[ "$PROCEED" != "Y" && "$PROCEED" != "y" ]]
then
PROCEED="N"
fi
fi
fi
}
ask_config_choices () {
# Track what will be updated
PLANNED_UPDATES=""
# Function to prompt for yes/no with default
prompt_yes_no () {
local prompt_text="$1"
local default_val="${2:-Y}"
local user_input
if [ "$WITH_DEFAULTS" = true ]; then
# In with-defaults mode, use default value
if [ "$default_val" = "Y" ]; then
return 0
else
return 1
fi
fi
if [ "$default_val" = "Y" ]; then
read -p "$prompt_text [Y/n] >>> " user_input
user_input=${user_input:-Y}
else
read -p "$prompt_text [y/N] >>> " user_input
user_input=${user_input:-N}
fi
if [[ "$user_input" == "Y" || "$user_input" == "y" ]]; then
return 0
else
return 1
fi
}
# Always include root.yml (essential file)
UPDATE_ROOT="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}root.yml, "
# Always update namespace folder (required for config validation)
UPDATE_NAMESPACE="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}namespace/, "
# Ask about configurations to update
echo "📦 Select configurations to update:"
echo
# Ask about server.yml
if prompt_yes_no " - server.yml (default Gateway server config)?" "Y"; then
UPDATE_SERVER="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}server.yml, "
else
UPDATE_SERVER="N"
fi
# Ask about chains folder
if prompt_yes_no " - chains/ (default configs for each chain/network)?" "Y"; then
UPDATE_CHAINS="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}chains/, "
else
UPDATE_CHAINS="N"
fi
# Ask about connectors folder
if prompt_yes_no " - connectors/ (default configs for each DEX connector)?" "Y"; then
UPDATE_CONNECTORS="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}connectors/, "
else
UPDATE_CONNECTORS="N"
fi
# Ask about tokens folder
if prompt_yes_no " - tokens/ (default token lists for each chain/network)?" "Y"; then
UPDATE_TOKENS="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}tokens/, "
else
UPDATE_TOKENS="N"
fi
# Ask about pools folder
if prompt_yes_no " - pools/ (default pool lists for each DEX connector)?" "Y"; then
UPDATE_POOLS="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}pools/, "
else
UPDATE_POOLS="N"
fi
# Ask about rpc folder
if prompt_yes_no " - rpc/ (RPC provider configurations like Helius, Infura)?" "Y"; then
UPDATE_RPC="Y"
PLANNED_UPDATES="${PLANNED_UPDATES}rpc/, "
else
UPDATE_RPC="N"
fi
# Remove trailing comma and space
PLANNED_UPDATES=${PLANNED_UPDATES%, }
}
copy_configs () {
echo
# Make destination folder if needed
mkdir -p $HOST_CONF_PATH
# Preserve wallets directory if it exists
if [ -d "$HOST_CONF_PATH/wallets" ]; then
cp -r "$HOST_CONF_PATH/wallets" "$HOST_CONF_PATH/wallets.backup"
fi
# Track what was updated for final summary
UPDATED_ITEMS=""
# Note: conf/wallets/ is never touched by this script to preserve user wallets
# Copy based on user choices
# Always copy root.yml (essential file)
cp $TEMPLATE_DIR/root.yml $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}root.yml, "
# Copy server.yml if selected
if [ "$UPDATE_SERVER" = "Y" ]; then
cp $TEMPLATE_DIR/server.yml $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}server.yml, "
fi
# Copy connectors folder if selected
if [ "$UPDATE_CONNECTORS" = "Y" ]; then
cp -r $TEMPLATE_DIR/connectors $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}connectors/, "
fi
# Copy namespace folder if selected
if [ "$UPDATE_NAMESPACE" = "Y" ]; then
cp -r $TEMPLATE_DIR/namespace $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}namespace/, "
fi
# Copy chains folder if selected
if [ "$UPDATE_CHAINS" = "Y" ]; then
# Store original defaultWallet values before copying
ORIG_SOLANA_WALLET=""
ORIG_ETH_WALLET=""
if [ -f "$HOST_CONF_PATH/chains/solana.yml" ]; then
ORIG_SOLANA_WALLET=$(grep "^defaultWallet:" "$HOST_CONF_PATH/chains/solana.yml" | cut -d' ' -f2- | tr -d "'\"")
fi
if [ -f "$HOST_CONF_PATH/chains/ethereum.yml" ]; then
ORIG_ETH_WALLET=$(grep "^defaultWallet:" "$HOST_CONF_PATH/chains/ethereum.yml" | cut -d' ' -f2- | tr -d "'\"")
fi
# Copy the chains folder
cp -r $TEMPLATE_DIR/chains $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}chains/, "
# Restore original defaultWallet values if they weren't placeholders
if [ -n "$ORIG_SOLANA_WALLET" ] && [ "$ORIG_SOLANA_WALLET" != "<solana-wallet-address>" ]; then
perl -pi -e "s|defaultWallet: '<solana-wallet-address>'|defaultWallet: $ORIG_SOLANA_WALLET|" "$HOST_CONF_PATH/chains/solana.yml"
echo " Kept original Solana defaultWallet: $ORIG_SOLANA_WALLET"
fi
if [ -n "$ORIG_ETH_WALLET" ] && [ "$ORIG_ETH_WALLET" != "<ethereum-wallet-address>" ]; then
perl -pi -e "s|defaultWallet: '<ethereum-wallet-address>'|defaultWallet: $ORIG_ETH_WALLET|" "$HOST_CONF_PATH/chains/ethereum.yml"
echo " Kept original Ethereum defaultWallet: $ORIG_ETH_WALLET"
fi
fi
# Copy tokens folder if selected
if [ "$UPDATE_TOKENS" = "Y" ]; then
cp -r $TEMPLATE_DIR/tokens $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}tokens/, "
fi
# Copy pools folder if selected
if [ "$UPDATE_POOLS" = "Y" ]; then
cp -r $TEMPLATE_DIR/pools $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}pools/, "
fi
# Copy rpc folder if selected
if [ "$UPDATE_RPC" = "Y" ]; then
cp -r $TEMPLATE_DIR/rpc $HOST_CONF_PATH/
UPDATED_ITEMS="${UPDATED_ITEMS}rpc/, "
fi
# Note: wallets folder is preserved and never overwritten
# Restore wallets directory if it was backed up
if [ -d "$HOST_CONF_PATH/wallets.backup" ]; then
rm -rf "$HOST_CONF_PATH/wallets"
mv "$HOST_CONF_PATH/wallets.backup" "$HOST_CONF_PATH/wallets"
fi
# Remove trailing comma and space
UPDATED_ITEMS=${UPDATED_ITEMS%, }
echo
if [ -n "$UPDATED_ITEMS" ]; then
echo "✅ Successfully updated: $UPDATED_ITEMS"
else
echo "⚠️ No configurations were updated"
fi
}
link_certs () {
# Remove existing certs folder/symlink if it exists
if [ -L "$CERTS_TO_PATH" ] || [ -d "$CERTS_TO_PATH" ]; then
echo "Removing existing certs folder/symlink..."
rm -rf "$CERTS_TO_PATH"
fi
# Create symlink to Hummingbot certs folder
ln -s "$CERTS_FROM_PATH" "$CERTS_TO_PATH"
# Confirm that the symlink was created
if [ $? -eq 0 ]; then
echo "✅ Certificate symlink created successfully"
echo " Gateway will now use the same certificates as Hummingbot"
else
echo "Error creating symlink from $CERTS_TO_PATH to $CERTS_FROM_PATH"
exit 1
fi
}
echo
echo
echo "=============== SETUP GATEWAY ==============="
echo
if [ "$WITH_DEFAULTS" = true ]; then
echo "Running with --with-defaults: All configurations will be updated automatically."
else
echo "This script helps you initialize a Gateway server."
echo "It will copy default configuration files from the templates directory to your conf folder. You can choose which configurations to update."
echo "Optionally, it will also link to the Hummingbot client certificates so you can run Gateway in HTTPS mode."
fi
echo
# Ask user which configurations to update
ask_config_choices
# Ask about certificates
if [ "$WITH_DEFAULTS" = true ]; then
# Skip certificate linking in with-defaults mode
LINK_CERTS="N"
else
echo
read -p "Do you want to link to Hummingbot client certificates [y/N] >>> " LINK_CERTS
# Default to No if empty
LINK_CERTS=${LINK_CERTS:-N}
if [[ "$LINK_CERTS" == "Y" || "$LINK_CERTS" == "y" ]]
then
# Get the certificate path now, before showing summary
echo
read -p "Enter path to the Hummingbot certs folder [$HUMMINGBOT_CERTS_PATH] >>> " CERTS_FROM_PATH
# Use default if no input provided
if [ -z "$CERTS_FROM_PATH" ]; then
CERTS_FROM_PATH="$HUMMINGBOT_CERTS_PATH"
fi
# Validate the path
if [ ! -d "$CERTS_FROM_PATH" ]; then
echo "Error: $CERTS_FROM_PATH does not exist or is not a directory"
echo "Tip: Run 'gateway generate-certs' from Hummingbot to create certificates"
exit 1
fi
# Check if there are any .pem files in the source directory
PEM_COUNT=$(find "$CERTS_FROM_PATH" -maxdepth 1 -name "*.pem" | wc -l)
if [ "$PEM_COUNT" -eq 0 ]; then
echo "Error: No .pem files found in $CERTS_FROM_PATH"
echo "Tip: Run 'gateway generate-certs' from Hummingbot to create certificates"
exit 1
fi
fi
fi
# Show what will be updated and ask for final confirmation
echo
echo "📋 Summary of changes:"
echo
# Show configuration updates
echo "📦 Configuration updates:"
echo " FROM: $TEMPLATE_DIR"
echo " TO: $HOST_CONF_PATH"
echo
# List specific items to be updated
echo " Items to be updated:"
if [ "$UPDATE_SERVER" = "Y" ]; then
echo " - server.yml (default Gateway server configs)"
fi
if [ "$UPDATE_CHAINS" = "Y" ]; then
echo " - chains/ (default configs for each chain/network)"
fi
if [ "$UPDATE_CONNECTORS" = "Y" ]; then
echo " - connectors/ (default configs for each DEX connector)"
fi
if [ "$UPDATE_TOKENS" = "Y" ]; then
echo " - tokens/ (default token lists for each chain/network)"
fi
if [ "$UPDATE_POOLS" = "Y" ]; then
echo " - pools/ (default pool lists for each DEX connector)"
fi
if [ "$UPDATE_RPC" = "Y" ]; then
echo " - rpc/ (RPC provider configurations like Helius, Infura)"
fi
echo " - root.yml (always updated - essential file)"
echo " - namespaces/ (always updated - config schemas)"
# Show wallet preservation status
if [ -d "$HOST_CONF_PATH/wallets" ]; then
echo
echo "✅ Existing wallets/ directory will be preserved"
fi
# Check for existing defaultWallet values if chains will be updated
if [ "$UPDATE_CHAINS" = "Y" ]; then
EXISTING_WALLETS=""
if [ -f "$HOST_CONF_PATH/chains/solana.yml" ]; then
SOLANA_WALLET=$(grep "^defaultWallet:" "$HOST_CONF_PATH/chains/solana.yml" | cut -d' ' -f2- | tr -d "'\"")
if [ -n "$SOLANA_WALLET" ] && [ "$SOLANA_WALLET" != "<solana-wallet-address>" ]; then
EXISTING_WALLETS="Solana"
fi
fi
if [ -f "$HOST_CONF_PATH/chains/ethereum.yml" ]; then
ETH_WALLET=$(grep "^defaultWallet:" "$HOST_CONF_PATH/chains/ethereum.yml" | cut -d' ' -f2- | tr -d "'\"")
if [ -n "$ETH_WALLET" ] && [ "$ETH_WALLET" != "<ethereum-wallet-address>" ]; then
if [ -n "$EXISTING_WALLETS" ]; then
EXISTING_WALLETS="$EXISTING_WALLETS and Ethereum"
else
EXISTING_WALLETS="Ethereum"
fi
fi
fi
if [ -n "$EXISTING_WALLETS" ]; then
echo "✅ Existing defaultWallet values will be preserved ($EXISTING_WALLETS)"
fi
fi
# Show certificate linking if applicable
if [[ "$LINK_CERTS" == "Y" || "$LINK_CERTS" == "y" ]]
then
echo
echo "🔐 Certificates:"
echo " FROM: $CERTS_FROM_PATH"
echo " TO: $CERTS_TO_PATH"
echo " (Symlink will be created)"
fi
echo
prompt_proceed
if [[ "$PROCEED" == "Y" || "$PROCEED" == "y" ]]
then
copy_configs
# Link certificates if requested
if [[ "$LINK_CERTS" == "Y" || "$LINK_CERTS" == "y" ]]
then
echo
link_certs
fi
else
echo "Exiting..."
exit
fi
echo
echo "=============== SETUP COMPLETE ==============="
echo