40 lines
1.3 KiB
Plaintext
Executable File
40 lines
1.3 KiB
Plaintext
Executable File
#!/usr/bin/with-contenv bashio
|
|
|
|
preventconfig=$(bashio::cache.get preventconfig)
|
|
if $preventconfig; then
|
|
bashio::log.info "Prevent USE device from config"
|
|
exit 0
|
|
fi
|
|
|
|
autouse=$(bashio::cache.get autouse)
|
|
if $autouse; then
|
|
bashio::log.info "AutoShare All enabled, will not use devices from configuration"
|
|
exit 0
|
|
fi
|
|
|
|
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 inuse_device in "${!inuse_devices[@]}"; do
|
|
bashio::log.info "Device in use - ${inuse_device}"
|
|
done
|
|
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 [[ ${inuse_devices[@]} =~ .*${deviceid}.* ]]; then
|
|
if ! $use; then
|
|
result=$(/usr/bin/vhclient -t "STOP USING,${deviceid}")
|
|
bashio::log.info "STOP USING,${deviceid} - ${result}"
|
|
fi
|
|
else
|
|
if $use; then
|
|
result=$(/usr/bin/vhclient -t "AUTO USE DEVICE,${deviceid}")
|
|
bashio::log.info "AUTO USE DEVICE,${deviceid} - ${result}"
|
|
fi
|
|
fi
|
|
done
|
|
fi
|