EvoBSD/roles/post-install/files/motd-carp-state.sh
Jérémy Dubois b586b1fafe
Some checks failed
continuous-integration/drone/push Build is failing
Write and deploy motd-carp-state.sh
A script that checks the carp state and writes in the /etc/motd file if the
server is in backup or master state. Script is copied in /usr/share/scripts/
directory and a cron job is installed but disabled by default.
2020-08-25 17:57:22 +02:00

48 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
if [ ! -f /etc/motd-original ]; then
cp /etc/motd /etc/motd-original
fi
if [ ! -f /tmp/carp.state ]; then
echo "unknown" > /tmp/carp.state
fi
ifconfig carp0 | grep -q master
master=$?
ifconfig carp0 | grep -q backup
backup=$?
if [ "$master" -eq 0 ]; then
if [ $(cat /tmp/carp.state) = "master" ]; then
# We already were master, no change
exit 0
fi
cat /etc/motd-original - << EOF > /etc/motd
__ ______ _____________________
/ |/ / | / ___/_ __/ ____/ __ \
/ /|_/ / /| | \__ \ / / / __/ / /_/ /
/ / / / ___ |___/ // / / /___/ _, _/
/_/ /_/_/ |_/____//_/ /_____/_/ |_|
EOF
echo "master" > /tmp/carp.state
elif [ "$backup" -eq 0 ]; then
if [ $(cat /tmp/carp.state) = "backup" ]; then
# We already were backup, no change
exit 0
fi
cat /etc/motd-original - << EOF > /etc/motd
____ ___ ________ ____ ______
/ __ )/ | / ____/ //_/ / / / __ \
/ __ / /| |/ / / ,< / / / / /_/ /
/ /_/ / ___ / /___/ /| / /_/ / ____/
/_____/_/ |_\____/_/ |_\____/_/
EOF
echo "backup" > /tmp/carp.state
else
# No CARP
exit 0
fi