#!/bin/sh
set -e

echo "Init Data..."
mkdir -p /data
curl -L https://git.quanzhan.store/open-source/init/raw/branch/master/resource/web.zip -o /data/web.zip
chmod +x /data/web.zip
cd /data && unzip web.zip

echo "1. 更新系统..."
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
# // 清理源缓存
yum clean all && yum makecache
# // 更新源
yum -y update
yum -y install git openssl-devel
echo "2. 执行 Docker 安装脚本..."
# curl -fsSL https://get.docker.com/ | sh
# curl -sSL https://get.daocloud.io/docker | sh
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
sudo service docker start
systemctl enable docker
echo "3. 验证 docker 是否安装成功并在容器中执行一个测试的镜像..."
sudo docker run hello-world
echo "4. 执行 DockerCompose 安装脚本..."
curl -L https://git.quanzhan.store/open-source/init/raw/branch/master/docker/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -v
echo "5. 安装Docker软件..."
echo "5.1 portainer..."
docker run -d -p 8888:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /data/portainer/data:/data portainer/portainer