#!/bin/sh # # $Id$ # # Returns "domain name" as follows from the "hostname" or a similar # lookup. Required to make cfengine 'domain' variable match what cfservd # expects to see. WARN written for Linux. Test hostname on other Unix # flavors first as non-root user to ensure -f option does no harm. # # example.com <- foo.example.com # example.com <- longer.test.example.com # example.com <- even.longer.test.example.com # NOTE if have NIS could use 'domainname' command. # TODO parse domainname from reverse lookup of first IP bound to, say, # eth0, which is more likely what cfservd will see when it does a # gethostbyaddr() on the connecting client. But this is more complex... # WARN BSD doesn't have an -f option to hostname! DOMAIN=$( hostname -f | sed 's/^.*\.\([^.]*\.[^.]*\)$/\1/' ) if ! echo "$DOMAIN" | fgrep . >/dev/null; then # cfengine does not care about non-zero exit from ExecResult(), so # send error log elsewhere, and undefine the domain logger -i -t `basename $0` "no dot in domain: name=$DOMAIN" DOMAIN= fi echo $DOMAIN