#! /bin/bash
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Lars Mueller <lars at samba dot org>
# Author: Andreas Schneider <mail at cynapses dot org>
#
# ntpdate
#
# Script to retrieve the date from an configured NTP server if the network
# goes online.
#

unset ${!LC_*} LANGUAGE
export LANG="POSIX"
export PATH="/sbin:/usr/sbin:/bin/:/usr/bin"

numArgs=$#
configname="$1"
shift
interface="$1"
shift
# And shift away the '-o'.
shift
options="$@"

# Log functions
function log_dbg()
{
  	case "${options}" in
		*debug*)
			logger -t $0 -p daemon.debug "$1"
			;;
	esac
}
function log_err()
{
	logger -t $0 -p daemon.err "$1"
	exit 1
}

# Main case switch
case "$0" in
	*if-up.d*)
	if rcntp status 2>&1; then
		log_msg=$( rcntp restart 2>&1 )
		log_dbg "${log_msg}"
	else
		if chkconfig -c ntp 2>&1; then
			log_msg=$( rcntp ntptimeset 2>&1 )
    			log_dbg "${log_msg}"
		fi
	fi
	;;
	*if-down.d*)
		# nothing to do for the NTP daemon if we go offline
	;;
	*)
		log_err "Don't know what to do.  This script used to be called from dir if-{up,down}.d/."
	;;
esac

