samba36: add a stripped-down multicall samba 3.6, including smbd, nmbd and smbpasswd...
[openwrt/svn-archive/archive.git] / net / samba36 / files / samba.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2011 OpenWrt.org
3
4 START=60
5
6 smb_header() {
7 local name
8 local workgroup
9 local description
10 local homes
11
12 config_get name $1 name
13 config_get workgroup $1 workgroup
14 config_get description $1 description
15 config_get homes $1 homes
16
17 [ -z "$name" ] && name=openwrt
18 [ -z "$workgroup" ] && workgroup=openwrt
19 [ -z "$description" ] && description=openwrt
20
21 cp /etc/samba/smb.conf.template /tmp/smb.conf
22 [ -L /etc/samba/smb.conf ] || ln -nsf /tmp/smb.conf /etc/samba/smb.conf
23 sed -i "s/|NAME|/$name/g" /tmp/smb.conf
24 sed -i "s/|WORKGROUP|/$workgroup/g" /tmp/smb.conf
25 sed -i "s/|DESCRIPTION|/$description/g" /tmp/smb.conf
26 [ "$homes" == "1" ] && {
27 echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /tmp/smb.conf
28 }
29 }
30
31 smb_add_share() {
32 local name
33 local path
34 local users
35 local read_only
36 local guest_ok
37 local create_mask
38 local dir_mask
39
40 config_get name $1 name
41 config_get path $1 path
42 config_get users $1 users
43 config_get read_only $1 read_only
44 config_get guest_ok $1 guest_ok
45 config_get create_mask $1 create_mask
46 config_get dir_mask $1 dir_mask
47
48 [ -z "$name" -o -z "$path" ] && return
49
50 echo -e "\n[$name]\n\tpath = $path" >> /tmp/smb.conf
51 [ -n "$users" ] && echo -e "\tvalid users = $users" >> /tmp/smb.conf
52 [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /tmp/smb.conf
53 [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /tmp/smb.conf
54 [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /tmp/smb.conf
55 [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /tmp/smb.conf
56 }
57
58 start() {
59 config_load samba
60 config_foreach smb_header samba
61 config_foreach smb_add_share sambashare
62 service_start /usr/sbin/smbd -D
63 service_start /usr/sbin/nmbd -D
64 }
65
66 stop() {
67 service_stop /usr/sbin/smbd
68 service_stop /usr/sbin/nmbd
69 }