summaryrefslogtreecommitdiff
blob: 7092a77e93f61c51494903875c079098e89ff7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2 
# $Header: /var/cvsroot/gentoo/users/beejay/baselayout/etc/init.d.old/domainname,v 1.1 2003/12/31 20:30:00 beejay Exp $


depend() {
	need checkroot hostname
	before bootmisc
}

checkconfig_nis() {
	if [ ! -f /etc/nisdomainname ] || [ -z "$(< /etc/nisdomainname)" ]
	then
#		eerror "You need to set /etc/nisdomainname to a valid NIS domainname"
		return 1
	fi
	return 0
}

checkconfig_dns() {
	if [ ! -f /etc/dnsdomainname ] || [ -z "$(< /etc/dnsdomainname)" ]
	then
#		eerror "You need to set /etc/dnsdomainname to a valid DNS domainname"
		return 1
	fi
	return 0
}

start() {
	local mynisdomain=
	local mydnsdomain=
	local retval=0
	local retval2=2
	
	if checkconfig_nis
	then
		mynisdomain="$(< /etc/nisdomainname)"

		ebegin "Setting NIS domainname to ${mynisdomain}"
		/bin/domainname "${mynisdomain}"
		retval=$?
		eend ${retval} "Failed to set the NIS domainname"
		
	fi

	if checkconfig_dns
	then
		mydnsdomain="$(< /etc/dnsdomainname)"

		[ ! -f /etc/resolv.conf ] && touch /etc/resolv.conf
		ebegin "Setting DNS domainname to ${mydnsdomain}"
		gawk -v DOMAIN="${mydnsdomain}" \
			'BEGIN { print "domain " DOMAIN }
			 $0 !~ /^[[:space:]]*domain/ { print }' \
			/etc/resolv.conf > /etc/resolv.conf.new
		retval2=$?
		[ "${retval2}" -eq 0 ] \
			&& (mv -f /etc/resolv.conf.new /etc/resolv.conf) \
			|| (rm -f /etc/resolv.conf.new)
		eend ${retval2} "Failed to set the DNS domainname"
	fi

	retval=$((retval + retval2))
	
	return ${retval}
}


# vim:ts=4