Annotation of embedaddon/dhcp/contrib/sethostname.sh, revision 1.1
1.1 ! misho 1: #!/bin/sh
! 2:
! 3: # This script can be installed in /etc/dhclient-enter-hooks to set the client's
! 4: # hostname based either on the hostname that the DHCP server supplied or the
! 5: # hostname in whatever ptr record exists for the assigned IP address.
! 6:
! 7: if [ x$new_host_name = x ]; then
! 8: ptrname=`echo $new_ip_address \
! 9: |sed -e \
! 10: 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1.in-addr.arpa/'`
! 11: (echo "set type=ptr"; echo "$ptrname") |nslookup >/tmp/nslookup.$$
! 12: set `sed -n -e "s/$ptrname[ ]*\(canonical \)*name *= *\(.*\)/\2 \1/p" \
! 13: < /tmp/nslookup.$$` _
! 14: if [ x$1 = x_ ]; then
! 15: new_host_name=""
! 16: else
! 17: if [ $# -gt 1 ] && [ x$2 = xcanonical ]; then
! 18: new_host_name=`sed -n -e "s/$1[ ]*name *= *\(.*\)/\1/p" \
! 19: </tmp/nslookup.$$`
! 20: else
! 21: new_host_name=$1
! 22: fi
! 23: fi
! 24: rm /tmp/nslookup.$$
! 25: fi
! 26: if [ x$new_host_name != x ]; then
! 27: hostname $new_host_name
! 28: fi
! 29:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>