#!/bin/bash

version=$(curl -s https://download.docker.com/linux/static/stable/x86_64/ | grep -ioP 'docker-\d+\.\d+\.\d+\.tgz\"' | sed 's/"//g' | sort -rV | head -n 1)

wget https://download.docker.com/linux/static/stable/x86_64/$version
tar xvf $version
mv docker/* /usr/bin
rm -r docker*

mkdir -p $HOME/.docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.34.0/docker-compose-linux-x86_64 -o $HOME/.docker/cli-plugins/docker-compose

cat << EOF > /root/.bashrc


# Docker plugins
export PATH=$HOME/.docker/cli-plugins:$PATH
EOF

link=$(curl -s https://api.github.com/repos/docker/buildx/releases | jq -r .[0].zipball_url)
curl -s $link -o /usr/bin/buildx

msd -c docker dockerd