You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.1 KiB

  1. #!/bin/sh
  2. . /usr/share/libubox/jshn.sh
  3. device_get_vars() {
  4. json_init
  5. json_load "$(ubus call block info)"
  6. json_select devices || return 1
  7. json_get_keys keys
  8. for key in $keys
  9. do
  10. json_select $key
  11. json_get_var device device
  12. [ "$device" = "$1" ] && {
  13. shift
  14. json_get_vars $@
  15. json_select ..
  16. json_select ..
  17. return 0
  18. }
  19. json_select ..
  20. done
  21. json_select ..
  22. return 2
  23. }
  24. [ -f /var/run/config/ksmbd ] || {
  25. mkdir -p /var/run/config && touch /var/run/config/ksmbd
  26. }
  27. [ "$ACTION" = "add" ] && {
  28. device_get_vars $DEVICE label mount || {
  29. logger -t ksmbd-hotplug "Failed to get $DEVICE info"
  30. exit 1
  31. }
  32. [ -n "$mount" ] && {
  33. uci -c /var/run/config batch <<-EOF
  34. set ksmbd.$DEVICE="share"
  35. set ksmbd.$DEVICE.name="${label:-$DEVICE}"
  36. set ksmbd.$DEVICE.path="$mount"
  37. set ksmbd.$DEVICE.browseable="yes"
  38. set ksmbd.$DEVICE.read_only="yes"
  39. set ksmbd.$DEVICE.guest_ok="yes"
  40. commit ksmbd
  41. EOF
  42. /etc/init.d/ksmbd reload
  43. }
  44. }
  45. [ "$ACTION" = "remove" ] && {
  46. uci -c /var/run/config batch <<-EOF
  47. delete ksmbd.$DEVICE
  48. commit ksmbd
  49. EOF
  50. /etc/init.d/ksmbd reload
  51. }