A hook script in "/etc/dhcp3/dhclient-exit-hooks.d/" should be able to fix this.
As has been mentioned, X might get angry, but you could always check for a running X before changing the hostname (assuming it's better to have the wrong hostname than it is to have a non-working X).
Signaling a "no network" error to users could be done with /etc/motd, /etc/issue and/or xmessage
A slight improvement on the interface guessing might be chasing up the default gateway:
A hook script in "/etc/dhcp3/ dhclient- exit-hooks. d/" should be able to fix this.
As has been mentioned, X might get angry, but you could always check for a running X before changing the hostname (assuming it's better to have the wrong hostname than it is to have a non-working X).
Signaling a "no network" error to users could be done with /etc/motd, /etc/issue and/or xmessage
A slight improvement on the interface guessing might be chasing up the default gateway:
host $(ifconfig `ip route | awk '/^default/{print $5}'` | sed -rne 's/.*inet addr:(. *)Bcast. */\1/p' ) | cut --delim \ --field 5