summaryrefslogblamecommitdiffstats
path: root/dhcpcd-hooks/30-hostname
blob: 0521f49d418e772556c4cdb37df6cae7f9de4752 (plain) (tree)
1
2
3
4
5
6
7
8




                                             
                                                    

                                                                


                       





                              

                                                 
                    
                                                 
                  


          
                 
                                                                      
    
# Set the hostname from DHCP data if required

need_hostname()
{
	case "$(hostname)" in
	""|"(none)"|localhost|localhost.localdomain)
		[ -n "$new_host_name" -o -n "$new_fqdn_name" ];;
	"$old_host_name"|"$old_fqdn_name")
		true;;
	*)
		false;;
	esac
}

set_hostname()
{
	if need_hostname; then
		if [ -n "$new_host_name" ]; then
			hostname "$new_host_name"
		else
			hostname "$new_fqdn_name"
		fi
	fi
}

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