23 lines
851 B
Plaintext
Executable File
23 lines
851 B
Plaintext
Executable File
#!/usr/bin/with-contenv bashio
|
|
|
|
if bashio::config.has_value 'usbdevices'; then
|
|
options=$(bashio::api.supervisor GET "/addons/self/options/config")
|
|
usbdevices_json=$(echo $options | jq -c '.usbdevices[]')
|
|
readarray -t usbdevices < <(echo "$usbdevices_json")
|
|
mapfile -t inuse_devices < <(/usr/bin/vh_list_inuse_devices)
|
|
for usbdevice in "${usbdevices[@]}"; do
|
|
use=$(echo $usbdevice | jq '. | if .use then true else false end')
|
|
device=$(echo $usbdevice | jq '.device | tostring')
|
|
deviceid=$(echo $device | sed 's/.*(\(.*\)).*/\1/g')
|
|
if $use; then
|
|
bashio::log.info "USE,${deviceid}"
|
|
/usr/bin/vhclient -t "USE,${deviceid}"
|
|
else
|
|
if [[ "${inuse_devices[@]}" =~ "$device" ]]; then
|
|
bashio::log.info "STOP USING,${deviceid}"
|
|
/usr/bin/vhclient -t "STOP USING,${deviceid}"
|
|
fi
|
|
fi
|
|
done
|
|
fi
|