forked from hummingbot/gateway
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgateway-create.sh
executable file
·167 lines (152 loc) · 4.35 KB
/
gateway-create.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# init
echo
echo
echo "=============== CREATE A NEW GATEWAY INSTANCE ==============="
echo
echo
echo "ℹ️ Press [ENTER] for default values:"
echo
echo
read -p "Enter Gateway version you want to use [latest/development] (default = \"latest\") >>> " GATEWAY_TAG
if [ "$GATEWAY_TAG" == "" ]
then
GATEWAY_TAG="latest"
fi
# Check if container with same version already exists
if docker ps -a | grep -q "hummingbot/gateway:$GATEWAY_TAG"; then
echo
echo "A Gateway container with the same version '$GATEWAY_TAG' already exists on this machine."
echo "Remove the existing version by running 'docker rm <container-name>' before creating a new one."
echo "Aborting..."
exit
fi
# Ask the user for the name of the new Gateway instance
read -p "Enter a name for your new Gateway instance (default = \"gateway\") >>> " INSTANCE_NAME
if [ "$INSTANCE_NAME" == "" ]
then
INSTANCE_NAME="gateway"
DEFAULT_FOLDER="gateway_files"
else
DEFAULT_FOLDER="${INSTANCE_NAME}_files"
fi
# Ask the user for the folder location to save files
read -p "Enter the folder name where your Gateway files will be saved (default = \"$DEFAULT_FOLDER\") >>> " FOLDER
if [ "$FOLDER" == "" ]
then
FOLDER=$PWD/$DEFAULT_FOLDER
elif [[ ${FOLDER::1} != "/" ]]; then
FOLDER=$PWD/$FOLDER
fi
CONF_FOLDER="$FOLDER/conf"
LOGS_FOLDER="$FOLDER/logs"
CERTS_FOLDER="$FOLDER/certs"
# Ask the user for the hummingbot certs passphrase
prompt_passphrase () {
echo
read -s -p "Enter the passphrase you used to generate certificates in Hummingbot >>> " PASSPHRASE
if [ "$PASSPHRASE" == "" ]
then
echo
echo
echo "!! Error: passphrase cannot be blank"
prompt_passphrase
fi
}
prompt_passphrase
# Get GMT offset from local system time
GMT_OFFSET=$(date +%z)
# Check available open port for Gateway
PORT=15888
LIMIT=$((PORT+1000))
while [[ $PORT -le LIMIT ]]
do
if [[ $(netstat -nat | grep "$PORT") ]]; then
# check another port
((PORT = PORT + 1))
else
break
fi
done
echo
echo "ℹ️ Confirm below if the instance and its folders are correct:"
echo
printf "%30s %5s\n" "Gateway instance name:" "$INSTANCE_NAME"
printf "%30s %5s\n" "Version:" "hummingbot/gateway:$GATEWAY_TAG"
echo
printf "%30s %5s\n" "Hummingbot instance ID:" "$HUMMINGBOT_INSTANCE_ID"
printf "%30s %5s\n" "Gateway conf path:" "$CONF_FOLDER"
printf "%30s %5s\n" "Gateway log path:" "$LOGS_FOLDER"
printf "%30s %5s\n" "Gateway certs path:" "$CERTS_FOLDER"
printf "%30s %5s\n" "Gateway port:" "$PORT"
echo
prompt_existing_certs_path () {
echo
read -p "Enter the path to the folder where Hummingbot certificates are stored >>> " CERTS_PATH_TO_COPY
if [ "$CERTS_PATH_TO_COPY" == "" ]
then
echo
echo "After installation, set certificatePath in $CONF_FOLDER/server.yml and restart Gateway"
else
# Check if source folder exists
if [ ! -d "$CERTS_PATH_TO_COPY" ]; then
echo "Error: $CERTS_PATH_TO_COPY does not exist or is not a directory"
exit 1
fi
# Copy all files in the source folder to the destination folder
cp -r $CERTS_PATH_TO_COPY/* $CERTS_FOLDER/
# Confirm that the files were copied
if [ $? -eq 0 ]; then
echo "Files successfully copied from $CERTS_PATH_TO_COPY to $CERTS_FOLDER"
else
echo "Error copying files from $CERTS_PATH_TO_COPY to $CERTS_FOLDER"
exit 1
fi
fi
}
prompt_proceed () {
echo
read -p "Do you want to proceed with installation? [Y/N] >>> " PROCEED
if [ "$PROCEED" == "" ]
then
prompt_proceed
else
if [[ "$PROCEED" != "Y" && "$PROCEED" != "y" ]]
then
PROCEED="N"
fi
fi
}
# Execute docker commands
create_instance () {
echo
echo "Creating Gateway instance ... "
echo
# 1) Create main folder for your new instance
mkdir $FOLDER
# 2) Create subfolders for gateway files
mkdir $CONF_FOLDER
mkdir $LOGS_FOLDER
mkdir $CERTS_FOLDER
# 3) Set required permissions to save gateway passphrase the first time
sudo chmod a+rw $CONF_FOLDER $CERTS_FOLDER
prompt_existing_certs_path
# Launch a new instance of gateway
docker run \
--name $INSTANCE_NAME \
-p $PORT:$PORT \
-p 8080:8080 \
-v $CONF_FOLDER:/usr/src/app/conf \
-v $LOGS_FOLDER:/usr/src/app/logs \
-v $CERTS_FOLDER:/usr/src/app/certs \
-e GATEWAY_PASSPHRASE="$PASSPHRASE" \
hummingbot/gateway:$GATEWAY_TAG
}
prompt_proceed
if [[ "$PROCEED" == "Y" || "$PROCEED" == "y" ]]
then
create_instance
else
echo " Aborted"
echo
fi