Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Last active September 15, 2023 14:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amcgregor/1522110 to your computer and use it in GitHub Desktop.
Save amcgregor/1522110 to your computer and use it in GitHub Desktop.
A convenient motd-creation script for Gentoo servers.
#!/bin/sh
# Place in /etc/motd.d and drop the .sh suffix.
echo -e "\n\033[1mWelcome to Gentoo Linux!\033[0m"
echo -e "\nThis server is maintained by \033[1m$(cat /etc/maintainer)\033[0m."
echo -e "Contact \033[1m$(cat /etc/maintainer-address)\033[0m for support."
echo en "\n \033[1;32m*\033[0m "
lsb_release -d -s | sed s/\"//g
echo -en " \033[1;32m*\033[0m "
uname -snmpr
MAX=$(($(cat /proc/cpuinfo | grep processor | wc -l) - 1))
LOAD=$(cat /proc/loadavg | cut -d '.' -f 1)
if [ $LOAD -gt $(($MAX * 4)) ]
then echo -en " \033[1;31m*\033[0m"
elif [ $LOAD -gt $MAX ]
then echo -en " \033[1;33m*\033[0m"
else echo -en " \033[1;32m*\033[0m"
fi
uptime
echo -en " \033[1;32m*\033[0m IPv4 Network Interfaces: \033[1m"
ifconfig | grep 'inet ' | cut -d ' ' -f 10 | tr '\n' ' '
echo -e "\033[0m"
echo -en " \033[1;32m*\033[0m IPv6 Network Interfaces: \033[1m"
ifconfig | grep 'inet6 ' | cut -d ' ' -f 10 | tr '\n' ' '
echo -e "\033[0m"
#!/bin/bash
# Place in /etc/motd.d and drop the .sh suffix.
if [ ! -e /var/tmp/.updates ] ; then
/usr/local/sbin/check-updates > /var/tmp/.updates
fi
cat /var/tmp/.updates
#!/bin/sh
# Place in /usr/local/sbin and drop the .sh suffix.
SYS=$(emerge -uDNpq system | grep ebuild | wc -l)
WRL=$(emerge -uDNpq world | grep ebuild | wc -l)
SEC=$(glsa-check -l affected 2> /dev/null | grep \\[ | wc -l)
TOT=$(glsa-check -l all 2> /dev/null | grep \\[ | wc -l)
NEWS=$(eselect news list | grep unread | wc -l)
SYSC="\033[1;32m"
WRLC=$SYSC
SECC=$SYSC
if [ $SYS -gt 0 ] ; then
SYSC="\033[1;33m"
fi
if [ $WRL -gt 0 ] ; then
WRLC="\033[1;33m"
fi
if [ $SEC -gt 0 ] ; then
SECC="\033[1;31m"
fi
echo -e "\nPortage and GLSA status:\n"
echo -e " ${SYSC}* ${SYS}\033[0m system packages have updates available."
echo -e " ${SECC}* ${SEC}\033[0m of \033[1m${TOT}\033[0m security advisories affect this server."
echo -e " ${WRLC}* ${WRL}\033[0m packages in total can be updated."
if [ $NEWS -gt 0 ] ; then
echo -e "\n\033[1;33mImportant:\033[0m There are \033[1m${NEWS}\033[0m unread news items."
fi
#!/bin/bash
# Place in /usr/local/sbin and drop the .sh suffix.
# Configure this to run between once every minute and once every five.
cd /etc/motd.d
rm -f /tmp/motd-tmp
touch /tmp/motd-tmp
for SCRIPT in $(ls); do
test -x ${SCRIPT} || continue
./${SCRIPT} >> /tmp/motd-tmp
done
echo >> /tmp/motd-tmp
mv /tmp/motd-tmp /etc/motd
#!/bin/sh
# Place in /etc/portage/postsync.d and drop the .sh suffix.
# Would be nice if this could also run after every package installation.
rm /var/tmp/.updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment