#!/bin/bash
#
# apt-autoupdate    This shell script enables the automatic 
#                   system (APT) updates
#
# Author:       Jaroslaw.Polok@cern.ch
#
# chkconfig:    345 11 89
#
# description:  Enable daily run of apt-get, a program updater.
# processname:  apt-autoupdate
# config: /etc/apt/apt.conf
#

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

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

RETVAL=0

start() {
        echo -n $"Enabling automatic system update (APT): "
        touch "$lockfile" && success || failure
        RETVAL=$?
        echo
        APTINTERACTIVE=0 APTBOOTRUN=1 /usr/sbin/apt-autoupdate
}

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

restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|force-reload)
        restart
        ;;
  reload)
        ;;
  condrestart)
        [ -f "$lockfile" ] && restart
        ;;
  status)
        if [ -f $lockfile ]; then
                echo $"Automatic system update (APT) is enabled."
                RETVAL=0
        else
                echo $"Automatic system update (APT) is disabled."
                RETVAL=3
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|
condrestart}"
        exit 1
esac

exit $RETVAL

