1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2012 OpenWrt.org
8 config_get interface $1 interface "loopback lan"
12 . /lib/functions/network.sh
15 for net in $interface; do
17 network_get_device device "$net" && {
19 network_get_subnet subnet "$net" && echo -n "$subnet "
20 network_get_subnet6 subnet "$net" && echo -n "$subnet "
23 echo -n "${device:-$net} "
27 local name workgroup description charset
28 local hostname="$(uci_get system.@system[0].hostname)"
30 config_get name $1 name "${hostname:-OpenWrt}"
31 config_get workgroup $1 workgroup "${hostname:-OpenWrt}"
32 config_get description $1 description "Samba on ${hostname:-OpenWrt}"
33 config_get charset $1 charset "UTF-8"
36 sed -e "s#|NAME|#$name#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
44 config_get_bool homes $1 homes 0
46 cat <<EOT >> /var/etc/smb.conf
49 comment = Home Directories
56 [ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
69 config_get name $1 name
70 config_get path $1 path
71 config_get users $1 users
72 config_get read_only $1 read_only
73 config_get guest_ok $1 guest_ok
74 config_get create_mask $1 create_mask
75 config_get dir_mask $1 dir_mask
76 config_get browseable $1 browseable
78 [ -z "$name" -o -z "$path" ] && return
80 echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
81 [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
82 [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
83 [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
84 [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
85 [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
86 [ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
91 config_foreach smb_header samba
92 config_foreach smb_add_share sambashare
93 service_start /usr/sbin/smbd -D
94 service_start /usr/sbin/nmbd -D
98 service_stop /usr/sbin/smbd
99 service_stop /usr/sbin/nmbd