PageRenderTime 23328ms CodeModel.GetById 23246ms app.highlight 4ms RepoModel.GetById 76ms app.codeStats 0ms

/dhcp3/dhclient-enter-hooks.d/samba

http://github.com/brinkman83/bashrc
Shell | 75 lines | 50 code | 15 blank | 10 comment | 11 complexity | 5bae14f7119e76a44cd7f83374dc27fd MD5 | raw file
 1#!/bin/sh
 2
 3SAMBA_DHCP_CONF=/etc/samba/dhcp.conf
 4
 5netbios_setup() {
 6	# No need to continue if we're called with an unsupported option
 7
 8	case $reason in
 9	BOUND|RENEW|REBIND|REBOOT|EXPIRE|FAIL|RELEASE|STOP)
10		;;
11	*)
12		return
13		;;
14	esac
15
16	umask 022
17
18	local other_servers=""
19	local serverlist=""
20
21	# the destination file won't exist yet on the first run after 
22	# installing samba
23	if [ -e $SAMBA_DHCP_CONF ]
24	then
25		# don't continue if no settings have changed
26		if [ "$new_netbios_name_servers" = "$old_netbios_name_servers" ] \
27		   && [ "$new_netbios_scope" = "$old_netbios_scope" ] \
28		   && [ -n "$new_netbios_name_servers" ]
29		then
30			return
31		fi
32
33		# reparse our own file
34		other_servers=`sed -n -e"s/[[:space:]]$interface:[^[:space:]]*//g; \
35			s/^[[:space:]]*wins server[[:space:]]*=[[:space:]]*//pi" \
36			$SAMBA_DHCP_CONF`
37
38		serverlist="$other_servers"
39	fi
40
41	for server in $new_netbios_name_servers
42	do
43		serverlist="$serverlist $interface:$server"
44	done
45
46	echo -n > ${SAMBA_DHCP_CONF}.new
47
48	# If we're updating on failure/expire, AND there are no WINS
49	# servers for other interfaces, leave the file empty.
50	if [ -z "$other_servers" ]
51	then
52		if [ "$reason" = FAIL ] || [ "$reason" = EXPIRE ]
53		then
54			mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
55			return
56		fi
57	fi
58
59	if [ -n "$serverlist" ]
60	then
61		echo "   wins server = $serverlist" >> ${SAMBA_DHCP_CONF}.new
62	fi
63	if [ -n "$new_netbios_scope" ]
64	then
65		echo "   netbios scope = $new_netbios_scope" >> ${SAMBA_DHCP_CONF}.new
66	fi
67	mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
68
69	# reload the samba server
70	# We don't necessarily have the samba package installed. #414841
71	[ -x /etc/init.d/samba ] && /usr/sbin/invoke-rc.d samba reload
72
73}
74
75netbios_setup