#! /bin/sh

# set -v
# set -x

if [ -x /usr/bin/logger ]; then
	LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
else
	LOGGER=echo
fi
  
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
   [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  current_hostname=`/bin/hostname`
  current_domain=`echo "$current_hostname | sed -e 's/^[^\.]*\.//'`
  if ! grep "$current_domain" /etc/resolv.conf >/dev/null; then
    current_hostname=""
  fi
  if [ x$current_hostname = x ] || [ x$current_hostname = xlocalhost ]; then
    new_host_name=`host $new_ip_address | sed -e 's/^.*domain name pointer //'`
    $LOGGER "New Hostname: $new_host_name"
    hostname $new_host_name
  fi
#  $LOGGER "New time-server: $new_time_server"
#  $LOGGER "New dhcp-server-identifier: $new_dhcp_server_identifier"
  ntp_server="${new_time_server:=${new_dhcp_server_identifier}}"
  [ -f /var/run/ntpd.pid ] && \
  $LOGGER "ntpd appears to be running; skipping ntpdate" || \
  (/usr/sbin/ntpdate -s ${ntp_server} && \
  ($LOGGER "Used ntp_server: $ntp_server" && echo "server ${ntp_server}" >/etc/ntp.conf && ntpd -p /var/run/ntpd.pid) || \
  $LOGGER "Failed to use ntp_server: $ntp_server")
else
  $LOGGER "reason was $reason"
fi

# if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || \
#    [ x$reason = xTIMEOUT ]; then
#     new_host_name="localhost"
#     $LOGGER "New Hostname: $new_host_name"
#     hostname $new_host_name
# fi
  
exit 0
