samba36: Enable umdnsd support
[openwrt/openwrt.git] / package / network / services / samba36 / files / samba.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2012 OpenWrt.org
3
4 START=60
5 USE_PROCD=1
6
7 smb_header() {
8 config_get samba_iface $1 interface "loopback lan"
9
10 # resolve interfaces
11 local interfaces=$(
12 . /lib/functions/network.sh
13
14 local net
15 for net in $samba_iface; do
16 local device
17 network_is_up $net || continue
18 network_get_device device "$net"
19 echo -n "${device:-$net} "
20 done
21 )
22
23 local name workgroup description charset
24 local hostname="$(uci_get system.@system[0].hostname)"
25
26 config_get name $1 name "${hostname:-OpenWrt}"
27 config_get workgroup $1 workgroup "${hostname:-OpenWrt}"
28 config_get description $1 description "Samba on ${hostname:-OpenWrt}"
29 config_get charset $1 charset "UTF-8"
30
31 mkdir -p /var/etc
32 sed -e "s#|NAME|#$name#g" \
33 -e "s#|WORKGROUP|#$workgroup#g" \
34 -e "s#|DESCRIPTION|#$description#g" \
35 -e "s#|INTERFACES|#$interfaces#g" \
36 -e "s#|CHARSET|#$charset#g" \
37 /etc/samba/smb.conf.template > /var/etc/smb.conf
38
39 local homes
40 config_get_bool homes $1 homes 0
41 [ $homes -gt 0 ] && {
42 cat <<EOT >> /var/etc/smb.conf
43
44 [homes]
45 comment = Home Directories
46 browsable = no
47 read only = no
48 create mode = 0750
49 EOT
50 }
51
52 [ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
53 }
54
55 smb_add_share() {
56 local name
57 local path
58 local users
59 local read_only
60 local guest_ok
61 local create_mask
62 local dir_mask
63 local browseable
64
65 config_get name $1 name
66 config_get path $1 path
67 config_get users $1 users
68 config_get read_only $1 read_only
69 config_get guest_ok $1 guest_ok
70 config_get create_mask $1 create_mask
71 config_get dir_mask $1 dir_mask
72 config_get browseable $1 browseable
73
74 [ -z "$name" -o -z "$path" ] && return
75
76 echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
77 [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
78 [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
79 [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
80 [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
81 [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
82 [ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
83 }
84
85 init_config() {
86 config_load samba
87 config_foreach smb_header samba
88 config_foreach smb_add_share sambashare
89 }
90
91 service_triggers() {
92 procd_add_reload_trigger samba
93
94 local i
95 for i in $samba_iface; do
96 procd_add_reload_interface_trigger $i
97 done
98 }
99
100 start_service() {
101 init_config
102
103 procd_open_instance
104 procd_add_mdns "smb" "tcp" "445"
105 procd_set_param command /usr/sbin/smbd -F
106 procd_set_param respawn
107 procd_set_param file /var/etc/smb.conf
108 procd_close_instance
109
110 procd_open_instance
111 procd_set_param command /usr/sbin/nmbd -F
112 procd_set_param respawn
113 procd_set_param file /var/etc/smb.conf
114 procd_close_instance
115 }