76 lines
3.6 KiB
Plaintext
76 lines
3.6 KiB
Plaintext
|
#!/bin/sh
|
||
|
|
||
|
# Update dynamic MOTD file
|
||
|
# {{ ansible_managed }}
|
||
|
|
||
|
set -o errexit
|
||
|
|
||
|
TMPFILE=$(mktemp)
|
||
|
TGTFILE=/run/blse-motd.dynamic
|
||
|
{% if ansible_distribution_release == "jessie" %}
|
||
|
BLSEVER="BLSE 2.x (Debian Jessie)"
|
||
|
{% elif ansible_distribution_release == "stretch" %}
|
||
|
BLSEVER="BLSE 2.1 (Debian Stretch)"
|
||
|
{% elif ansible_distribution_release == "buster" %}
|
||
|
BLSEVER="BLSE 2.2 (Debian Buster)"
|
||
|
{% elif ansible_distribution_release == "bullseye" %}
|
||
|
BLSEVER="BLSE 2.3 (Debian Bullseye)"
|
||
|
{% elif ansible_distribution_release == "bookworm" %}
|
||
|
BLSEVER="BLSE 2.4 (Debian Bookworm)"
|
||
|
{% endif %}
|
||
|
|
||
|
echo >> $TMPFILE
|
||
|
echo "\033[01;34mBoniface Labs Server Environment \033[01;36m${BLSEVER}\033[0m" >> $TMPFILE
|
||
|
echo -n "> \033[01;32m$(hostname)\033[0m" >> $TMPFILE
|
||
|
if test -f /etc/hostdesc; then
|
||
|
echo " - $( cat /etc/hostdesc )" >> $TMPFILE
|
||
|
else
|
||
|
echo >> $TMPFILE
|
||
|
fi
|
||
|
echo -n "> " >> $TMPFILE
|
||
|
|
||
|
# Get virtual machine info from vhostmd if it exists
|
||
|
VENDOR="$(/usr/sbin/dmidecode | grep Vendor | tr -d ' \t\n\r')"
|
||
|
if [ "$VENDOR" = "Vendor:Bochs" ] || [ "$VENDOR" = "Vendor:SeaBIOS" ]; then
|
||
|
hvhostname=$(/usr/sbin/vm-dump-metrics | grep -A1 HostName | awk -F'>' '{ if ($1 == " <value") print $2 }')
|
||
|
hvvirtproductinfo=$(/usr/sbin/vm-dump-metrics | grep -A1 VirtProductInfo | awk -F'>' '{ if ($1 == " <value") print $2 }')
|
||
|
if [ "$hvhostname" ]; then
|
||
|
echo "\033[1;37mKVM virtual machine\033[0m on node \033[1;31m${hvhostname}\033[0m (${hvvirtproductinfo})" >> $TMPFILE
|
||
|
else
|
||
|
echo "\033[1;37mRemote KVM virtual machine\033[0m" >> $TMPFILE
|
||
|
fi
|
||
|
elif [ "$VENDOR" = 'Vendor:DigitalOcean' ]; then
|
||
|
echo "\033[1;37mRemote KVM virtual machine\033[0m on \033[1;31mDigitalOcean\033[0m" >> $TMPFILE
|
||
|
else
|
||
|
# Are we a KVM hypervsor
|
||
|
if [ "$(hostname | grep dcrhv)" ]; then
|
||
|
echo "\033[1;37mRouter Hypervisor\033[0m on \033[1;31m$(/usr/sbin/dmidecode | grep -A1 'Base Board Information' | tail -1 | awk -F':' '{print $2}' | tr -s ' ' | sed 's/^ //' )\033[0m hardware" >> $TMPFILE
|
||
|
# Are we a Ceph node?
|
||
|
elif [ "$(hostname | grep ceph)" ]; then
|
||
|
echo "\033[1;37mCeph Storage Node\033[0m on \033[1;31m$(/usr/sbin/dmidecode | grep -A1 'Base Board Information' | tail -1 | awk -F':' '{print $2}' | tr -s ' ' | sed 's/^ //' )\033[0m hardware" >> $TMPFILE
|
||
|
# Are we a GPU node?
|
||
|
elif [ "$(hostname | grep gpu)" ]; then
|
||
|
echo "\033[1;37mGPU Processing Host\033[0m on \033[1;31m$(/usr/sbin/dmidecode | grep -A1 'Base Board Information' | tail -1 | awk -F':' '{print $2}' | tr -s ' ' | sed 's/^ //' )\033[0m hardware" >> $TMPFILE
|
||
|
# Are we Base?
|
||
|
elif [ "$(hostname | grep base)" ]; then
|
||
|
echo "\033[1;37mHome Base\033[0m on \033[1;31m$(/usr/sbin/dmidecode | grep -A1 'Base Board Information' | tail -1 | awk -F':' '{print $2}' | tr -s ' ' | sed 's/^ //' )\033[0m hardware" >> $TMPFILE
|
||
|
# Are we Env?
|
||
|
elif [ "$(hostname | grep env)" ]; then
|
||
|
echo "\033[1;37mEnvironmental Monitor\033[0m on \033[1;31mRaspberry Pi\033[0m hardware" >> $TMPFILE
|
||
|
# Are we Kal?
|
||
|
elif [ "$(hostname | grep kal)" ]; then
|
||
|
echo "\033[1;37mVoice Control Node\033[0m on \033[1;31mRaspberry Pi\033[0m hardware" >> $TMPFILE
|
||
|
# Are we IR?
|
||
|
elif [ "$(hostname | grep ir)" ]; then
|
||
|
echo "\033[1;37mInfared Control Node\033[0m on \033[1;31mRaspberry Pi\033[0m hardware" >> $TMPFILE
|
||
|
# Otherwise, we're generic
|
||
|
else
|
||
|
echo "\033[1;37mGeneric server\033[0m on \033[1;31m$(/usr/sbin/dmidecode | grep -A1 'Base Board Information' | tail -1 | awk -F':' '{print $2}' | tr -s ' ' | sed 's/^ //' )\033[0m hardware" >> $TMPFILE
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
echo "> $(/bin/uname -srvmo)" >> $TMPFILE
|
||
|
|
||
|
mv $TMPFILE $TGTFILE || rm $TMPFILE
|
||
|
chmod 644 $TGTFILE
|