This commit is contained in:
Hans Karlinius
2024-12-01 05:35:08 +01:00
parent e56df7db03
commit a077be3c4c
8 changed files with 32 additions and 29 deletions
@@ -8,24 +8,26 @@ if bashio::config.has_value 'usbdevices'; then
#usbdevices=($(bashio::config 'usbdevices'))
#bashio::log.info "Devices: ${usbdevices}"
options=$(bashio::api.supervisor GET "/addons/self/options/config")
bashio::log.info "Options: ${options}"
#bashio::log.info "Options: ${options}"
usbdevices_json=$(echo $options | jq -c '.usbdevices[]')
readarray -t usbdevices < <(echo "$usbdevices_json")
bashio::log.info "Devices: ${usbdevices[@]}"
#bashio::log.info "Devices: ${usbdevices[@]}"
mapfile -t inuse_devices < <(/usr/bin/vh_list_inuse_devices)
bashio::log.info "Inuse devices: ${inuse_devices[@]}"
#bashio::log.info "Inuse devices: ${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')
#bashio::log.info "Use: ${use} Device: ${device} Deviceid: ${deviceid}"
if $use; then
bashio::log.info "AUTO USE DEVICE,${deviceid}"
/usr/bin/vhclient -t "AUTO USE DEVICE,${deviceid}"
#bashio::log.info "AUTO USE DEVICE,${deviceid}"
#/usr/bin/vhclient -t "AUTO USE DEVICE,${deviceid}"
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}"
/usr/bin/vhclient -t "STOP USING,${deviceid}"
fi
fi
done