#!/bin/bash

STEPS=9
STEP=1
STATUS_NAME=

progress () {
    echo "$STEP $STEPS" > /tmp/on-premise-progress.txt
    echo "$STATUS_NAME" >> /tmp/on-premise-progress.txt
    STEP=$((STEP+1))
}

echo "1 $STEPS" > /tmp/on-premise-progress.txt
echo "Starting" >> /tmp/on-premise-progress.txt

echo "2 $STEPS" > /tmp/on-premise-progress.txt
echo "apt-get install -y git" >> /tmp/on-premise-progress.txt
apt-get install -y git



echo "3 $STEPS" > /tmp/on-premise-progress.txt
echo "Install docker" >> /tmp/on-premise-progress.txt
wget -qO- https://get.docker.com/ | sh

echo "4 $STEPS" > /tmp/on-premise-progress.txt
echo "obtain compose version" >> /tmp/on-premise-progress.txt
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort | tail -n 1`

echo "5 $STEPS" > /tmp/on-premise-progress.txt
echo "Installing docker-compose" >> /tmp/on-premise-progress.txt
sudo curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

echo "6 $STEPS" > /tmp/on-premise-progress.txt
echo "Setup docker-compose" >> /tmp/on-premise-progress.txt
chmod +x /usr/local/bin/docker-compose

echo "7 $STEPS" > /tmp/on-premise-progress.txt
echo "Installing bash completion for docker-compose" >> /tmp/on-premise-progress.txt
sh -c "curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose"

echo "8 $STEPS" > /tmp/on-premise-progress.txt
echo "Setup user permissions" >> /tmp/on-premise-progress.txt
echo "usermod -a -G docker $USER"
usermod -a -G docker $USER

echo "9 $STEPS" > /tmp/on-premise-progress.txt
echo "Complete" >> /tmp/on-premise-progress.txt
