#!/bin/bash
#
# fetch-crl-boot  This shell script enables a run of fetch-crl on boot.
#
# Author:       Steve Traylen <steve.traylen@cern.ch>
#
# chkconfig:	- 50 01
#
# description:  Run of fetch-crl, a crl updater on boot up
# processname:  fetch-crl
# config: /etc/fetch-crl.conf
#

# source function library
. /etc/rc.d/init.d/functions

lockfile=/var/lock/subsys/fetch-crl-boot

RETVAL=0

start() {
	action $"Running fetch-crl on boot can take a while: " /usr/sbin/fetch-crl  -a 24 --quiet
	RETVAL=$?
	[ "$RETVAL" = 0 ] && touch $lockfile
}

stop() {
	RETVAL=0
	[ "$RETVAL" = 0 ] && rm -f $lockfile
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop) 
	stop
	;;
  restart|force-reload)
	restart
	;;
  condrestart)
        if [ -f $lockfile ]  ; then
           stop
           start
        fi
        ;;
  reload)
	;;
  status)
         if [ -f $lockfile ]  ; then
           echo -n $"fetch-crl-boot lockfile present" && success
           RETVAL=0
         else
           echo -n $"fetch-crl-boot lockfile not-present" && failure
           RETVAL=1
         fi
         echo
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
	exit 1
esac

exit $RETVAL
