1 #!/bin/sh /etc/rc.common
7 config_get samba_iface
$1 interface
"loopback lan"
11 .
/lib
/functions
/network.sh
14 for net
in $samba_iface; do
16 network_is_up
$net ||
continue
17 network_get_device device
"$net"
18 echo -n "${device:-$net} "
22 local workgroup description charset
23 # we dont use netbios anymore as default and wsd/avahi is dns based
24 local hostname
="$(cat /proc/sys/kernel/hostname)"
26 config_get workgroup
$1 workgroup
"WORKGROUP"
27 config_get description
$1 description
"Samba on OpenWrt"
28 config_get charset
$1 charset
"UTF-8"
30 config_get_bool MACOS
$1 macos
0
31 config_get_bool DISABLE_NETBIOS
$1 disable_netbios
0
32 config_get_bool DISABLE_AD_DC
$1 disable_ad_dc
0
33 config_get_bool DISABLE_WINBIND
$1 disable_winbind
0
36 sed -e "s#|NAME|#$hostname#g" \
37 -e "s#|WORKGROUP|#$workgroup#g" \
38 -e "s#|DESCRIPTION|#$description#g" \
39 -e "s#|INTERFACES|#$interfaces#g" \
40 -e "s#|CHARSET|#$charset#g" \
41 /etc
/samba
/smb.conf.template
> /var
/etc
/smb.conf
43 echo -e "\n######### Dynamic written config options #########\n" >> /var
/etc
/smb.conf
44 if [ "$DISABLE_NETBIOS" -eq 1 ] ||
[ ! -x /usr
/sbin
/nmbd
]; then
45 echo -e "\tdisable netbios = yes" >> /var
/etc
/smb.conf
49 config_get_bool homes
$1 homes
0
51 cat <<EOT >> /var/etc/smb.conf
54 comment = Home Directories
62 [ -L /etc
/samba
/smb.conf
] ||
ln -nsf /var
/etc
/smb.conf
/etc
/samba
/smb.conf
78 local timemachine_maxsize
81 config_get name
$1 name
82 config_get path
$1 path
83 config_get users
$1 users
84 config_get create_mask
$1 create_mask
85 config_get dir_mask
$1 dir_mask
86 config_get browseable
$1 browseable
87 config_get read_only
$1 read_only
88 config_get guest_ok
$1 guest_ok
89 config_get guest_only
$1 guest_only
90 config_get inherit_owner
$1 inherit_owner
91 config_get vfs_objects
$1 vfs_objects
92 config_get_bool timemachine
$1 timemachine
0
93 config_get timemachine_maxsize
$1 timemachine_maxsize
94 config_get_bool force_root
$1 force_root
0
96 [ -z "$name" -o -z "$path" ] && return
98 echo -e "\n[$name]\n\tpath = $path" >> /var
/etc
/smb.conf
100 if [ "$force_root" -eq 1 ]; then
101 echo -e "\tforce user = root" >> /var
/etc
/smb.conf
102 echo -e "\tforce group = root" >> /var
/etc
/smb.conf
104 [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var
/etc
/smb.conf
107 [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var
/etc
/smb.conf
108 [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var
/etc
/smb.conf
110 [ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var
/etc
/smb.conf
111 [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var
/etc
/smb.conf
112 [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var
/etc
/smb.conf
113 [ -n "$guest_only" ] && echo -e "\tguest only = $guest_only" >> /var
/etc
/smb.conf
114 [ -n "$inherit_owner" ] && echo -e "\tinherit owner = $inherit_owner" >> /var
/etc
/smb.conf
116 if [ "$MACOS" -eq 1 ]; then
117 vfs_objects
="catia fruit streams_xattr $vfs_objects"
118 echo -e "\tfruit:encoding = native" >> /var
/etc
/smb.conf
119 echo -e "\tfruit:metadata = stream" >> /var
/etc
/smb.conf
120 echo -e "\tfruit:veto_appledouble = no" >> /var
/etc
/smb.conf
121 # avoid mixed shares order for aapl
122 if [ "$timemachine" -eq 1 ]; then
123 echo -e "\tfruit:time machine = yes" >> /var
/etc
/smb.conf
124 [ -n "$timemachine_maxsize" ] && echo -e "\tfruit:time machine max size = ${timemachine_maxsize}G" >> /var
/etc
/smb.conf
128 [ -n "$vfs_objects" ] && echo -e "\tvfs objects = $vfs_objects" >> /var
/etc
/smb.conf
133 [ -d /var
/lib
/samba
] || mkdir
-p /var
/lib
/samba
134 [ -d /var
/cache
/samba
] || mkdir
-p /var
/cache
/samba
135 [ -d /var
/run
/samba
] || mkdir
-p /var
/run
/samba
136 [ -d /var
/log
/samba
] || mkdir
-p /var
/log
/samba
137 [ -d /var
/lock
] && chmod 0755 /var
/lock ||
{
143 config_foreach smb_header samba
144 config_foreach smb_add_share sambashare
148 PROCD_RELOAD_DELAY
=2000
150 procd_add_reload_trigger
"dhcp" "system" "samba4"
153 for i
in $samba_iface; do
154 procd_add_reload_interface_trigger
$i
161 # start main AD-DC daemon, will spawn (smbd,nmbd,winbindd) as needed/configured.
162 if [ "$DISABLE_AD_DC" -ne 1 ] && [ -x /usr
/sbin
/samba
]; then
164 procd_set_param
command /usr
/sbin
/samba
-F
165 procd_set_param respawn
166 procd_set_param
file /var
/etc
/smb.conf
169 # start fileserver daemon
171 procd_set_param
command /usr
/sbin
/smbd
-F
172 procd_set_param respawn
173 procd_set_param
file /var
/etc
/smb.conf
176 # start netbios daemon
177 if [ "$DISABLE_NETBIOS" -ne 1 ] && [ -x /usr
/sbin
/nmbd
]; then
179 procd_set_param
command /usr
/sbin
/nmbd
-F
180 procd_set_param respawn
181 procd_set_param
file /var
/etc
/smb.conf
184 # start winbind daemon
185 if [ "$DISABLE_WINBIND" -ne 1 ] && [ -x /usr
/sbin
/winbindd
]; then
187 procd_set_param
command /usr
/sbin
/winbindd
-F
188 procd_set_param respawn
189 procd_set_param
file /var
/etc
/smb.conf
193 # lower priority using renice (if found)
194 if [ -x /usr
/bin
/renice
]; then
195 [ -x /usr
/sbin
/samba
] && renice
-n 2 $
(pidof samba
)
196 [ -x /usr
/sbin
/smbd
] && renice
-n 2 $
(pidof smbd
)
197 [ -x /usr
/sbin
/nmbd
] && renice
-n 2 $
(pidof nmbd
)
198 [ -x /usr
/sbin
/winbindd
] && renice
-n 2 $
(pidof winbindd
)