Newer
Older
clusterSetupDev / scripts / lxc / multipassInstallPreRequired.sh
function multipassExecTaskV1
{
	host=$1
	echo $host
	set -x

	machine="localhost"
	if [ "$machine" == "multipass" ]
	then
		executor="sudo lxc exec $host --"
	fi
	$executor	sudo apt update -y 
	$executor	sudo apt install ansible -y 
	$executor	mkdir repo
	$executor	git config --global user.email "agalyadoss@gmail.com"
	$executor	git config --global user.name "Agalya Ramadoss"
	$executor	sudo addgroup --gid 8055 boss 
	$executor	sudo adduser --system  --shell /bin/bash --uid 805501 --gid 8055 aboss 
	$executor	sudo adduser --system  --shell /bin/bash --uid 905501 --gid 8055 adoss
	$executor	sudo usermod -aG sudo aboss
	$executor	sudo usermod -aG sudo adoss
	$executor	sudo sh -c "echo aboss:$root_password|sudo chpasswd"
	$executor	sudo sh -c "echo adoss:$root_password|sudo chpasswd"
	$executor	sudo sed -i  "s/#   PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/ssh_config            
	$executor	sudo sed -i  "s/#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config            
	$executor	sudo sed -i  "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config            
	$executor	sudo sed -i  "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config 
	$executor	sudo sh -c "ssh-keygen -N ''  -q -f ~/.ssh/id_rsa  -t rsa -b 4096 -C root"

			

} 
function multipassExecTask
{
	host=$1
	echo $host
	sudo lxc exec $host -- sudo apt update -y 
	sudo lxc exec $host -- sudo apt install ansible -y 
	sudo lxc exec $host -- sudo snap install multipass-sshfs -y 
	sudo lxc exec $host -- mkdir repo
	sudo lxc exec $host -- git config --global user.email "agalyadoss@gmail.com"
	sudo lxc exec $host -- git config --global user.name "Agalya Ramadoss"
	sudo lxc exec $host -- sudo addgroup --gid 8055 boss 
	sudo lxc exec $host -- sudo adduser --system  --shell /bin/bash --uid 805501 --gid 8055 aboss 
	sudo lxc exec $host -- sudo adduser --system  --shell /bin/bash --uid 905501 --gid 8055 adoss
	sudo lxc exec $host -- sudo usermod -aG sudo aboss
	sudo lxc exec $host -- sudo usermod -aG sudo adoss
#	sudo lxc exec $host -- sudo sh -c "echo $root_password\n$root_password|sudo passwd aboss"
#	sudo lxc exec $host -- echo sh -c "$root_password|sudo passwd adoss"
	sudo lxc exec $host -- sudo sh -c "echo aboss:$root_password|sudo chpasswd"
	sudo lxc exec $host -- sudo sh -c "echo adoss:$root_password|sudo chpasswd"
	sudo lxc exec $host --	sudo sed -i  "s/#   PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/ssh_config            
	sudo lxc exec $host -- sudo sed -i  "s/#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config            
	sudo lxc exec $host -- sudo sed -i  "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config            
	sudo lxc exec $host -- sudo sed -i  "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config 
#	sudo lxc exec $host -- sudo ssh-keygen -t rsa -b 4096 -C "root"
	sudo lxc exec $host -- sudo sh -c "ssh-keygen -N ''  -q -f ~/.ssh/id_rsa  -t rsa -b 4096 -C root"
#	sudo lxc exec $host -- sudo vim /etc/ssh/sshd_config
#	sudo lxc exec $host -- sudo passwd
#	sudo lxc exec $host -- sudo vim /root/.ssh/authorized_keys 
#	sudo lxc restart $host
#	sudo lxc exec $host -- sudo vim /etc/default/kubelet
			

} 
function multipassExecPostTask
{ 
	host=$1
	echo $host
	id_rsa=`sudo lxc exec $host  -- sudo cat /root/.ssh/id_rsa.pub`
	for  chost in  `cat hosts` 
	do
		echo $chost
		sudo lxc exec $chost  -- sudo sh -c "echo '$id_rsa'>>  /root/.ssh/authorized_keys"
		echo "sleeping for 1 seconds copy from $host  to $chost "
		sleep 1
	done
	
}

function multipassExecPostTaskV1
{ 
	host=$1
	echo $host
	machine="multipass"
	if [ "$machine" == "multipass" ]
	then
		executor="sudo lxc exec $host --"
	fi
	id_rsa=`$executor sudo cat /root/.ssh/id_rsa.pub`
	for  chost in  `cat hosts` 
	do
		echo $chost
		$executor sudo sh -c "echo '$id_rsa'>>  /root/.ssh/authorized_keys"
		echo "sleeping for 1 seconds copy from $host  to $chost "
		sleep 1
	done
	
}
function multipassExecSshVerifyV1
{ 
	set -x
	host=$1
	echo $host
	machine="localhost"
	if [ "$machine" == "multipass" ]
	then
		executor="sudo lxc exec $host --"
	fi
	for  chost in  `cat hosts` 
	do
		echo $chost
		$executor sudo sh -c "ssh-keyscan $host >> /root/.ssh/known_hosts"
		#sudo lxc exec $chost  -- sudo ssh $host
		#ssh-keyscan us-mc02-pac-mp-ub2204-en0-kubeadm-2   >> $HOME/.ssh/known_hosts
	done
}
function multipassExecSshVerify 
{ 
	host=$1
	echo $host
	for  chost in  `cat hosts` 
	do
		echo $chost
		sudo lxc exec $chost  -- sudo sh -c "ssh-keyscan $host >> /root/.ssh/known_hosts"
		#sudo lxc exec $chost  -- sudo ssh $host
		#ssh-keyscan us-mc02-pac-mp-ub2204-en0-kubeadm-2   >> $HOME/.ssh/known_hosts
	done
}
#Main 
if [ "$root_password" == "" ] 
then
	echo "Please export root_password"
	exit 1
fi

for  host in  `cat hosts` 
do 
	multipassExecTask   $host 
	echo $host 
done
for  host in  `cat hosts` 
do 
	multipassExecPostTask   $host 
done
for  host in  `cat hosts` 
do 
	multipassExecSshVerify   $host 
done