#!/bin/sh
echo "87.107.132.77   master1" >> /etc/hosts;
echo "31.7.74.79      master2" >> /etc/hosts;
echo "87.107.132.78   worker1" >> /etc/hosts;
echo "31.7.74.118     worker2" >> /etc/hosts;
echo "31.7.74.96      worker3" >> /etc/hosts;




sudo apt update -y;
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y;
sudo apt install -y docker.io;
sudo systemctl start docker;
sudo systemctl enable docker;

# installing docker swarm

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -;
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable";
sudo apt update -y;
sudo apt install docker-ce -y;

# create user dockerman 
sudo useradd -m dockerman;
sudo usermod -aG docker dockerman;
# add to sudoers
sudo echo "dockerman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers;


# Get active primary interface name
interface=$(ip route | awk '/^default/ { print $5 }');
# Get IP address of active primary interface
ip=$(ip addr show $interface | awk '/inet / { sub("/.*", "", $2); print $2 }');
export HOST_IP=$ip;
export INT_name=$interface;

# remove ufw
sudo ufw disable;
# purge ufw
sudo apt-get purge ufw -y;


# disable swap
sudo swapoff -a;
sudo sed -i '/ swap / s/^/#/' /etc/fstab;

# set initial iptables rules



# open docker swarm ports in iptables




