#!/bin/bash

sudo apt-get install sshpass
#ssh_global_user="parablu"
#ALLIPS="172.104.22.451"
SSH_PORT=22
#SSH_PASSWORD="P@rablu123"
#SUDO_BASH_PASSWORD="P@rablu123"
cat /dev/zero | ssh-keygen -q -N "" > /dev/null
mkdir -p /home/$ssh_global_user/.ssh
SCRIPT_DIR=`pwd`
sleep 1s
tput clear
echo "PERFORMING SSH CONNECTIVITY..............."
sleep 2s
read -p "Enter the SSH User [ Should be same across all Machines ]:" ssh_global_user
read -p "Enter the IP's of Machines [If multiple give a space as separator ]:" ALLIPS

for eachip in ${ALLIPS[@]}
do
	read -p "Enter the SSH Password for [ $eachip ] with User [ $ssh_global_user ]:" SSH_PASSWORD
	sudo sshpass -p $SSH_PASSWORD ssh-copy-id -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no $ssh_global_user@$eachip
	sleep 3s

	read -p "Enter the Sudo Bash Password for User [ $ssh_global_user ] in [ $eachip ]:" SUDO_BASH_PASSWORD
	ssh -t $ssh_global_user@$eachip  "cd $SCRIPT_DIR && echo $SUDO_BASH_PASSWORD | sudo -S bash -x slave_ssh_config.sh $ssh_global_user"

done

