#!/bin/bash
# chkconfig: 5 32 10
# description: update notifier Daemon
# processname: simple update notifier
### BEGIN INIT INFO
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 5
# Default-Stop:	0 6
# Short-Description: Start update notifier on boot
# Description: This script starts the  update notifier Daemon
### END INIT INFO

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

lockfile=/var/lock/subsys/update-notifier
RUN_DIR=/usr/share/simple-notifier/scripts/update-check

RETVAL=0
# Force the updater to start on boot 
    if ! test -f "$lockfile"; then
    chkconfig --add update-notifier 
    fi
start() {
	gprintf "Starting update notifier:"
    $RUN_DIR &
	touch "$lockfile" && success || failure
	RETVAL=$?
	echo
}

stop() {
	gprintf "Stopping update notifier:"
	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
		gprintf "Update notifier is enabled.\n"
		RETVAL=0
	else
		gprintf "Update notifier is disabled.\n"
		RETVAL=3
	fi
	;;
  *)
	gprintf "Usage: %s {start|stop|status|restart|reload|force-reload|condrestart}\n" "$0"
	exit 1
esac

exit $RETVAL
