source: packages/net/samba3/files/samba.init @ 29354

Last change on this file since 29354 was 29354, checked in by jow, 4 years ago

[packages] samba3: expose interfaces configuration in uci, move generated smb.conf to /var/etc, bump pkg release

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/sh /etc/rc.common
2# Copyright (C) 2008-2011 OpenWrt.org
3
4START=60
5
6smb_header() {
7        local name
8        local workgroup
9        local description
10        local homes
11        local interface
12
13        config_get name $1 name
14        config_get workgroup $1 workgroup
15        config_get description $1 description
16        config_get homes $1 homes
17        config_get interface $1 interface "lan"
18
19        # resolve interfaces
20        local interfaces=$(
21                include /lib/network
22                scan_interfaces
23                local net ifname; for net in $interface; do
24                        config_get ifname "$net" ifname "$net"
25                        echo -n "$ifname "
26                done
27        )
28
29        [ -z "$name" ] && name=openwrt
30        [ -z "$workgroup" ] && workgroup=openwrt
31        [ -z "$description" ] && description=openwrt
32
33        mkdir -p /var/etc
34        cp /etc/samba/smb.conf.template /var/etc/smb.conf
35        [ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
36        sed -i "s/|NAME|/$name/g" /var/etc/smb.conf
37        sed -i "s/|WORKGROUP|/$workgroup/g" /var/etc/smb.conf
38        sed -i "s/|DESCRIPTION|/$description/g" /var/etc/smb.conf
39        sed -i "s/|INTERFACES|/$interfaces/g" /var/etc/smb.conf
40        [ "$homes" == "1" ] && {
41                echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /var/etc/smb.conf
42        }
43}
44
45smb_add_share() {
46        local name
47        local path
48        local users
49        local read_only
50        local guest_ok
51        local create_mask
52        local dir_mask
53
54        config_get name $1 name
55        config_get path $1 path
56        config_get users $1 users
57        config_get read_only $1 read_only
58        config_get guest_ok $1 guest_ok
59        config_get create_mask $1 create_mask
60        config_get dir_mask $1 dir_mask
61
62        [ -z "$name" -o -z "$path" ] && return
63
64        echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
65        [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
66        [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
67        [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
68        [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
69        [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
70}
71
72start() {
73        config_load samba
74        config_foreach smb_header samba
75        config_foreach smb_add_share sambashare
76        service_start /usr/sbin/smbd -D
77}
78
79stop() {
80        service_stop /usr/sbin/smbd
81}
Note: See TracBrowser for help on using the repository browser.