From ef1efa756e0d0caef41216719dcc72c71b31d8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 26 Dec 2018 10:51:28 +0100 Subject: samba36: add package with hotplug.d script for auto sharing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new samba36-hotplug package provides a hotplug.d script for the "mount" subsystem. It automatically shares every mounted block device. It works by updating /var/run/config/samba file which: 1) Is read by procd init script 2) Gets wiped on reboot providing a consistent state 3) Can be safely updated without flash wearing or conflicting with user changes being made in /etc/config/samba Cc: Rosy Song Cc: Jo-Philipp Wich Signed-off-by: Rafał Miłecki --- .../network/services/samba36/files/samba.hotplug | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 package/network/services/samba36/files/samba.hotplug (limited to 'package/network/services/samba36/files/samba.hotplug') diff --git a/package/network/services/samba36/files/samba.hotplug b/package/network/services/samba36/files/samba.hotplug new file mode 100644 index 0000000000..e1ae64e655 --- /dev/null +++ b/package/network/services/samba36/files/samba.hotplug @@ -0,0 +1,56 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh + +device_get_vars() { + json_init + json_load "$(ubus call block info)" + + json_select devices + + json_get_keys keys + for key in $keys + do + json_select $key + + json_get_var device device + [ "$device" = "$1" ] && { + shift + json_get_vars $@ + json_select .. + break + } + + json_select .. + done + + json_select .. +} + +[ -f /var/run/config/samba ] || { + mkdir -p /var/run/config && touch /var/run/config/samba +} + +[ "$ACTION" = "add" ] && { + device_get_vars $DEVICE label mount + [ -n "$mount" ] && { + uci -c /var/run/config batch <<-EOF + set samba.$DEVICE="sambashare" + set samba.$DEVICE.name="$label" + set samba.$DEVICE.path="$mount" + set samba.$DEVICE.browseable="yes" + set samba.$DEVICE.read_only="yes" + set samba.$DEVICE.guest_ok="yes" + commit samba + EOF + /etc/init.d/samba reload + } +} + +[ "$ACTION" = "remove" ] && { + uci -c /var/run/config batch <<-EOF + delete samba.$DEVICE + commit samba + EOF + /etc/init.d/samba reload +} -- cgit v1.2.3