r13132: Old fix from Lars
[tprouty/samba.git] / packaging / Debian / debian-unstable / samba-common.dhcp
1 #!/bin/sh
2
3 SAMBA_DHCP_CONF=/etc/samba/dhcp.conf
4 SAMBA_DHCP_CONF_INFO_FILE=""
5
6 netbios_setup() {
7         # No need to continue if we're called with an unsupported option
8
9         if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
10            && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ] \
11            && [ "$reason" != EXPIRE ] && [ "$reason" != FAIL ]
12         then
13                 return
14         fi
15
16         # Nor should we continue if no settings have changed
17         if [ "$new_netbios_name_servers" = "$old_netbios_name_servers" ] \
18            && [ "$new_netbios_scope" = "$old_netbios_scope" ]
19            && [ -f $SAMBA_DHCP_CONF ]
20         then
21                 return
22         fi
23
24         # reparse our own file
25         local other_servers=`sed -n -e"s/[[:space:]]$interface:[^[:space:]]*//g; \
26                 s/^[[:space:]]*wins server[[:space:]]*=[[:space:]]*//pi" \
27                 $SAMBA_DHCP_CONF`
28
29         umask 022
30
31         local serverlist="$other_servers"
32         for server in $new_netbios_name_servers
33         do
34                 serverlist="$serverlist $interface:$server"
35         done
36
37         echo -n > $SAMBA_DHCP_CONF
38         test -n "$SAMBA_DHCP_CONF_INFO_FILE" -a -f "$SAMBA_DHCP_CONF_INFO_FILE" && \
39                 cat "$SAMBA_DHCP_CONF_INFO_FILE" >> $SAMBA_DHCP_CONF
40
41         # If we're updating on failure/expire, AND there are no WINS
42         # servers for other interfaces, leave the file empty.
43         if [ -z "$other_servers" ]
44         then
45                 if [ "$reason" = FAIL ] || [ "$reason" = EXPIRE ]
46                 then
47                         return
48                 fi
49         fi
50
51         if [ -n "$serverlist" ]
52         then
53                 echo "   wins server =$serverlist" >> $SAMBA_DHCP_CONF
54         fi
55         if [ -n "$new_netbios_scope" ]
56         then
57                 echo "   netbios scope = $new_netbios_scope" >> $SAMBA_DHCP_CONF
58         fi
59 }
60
61 netbios_setup