#!/bin/bash

source /opt/scripts_local/shared_functions.sh

echo "Check if docker is installed..."
docker --version &> /dev/null
if ! [ $? -eq 0 ]; then
  # >>>>>>>> Download Docker
  echo "Docker not installed"
  echo "Downloading docker from docker.com"
  curl -fsSL get.docker.com -o get-docker.sh
  # Install Docker using the stable channel (instead of the default "edge")
  CHANNEL=stable 
  echo "Installing docker from docker.com"
  sudo sh get-docker.sh
  # Remove Docker install script
  rm get-docker.sh
  sudo usermod -aG docker dbi
else
  echo "Docker installed, skipping"
fi

echo "Check if docker-compose is installed..."
docker-compose --version &> /dev/null
# Docker-compose
if ! [ $? -eq 0 ]; then
  echo "docker-compose not present. Installing..."
  echo "Downloading docker-compose."
  sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  sudo chmod +x /usr/local/bin/docker-compose
else
  echo "docker-compose installed, skipping"
fi

docker --version
docker-compose --version