#!/bin/bash


# 获取环境信息
/usr/local/bin/agent-wdd info all
cat /usr/local/etc/wdd/agent-wdd-config.yaml

# 手动执行全部的命令
/usr/local/bin/agent-wdd base ssh key
/usr/local/bin/agent-wdd base ssh config

/usr/local/bin/agent-wdd base tools
/usr/local/bin/agent-wdd base swap
/usr/local/bin/agent-wdd base firewall
/usr/local/bin/agent-wdd base selinux
/usr/local/bin/agent-wdd base sysconfig

/usr/local/bin/agent-wdd zsh

# 首先需要下载所有的依赖！

/usr/local/bin/agent-wdd base docker local
/usr/local/bin/agent-wdd base dockercompose local

# 仅在主节点执行
/usr/local/bin/agent-wdd base docker config

/usr/local/bin/agent-wdd base harbor install


# 主节点执行
# 安装octopus-agent
mv agent-wdd_linux_amd64 /usr/local/bin/agent-wdd
chmod +x /usr/local/bin/agent-wdd

# 主节点安装ssh-key
/usr/local/bin/agent-wdd base ssh config
/usr/local/bin/agent-wdd base ssh key

# 批量执行命令
host_list=(
   172.16.100.56
   172.16.100.57
   172.16.100.58
)
for server in "${host_list[@]}";do
   echo "current ip is $server"
   ssh root@${server} "rm -rf /var/lib/docker/nfs_data/*"
   echo ""
done


# 主节点批量安装key

# 复制 同步文件
export server=172.16.100.62

scp /usr/local/bin/agent-wdd root@${server}:/usr/local/bin/agent-wdd
ssh root@${server} "/usr/local/bin/agent-wdd base ssh config"
ssh root@${server} "/usr/local/bin/agent-wdd base ssh key"


# 安装docker-compose
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
chmod +x  /usr/local/bin/docker-compose

# ssh root@${server} "/usr/local/bin/agent-wdd base tools"


# 磁盘初始化
ssh root@${server} "mkdir /root/wdd"
scp /root/wdd/disk.sh root@${server}:/root/wdd/
ssh root@${server} "bash /root/wdd/disk.sh"

# 复制文件-docker
scp /root/wdd/docker-amd64-20.10.15.tgz root@${server}:/root/wdd/docker-amd64-20.10.15.tgz
scp /root/wdd/docker-compose-v2.18.0-linux-amd64  root@${server}:/root/wdd/

# 批量执行agent-wdd的命令
ssh root@${server} "/usr/local/bin/agent-wdd info all"
ssh root@${server} "cat /usr/local/etc/wdd/agent-wdd-config.yaml"



ssh root@${server} "/usr/local/bin/agent-wdd base swap"
ssh root@${server} "/usr/local/bin/agent-wdd base firewall"
ssh root@${server} "/usr/local/bin/agent-wdd base selinux"
ssh root@${server} "/usr/local/bin/agent-wdd base sysconfig"

ssh root@${server} "/usr/local/bin/agent-wdd base docker local"
ssh root@${server} "/usr/local/bin/agent-wdd base dockercompose local"

# 仅在主节点执行
/usr/local/bin/agent-wdd base docker config

# 下发docker的配置
scp /etc/docker/daemon.json root@${server}:/etc/docker/daemon.json
ssh root@${server} "cat /etc/docker/daemon.json"
ssh root@${server} "systemctl restart docker"
ssh root@${server} "docker info"

wget https://oss.demo.uavcmlc.com/cmlc-installation/tmp/nginx=1.27.0=2025-03-11=402.tar.gz && docker load < nginx=1.27.0=2025-03-11=402.tar.gz && docker run -it --rm harbor.cdcyy.com.cn/cmii/nginx:1.27.0


# 主节点执行 安装harbor仓库
/usr/local/bin/agent-wdd base harbor install

# 安装rke kubectl
mv /root/wdd/rke_amd64 /usr/local/bin/rke
chmod +x /usr/local/bin/rke

mv /root/wdd/kubectl /usr/local/bin/kubectl
chmod +x /usr/local/bin/kubectl


# 安装 k8s-证书


curl -s https://172.29.137.125