samba.hotplug 981 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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
  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. break
  17. }
  18. json_select ..
  19. done
  20. json_select ..
  21. }
  22. [ -f /var/run/config/samba ] || {
  23. mkdir -p /var/run/config && touch /var/run/config/samba
  24. }
  25. [ "$ACTION" = "add" ] && {
  26. device_get_vars $DEVICE label mount
  27. [ -n "$mount" ] && {
  28. uci -c /var/run/config batch <<-EOF
  29. set samba.$DEVICE="sambashare"
  30. set samba.$DEVICE.name="$label"
  31. set samba.$DEVICE.path="$mount"
  32. set samba.$DEVICE.browseable="yes"
  33. set samba.$DEVICE.read_only="yes"
  34. set samba.$DEVICE.guest_ok="yes"
  35. commit samba
  36. EOF
  37. /etc/init.d/samba reload
  38. }
  39. }
  40. [ "$ACTION" = "remove" ] && {
  41. uci -c /var/run/config batch <<-EOF
  42. delete samba.$DEVICE
  43. commit samba
  44. EOF
  45. /etc/init.d/samba reload
  46. }