#!/bin/bash STACK_VERSION=$1 PROCESSOR_TYPE=$2 $COMPOSE_FILE get_stack_version() { if [[ -n "$STACK_VERSION" ]]; then echo 'use provided version' echo $STACK_VERSION else STACK_VERSION=$(curl -X 'GET' 'https://api.callabacloud.com/getCallabaCloudVersion' \ --header "Content-Type: application/json" \ -d '{"version_name":"parrot"}' | jq -r '.[].version_number') echo 'use version by default' echo $STACK_VERSION fi if [[ $? -ne 0 || -z "$STACK_VERSION" ]]; then echo "Error: Failed to get stack version" exit 1 fi export STACK_VERSION } stop_containers() { local containers=$(sudo docker ps -q --filter='name=callabacloud-*') if [[ -n "$containers" ]]; then if sudo docker stop --time 60 $containers; then echo "Stopped successfully" else echo "Error: Unable to stop containers" >&2 return 1 fi else echo "No containers to stop" fi } remove_containers() { local containers=$(sudo docker ps -a -q --filter='name=callabacloud-*') if [[ -n "$containers" ]]; then if sudo docker rm $containers; then echo "Removed successfully" else echo "Error: Unable to remove containers" >&2 return 1 fi else echo "No containers to remove" fi } remove_old_images() { OLD_STACK_VERSION=$(cat STACK_VERSION.txt) local images=$(sudo docker images -q --filter=reference="registry.callabacloud.com/*/*:$OLD_STACK_VERSION") if [[ -n "$images" ]]; then if sudo docker rmi -f $images; then echo "Images are removed successfully" else echo "Error: Unable to remove images" >&2 return 1 fi else echo "No images to remove" fi } start_docker_compose() { echo $STACK_VERSION if [[ "$PROCESSOR_TYPE" == "nvidia" ]]; then echo 'Installing with NVIDIA CUDA...' COMPOSE_FILE="docker-compose.cc-full-run-linux-nvidia.yml" else echo 'Installing...' COMPOSE_FILE="docker-compose.cc-full-run-linux.yml" fi sudo -E docker-compose -f $COMPOSE_FILE up -d if [[ $? -ne 0 ]]; then echo "Error: Failed to start docker-compose with Callaba Cloud" exit 1 fi sudo -E docker-compose -f webrtc/docker-compose.cc-webrtc.yml up -d sudo -E docker exec callabacloud-api rm /opt/installation-unfinished sudo -E docker restart callabacloud-api if [[ $? -ne 0 ]]; then echo "Error: Failed to start docker-compose with Callaba Cloud" exit 1 else echo "Callaba on-premise $STACK_VERSION has deployed successfully" fi } main() { echo "Are you sure you want to update/downgrade Callaba $STACK_VERSION ? (y/yes to confirm)" read -r confirmation if [[ "$confirmation" == "y" || "$confirmation" == "yes" ]]; then get_stack_version stop_containers remove_containers start_docker_compose remove_old_images echo $STACK_VERSION >STACK_VERSION.txt echo -e "Within 2-3 minutes, Callaba Dashboard will be available at \033[4;34mhttp://public-ip\033[0m, for example, \033[4;34mhttp://127.0.0.1\033[0m." else echo "Operation cancelled." fi } main