mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-28 04:14:00 +02:00
bashio now emits deprecation warnings for bashio::addon.* calls. This migrates all 227 call-sites across 86 files to use the new bashio::app.* API. Cross-compatibility is preserved in two ways: 1. bashio-standalone.sh: adds bashio::app.* functions that forward to bashio::addon.* (used when running without HA Supervisor). Also adds the missing ingress_url, restart and stop stubs. 2. ha_entrypoint.sh: injects a one-liner compat shim after the shebang of every cont-init and service script at container startup. On old bashio installations (bashio::app.* absent) the shim defines bashio::app.* as thin wrappers around bashio::addon.*; on new bashio the guard condition is true so the block is a no-op. The probe script in ha_entrypoint.sh is also updated to try bashio::app.version before falling back to bashio::addon.version. https://claude.ai/code/session_011FWFBhYQ6VS5FauSqv4UMo
58 lines
2.1 KiB
Bash
Executable File
58 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bashio
|
|
# shellcheck shell=bash
|
|
|
|
# Export CSRF
|
|
# Borrowed from https://github.com/BenoitAnastay/paperless-home-assistant-addon/blob/main/paperless-ngx/rootfs/etc/s6-overlay/s6-rc.d/init-paperless/run
|
|
declare -a urls=()
|
|
CSRF=""
|
|
# Get HA Port
|
|
result=$(bashio::api.supervisor GET /core/info true || true)
|
|
port=$(bashio::jq "$result" ".data.port")
|
|
addon_port=$(bashio::app.port 9810)
|
|
|
|
# Get all possible URLs
|
|
result=$(bashio::api.supervisor GET /core/api/config true || true)
|
|
urls+=("$(bashio::info.hostname).local")
|
|
urls+=("$(bashio::info.hostname)")
|
|
urls+=("$(bashio::jq "$result" '.internal_url' | cut -d'/' -f3 | cut -d':' -f1)")
|
|
urls+=("$(bashio::jq "$result" '.external_url' | cut -d'/' -f3 | cut -d':' -f1)")
|
|
|
|
# Get supported interfaces
|
|
for interface in $(bashio::network.interfaces); do
|
|
urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)")
|
|
urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)")
|
|
done
|
|
|
|
if bashio::config.has_value 'csrf_allowed'; then
|
|
bashio::log.info "Setup manually defined ALLOWED_CSRF domains"
|
|
|
|
while read -r line; do
|
|
urls+=("$line")
|
|
done <<< "$(bashio::config 'csrf_allowed')"
|
|
fi
|
|
|
|
# Add internal and external URL as it
|
|
if [[ "$(bashio::jq "$result" '.external_url')" != "null" ]]; then
|
|
CSRF=$(bashio::jq "$result" '.external_url')
|
|
fi
|
|
if [[ "$(bashio::jq "$result" '.internal_url')" != "null" ]]; then
|
|
CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF}
|
|
fi
|
|
|
|
# Loop through URls to add them in the CSRF string
|
|
for url in "${urls[@]}"; do
|
|
if bashio::var.has_value "${url}"; then
|
|
if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then
|
|
CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF}
|
|
if bashio::var.has_value "$(bashio::app.port 9810)"; then
|
|
CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF}
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
CSRF=${CSRF::-1}
|
|
|
|
# Save CSFR
|
|
echo -n "${CSRF}" > /var/run/s6/container_environment/PAPERLESS_CSRF_TRUSTED_ORIGINS
|
|
bashio::log.blue "PAPERLESS_CSRF_TRUSTED_ORIGINS is set to ${CSRF}"
|