2012-10-10 12:34:29 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2008-2012 OpenWrt.org
|
|
|
|
|
|
|
|
START=60
|
2015-10-30 15:32:54 +00:00
|
|
|
USE_PROCD=1
|
2012-10-10 12:34:29 +00:00
|
|
|
|
|
|
|
smb_header() {
|
2016-08-04 00:31:50 +00:00
|
|
|
config_get samba_iface $1 interface "loopback lan"
|
2012-10-10 12:34:29 +00:00
|
|
|
|
|
|
|
# resolve interfaces
|
|
|
|
local interfaces=$(
|
|
|
|
. /lib/functions/network.sh
|
|
|
|
|
|
|
|
local net
|
2016-08-04 00:31:50 +00:00
|
|
|
for net in $samba_iface; do
|
2012-10-10 12:34:29 +00:00
|
|
|
local device
|
2016-08-04 00:31:50 +00:00
|
|
|
network_is_up $net || continue
|
2017-08-24 23:51:24 +00:00
|
|
|
network_get_device device "$net"
|
2012-10-10 12:34:29 +00:00
|
|
|
echo -n "${device:-$net} "
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
|
|
|
local name workgroup description charset
|
|
|
|
local hostname="$(uci_get system.@system[0].hostname)"
|
|
|
|
|
2017-11-07 08:45:54 +00:00
|
|
|
config_get name $1 name "${hostname:-OpenWrt}"
|
|
|
|
config_get workgroup $1 workgroup "${hostname:-OpenWrt}"
|
|
|
|
config_get description $1 description "Samba on ${hostname:-OpenWrt}"
|
2012-10-10 12:34:29 +00:00
|
|
|
config_get charset $1 charset "UTF-8"
|
|
|
|
|
|
|
|
mkdir -p /var/etc
|
|
|
|
sed -e "s#|NAME|#$name#g" \
|
|
|
|
-e "s#|WORKGROUP|#$workgroup#g" \
|
|
|
|
-e "s#|DESCRIPTION|#$description#g" \
|
|
|
|
-e "s#|INTERFACES|#$interfaces#g" \
|
|
|
|
-e "s#|CHARSET|#$charset#g" \
|
|
|
|
/etc/samba/smb.conf.template > /var/etc/smb.conf
|
|
|
|
|
|
|
|
local homes
|
|
|
|
config_get_bool homes $1 homes 0
|
|
|
|
[ $homes -gt 0 ] && {
|
|
|
|
cat <<EOT >> /var/etc/smb.conf
|
|
|
|
|
|
|
|
[homes]
|
|
|
|
comment = Home Directories
|
|
|
|
browsable = no
|
|
|
|
read only = no
|
|
|
|
create mode = 0750
|
|
|
|
EOT
|
|
|
|
}
|
|
|
|
|
|
|
|
[ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
smb_add_share() {
|
|
|
|
local name
|
|
|
|
local path
|
|
|
|
local users
|
|
|
|
local read_only
|
|
|
|
local guest_ok
|
|
|
|
local create_mask
|
|
|
|
local dir_mask
|
2014-01-12 12:06:53 +00:00
|
|
|
local browseable
|
2012-10-10 12:34:29 +00:00
|
|
|
|
|
|
|
config_get name $1 name
|
|
|
|
config_get path $1 path
|
|
|
|
config_get users $1 users
|
|
|
|
config_get read_only $1 read_only
|
|
|
|
config_get guest_ok $1 guest_ok
|
|
|
|
config_get create_mask $1 create_mask
|
|
|
|
config_get dir_mask $1 dir_mask
|
2014-01-12 12:06:53 +00:00
|
|
|
config_get browseable $1 browseable
|
2012-10-10 12:34:29 +00:00
|
|
|
|
|
|
|
[ -z "$name" -o -z "$path" ] && return
|
|
|
|
|
|
|
|
echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
|
|
|
|
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
|
|
|
|
[ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
|
|
|
|
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
|
|
|
|
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
|
|
|
|
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
|
2014-01-12 12:06:53 +00:00
|
|
|
[ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
|
2012-10-10 12:34:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 15:32:54 +00:00
|
|
|
init_config() {
|
2012-10-10 12:34:29 +00:00
|
|
|
config_load samba
|
2018-12-25 19:30:12 +00:00
|
|
|
CONFIG_APPEND=1 UCI_CONFIG_DIR=/var/run/config config_load samba
|
|
|
|
|
2012-10-10 12:34:29 +00:00
|
|
|
config_foreach smb_header samba
|
|
|
|
config_foreach smb_add_share sambashare
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:32:54 +00:00
|
|
|
service_triggers() {
|
|
|
|
procd_add_reload_trigger samba
|
2016-08-04 00:31:50 +00:00
|
|
|
|
|
|
|
local i
|
|
|
|
for i in $samba_iface; do
|
|
|
|
procd_add_reload_interface_trigger $i
|
|
|
|
done
|
2015-10-30 15:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
|
|
|
init_config
|
|
|
|
|
|
|
|
procd_open_instance
|
2018-08-17 02:32:59 +00:00
|
|
|
procd_add_mdns "smb" "tcp" "445"
|
2015-10-30 15:32:54 +00:00
|
|
|
procd_set_param command /usr/sbin/smbd -F
|
|
|
|
procd_set_param respawn
|
2016-08-04 00:31:50 +00:00
|
|
|
procd_set_param file /var/etc/smb.conf
|
2015-10-30 15:32:54 +00:00
|
|
|
procd_close_instance
|
|
|
|
|
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command /usr/sbin/nmbd -F
|
|
|
|
procd_set_param respawn
|
2016-08-04 00:31:50 +00:00
|
|
|
procd_set_param file /var/etc/smb.conf
|
2015-10-30 15:32:54 +00:00
|
|
|
procd_close_instance
|
2012-10-10 12:34:29 +00:00
|
|
|
}
|