Skip to content

Instantly share code, notes, and snippets.

@phieber
Forked from amcgregor/00-header.sh
Last active January 4, 2016 13:49
Show Gist options
  • Save phieber/8630830 to your computer and use it in GitHub Desktop.
Save phieber/8630830 to your computer and use it in GitHub Desktop.
#!/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 -e "\n \033[1;32m*\033[0m $(cat /etc/gentoo-release)"
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 Interface: \033[1m"
ifconfig venet0 | grep 'RX bytes' | sed -e 's/^ *//g;'
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 [ $(find /tmp/.updates -mtime 1 | wc -l) -gt 0 ] ; then
/etc/motd.d/check-updates.sh > /tmp/.updates
fi
cat /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 -e '] *N *2' | 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 [0-9]*.sh); 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 /tmp/.updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment