#!/bin/bash

portainer_install(){
    echo "portainer install"
    if ! ssh root@${IP_LIST[0]} 'docker stack ls |grep portainer &> /dev/null';then
    	for ip in ${IP_LIST[@]}
    	do
            scp Install_Packages/portainer.tar root@${ip}:/tmp/
            ssh root@${ip} "docker load -i /tmp/portainer.tar"
        done
#        ssh root@${IP_LIST[0]} "docker node update --label-add nodeportainer=Portainer $(docker node ls|grep \*|grep -v ID |awk '{print $1}')"
        scp Template/portainer-agent-stack.yml root@${IP_LIST[0]}:${DOCKER_COMPOSE_DIR}/portainer-agent-stack.yml
        ssh root@${IP_LIST[0]} "docker stack deploy -c ${DOCKER_COMPOSE_DIR}/portainer-agent-stack.yml portainer" 
        if [ $? -ne 0 ];then
            echo "portainer install failed"
        fi
    fi
}
