# set host name

set_hostname() {
    local current_hostname

    if [ -n "$new_host_name" ]; then
        current_hostname=$(hostname)

        # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
        if [ -z "$current_hostname" ] ||
           [ "$current_hostname" = '(none)' ] ||
           [ "$current_hostname" = 'localhost' ] ||
           [ "$current_hostname" = 'localhost.localdomain' ] ||
           [ "$current_hostname" = "$old_host_name" ]; then
           if [ "$new_host_name" != "$old_host_name" ]; then
               hostname "$new_host_name"
           fi
        fi
    fi
}

case "$reason" in
    BOUND|RENEW|REBIND|REBOOT)
        set_hostname ;;
esac
