#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          debathena-auto-update
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run an update at boot time
# Description:       Run an update at boot time
### END INIT INFO
#
# This script is part of the debathena-auto-update package
# See /usr/share/doc/debathena-auto-update/copyright

machtype -v -L | grep -q "debathena-cluster" || exit 0

. /lib/lsb/init-functions

case "$1" in
start)
	if [ -f /var/lib/athena-update-status ]; then
	    updlast=$(awk -F\| '{print $2;}' /var/lib/athena-update-status)
	    time=$(date +%s)
	    if echo $updlast | grep -q ^[0-9]*$; then
		elapsed=`echo $time - $updlast | bc`
		if [ $elapsed -lt 86400 ]; then
		    exit 0
		fi
	    fi
	fi
	log_action_msg "Workstation has not checked for an update in 24 hours"
	log_action_msg "Forcing an update now (this can take up to 15 minutes)"
	if /usr/sbin/athena-auto-update; then
	    log_end_msg 0
	else
	    log_end_msg 1
	fi
	;;
stop|restart|reload|force-reload|status)
	exit 0
	;;
*)
	log_action_msg "Usage: /etc/init.d/debathena-auto-update {start}"
	exit 1
	;;
esac
exit 0
