mirror of
https://github.com/hassio-addons/bashio.git
synced 2025-05-06 12:01:25 +00:00
🔨 Re-branding of the Supervisor API (#16)
* 🔨 Re-branding of the Supervisor API * 🚑 Fix typo in the supervisor token
This commit is contained in:
parent
5c7f2914cd
commit
a4b2a4cc1a
15 changed files with 196 additions and 196 deletions
172
lib/os.sh
Normal file
172
lib/os.sh
Normal file
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Home Assistant Add-ons: Bashio
|
||||
# Bashio is an bash function library for use with Home Assistant add-ons.
|
||||
#
|
||||
# It contains a set of commonly used operations and can be used
|
||||
# to be included in add-on scripts to reduce code duplication across add-ons.
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates HassOS to the latest version.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Version to update to (optional)
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.update() {
|
||||
local version=${1:-}
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if bashio::var.has_value "${version}"; then
|
||||
version=$(bashio::var.json version "${version}")
|
||||
bashio::api.supervisor POST /os/update "${version}"
|
||||
else
|
||||
bashio::api.supervisor POST /os/update
|
||||
fi
|
||||
bashio::cache.flush_all
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates HassOS CLI to the latest version.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Version to update to (optional)
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.update_cli() {
|
||||
local version=${1:-}
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if bashio::var.has_value "${version}"; then
|
||||
version=$(bashio::var.json version "${version}")
|
||||
bashio::api.supervisor POST /os/update/cli "${version}"
|
||||
else
|
||||
bashio::api.supervisor POST /os/update/cli
|
||||
fi
|
||||
bashio::cache.flush_all
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Load HassOS host configuration from USB stick.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.config_sync() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::api.supervisor POST /os/config/sync
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a JSON object with generic Home Asssistant information.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Cache key to store results in (optional)
|
||||
# $2 jq Filter to apply on the result (optional)
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os() {
|
||||
local cache_key=${1:-'os.info'}
|
||||
local filter=${2:-}
|
||||
local info
|
||||
local response
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}" "$@"
|
||||
|
||||
if bashio::cache.exists "${cache_key}"; then
|
||||
bashio::cache.get "${cache_key}"
|
||||
return "${__BASHIO_EXIT_OK}"
|
||||
fi
|
||||
|
||||
if bashio::cache.exists 'os.info'; then
|
||||
info=$(bashio::cache.get 'supervisor.os')
|
||||
else
|
||||
info=$(bashio::api.supervisor GET /os/info false)
|
||||
bashio::cache.set 'os.info' "${info}"
|
||||
fi
|
||||
|
||||
response="${info}"
|
||||
if bashio::var.has_value "${filter}"; then
|
||||
response=$(bashio::jq "${info}" "${filter}")
|
||||
fi
|
||||
|
||||
bashio::cache.set "${cache_key}" "${response}"
|
||||
printf "%s" "${response}"
|
||||
|
||||
return "${__BASHIO_EXIT_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of HassOS.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.version() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::os 'os.info.version' '.version'
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of HassOS.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.version_latest() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::os 'os.info.version_latest' '.version_latest'
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if there is an update available for the Supervisor.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.update_available() {
|
||||
local version
|
||||
local last_version
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
|
||||
version=$(bashio::os.version)
|
||||
last_version=$(bashio::os.last_version)
|
||||
|
||||
if [[ "${version}" = "${last_version}" ]]; then
|
||||
return "${__BASHIO_EXIT_NOK}"
|
||||
fi
|
||||
|
||||
return "${__BASHIO_EXIT_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the CLI version of HassOS.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.version_cli() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::os 'os.info.version_cli' '.version_cli'
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest CLI version of HassOS.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.version_cli_latest() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::os 'os.info.version_cli_latest' '.version_cli_latest'
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if there is an update available for the Supervisor.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.update_available_cli() {
|
||||
local version
|
||||
local last_version
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
|
||||
version=$(bashio::os.version_cli)
|
||||
last_version=$(bashio::os.version_cli_latest)
|
||||
|
||||
if [[ "${version}" = "${last_version}" ]]; then
|
||||
return "${__BASHIO_EXIT_NOK}"
|
||||
fi
|
||||
|
||||
return "${__BASHIO_EXIT_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the board running HassOS.
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::os.board() {
|
||||
bashio::log.trace "${FUNCNAME[0]}"
|
||||
bashio::os 'os.info.board' '.board'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue