forked from openwrt/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ksmbd-tools: add package with hotplug.d script for auto sharing
One of common use cases for SMB3 server in routers is sharing hotplugged drives. Users make many attempts setting that up which often are not optimal. This script handles it in the cleanest way by using: 1. hotplug.d mount subsystem 2. runtime config in the /var/run/config/ It provides a working basic solution that can be later adjusted by modifying provided hotplug script. A pretty much idential solution was part of the samba36 package. It was added in the OpenWrt commit ef1efa7 ("samba36: add package with hotplug.d script for auto sharing") as an answer for feature required by the Rosinson company. Cc: Jo-Philipp Wich <[email protected]> Signed-off-by: Rafał Miłecki <[email protected]>
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/sh | ||
|
||
. /usr/share/libubox/jshn.sh | ||
|
||
device_get_vars() { | ||
json_init | ||
json_load "$(ubus call block info)" | ||
|
||
json_select devices || return 1 | ||
|
||
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 .. | ||
json_select .. | ||
return 0 | ||
} | ||
|
||
json_select .. | ||
done | ||
|
||
json_select .. | ||
|
||
return 2 | ||
} | ||
|
||
[ -f /var/run/config/ksmbd ] || { | ||
mkdir -p /var/run/config && touch /var/run/config/ksmbd | ||
} | ||
|
||
[ "$ACTION" = "add" ] && { | ||
device_get_vars $DEVICE label mount || { | ||
logger -t ksmbd-hotplug "Failed to get $DEVICE info" | ||
exit 1 | ||
} | ||
[ -n "$mount" ] && { | ||
uci -c /var/run/config batch <<-EOF | ||
set ksmbd.$DEVICE="share" | ||
set ksmbd.$DEVICE.name="${label:-$DEVICE}" | ||
set ksmbd.$DEVICE.path="$mount" | ||
set ksmbd.$DEVICE.browseable="yes" | ||
set ksmbd.$DEVICE.read_only="yes" | ||
set ksmbd.$DEVICE.guest_ok="yes" | ||
commit ksmbd | ||
EOF | ||
/etc/init.d/ksmbd reload | ||
} | ||
} | ||
|
||
[ "$ACTION" = "remove" ] && { | ||
uci -c /var/run/config batch <<-EOF | ||
delete ksmbd.$DEVICE | ||
commit ksmbd | ||
EOF | ||
/etc/init.d/ksmbd reload | ||
} |