#!/bin/bash
#
# apt-cron      This shell script enables dalily run of apt
#
# chkconfig:    2345 95 05
# description:  Enable daily run of apt update
# Author:       USAMI Kosuke <usami-k@yc5.so-net.ne.jp>
#

. /etc/rc.d/init.d/functions

lockfile=/var/lock/subsys/apt-cron

start() {
    echo -n $"Enabling daily apt update: "
    touch "$lockfile" && success || failure
    RETVAL=$?
    echo
}

stop() {
    echo -n $"Disabling daily apt update: "
    rm -f "$lockfile" && success || failure
    RETVAL=$?
    echo
}

case "$1" in
    start)
        start
        ;;
    stop) 
        stop
        ;;
    status)
        if [ -f "$lockfile" ]; then
            echo $"Daily apt update is enabled."
        else
            echo $"Daily apt update is disabled."
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        RETVAL=1
esac

exit $RETVAL

