#!/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
|
|
}
|