#/bin/bash
set -x
# Manual Docker install for bionic -- Quick and Dirty

export DEBIAN_FRONTEND=noninteractive
export PATH=/root/sbin:/usr/local/sbin:/sbin:/usr/sbin:/root/bin:/usr/local/bin:/bin:/usr/bin:/opt/puppetlabs/bin:/opt/docker

sudo bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install linux-image-extra-virtual unzip curl git > /dev/null 2>&1 & disown'
# sudo DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install linux-image-extra-virtual unzip
sudo groupadd --force --system docker
sudo usermod --append --groups docker techstaff
sudo wget --tries 5 --quiet https://mirror.cs.uchicago.edu/docker_bootstrap/docker.service --output-document /etc/systemd/system/docker.service &
sudo wget --tries 5 --quiet https://mirror.cs.uchicago.edu/docker_bootstrap/docker.socket --output-document /etc/systemd/system/docker.socket &
sudo wget --tries 5 --quiet https://mirror.cs.uchicago.edu/docker_bootstrap/docker-compose-Linux-x86_64 --output-document /usr/bin/docker-compose &
sudo wget --tries 5 --quiet https://mirror.cs.uchicago.edu/docker_bootstrap/docker-17.03.2-ce.tgz --output-document /opt/docker-17.03.2-ce.tgz
sudo tar --extract --gunzip --file /opt/docker-17.03.2-ce.tgz --directory /opt
sudo rm -rf /usr/bin/docker*
sudo cp --preserve -r /opt/docker/* /usr/bin/
sudo ln -sf /var/run/systemd/resolve/resolv.conf /etc/resolv.conf 
sudo mkdir --parents /etc/docker
sudo tee --append /etc/docker/daemon.json << EOF
{
  "log-level": "info"
}
EOF
sudo chmod --quiet 0744 /etc/docker/daemon.json
sudo systemctl --quiet --force daemon-reload
sudo systemctl --force --quiet enable docker
sudo chmod --quiet gu+x /usr/bin/docker-compose &
sudo chgrp --quiet docker /usr/bin/docker-compose &
sudo systemctl --force stop docker
sudo systemctl --force start docker
sleep 2
sudo systemctl --force restart docker
exit 0
