#!/bin/sh
#
# Author: Petter Reinholdtsen <pere@hungry.com>
# Date:   1999-05-27
#
# chkconfig: 2345 52 78
# description: Send message when machine is rebooted.

# Where to send the email
ADMIN=root

# Should we send an email? (true or false) 
ENABLED=false

# Include the content of this file if it exist.
BOOTREMINDER=/etc/bootreminder

[ -f /etc/default/report-reboot ] && . /etc/default/report-reboot

[ false = "$ENABLED" ] && exit 0

do_start() {
    # Name of host
    HOST=`uname -n`
    (
        # Make sure uname, date, uptime, last and mail is available in the PATH
        export PATH=/bin:/usr/bin:$PATH

        echo "Host '$HOST' has been down."
        echo

        echo -n "Date:   "
        date

        echo -n "Uptime:"
        uptime

        echo
        echo "The last users was:"
        last -5
        echo

        if test -f $BOOTREMINDER; then
            cat $BOOTREMINDER
        fi
        echo
        echo "Report from $0."
    ) | mail -s "Host $HOST rebooted" $ADMIN
}

case "$1" in
    start)
	do_start
	;;
    stop)
	;;
    restart|force-reload)
	;;
    *)
	echo $"Usage: $0 {start|stop|restart|force-reload}"
	exit 2
esac
exit 0
