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