diff options
author | Rosy Song <rosysong@rosinson.com> | 2018-05-02 10:48:36 +0800 |
---|---|---|
committer | John Crispin <john@phrozen.org> | 2018-05-02 09:18:27 +0200 |
commit | fd569e5e9d0a46ea957cb253e97a4b3ea8c2c540 (patch) | |
tree | 9c2a6ec223a2318b4f829143d31875deaef7d82e /package/network/services/samba36/files/lib | |
parent | 2c4294f78612d038a2b130171fe25ed8e6569bae (diff) | |
download | upstream-fd569e5e9d0a46ea957cb253e97a4b3ea8c2c540.tar.gz upstream-fd569e5e9d0a46ea957cb253e97a4b3ea8c2c540.tar.bz2 upstream-fd569e5e9d0a46ea957cb253e97a4b3ea8c2c540.zip |
samba36: add hotplug support
Add hotplug handle script for storage devices,
this will add corresponding option in the
/etc/config/samba file automatically.
Signed-off-by: Rosy Song <rosysong@rosinson.com>
Diffstat (limited to 'package/network/services/samba36/files/lib')
-rw-r--r-- | package/network/services/samba36/files/lib/samba.sh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/package/network/services/samba36/files/lib/samba.sh b/package/network/services/samba36/files/lib/samba.sh new file mode 100644 index 0000000000..a72a2a1933 --- /dev/null +++ b/package/network/services/samba36/files/lib/samba.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# +# Copyright (C) 2018 OpenWrt.org +# Copyright (C) 2018 rosysong@rosinson.com +# + +. /lib/functions.sh + +FLAG_DEV_TYPE= +FLAG_DEV_MOPT= +FLAG_HAS_SECT= + +samba_dev_filter() { # <devname> <[path,/dev/]> + case $1 in + ${2}mtdblock*|\ + ${2}ubi*) + FLAG_DEV_TYPE="mtd" + ;; + ${2}loop*|\ + ${2}mmcblk*|\ + ${2}sd*|\ + ${2}hd*|\ + ${2}md*|\ + ${2}nvme*|\ + ${2}vd*|\ + ${2}xvd*) + FLAG_DEV_TYPE="not-mtd" + ;; + *) + [ -b ${2}${1} ] && FLAG_DEV_TYPE="not-mtd" + [ -b /dev/mapper/$1 ] && FLAG_DEV_TYPE="not-mtd" + ;; + esac +} + +samba_cfg_lookup() { # <section> <name> + config_get name $1 name + [ "$name" = "$2" ] || return + FLAG_HAS_SECT=y +} + +samba_cfg_delete() { # <section> <name> + config_get name $1 name + [ "$name" = "$2" ] || return + uci -q delete samba.$1 +} + +samba_find_mount_point() { # <devname> + # search mount point in /proc/mounts + while read l; do + local d=$(echo $l | awk '/^\/dev/ {print $1}') + [ "$d" = "/dev/$1" ] || continue + + FLAG_DEV_MOPT=$(echo $l | awk '/^\/dev/ {print $2}') + break + done < /proc/mounts +} + +_samba_add_section() { # <devname> <mount point> + uci -q batch <<-EOF + add samba sambashare + set samba.@sambashare[-1].browseable='yes' + set samba.@sambashare[-1].name='$1' + set samba.@sambashare[-1].path='$2' + set samba.@sambashare[-1].users='root' + set samba.@sambashare[-1].read_only='no' + set samba.@sambashare[-1].guest_ok='yes' + set samba.@sambashare[-1].create_mask='0755' + set samba.@sambashare[-1].dir_mask='0755' + EOF +} + +samba_add_section() { # <devname> [<mount point>] + FLAG_HAS_SECT= + FLAG_DEV_MOPT= + + config_foreach samba_cfg_lookup sambashare $1 + [ -z "$FLAG_HAS_SECT" ] || return + + samba_find_mount_point $1 + [ -n "$FLAG_DEV_MOPT" ] || return + + [ -n "$2" -a "$2" = "$FLAG_DEV_MOPT" ] || \ + _samba_add_section $1 $FLAG_DEV_MOPT +} + +samba_delete_section() { # <devname> + config_foreach samba_cfg_delete sambashare $1 +} |