fixes samba3 to use gawk instead of mawk
[openwrt/svn-archive/archive.git] / net / samba3 / files / samba.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3
4 . /etc/functions.sh
5
6 START=45
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 sed -i "s/|NAME|/$name/g" /tmp/smb.conf
26 sed -i "s/|WORKGROUP|/$workgroup/g" /tmp/smb.conf
27 sed -i "s/|DESCRIPTION|/$description/g" /tmp/smb.conf
28 [ "$homes" == "1" ] && {
29 echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /tmp/smb.conf
30 }
31 }
32
33 smb_add_share() {
34 local name
35 local path
36 local users
37 local read_only
38 local guest_ok
39 local create_mask
40 local dir_mask
41
42 config_get name $1 name
43 config_get path $1 path
44 config_get users $1 users
45 config_get read_only $1 read_only
46 config_get guest_ok $1 guest_ok
47 config_get create_mask $1 create_mask
48 config_get dir_mask $1 dir_mask
49
50 [ -z "$name" -o -z "$path" ] && return
51
52 echo -e "\n[$name]\n\tpath = $path" >> /tmp/smb.conf
53 [ -n "$users" ] && echo -e "\tvalid users = $users" >> /tmp/smb.conf
54 [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /tmp/smb.conf
55 [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /tmp/smb.conf
56 [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /tmp/smb.conf
57 [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /tmp/smb.conf
58 }
59
60 start() {
61 config_load samba
62 config_foreach smb_header samba
63 config_foreach smb_add_share sambashare
64 smbd -D
65 }
66
67 stop() {
68 killall smbd
69 }