From 53d2410ce3d6e73fe8843caef6375ff18d0a05ea Mon Sep 17 00:00:00 2001 From: wallaceosmar Date: Sat, 23 Nov 2024 16:56:08 +0000 Subject: [PATCH] Atualizar install.sh --- install.sh | 84 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/install.sh b/install.sh index 8362e34..6ac23d2 100644 --- a/install.sh +++ b/install.sh @@ -116,49 +116,27 @@ load_env_file() { fi } -# Main installation logic -install_application() { - ensure_data_directory - check_disk_space - handle_env_file - load_env_file - - if command_exists docker; then - echo "Docker detected. Proceeding with Docker setup..." - curl -o docker-compose.yml $DOCKER_COMPOSE_URL - echo "docker-compose.yml downloaded successfully." - echo "Running Docker Compose with the environment variables..." - docker-compose --env-file "$ENV_FILE" up -d - elif command_exists kubectl || command_exists k3s; then - echo "K3s or Kubernetes detected. Proceeding with Kubernetes setup..." - curl -o kubernetes-deploy.yaml $KUBERNETES_DEPLOY_URL - echo "kubernets-deploy.yaml downloaded successfully." - echo "Applying Kubernetes deployment..." - kubectl apply -f kubernetes-deploy.yaml - else - echo "Neither Docker nor Kubernetes is installed." - read -p "Would you like to install Docker or K3s? (docker/k3s): " choice +# Function to prompt for Docker or K3s installation +prompt_installation_choice() { + echo "Neither Docker nor Kubernetes is installed." + while true; do + read -rp "Would you like to install Docker or K3s? (docker/k3s): " choice case "$choice" in - docker ) + docker) install_docker - curl -o docker-compose.yml $DOCKER_COMPOSE_URL - echo "docker-compose.yml downloaded successfully." - echo "Running Docker Compose with the environment variables..." - docker-compose --env-file "$ENV_FILE" up -d + setup_docker + break ;; - k3s ) + k3s) install_k3s - curl -o kubernetes-deploy.yaml $KUBERNETES_DEPLOY_URL - echo "kubernets-deploy.yaml downloaded successfully." - echo "Applying Kubernetes deployment..." - kubectl apply -f kubernetes-deploy.yaml + setup_k3s + break ;; - * ) - echo "Invalid choice. Exiting." - exit 1 + *) + echo "Invalid choice. Please enter 'docker' or 'k3s'." ;; esac - fi + done } # Function to install Docker @@ -170,6 +148,14 @@ install_docker() { echo "Docker installed successfully." } +# Function to set up Docker +setup_docker() { + curl -o docker-compose.yml $DOCKER_COMPOSE_URL + echo "docker-compose.yml downloaded successfully." + echo "Running Docker Compose with the environment variables..." + docker-compose --env-file "$ENV_FILE" up -d +} + # Function to install K3s install_k3s() { echo "K3s is not installed. Installing K3s..." @@ -177,5 +163,31 @@ install_k3s() { echo "K3s installed successfully." } +# Function to set up K3s +setup_k3s() { + curl -o kubernetes-deploy.yaml $KUBERNETES_DEPLOY_URL + echo "kubernets-deploy.yaml downloaded successfully." + echo "Applying Kubernetes deployment..." + kubectl apply -f kubernetes-deploy.yaml +} + +# Main installation logic +install_application() { + ensure_data_directory + check_disk_space + handle_env_file + load_env_file + + if command_exists docker; then + echo "Docker detected. Proceeding with Docker setup..." + setup_docker + elif command_exists kubectl || command_exists k3s; then + echo "K3s or Kubernetes detected. Proceeding with Kubernetes setup..." + setup_k3s + else + prompt_installation_choice + fi +} + # Run the installation process install_application