#!/bin/sh
#
# nopi		Start/Stop the no-ip.com client.
#
# chkconfig:	2345 15 89
#
# description:	When configured correctly, the client will check your IP \
#		address at a given time interval checking to see if your IP \
#		has changed. If your IP address has changed it will notify \
#		No-IP DNS servers and update the IP corresponding to your \
#		No-IP/No-IP+ hostname.
#
# processname:	noip
# config:	/etc/noip
# pidfile:	/var/run/noip.pid # don't know if it's true

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

# Source noip configuration.
if [ -f /etc/sysconfig/noip ]; then
	. /etc/sysconfig/noip
fi

start() {
	if [ -f /var/lock/subsys/noip ]; then
		msg_already_running noip
		return
	fi

	if [ ! -s /etc/noip.conf ]; then
		echo "You should first run $0 config to prepare configuration";
		exit 3
	fi

	msg_starting noip
	daemon /usr/sbin/noip $OPTIONS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/noip
}

stop() {
	if [ ! -f /var/lock/subsys/noip ]; then
		msg_not_running noip
		return
	fi

	msg_stopping noip
	killproc noip
	rm -f /var/lock/subsys/noip > /dev/null 2>&1
}

RETVAL=0
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  config|status)
  	noip -C
	noip -S
  	;;
  *)
	msg_usage "$0 {start|stop|restart|config|status}"
	exit 3
	;;
esac

exit $RETVAL
