forked from hummingbot/hummingbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·146 lines (139 loc) · 3.82 KB
/
update.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
#!/bin/bash
# init
# =============================================
# Specify hummingbot version
select_version () {
echo
echo
echo "=============== UPDATE HUMMINGBOT INSTANCE ==============="
echo
echo
echo "ℹ️ Press [ENTER] for default values:"
echo
read -p " Enter Hummingbot version to update [latest/development] (default = \"latest\") >>> " TAG
if [ "$TAG" == "" ]
then
TAG="latest"
fi
}
# List all docker instances using the same image
list_instances () {
echo
echo "List of all docker containers using the \"$TAG\" version:"
echo
docker ps -a --filter ancestor=coinalpha/hummingbot:$TAG
echo
echo "⚠️ WARNING: This will attempt to update all instances. Any containers not in Exited () STATUS will cause the update to fail."
echo
echo "ℹ️ TIP: Connect to a running instance using \"./start.sh\" command and \"exit\" from inside Hummingbot."
echo "ℹ️ TIP: You can also remove unused instances by running \"docker rm [NAME]\" in the terminal."
echo
read -p " Do you want to continue? [Y/N] >>> " CONTINUE
if [ "$CONTINUE" == "" ]
then
CONTINUE="Y"
fi
}
# List all directories in the current folder
list_dir () {
echo
echo " List of folders in your directory:"
echo
ls -d1 */ 2>&1 | sed 's/^/ 📁 /'
echo
}
# Ask the user for the folder location of each instance
prompt_folder () {
for instance in "${INSTANCES[@]}"
do
if [ "$instance" == "hummingbot-instance" ]
then
DEFAULT_FOLDER="hummingbot_files"
else
DEFAULT_FOLDER="${instance}_files"
fi
read -p " Enter the destination folder for $instance (default = \"$DEFAULT_FOLDER\") >>> " FOLDER
if [ "$FOLDER" == "" ]
then
FOLDER=$PWD/$DEFAULT_FOLDER
elif [[ ${FOLDER::1} != "/" ]]; then
FOLDER=$PWD/$FOLDER
fi
# Store folder names into an array
FOLDERS+=($FOLDER)
done
}
# Display instances and destination folders then prompt to proceed
confirm_update () {
echo
echo "ℹ️ Confirm below if the instances and their folders are correct:"
echo
num="0"
printf "%30s %5s %10s\n" "INSTANCE" " " "FOLDER"
for instance in "${INSTANCES[@]}"
do
printf "%30s %5s %10s\n" ${INSTANCES[$num]} " ----------> " ${FOLDERS[$num]}
num=$[$num+1]
done
echo
read -p " Proceed? [Y/N] >>> " PROCEED
if [ "$PROCEED" == "" ]
then
PROCEED="Y"
fi
}
# Execute docker commands
execute_docker () {
# 1) Delete instance and old hummingbot image
echo
echo "Removing docker containers first ..."
docker rm ${INSTANCES[@]}
echo
# 2) Delete old image
docker image rm coinalpha/hummingbot:$TAG
# 3) Re-create instances with the most recent hummingbot version
echo "Re-creating docker containers with updated image ..."
j="0"
for instance in "${INSTANCES[@]}"
do
docker run -itd --log-opt max-size=10m --log-opt max-file=5 \
--network host \
--name ${INSTANCES[$j]} \
--mount "type=bind,source=${FOLDERS[$j]}/hummingbot_conf,destination=/conf/" \
--mount "type=bind,source=${FOLDERS[$j]}/hummingbot_logs,destination=/logs/" \
--mount "type=bind,source=${FOLDERS[$j]}/hummingbot_data,destination=/data/" \
--mount "type=bind,source=${FOLDERS[$j]}/hummingbot_scripts,destination=/scripts/" \
--mount "type=bind,source=${FOLDERS[$j]}/hummingbot_certs,destination=/certs/" \
coinalpha/hummingbot:$TAG
j=$[$j+1]
done
echo
echo "Update complete! All running docker instances:"
echo
docker ps
echo
echo "ℹ️ Run command \"./start.sh\" to connect to an instance."
echo
}
select_version
list_instances
if [ "$CONTINUE" == "Y" ]
then
# Store instance names in an array
declare -a INSTANCES
INSTANCES=( $(docker ps -a --filter ancestor=coinalpha/hummingbot:$TAG --format "{{.Names}}") )
list_dir
declare -a FOLDERS
prompt_folder
confirm_update
if [ "$PROCEED" == "Y" ]
then
execute_docker
else
echo " Update aborted"
echo
fi
else
echo " Update aborted"
echo
fi