#! /bin/sh

### BEGIN INIT INFO
# Provides:          fetch-crl-cron
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Enable daily run of fetch-crl
# Description:       This shell script enables the automatic use of fetch-crl
### END INIT INFO

# Author: Mattias Ellert <mattias.ellert@physics.uu.se>

# source function library
. /lib/lsb/init-functions

# source any environment settings, e.g. for HTTP proxies
[ -f /etc/default/fetch-crl ] && . /etc/default/fetch-crl

lockfile=/var/lock/fetch-crl-cron

RETVAL=0

start() {
    touch $lockfile
    log_success_msg "Enabling periodic fetch-crl"
    RETVAL=0
}

stop() {
    rm -f $lockfile
    log_success_msg "Disabling periodic fetch-crl"
    RETVAL=0
}

restart() {
    stop
    start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|force-reload)
	restart
	;;
    condrestart)
	[ -f $lockfile ] && restart
	;;
    reload)
	;;
    status)
	if [ -f $lockfile ] ; then
	    log_success_msg "Periodic fetch-crl is enabled"
	    RETVAL=0
	else
	    log_success_msg "Periodic fetch-crl is disabled"
	    RETVAL=3
	fi
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
	RETVAL=1
esac

exit $RETVAL
