#!/bin/bash


master_server_list=(192.168.35.105 192.168.35.114 192.168.35.115)
worker_server_list=(192.168.35.55 192.168.35.86 192.168.35.89 192.168.35.93 192.168.35.95 192.168.35.96 192.168.35.101 192.168.35.103 192.168.35.104)

all_server_list=(192.168.35.105 192.168.35.114 192.168.35.115 192.168.35.55 192.168.35.86 192.168.35.89 192.168.35.93 192.168.35.95 192.168.35.96 192.168.35.101 192.168.35.103 192.168.35.104)



all_server_list=(192.168.40.53 192.168.40.54 192.168.40.55)

all_server_list=(192.168.35.105 192.168.35.114 192.168.35.115 dev-worker-01 dev-worker-02 dev-worker-03 dev-worker-04 dev-worker-05 dev-worker-06 dev-worker-07 dev-worker-08 dev-worker-09 dev-worker-10 dev-worker-11 dev-worker-12)


for server in "${all_server_list[@]}";do
   echo "server is ${server}"
   
  scp /etc/docker/daemon.json root@"${server}":/etc/docker/daemon.json
ssh root@"${server}" "systemctl reload docker"
ssh root@"${server}" "docker info"
  
done


count=1
for server in "${all_server_list[@]}";do
   echo "server is ${server}"


#   sshpass -p "scyd@lab1234" ssh root@"${server}" "echo \"root:tY\$@Go7jS#h2\" | chpasswd"
#
sshpass -p "scyd@lab1234" 

echo root:V2ryStr@ngPss| chpasswd

echo root:Len3#io7%2k | chpasswd
echo root:Io7.*GaaBxA | chpasswd

mkdir -p  /root/.ssh/
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDPFSLFi0rzZSXf6laZ/s4AFCsgZBu8tyCx4bCmB3/k6x7xH1rjk/EZ8N2ZWV2CyTyjHCghu94ZmV0e6/FeC/KdBH96A69fGrq0HjsvAHTTvyEmmtrWmB7OAjhWloaovj1V8B1bTC9IZsZ4lN7agZ8u/uHzri2esXduTzXc186Q6h8lm1t5Gh7RGYGPdaXIjaFLxVSmdci+4eoS+EOEo/mspJB34TFuN8xEBzA3N06tmjAPtVpi0RFa6n/L9CUp2OQBJ8EQVgOYY6t5i3prLl29K9zSRX46ue+9jWbzfyKfKHk7jCfjnH6BG47/sbWoAyYPdkfSwvCZBroOjQh4gf3Ga4Gt4e7+rQ4sT3mrHUtXRd+g+0u9XOsYpHCTwwbtSiDJ+6DfdZYuJOeqgL82zeaJeFu0IXLhgn/q96aVbF15MLD1gGkXj/FFFGGWJfr5zrZJVWrm0NRCaxJftUHNpnK0MrMCqsHSxmkdypUzN6n020NkNGUE1UMUU4O48O4PsE= root@ops-01.ecs.io
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBO6IjOcco9eAvA/T7LDsylCgjKJlLrVXY1zxO1/mX/MTzVZGuAhbikFJT2ZN2Up8iED+pJwpcps3LlA1wOjQC3Q= root@ops-04.ecs.io" >> /root/.ssh/authorized_keys

#    host_name="dev-worker-0"${count}
#   ((count++))
#   echo "${server} $host_name" >> /root/wdd/1.txt
#   echo ""
#   ssh root@"${server}" "hostnamectl set-hostname $host_name"
#   ssh root@"${server}" "hostname"
#   echo ""

#    ssh root@"${server}" "echo yes"


export server=192.168.40.73
scp /usr/local/bin/octopus-agent root@${server}:/usr/local/bin/octopus-agent
ssh root@${server} "mkdir /root/wdd"
ssh root@${server} "chmod +x /usr/local/bin/octopus-agent"
ssh root@${server} "printf 'ssh\n' | octopus-agent --mode=bastion"

scp /root/wdd/disk.sh root@${server}:/root/wdd/disk.sh
ssh root@${server} "bash /root/wdd/disk.sh"

nmcli connection modify "eth0" ipv4.dns "192.168.34.40,119.29.29.29"
nmcli connection up "eth0"
nmcli dev show | grep DNS

scp /etc/ssh/sshd_config root@"${server}":/etc/ssh/sshd_config
ssh root@"${server}" "systemctl restart sshd"


ssh root@"${server}" "nmcli connection modify \"eth0\" ipv4.dns \"192.168.34.40,119.29.29.29\"
nmcli connection up \"eth0\""
 ssh root@"${server}" "nmcli dev show | grep DNS"

ssh root@"${server}" "yum install -y net-tools iputils bind-utils lsof curl wget vim mtr htop"

scp /root/wdd/docker-amd64-20.10.15.tgz root@${server}:/root/wdd/docker-amd64-20.10.15.tgz
scp /root/wdd/docker-compose-linux-x86_64-v2.18.0  root@${server}:/root/wdd/

ssh root@${server} "printf 'firewall\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'sysconfig\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'swap\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'selinux\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'docker\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'dockercompose\n' | octopus-agent --mode=bastion"
ssh root@${server} "printf 'harbor\n' | octopus-agent --mode=bastion"


scp /etc/docker/daemon.json root@"${server}":/etc/docker/daemon.json
ssh root@"${server}" "systemctl restart docker"

ssh root@"${server}" "docker login -u rad02_drone -p Drone@1234 harbor.cdcyy.com.cn"
ssh root@"${server}" "yum install -y nfs-utils rpcbind"
ssh root@"${server}" "yum install -y chrony && systemctl start chronyd && systemctl enable chronyd"
ssh root@"${server}" "systemctl start nfs nfs-client nfs-common && systemctl enable nfs nfs-client nfs-common && systemctl status nfs nfs-client nfs-common -l | grep \"active (running)\""


mv ctop-0.7.7-linux-amd64 /usr/local/bin/ctop
chmod +x /usr/local/bin/ctop

printf 'firewall\n' | octopus-agent --mode=bastion
printf 'sysconfig\n' | octopus-agent --mode=bastion
printf 'swap\n' | octopus-agent --mode=bastion
printf 'selinux\n' | octopus-agent --mode=bastion
printf 'docker\n' | octopus-agent --mode=bastion
printf 'dockercompose\n' | octopus-agent --mode=bastion