Files
home-assistant-addons/vhclient/rootfs/etc/s6-overlay/s6-rc.d/test/run
T
Hans Karlinius 3ba66c8c2f test
2024-11-30 07:40:59 +01:00

51 lines
1.9 KiB
Plaintext
Executable File

#!/command/with-contenv bashio
#set -x
#test=($(bashio::config 'test'))
#test+=('one', 'two')
#bashio::config::update 'test' "${test[@]}"
#bashio::addon.option 'test' $test[@]
#TEST
#bashio::addon.option 'usbdevices' { 'name': 'one', 'use': false}
#my_array=($(bashio::config 'my_array'))
#my_array+=('one') # Add a new item to the array
#my_array+=({ 'name': 'one', 'use': false}) # Add a new item to the array
#bashio::config::update 'my_array' "${my_array[@]}"
#list1=$(/usr/bin/vhclient -t LIST)
#list2=$(eval 'grep "--" <<< "$list1"')
#bashio::log.info "${list1}"
#bashio::log.info "${list2}"
#mapfile -t devices < <(/usr/bin/vhclient -t LIST)
mapfile -t devices < <(/usr/bin/vh_list_devices)
for device in "${devices[@]}"; do
#options=$(bashio::addon.options)
options=$(bashio::api.supervisor GET "/addons/self/options/config")
gurka=$(printf $options | jq --arg device "$device" '.usbdevices[] | select(.device == ($device))')
bashio::log.info "Options: ${gurka}"
if [[ ! " ${options}.usbdevices[*] " =~ [[:space:]]${device}[[:space:]] ]]; then
bashio::log.info "Adding to config: ${device}"
options_updated=$(printf $options | jq --arg device "$device" '.usbdevices |= . + [{ device: ($device), use: false }]')
bashio::log.info "Options updated: ${options_updated}"
#payload=$(bashio::var.json options "^${new_options}")
#options_payload='{"options": ${options_updated}}'
options_payload=$(printf $options_updated | jq '. = { options: . }')
bashio::log.info "Payload: ${options_payload}"
bashio::api.supervisor POST "/addons/self/options" "${options_payload}"
fi
done
#options=$(bashio::addon.options)
#new_options=$(echo $options | jq .usbdevices += [{ device: 'ONE', use: false }])
#payload=$(bashio::var.json options "^${new_options}")
#bashio::api.supervisor POST "/addons/self/options" "${payload}"
curl -sH "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons/self/info | jq .data.options