1#!/bin/sh 2# a program to (hopefully) figure out what your domain name is 3 4# 1. use the environment: $DOMAIN and $DOMAINNAME is the best 5if [ "X$DOMAIN" != "X" ]; then 6 echo "$DOMAIN" 7 exit 0 8fi 9if [ "X$DOMAINNAME" != "X" ]; then 10 echo "$DOMAINNAME" 11 exit 0 12fi 13 14# 1. if a mailer is on this machine, let's try it's configuration 15x=`cat /var/qmail/control/defaultdomain` 16if [ "X$x" != "X" ]; then 17 echo "$x" 18 exit 0 19fi 20 21# 2. /etc/resolv.conf may contain a "domain" entry. 22x=`egrep '^domain' /etc/resolv.conf | awk '{ print $2 }'` 23if [ "X$x" != "X" ]; then 24 echo "$x" 25 exit 0 26fi 27 28# 3. dnsdomainname and domainname are specific to linuxish and nis systems 29# nevertheless: we are hopeful... (Chris Jantzen) 30x=`(dnsdomainname || domainname || nisdomainname) 2>/dev/null 2>&1` 31if [ "X$x" != "X" ]; then 32 if [ "X$x" != "X(none)" ]; then 33 echo "$x" 34 exit 0 35 fi 36fi 37 38# 4. under solaris, the first "record" in /etc/hosts that isn't loopback 39# is the local machine. we strip off the host part and pray it's right. 40x=`sed -e 's/#.*//' /etc/hosts | egrep '\.' | egrep -v '^127\.0\.0\.1[ ]' | head -1 | awk '{ for (I = 2; I <= NF; I++) { if ($I ~ /\./) { print $I } } }' | sort -u | head -1 | sed -e 's/^[^\.]*\.//'` 41if [ "X$x" != "X" ]; then 42 echo "$x" 43 exit 0 44fi 45 46# 5. HP/UX and AIX show FQDN in "hostname" (Simon Matter) 47x=`hostname` 48y=`echo -n "$x" | sed -e 's/[^\.]*//g' | wc -c | sed -e 's/[^0-9]//g'` 49if [ "X$y" != "X0" ]; then 50 # okay... x may contain our domain name... let's hope it gets mail 51 echo "$x" 52 exit 0 53fi 54 55# unknown 56echo '(none)' 57exit 1 58