#! /bin/sh
### BEGIN INIT INFO
# Provides:          update-hostname
# Required-Start:    $remote_fs hostname
# Required-Stop:
# Should-Start:      $network
# X-Start-Before:    $syslog
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Set hostname based on current IP address
# Description:
### END INIT INFO
#
# This script is almost the same as the hostname.dhcp script in
# nfsbooted.  Perhaps the two should be combined into a separate
# package?

UPDATE=/usr/sbin/update-hostname-from-ip

ENABLED=false

[ -f /etc/default/update-hostname ] && . /etc/default/update-hostname

[ -x "$UPDATE" -a true = "$ENABLED" ] || exit 0

. /lib/lsb/init-functions

do_status() {
    NAME=`uname -n`
    log_action_msg "Hostname is '$NAME'."
}

do_start() {
    FLAGS=""
    [ "$VERBOSE" != no ] && log_action_begin_msg "Updating hostname from DNS"
    "$UPDATE" -q
    ES=$?
    if [ "$VERBOSE" != no ] ; then
	log_action_end_msg $ES
	do_status
    else
	if [ 0 -ne "$ES" ] ; then
	    log_failure_msg "Unable to update hostname from DNS"
	fi
    fi
}

do_stop() {
    :
}

case "$1" in
    start)
	do_start
	;;
    stop)
	do_stop
	;;
    restart|force-reload)
	do_start
	do_stop
	;;
    status)
	do_status
	;;
    *)
	echo "Usage: $0 {start|stop|restart|force-reload|status}"
	exit 2
esac
exit 0
