#!/bin/bash
# Function to check if a command is available
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to install Docker on Ubuntu
install_docker_ubuntu() {
if command_exists docker; then
echo "Docker is already installed. Skipping installation."
else
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
fi
}
# Function to install Docker Compose
install_docker_compose() {
if command_exists docker-compose; then
echo "Docker Compose is already installed. Skipping installation."
else
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
}
# Main script
echo "Checking Docker installation..."
install_docker_ubuntu
echo "Checking Docker Compose installation..."
install_docker_compose