prometheus-node-exporter-lua: add dawn exporter
[feed/packages.git] / net / samba4 / files / samba.init
1 #!/bin/sh /etc/rc.common
2
3 START=98
4 USE_PROCD=1
5
6 SAMBA_IFACE=""
7
8 smb_header() {
9 config_get SAMBA_IFACE $1 interface "lan"
10
11 # resolve interfaces
12 local interfaces
13 interfaces=$(
14 . /lib/functions/network.sh
15
16 local net
17 for net in $SAMBA_IFACE; do
18 local device
19 network_is_up $net || continue
20 network_get_device device "$net"
21 printf "%s " "${device:-$net}"
22 done
23 )
24
25 local workgroup description charset
26 # we dont use netbios anymore as default and wsd/avahi is dns based
27 local hostname
28 hostname="$(cat /proc/sys/kernel/hostname)"
29
30 config_get workgroup $1 workgroup "WORKGROUP"
31 config_get description $1 description "Samba on OpenWrt"
32 config_get charset $1 charset "UTF-8"
33
34 config_get_bool MACOS $1 macos 0
35 config_get_bool DISABLE_NETBIOS $1 disable_netbios 0
36 config_get_bool DISABLE_AD_DC $1 disable_ad_dc 0
37 config_get_bool DISABLE_WINBIND $1 disable_winbind 0
38 config_get_bool DISABLE_ASYNC_IO $1 disable_async_io 0
39 config_get_bool ALLOW_LEGACY_PROTOCOLS $1 allow_legacy_protocols 0
40
41 mkdir -p /var/etc
42 sed -e "s#|NAME|#$hostname#g" \
43 -e "s#|WORKGROUP|#$workgroup#g" \
44 -e "s#|DESCRIPTION|#$description#g" \
45 -e "s#|INTERFACES|#$interfaces#g" \
46 -e "s#|CHARSET|#$charset#g" \
47 /etc/samba/smb.conf.template > /var/etc/smb.conf
48
49 {
50 printf "\n######### Dynamic written config options #########\n"
51 if [ "$DISABLE_NETBIOS" -eq 1 ] || [ ! -x /usr/sbin/nmbd ]; then
52 printf "\tdisable netbios = yes\n"
53 fi
54
55 if [ "$DISABLE_ASYNC_IO" -eq 1 ]; then
56 printf "\taio read size = 0\n"
57 printf "\taio write size = 0\n"
58 # sendfile bug: https://bugzilla.samba.org/show_bug.cgi?id=14095
59 printf "\tuse sendfile = no\n"
60 fi
61
62 if [ "$ALLOW_LEGACY_PROTOCOLS" -eq 1 ]; then
63 logger -p daemon.info -t 'samba4-server' "Legacy Protocols allowed, don't use this option for secure environments!"
64 printf "\tserver min protocol = NT1\n"
65 printf "\tlanman auth = yes\n"
66 printf "\tntlm auth = ntlmv1-permitted\n"
67 fi
68 } >> /var/etc/smb.conf
69
70 [ -e /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
71
72 if [ ! -L /etc/samba/smb.conf ]; then
73 logger -p daemon.warn -t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
74 fi
75
76 }
77
78 smb_add_share() {
79 local name
80 local path
81 local users
82 local create_mask
83 local dir_mask
84 local browseable
85 local read_only
86 local writeable
87 local guest_ok
88 local guest_only
89 local inherit_owner
90 local vfs_objects
91 local timemachine
92 local timemachine_maxsize
93 local force_root
94 local write_list
95 local read_list
96
97 config_get name $1 name
98 config_get path $1 path
99 config_get users $1 users
100 config_get create_mask $1 create_mask
101 config_get dir_mask $1 dir_mask
102 config_get browseable $1 browseable
103 config_get read_only $1 read_only
104 config_get writeable $1 writeable
105 config_get guest_ok $1 guest_ok
106 config_get guest_only $1 guest_only
107 config_get inherit_owner $1 inherit_owner
108 config_get vfs_objects $1 vfs_objects
109 config_get_bool timemachine $1 timemachine 0
110 config_get timemachine_maxsize $1 timemachine_maxsize
111 config_get_bool force_root $1 force_root 0
112 config_get write_list $1 write_list
113 config_get read_list $1 read_list
114
115 [ -z "$name" ] || [ -z "$path" ] && return
116
117 {
118 printf "\n[$name]\n\tpath = %s\n" "$path"
119
120 if [ "$force_root" -eq 1 ]; then
121 printf "\tforce user = root\n"
122 printf "\tforce group = root\n"
123 else
124 [ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
125 fi
126
127 [ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
128 [ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
129
130 [ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
131 [ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
132 [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
133 [ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
134 [ -n "$guest_only" ] && printf "\tguest only = %s\n" "$guest_only"
135 [ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
136
137 [ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
138 [ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
139
140 if [ "$MACOS" -eq 1 ]; then
141 vfs_objects="catia fruit streams_xattr $vfs_objects"
142 printf "\tfruit:encoding = native\n"
143 printf "\tfruit:metadata = stream\n"
144 printf "\tfruit:veto_appledouble = no\n"
145 # avoid mixed shares order for aapl
146 if [ "$timemachine" -eq 1 ]; then
147 printf "\tfruit:time machine = yes\n"
148 [ -n "$timemachine_maxsize" ] && printf "\tfruit:time machine max size = %sG\n" "${timemachine_maxsize}"
149 fi
150 fi
151
152 [ -n "$vfs_objects" ] && printf "\tvfs objects = %s\n" "$vfs_objects"
153 } >> /var/etc/smb.conf
154 }
155
156 init_config() {
157 # Create samba dirs
158 [ -d /var/lib/samba ] || mkdir -p /var/lib/samba
159 [ -d /var/cache/samba ] || mkdir -p /var/cache/samba
160 [ -d /var/run/samba ] || mkdir -p /var/run/samba
161 [ -d /var/log/samba ] || mkdir -p /var/log/samba
162 [ -d /var/lock ] || mkdir -p /var/lock
163 chmod 0755 /var/lock
164
165 config_load samba4
166 config_foreach smb_header samba
167 config_foreach smb_add_share sambashare
168 }
169
170 service_triggers() {
171 # PROCD_RELOAD_DELAY=1000
172
173 procd_add_reload_trigger "dhcp" "system" "samba4"
174
175 local i
176 for i in $SAMBA_IFACE; do
177 procd_add_reload_interface_trigger $i
178 done
179 }
180
181 start_service() {
182 init_config
183
184 if [ ! -e /etc/samba/smb.conf ]; then
185 logger -p daemon.error -t 'samba4-server' "missing config /etc/samba/smb.conf!"
186 exit 1
187 fi
188
189 local nice_value
190 config_get nice_value extra samba_nice 0
191
192 # start main AD-DC daemon, will spawn (smbd,nmbd,winbindd) as needed/configured.
193 if [ "$DISABLE_AD_DC" -ne 1 ] && [ -x /usr/sbin/samba ]; then
194 procd_open_instance
195 procd_set_param command /usr/sbin/samba -F
196 procd_set_param nice $nice_value
197 procd_set_param respawn
198 procd_set_param file /etc/samba/smb.conf
199 procd_set_param limits nofile=16384
200 procd_close_instance
201 else
202 # start fileserver daemon
203 procd_open_instance
204 procd_set_param command /usr/sbin/smbd -F
205 procd_set_param nice $nice_value
206 procd_set_param respawn
207 procd_set_param file /etc/samba/smb.conf
208 procd_set_param limits nofile=16384
209 procd_close_instance
210
211 # start netbios daemon
212 if [ "$DISABLE_NETBIOS" -ne 1 ] && [ -x /usr/sbin/nmbd ]; then
213 procd_open_instance
214 procd_set_param command /usr/sbin/nmbd -F
215 procd_set_param nice $nice_value
216 procd_set_param respawn
217 procd_set_param file /etc/samba/smb.conf
218 procd_close_instance
219 fi
220 # start winbind daemon
221 if [ "$DISABLE_WINBIND" -ne 1 ] && [ -x /usr/sbin/winbindd ]; then
222 procd_open_instance
223 procd_set_param command /usr/sbin/winbindd -F
224 procd_set_param nice $nice_value
225 procd_set_param respawn
226 procd_set_param file /etc/samba/smb.conf
227 procd_close_instance
228 fi
229 fi
230 }