dotfiles/bin/generate-motd

46 lines
1.1 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/zsh
# Eryn Wells <eryn@erynwells.me>
MOTD_FILE=/etc/motd
binary_exists() {
hash $1 1>/dev/null 2>&1
return $?
}
if [[ ! -w "$MOTD_FILE" ]]; then
echo "$MOTD_FILE is not wrtiable by $USER" >&2
exit 1
fi
# If lolcat is installed, dump a colorful message to the MOTD file. :)
local cat_program=cat
local cat_args=''
if binary_exists lolcat; then
echo "Enabling rainbows"
cat_program=lolcat
cat_args=-f
fi
local hello_message="\nThis machine is called `hostname`.\n"
local hardware_model=`sysctl -n hw.model`
if [[ -n "$hardware_model" ]]; then
hello_message+="Its a $hardware_model "
fi
local os_version=`sysctl -n kern.osproductversion`
local product_name=`sw_vers --productName`
local os_build=`sw_vers --buildVersion`
if [[ -n "$os_version" && -n "$os_build" ]]; then
hello_message+="running $product_name $os_version ($os_build)."
elif [[ -n "$os_version" ]]; then
hello_message+="running $product_name $os_version."
fi
hello_message+="\n"
echo "Writing MOTD"
print -P $hello_message | $cat_program $cat_args > $MOTD_FILE