#!/bin/bash

echo "reboot to erase the old configurations;"
bash ~/reboot.sh
echo "rebooting"
countdown=40
while [ $countdown -gt 0 ]; do
	echo -ne "counting down: $countdown s \033[0K\r"
	sleep 1
	countdown=$((countdown - 1))
done

assign_ip(){
	local dev=$1
	local eth_num=$2
	local ip=$3
	ssh $dev "ip link set dev eth$eth_num up"
	ssh $dev "ip addr add $ip dev eth$eth_num"
}

echo "assigning IP on router1"

assign_ip "router1" 1 "10.5.1.2/24"
assign_ip "router1" 2 "10.5.3.3/24"
assign_ip "router1" 3 "10.5.4.2/24"
assign_ip "router1" 4 "10.5.2.3/24"


echo "assigning IP on router2"

assign_ip "router2" 1 "10.5.2.2/24"
assign_ip "router2" 2 "10.5.3.4/24"
assign_ip "router2" 3 "10.5.6.1/24"
assign_ip "router2" 4 "10.5.5.5/24"


echo "assigning IP on router3"

assign_ip "router3" 1 "10.5.3.2/24"
assign_ip "router3" 2 "10.5.4.3/24"
assign_ip "router3" 3 "10.5.6.2/24"
assign_ip "router3" 4 "10.5.7.1/24"

echo "assigning IP on router4"

assign_ip "router4" 1 "10.5.2.4/24"
assign_ip "router4" 2 "10.5.5.4/24"
assign_ip "router4" 3 "10.5.7.2/24"

echo "assigning IP on pc1"

assign_ip "pc1" 1 "10.5.1.1/24"


echo "assigning IP on pc2"

assign_ip "pc2" 1 "10.5.2.1/24"

echo "assigning IP on pc3" 

assign_ip "pc3" 1 "10.5.3.1/24"
bash ~/checkip.sh
