#!/bin/bash
# les bases 
#  noeud hb1  : 192.168.0.115 
#  noeud hb2  : 192.168.0.116 
#  addr virt. : 192.168.0.117 
    
sed -i 's/bookworm/hb1/g' /etc/host{s,name}
apt update
apt install -y heartbeat apache2 net-tools
systemctl disable apache2

cat <<EOT> /etc/network/interfaces.d/enp0s3
allow-hotplug enp0s3
iface enp0s3 inet static
address 192.168.0.115/24 # a adapter pour hb2
EOT

cat <<EOT> /etc/network/interfaces.d/enp0s8
allow-hotplug enp0s8
iface enp0s8 inet static
address 10.0.0.1/24      # a adapter pour hb2
EOT

cd /usr/share/doc/heartbeat
gunzip *.gz
cp ha.cf /etc/ha.d
cp haresources /etc/ha.d
cp authkeys /etc/ha.d
cd /etc/ha.d
echo "192.168.0.116 hb2" >> /etc/hosts # a adapter pour hb2

cat <<EOT >> /etc/ha.d/ha.cf
bcast enp0s8
node hb1
node hb2
pacemaker off
EOT

# echo " hb1 192.168.0.117 apache2" >> /etc/ha.d/haresources pou Debian buster
echo " hb1 192.168.0.117/24/enp0s3 apache2" >> /etc/ha.d/haresources 

cat <<EOT >> /etc/ha.d/authkeys
auth 1
1 crc
EOT

chmod 600 /etc/ha.d/authkeys
echo hb1 > /var/www/html/index.html # a adapter pour hb2
 #