Menu

[r10367]: / legacy / etc / rc.d / hosts  Maximize  Restore  History

Download this file

41 lines (34 with data), 1.2 kB

#!/bin/sh
# Copyright (c) 2007-2009 Volker Theile (votdev@gmx.de)
# All rights reserved.

# PROVIDE: hosts
# REQUIRE: netif
# BEFORE: NETWORKING

. /etc/rc.subr
. /etc/util.subr
. /etc/configxml.subr

echo "Updating hosts."

# LAN IF/ADDR
_ifn=`configxml_get "//interfaces/lan/if"`
_ifn=`get_if ${_ifn}`
_ipaddr=`get_ipaddr inet ${_ifn}`

# Generate /etc/hosts file
/usr/local/bin/xml sel -t -m "//system[hostname != '' and domain != '']" \
	-v "concat('::1 localhost localhost.',domain)" -n \
	-v "concat('127.0.0.1 localhost localhost.',domain)" -n \
	-i "//interfaces/lan/ipaddr[. != 'dhcp']" \
		-v "concat(//interfaces/lan/ipaddr,' ',hostname,'.',domain,' ',hostname)" -n \
	-b \
	-i "//interfaces/lan/ipaddr[. = 'dhcp']" \
		-i "string-length('${_ipaddr}') > 0" \
			-v "concat('${_ipaddr}',' ',hostname,'.',domain,' ',hostname)" -n \
		-b \
	-b \
	-m "//system/hosts" \
		-i "string-length(name) > 0" -v "concat(address,' ',name)" -n -b \
	-b \
	${configxml_file} | /usr/local/bin/xml unesc > /etc/hosts

# Generate /etc/hosts.allow file
/usr/local/bin/xml sel -t -m "//system/hostsacl/rule" \
	-v "." -n \
	${configxml_file} | /usr/local/bin/xml unesc > /etc/hosts.allow
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.