[packages_10.03.2] samba3: merge r28303 - r31247
[10.03/packages.git] / net / samba3 / files / samba.init
index ad8f268..6d755ea 100755 (executable)
@@ -1,31 +1,66 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2008-2010 OpenWrt.org
+# Copyright (C) 2008-2011 OpenWrt.org
 
 START=60
 
 smb_header() {
-       local name
-       local workgroup
-       local description
+       local interface
+       config_get interface $1 interface "loopback lan"
+
+       # resolve interfaces
+       local interfaces=$(
+               include /lib/network
+               scan_interfaces
+
+               local net
+               for net in $interface; do
+                       local ifname
+                       config_get ifname "$net" ifname
+                       [ -n "$ifname" ] && {
+                               local ipaddr netmask
+                               config_get ipaddr  "$net" ipaddr
+                               config_get netmask "$net" netmask
+                               [ -n "$ipaddr" ] && echo -n "$ipaddr/${netmask:-255.255.255.255} "
+
+                               local ip6addr
+                               config_get ip6addr "$net" ip6addr
+                               [ -n "$ip6addr" ] && echo -n "$ip6addr "
+                       }
+
+                       echo -n "${ifname:-$net} "
+               done
+       )
+
+       local name workgroup description charset
+       local hostname="$(uci_get system.@system[0].hostname)"
+
+       config_get name        $1 name        "${hostname:-OpenWrt}"
+       config_get workgroup   $1 workgroup   "${hostname:-OpenWrt}"
+       config_get description $1 description "Samba on ${hostname:-OpenWrt}"
+       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
 
-       config_get name $1 name
-       config_get workgroup $1 workgroup
-       config_get description $1 description
-       config_get homes $1 homes
-
-       [ -z "$name" ] && name=openwrt
-       [ -z "$workgroup" ] && workgroup=openwrt
-       [ -z "$description" ] && description=openwrt
-
-       cp /etc/samba/smb.conf.template /tmp/smb.conf
-       [ -L /etc/samba/smb.conf ] || ln -nsf /tmp/smb.conf /etc/samba/smb.conf
-       sed -i "s/|NAME|/$name/g" /tmp/smb.conf
-       sed -i "s/|WORKGROUP|/$workgroup/g" /tmp/smb.conf
-       sed -i "s/|DESCRIPTION|/$description/g" /tmp/smb.conf
-       [ "$homes" == "1" ] && {
-               echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /tmp/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() {
@@ -47,23 +82,21 @@ smb_add_share() {
 
        [ -z "$name" -o -z "$path" ] && return
 
-       echo -e "\n[$name]\n\tpath = $path" >> /tmp/smb.conf
-       [ -n "$users" ] && echo -e "\tvalid users = $users" >> /tmp/smb.conf
-       [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /tmp/smb.conf
-       [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /tmp/smb.conf
-       [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /tmp/smb.conf
-       [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /tmp/smb.conf
+       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
 }
 
 start() {
        config_load samba
        config_foreach smb_header samba
        config_foreach smb_add_share sambashare
-       smbd -D
-       nmbd -D
+       service_start /usr/sbin/smbd -D
 }
 
 stop() {
-       killall smbd
-       killall nmbd
+       service_stop /usr/sbin/smbd
 }