Files
deploy/bash_scripts/hummingbot-update.sh

151 lines
3.8 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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=hummingbot/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 hummingbot/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]} \
-v ${FOLDERS[$j]}/conf:/conf \
-v ${FOLDERS[$j]}/conf/connectors:/conf/connectors \
-v ${FOLDERS[$j]}/conf/strategies:/conf/strategies \
-v ${FOLDERS[$j]}/logs:/logs \
-v ${FOLDERS[$j]}/data:/data \
-v ${FOLDERS[$j]}/pmm-scripts:/pmm-scripts \
-v ${FOLDERS[$j]}/scripts:/scripts \
-v ${FOLDERS[$j]}/certs:/certs \
hummingbot/hummingbot:$TAG
j=$[$j+1]
# Update file ownership
done
echo
echo "Update complete! All running docker instances:"
echo
docker ps
echo
echo " Run command \"./hummingbot-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=hummingbot/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