#!/bin/bash
#
# Laurent Culioli <laurent@mandrakesoft.com>
#
# Startup script for ez-ipudate  $Revision: 1.0 $
#
# chkconfig: 345 86 15
#  
# processname: ez-ipupdate
# description: check and update your IP to dynamic DNS Server
# pidfile: /var/run/ez-ipudpate.pid
# config: /etc/ez-ipupdate.conf

# Source function library.
. /etc/init.d/functions

RETVAL=0


ez_config=/etc/ez-ipupdate.conf
ez_bin=/usr/bin/ez-ipupdate
ez_cache=`grep -E '^[[:space:]]*cache-file' $ez_config |  cut -d "=" -f2 `

start() {
	gprintf "Starting ez-ipupdate: "
	$ez_bin -d -c $ez_config
	RETVAL=$?
	[ $RETVAL = 0 ] && touch /var/lock/subsys/ez-ipupdate
	echo
}
stop() {
	gprintf "Stopping ez-ipupdate: "
	killproc ez-ipupdate
	RETVAL=$?
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/ez-ipupdate
	echo
}

# See how we were called.
case "$1" in
	start)
		start
;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	reload)
	        gprintf "Re-reading ez-ipupdate config: "
		killproc ez-ipupdate -HUP
		RETVAL=$?
		echo
		;;
		
	status)
		status ez-ipupdate
		RETVAL=$?
		LAST_IP=`cat $ez_cache | cut -d "," -f2`
		gprintf "last IP update : %s\n" "$LAST_IP"
		;;
	*)
		gprintf "Usage: ez-ipupdate  {start|stop|restart|reload|status}\n"
		RETVAL=1
esac
exit $RETVAL
