#!/usr/bin/env bash
# 文件名: containerd_install.sh

VERSION=1.7.18
DATA_ROOT=/data/containerd
TEMP_PATH=$(mktemp -d)
PKG_URL=https://dl.vqiu.cn/package/containerd/containerd-${VERSION}-${ARCH}.tar.gz 

# 判断环境平台
if [ -z "${ARCH}" ]; then
  case $(uname -m) in
    x86_64) ARCH=amd64 ;;
    aarch64) ARCH=arm64 ;;
    *) printf "$err: 不支持该平台 $(uname -m)"; exit 1 ;;
  esac
fi

cat >/etc/sysctl.d/99-containerd.conf <<EOF
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF


cd ${TEMP_PATH}
if [[ ! -e ${PKGPKG_URL##*/} ]]
then
    wget ${PKG_URL} || wget ${PKG_URL/https/http}
fi
tar axvf containerd-${VERSION}-${ARCH}.tar.gz -C /usr/local

install -d /etc/containerd
containerd config default >/etc/containerd/config.toml

sed -i -e "s/^root = .*/root = ${DATA_DIR}/" \
       -e "s/SystemdCgroup =.*/SystemdCgroup = true/" \
       /etc/containerd/config.toml

systemctl enable containerd --now
