#!/bin/sh
### BEGIN INIT INFO
# Provides: kernelbootlog
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple logger for lsmod/interrupts/dmesg info
# Description: Simple logger for lsmod/interrupts/dmesg info
### END INIT INFO
WITHOUT_RC_COMPAT=1

DIR=/var/log/kernelbootlog

# Source function library.
. /etc/init.d/functions
RETVAL=0

start()
{
	mkdir -p $DIR

	if ! cd $DIR; then
		exit -1
	fi

	if [ ! -d ".git" ]; then
		git init > /dev/null
	fi

	dmesg > dmesg
	cat /proc/interrupts > interrupts
	cat /proc/cmdline > cmdline
	cat /proc/cpuinfo > cpuinfo
	cat /proc/iomem > iomem
	cat /proc/ioports > ioports
	cat /proc/mtrr > mtrr
	cat /proc/version > version
	lspci > lspci
	gzip -d < /proc/config.gz > config
	lsmod | sed 1d | sort > lsmod

	git add * > /dev/null
	git config user.name kernelbootlog
	git config user.email root@`hostname`
	git commit -a -m 'boot at '`date -I` > /dev/null

	RETVAL=$?
	return $RETVAL
}

stop()
{
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --expect-user root -- acpid
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

