#!/usr/bin/env bash
which curl
if [[ $? -ne 0 ]]; then
  apt install curl -y
fi
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
rm -f /etc/apt/sources.list.d/*docker-ce*
arch=`uname -m`
if [[ $arch == "x86_64" ]]; then
  arch = "amd64"
fi
echo "deb [arch=armhf] https://mirrors4.tuna.tsinghua.edu.cn/docker-ce/linux/debian/ $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker-ce.list
apt update
apt install -y docker-ce
mkdir -p /etc/docker
txt='{
  "exec-opts": ["native.cgroupdriver=cgroupfs"],
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}'
echo $txt > /etc/docker/daemon.json
systemctl daemon-reload
if [[ $? -eq 0 ]]; then
  systemctl enable docker
  systemctl restart docker
else
  echo "Could not start docker"
  exit 1
fi