mirror of
https://github.com/hassio-addons/addon-debian-base.git
synced 2025-05-07 04:31:30 +00:00
💓 Resurrect Debian base images, based on Buster
This commit is contained in:
parent
c760eec657
commit
d65b375803
22 changed files with 138 additions and 3601 deletions
309
.gitlab-ci.yml
309
.gitlab-ci.yml
|
@ -1,302 +1,17 @@
|
|||
---
|
||||
image: docker:stable
|
||||
include: https://raw.githubusercontent.com/hassio-addons/organization/master/gitlabci/addon.yml
|
||||
|
||||
variables:
|
||||
ADDON_GITHUB_REPO: hassio-addons/addon-debian-base
|
||||
ADDON_SLUG: debian-base
|
||||
ADDON_TARGET: base
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_HUB_ORG: hassioaddons
|
||||
ADDON_GITHUB_REPO: "hassio-addons/addon-debian-base"
|
||||
ADDON_SLUG: "debian-base"
|
||||
ADDON_TARGET: "base"
|
||||
|
||||
stages:
|
||||
- preflight
|
||||
- build
|
||||
- scan
|
||||
- deploy
|
||||
ADDON_LEGACY_TAGS: "true"
|
||||
ADDON_PUBLISH: "false"
|
||||
ADDON_QEMU: "true"
|
||||
|
||||
# Generic DIND template
|
||||
.dind: &dind
|
||||
before_script:
|
||||
- docker info
|
||||
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" registry.gitlab.com
|
||||
services:
|
||||
- name: docker:dind
|
||||
command: ["--experimental"]
|
||||
|
||||
# Generic preflight template
|
||||
.preflight: &preflight
|
||||
stage: preflight
|
||||
tags:
|
||||
- preflight
|
||||
|
||||
# Generic build template
|
||||
.build: &build
|
||||
<<: *dind
|
||||
stage: build
|
||||
script:
|
||||
- apk --no-cache add curl
|
||||
- |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v2.12.0/qemu-aarch64-static.tar.gz" | \
|
||||
tar zxvf - -C ./base/rootfs/usr/bin/
|
||||
- |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v2.12.0/qemu-arm-static.tar.gz" | \
|
||||
tar zxvf - -C ./base/rootfs/usr/bin/
|
||||
- |
|
||||
docker run \
|
||||
--privileged \
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--volume "$PWD":/docker \
|
||||
hassioaddons/build-env:latest \
|
||||
--image "addon" \
|
||||
--cache-from "${DOCKER_HUB_ORG}/${ADDON_SLUG}-${ADDON_ARCH}" \
|
||||
--cache-tag "test" \
|
||||
--git-url "https://github.com/${ADDON_GITHUB_REPO}" \
|
||||
--target "${ADDON_TARGET}" \
|
||||
--tag-latest \
|
||||
--git \
|
||||
--${ADDON_ARCH}
|
||||
- |
|
||||
docker tag \
|
||||
"addon:latest" \
|
||||
"registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
- |
|
||||
docker push \
|
||||
"registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
tags:
|
||||
- build
|
||||
|
||||
# Generic scan template
|
||||
.scan: &scan
|
||||
<<: *dind
|
||||
stage: scan
|
||||
allow_failure: true
|
||||
before_script:
|
||||
- docker info
|
||||
- docker run -d --name db arminc/clair-db:latest
|
||||
- docker run -p 6060:6060 --link db:postgres -d --name clair arminc/clair-local-scan:v2.0.1
|
||||
- apk add -U curl ca-certificates
|
||||
- |
|
||||
curl \
|
||||
--silent \
|
||||
--show-error \
|
||||
--location \
|
||||
--fail \
|
||||
--retry 3 \
|
||||
--output /usr/bin/clair-scanner \
|
||||
https://github.com/arminc/clair-scanner/releases/download/v8/clair-scanner_linux_amd64
|
||||
- chmod +x /usr/bin/clair-scanner
|
||||
- touch clair-whitelist.yml
|
||||
- echo "Waiting for Clair to start"
|
||||
- |
|
||||
while ! nc -z docker 6060; do
|
||||
sleep 1
|
||||
WAIT=$((${WAIT} + 1))
|
||||
if [ "${WAIT}" -gt 30 ]; then
|
||||
echo "Error > Timeout waiting for Clair to start"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
- docker pull "registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
script:
|
||||
- |
|
||||
clair-scanner \
|
||||
-c http://docker:6060 \
|
||||
--ip $(hostname -i) \
|
||||
-w clair-whitelist.yml \
|
||||
"registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
tags:
|
||||
- scan
|
||||
|
||||
# Generic deploy template
|
||||
.deploy: &deploy
|
||||
<<: *dind
|
||||
stage: deploy
|
||||
before_script:
|
||||
- apk --no-cache add curl
|
||||
- docker info
|
||||
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" registry.gitlab.com
|
||||
- docker pull "registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
- docker pull hassioaddons/build-env:latest
|
||||
- |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v2.12.0/qemu-aarch64-static.tar.gz" | \
|
||||
tar zxvf - -C ./base/rootfs/usr/bin/
|
||||
- |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v2.12.0/qemu-arm-static.tar.gz" | \
|
||||
tar zxvf - -C ./base/rootfs/usr/bin/
|
||||
script:
|
||||
- |
|
||||
docker run \
|
||||
--privileged \
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--volume "$PWD":/docker \
|
||||
hassioaddons/build-env:latest \
|
||||
--image "${DOCKER_HUB_ORG}/${ADDON_SLUG}-${ADDON_ARCH}" \
|
||||
--cache-from "registry.gitlab.com/${CI_PROJECT_PATH}/${ADDON_ARCH}" \
|
||||
--cache-tag "${CI_COMMIT_SHA}" \
|
||||
--git-url "https://github.com/${ADDON_GITHUB_REPO}" \
|
||||
--target "${ADDON_TARGET}" \
|
||||
--login "${DOCKER_LOGIN}" \
|
||||
--password "${DOCKER_PASSWORD}" \
|
||||
--git \
|
||||
--push \
|
||||
--squash \
|
||||
--${ADDON_ARCH}
|
||||
tags:
|
||||
- deploy
|
||||
|
||||
# Preflight jobs
|
||||
hadolint:
|
||||
<<: *preflight
|
||||
image: hadolint/hadolint:latest
|
||||
before_script:
|
||||
- hadolint --version
|
||||
script:
|
||||
- hadolint "${ADDON_TARGET}/Dockerfile"
|
||||
|
||||
shellcheck:
|
||||
<<: *preflight
|
||||
image:
|
||||
name: koalaman/shellcheck-alpine:stable
|
||||
entrypoint: [""]
|
||||
before_script:
|
||||
- shellcheck --version
|
||||
- apk --no-cache add grep
|
||||
- |
|
||||
find . -type f -print0 | \
|
||||
xargs -0 sed -i 's:#!/usr/bin/with-contenv bash:#!/bin/bash:g'
|
||||
script:
|
||||
- |
|
||||
for file in $(grep -IRl "#\!\(/usr/bin/env \|/bin/\)" --exclude-dir ".git" "${ADDON_TARGET}"); do
|
||||
if ! shellcheck --external-sources $file; then
|
||||
export FAILED=1
|
||||
else
|
||||
echo "$file OK"
|
||||
fi
|
||||
done
|
||||
if [ "${FAILED}" = "1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
yamllint:
|
||||
<<: *preflight
|
||||
image: sdesbure/yamllint
|
||||
before_script:
|
||||
- yamllint --version
|
||||
script:
|
||||
- yamllint .
|
||||
|
||||
jsonlint:
|
||||
<<: *preflight
|
||||
image: sahsu/docker-jsonlint
|
||||
before_script:
|
||||
- jsonlint --version || true
|
||||
script:
|
||||
- |
|
||||
for file in $(find . -type f -name "*.json"); do
|
||||
if ! jsonlint -q $file; then
|
||||
export FAILED=1
|
||||
else
|
||||
echo "$file OK"
|
||||
fi
|
||||
done
|
||||
if [ "${FAILED}" = "1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
markdownlint:
|
||||
<<: *preflight
|
||||
image:
|
||||
name: ruby:alpine
|
||||
entrypoint: [""]
|
||||
before_script:
|
||||
- gem install mdl
|
||||
- mdl --version
|
||||
script:
|
||||
- mdl --style all --warnings .
|
||||
|
||||
# Build Jobs
|
||||
build:armhf:
|
||||
<<: *build
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
|
||||
build:aarch64:
|
||||
<<: *build
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
|
||||
build:i386:
|
||||
<<: *build
|
||||
variables:
|
||||
ADDON_ARCH: i386
|
||||
|
||||
build:amd64:
|
||||
<<: *build
|
||||
variables:
|
||||
ADDON_ARCH: amd64
|
||||
|
||||
# Scan jobs
|
||||
clair:armhf:
|
||||
<<: *scan
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
|
||||
clair:aarch64:
|
||||
<<: *scan
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
|
||||
clair:i386:
|
||||
<<: *scan
|
||||
variables:
|
||||
ADDON_ARCH: i386
|
||||
|
||||
clair:amd64:
|
||||
<<: *scan
|
||||
variables:
|
||||
ADDON_ARCH: amd64
|
||||
|
||||
# Deploy jobs
|
||||
deploy:armhf:
|
||||
<<: *deploy
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
only:
|
||||
- master
|
||||
- /^v\d+\.\d+\.\d+(?:-(?:beta|rc)(?:(?:(?:\+|\.)?[a-zA-Z0-9]+)*)?)?$/
|
||||
except:
|
||||
- /^(?!master).+@/
|
||||
|
||||
deploy:aarch64:
|
||||
<<: *deploy
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
only:
|
||||
- master
|
||||
- /^v\d+\.\d+\.\d+(?:-(?:beta|rc)(?:(?:(?:\+|\.)?[a-zA-Z0-9]+)*)?)?$/
|
||||
except:
|
||||
- /^(?!master).+@/
|
||||
|
||||
deploy:i386:
|
||||
<<: *deploy
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
only:
|
||||
- master
|
||||
- /^v\d+\.\d+\.\d+(?:-(?:beta|rc)(?:(?:(?:\+|\.)?[a-zA-Z0-9]+)*)?)?$/
|
||||
except:
|
||||
- /^(?!master).+@/
|
||||
|
||||
deploy:amd64:
|
||||
<<: *deploy
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
only:
|
||||
- master
|
||||
- /^v\d+\.\d+\.\d+(?:-(?:beta|rc)(?:(?:(?:\+|\.)?[a-zA-Z0-9]+)*)?)?$/
|
||||
except:
|
||||
- /^(?!master).+@/
|
||||
ADDON_AARCH64_BASE: "arm64v8/debian:buster-20191118-slim"
|
||||
ADDON_AMD64_BASE: "amd64/debian:buster-20191118-slim"
|
||||
ADDON_ARMV7_BASE: "arm32v7/debian:buster-20191118-slim"
|
||||
ADDON_I386_BASE: "i386/debian:buster-20191118-slim"
|
||||
ADDON_ARMHF_BASE: "arm32v5/debian:buster-20191118-slim"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# MIT License
|
||||
|
||||
Copyright (c) 2017 Franck Nijhof
|
||||
Copyright (c) 2017-2019 Franck Nijhof
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
97
README.md
97
README.md
|
@ -4,6 +4,12 @@
|
|||
![Project Stage][project-stage-shield]
|
||||
[![License][license-shield]](LICENSE.md)
|
||||
|
||||
![Supports aarch64 Architecture][aarch64-shield]
|
||||
![Supports amd64 Architecture][amd64-shield]
|
||||
![Supports armhf Architecture][armhf-shield]
|
||||
![Supports armv7 Architecture][armv7-shield]
|
||||
![Supports i386 Architecture][i386-shield]
|
||||
|
||||
[![GitLab CI][gitlabci-shield]][gitlabci]
|
||||
![Project Maintenance][maintenance-shield]
|
||||
[![GitHub Activity][commits-shield]][commits]
|
||||
|
@ -11,6 +17,10 @@
|
|||
[![Discord][discord-shield]][discord]
|
||||
[![Community Forum][forum-shield]][forum]
|
||||
|
||||
[![Buy me a coffee][buymeacoffee-shield]][buymeacoffee]
|
||||
|
||||
[![Support my work on Patreon][patreon-shield]][patreon]
|
||||
|
||||
Docker Debian base images used by Community Hass.io Add-ons.
|
||||
|
||||
## About
|
||||
|
@ -21,40 +31,14 @@ Add-ons.
|
|||
While Home Assistant provides base images, the images provided by this
|
||||
repository contain some extras:
|
||||
|
||||
- Based on Debian Stretch (slim)
|
||||
- Based on Debian Buster (slim)
|
||||
- Adds [s6] as a process supervisor.
|
||||
- Adds `jq` & `curl`, since every add-on uses them.
|
||||
- Adds Docker [Label Schema][label-schema] support.
|
||||
- Adds a large Bash function library for use with an add-on.
|
||||
- Includes a Hass.io helper library: [Bashio][bashio]
|
||||
- Handles logs, add-on startup banners and update notifications.
|
||||
- Several small adjustments and improvements.
|
||||
|
||||
## Docker status
|
||||
|
||||
[![Docker Architecture][armhf-arch-shield]][armhf-dockerhub]
|
||||
[![Docker Version][armhf-version-shield]][armhf-microbadger]
|
||||
[![Docker Layers][armhf-layers-shield]][armhf-microbadger]
|
||||
[![Docker Pulls][armhf-pulls-shield]][armhf-dockerhub]
|
||||
[![Anchore Image Overview][armhf-anchore-shield]][armhf-anchore]
|
||||
|
||||
[![Docker Architecture][aarch64-arch-shield]][aarch64-dockerhub]
|
||||
[![Docker Version][aarch64-version-shield]][aarch64-microbadger]
|
||||
[![Docker Layers][aarch64-layers-shield]][aarch64-microbadger]
|
||||
[![Docker Pulls][aarch64-pulls-shield]][aarch64-dockerhub]
|
||||
[![Anchore Image Overview][aarch64-anchore-shield]][aarch64-anchore]
|
||||
|
||||
[![Docker Architecture][amd64-arch-shield]][amd64-dockerhub]
|
||||
[![Docker Version][amd64-version-shield]][amd64-microbadger]
|
||||
[![Docker Layers][amd64-layers-shield]][amd64-microbadger]
|
||||
[![Docker Pulls][amd64-pulls-shield]][amd64-dockerhub]
|
||||
[![Anchore Image Overview][amd64-anchore-shield]][amd64-anchore]
|
||||
|
||||
[![Docker Architecture][i386-arch-shield]][i386-dockerhub]
|
||||
[![Docker Version][i386-version-shield]][i386-microbadger]
|
||||
[![Docker Layers][i386-layers-shield]][i386-microbadger]
|
||||
[![Docker Pulls][i386-pulls-shield]][i386-dockerhub]
|
||||
[![Anchore Image Overview][i386-anchore-shield]][i386-anchore]
|
||||
|
||||
## Changelog & Releases
|
||||
|
||||
This repository keeps a change log using [GitHub's releases][releases]
|
||||
|
@ -75,9 +59,11 @@ Got questions?
|
|||
|
||||
You have several options to get them answered:
|
||||
|
||||
- The [Community Hass.io Add-ons Discord chat server][discord] for add-on
|
||||
support and feature requests.
|
||||
- The [Home Assistant Discord Chat Server][discord-ha] for general Home
|
||||
Assistant discussions and questions.
|
||||
- The Home Assistant [Community Forum][forum].
|
||||
- The Home Assistant [Discord Chat Server][discord] for general Home Assistant
|
||||
discussions and questions.
|
||||
- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit]
|
||||
|
||||
You could also [open an issue here][issue] GitHub.
|
||||
|
@ -110,7 +96,7 @@ our [GitHub Repository][repository].
|
|||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Franck Nijhof
|
||||
Copyright (c) 2017-2019 Franck Nijhof
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -130,53 +116,32 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
[aarch64-anchore-shield]: https://anchore.io/service/badges/image/d48a9351821e9af339e3b53455a2f869084529c376c4e3707b172ccfe76c4e60
|
||||
[aarch64-anchore]: https://anchore.io/image/dockerhub/hassioaddons%2Fdebian-base-aarch64%3Alatest
|
||||
[aarch64-arch-shield]: https://img.shields.io/badge/architecture-aarch64-blue.svg
|
||||
[aarch64-dockerhub]: https://hub.docker.com/r/hassioaddons/debian-base-aarch64
|
||||
[aarch64-layers-shield]: https://images.microbadger.com/badges/image/hassioaddons/debian-base-aarch64.svg
|
||||
[aarch64-microbadger]: https://microbadger.com/images/hassioaddons/debian-base-aarch64
|
||||
[aarch64-pulls-shield]: https://img.shields.io/docker/pulls/hassioaddons/debian-base-aarch64.svg
|
||||
[aarch64-version-shield]: https://images.microbadger.com/badges/version/hassioaddons/debian-base-aarch64.svg
|
||||
[amd64-anchore-shield]: https://anchore.io/service/badges/image/9378d163a8bcb1f3e52963a2e9d8d748f89ad332cd24e54d58341a371b2e5dae
|
||||
[amd64-anchore]: https://anchore.io/image/dockerhub/hassioaddons%2Fdebian-base-amd64%3Alatest
|
||||
[amd64-arch-shield]: https://img.shields.io/badge/architecture-amd64-blue.svg
|
||||
[amd64-dockerhub]: https://hub.docker.com/r/hassioaddons/debian-base-amd64
|
||||
[amd64-layers-shield]: https://images.microbadger.com/badges/image/hassioaddons/debian-base-amd64.svg
|
||||
[amd64-microbadger]: https://microbadger.com/images/hassioaddons/debian-base-amd64
|
||||
[amd64-pulls-shield]: https://img.shields.io/docker/pulls/hassioaddons/debian-base-amd64.svg
|
||||
[amd64-version-shield]: https://images.microbadger.com/badges/version/hassioaddons/debian-base-amd64.svg
|
||||
[armhf-anchore-shield]: https://anchore.io/service/badges/image/bfb2acc97d074eb8f656e7082ace5ac0dce2cc8b3621a653b273c39aa3ce474a
|
||||
[armhf-anchore]: https://anchore.io/image/dockerhub/hassioaddons%2Fdebian-base-armhf%3Alatest
|
||||
[armhf-arch-shield]: https://img.shields.io/badge/architecture-armhf-blue.svg
|
||||
[armhf-dockerhub]: https://hub.docker.com/r/hassioaddons/debian-base-armhf
|
||||
[armhf-layers-shield]: https://images.microbadger.com/badges/image/hassioaddons/debian-base-armhf.svg
|
||||
[armhf-microbadger]: https://microbadger.com/images/hassioaddons/debian-base-armhf
|
||||
[armhf-pulls-shield]: https://img.shields.io/docker/pulls/hassioaddons/debian-base-armhf.svg
|
||||
[armhf-version-shield]: https://images.microbadger.com/badges/version/hassioaddons/debian-base-armhf.svg
|
||||
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
|
||||
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
|
||||
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
|
||||
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
|
||||
[bashio]: https://github.com/hassio-addons/bashio
|
||||
[buymeacoffee-shield]: https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg
|
||||
[buymeacoffee]: https://www.buymeacoffee.com/frenck
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/y/hassio-addons/addon-debian-base.svg
|
||||
[commits]: https://github.com/hassio-addons/addon-debian-base/commits/master
|
||||
[contributors]: https://github.com/hassio-addons/addon-debian-base/graphs/contributors
|
||||
[discord-shield]: https://img.shields.io/discord/330944238910963714.svg
|
||||
[discord]: https://discord.gg/c5DvZ4e
|
||||
[discord-ha]: https://discord.gg/c5DvZ4e
|
||||
[discord-shield]: https://img.shields.io/discord/478094546522079232.svg
|
||||
[discord]: https://discord.me/hassioaddons
|
||||
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
|
||||
[forum]: https://community.home-assistant.io/?u=frenck
|
||||
[frenck]: https://github.com/frenck
|
||||
[gitlabci-shield]: https://gitlab.com/hassio-addons/addon-debian-base/badges/master/pipeline.svg
|
||||
[gitlabci]: https://gitlab.com/hassio-addons/addon-debian-base/pipelines
|
||||
[i386-anchore-shield]: https://anchore.io/service/badges/image/2f6b2d4b0531fb07e936d102c0cf3ee510f83f10ce043c82bf1987a4715273ee
|
||||
[i386-anchore]: https://anchore.io/image/dockerhub/hassioaddons%2Fdebian-base-i386%3Alatest
|
||||
[i386-arch-shield]: https://img.shields.io/badge/architecture-i386-blue.svg
|
||||
[i386-dockerhub]: https://hub.docker.com/r/hassioaddons/debian-base-i386
|
||||
[i386-layers-shield]: https://images.microbadger.com/badges/image/hassioaddons/debian-base-i386.svg
|
||||
[i386-microbadger]: https://microbadger.com/images/hassioaddons/debian-base-i386
|
||||
[i386-pulls-shield]: https://img.shields.io/docker/pulls/hassioaddons/debian-base-i386.svg
|
||||
[i386-version-shield]: https://images.microbadger.com/badges/version/hassioaddons/debian-base-i386.svg
|
||||
[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg
|
||||
[issue]: https://github.com/hassio-addons/addon-debian-base/issues
|
||||
[keepchangelog]: http://keepachangelog.com/en/1.0.0/
|
||||
[label-schema]: http://label-schema.org/
|
||||
[license-shield]: https://img.shields.io/github/license/hassio-addons/addon-debian-base.svg
|
||||
[maintenance-shield]: https://img.shields.io/maintenance/yes/2018.svg
|
||||
[maintenance-shield]: https://img.shields.io/maintenance/yes/2019.svg
|
||||
[patreon-shield]: https://www.frenck.nl/images/patreon.png
|
||||
[patreon]: https://www.patreon.com/frenck
|
||||
[project-stage-shield]: https://img.shields.io/badge/Project%20Stage-Production%20Ready-brightgreen.svg
|
||||
[reddit]: https://reddit.com/r/homeassistant
|
||||
[releases-shield]: https://img.shields.io/github/release/hassio-addons/addon-debian-base.svg
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ARG BUILD_FROM=debian:stretch-slim
|
||||
ARG BUILD_FROM=debian:buster-20191118-slim
|
||||
# hadolint ignore=DL3006
|
||||
FROM ${BUILD_FROM}
|
||||
|
||||
|
@ -10,45 +10,51 @@ ENV \
|
|||
PS1="$(whoami)@$(hostname):$(pwd)$ " \
|
||||
S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \
|
||||
S6_CMD_WAIT_FOR_SERVICES=1 \
|
||||
TERM="xterm"
|
||||
TERM="xterm-256color"
|
||||
|
||||
# Copy root filesystem
|
||||
COPY rootfs /
|
||||
|
||||
# Set shell
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# Install base system
|
||||
ARG BUILD_ARCH=amd64
|
||||
RUN \
|
||||
apt-get update \
|
||||
\
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
bash=4.4-5 \
|
||||
ca-certificates=20161130+nmu1 \
|
||||
curl=7.52.1-5+deb9u5 \
|
||||
jq=1.5+dfsg-1.3 \
|
||||
tzdata=2018e-0+deb9u1 \
|
||||
bash=5.0-4 \
|
||||
ca-certificates=20190110 \
|
||||
curl=7.64.0-4 \
|
||||
jq=1.5+dfsg-2+b1 \
|
||||
tzdata=2019c-0+deb10u1 \
|
||||
\
|
||||
&& if [ "${BUILD_ARCH}" = "i386" ]; then S6_ARCH="x86"; else S6_ARCH="${BUILD_ARCH}"; fi \
|
||||
&& S6_ARCH="${BUILD_ARCH}" \
|
||||
&& if [ "${BUILD_ARCH}" = "i386" ]; then S6_ARCH="x86"; fi \
|
||||
&& if [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \
|
||||
&& if [ "${BUILD_ARCH}" = "armhf" ]; then S6_ARCH="armhf"; fi \
|
||||
\
|
||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v1.21.4.0/s6-overlay-${S6_ARCH}.tar.gz" \
|
||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-${S6_ARCH}.tar.gz" \
|
||||
| tar zxvf - -C / \
|
||||
\
|
||||
&& mkdir -p /etc/fix-attrs.d \
|
||||
&& mkdir -p /etc/services.d \
|
||||
\
|
||||
&& \
|
||||
if [ "${BUILD_ARCH}" != "armhf" ]; then \
|
||||
rm -f /usr/bin/qemu-arm-static; \
|
||||
fi \
|
||||
&& curl -J -L -o /tmp/bashio.tar.gz \
|
||||
"https://github.com/hassio-addons/bashio/archive/v0.6.0.tar.gz" \
|
||||
&& mkdir /tmp/bashio \
|
||||
&& tar zxvf \
|
||||
/tmp/bashio.tar.gz \
|
||||
--strip 1 -C /tmp/bashio \
|
||||
\
|
||||
&& \
|
||||
if [ "${BUILD_ARCH}" != "aarch64" ]; then \
|
||||
rm -f /usr/bin/qemu-aarch64-static; \
|
||||
fi \
|
||||
&& mv /tmp/bashio/lib /usr/lib/bashio \
|
||||
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio \
|
||||
\
|
||||
&& rm -f -r /tmp/* \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /var/lib/{apt,dpkg,cache,log}/* \
|
||||
&& rm -rf /var/{cache,log}/*
|
||||
&& rm -fr \
|
||||
/tmp/* \
|
||||
/var/{cache,log}/* \
|
||||
/var/lib/apt/lists/*
|
||||
|
||||
# Entrypoint & CMD
|
||||
ENTRYPOINT [ "/init" ]
|
||||
|
@ -63,8 +69,11 @@ LABEL \
|
|||
io.hass.name="Addon Debian base for ${BUILD_ARCH}" \
|
||||
io.hass.description="Community Hass.io Add-ons: ${BUILD_ARCH} Debian base image" \
|
||||
io.hass.arch="${BUILD_ARCH}" \
|
||||
io.hass.type="addon" \
|
||||
io.hass.type="base" \
|
||||
io.hass.version=${BUILD_VERSION} \
|
||||
io.hass.base.version=${BUILD_VERSION} \
|
||||
io.hass.base.name="debian" \
|
||||
io.hass.base.image="hassioaddons/debian-base" \
|
||||
maintainer="Franck Nijhof <frenck@addons.community>" \
|
||||
org.label-schema.description="Community Hass.io Add-ons: ${BUILD_ARCH} Debian base image" \
|
||||
org.label-schema.build-date=${BUILD_DATE} \
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"image": "hassioaddons/debian-base-{arch}",
|
||||
"squash": true,
|
||||
"squash": false,
|
||||
"build_from": {
|
||||
"aarch64": "arm64v8/debian:stretch-slim",
|
||||
"amd64": "debian:stretch-slim",
|
||||
"armhf": "arm32v7/debian:stretch-slim",
|
||||
"i386": "i386/debian:stretch-slim"
|
||||
"aarch64": "arm64v8/debian:buster-20191118-slim",
|
||||
"amd64": "amd64/debian:buster-20191118-slim",
|
||||
"armhf": "arm32v5/debian:buster-20191118-slim",
|
||||
"armv7": "arm32v7/debian:buster-20191118-slim",
|
||||
"i386": "i386/debian:buster-20191118-slim"
|
||||
},
|
||||
"args": {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bashio
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Base Images
|
||||
# Displays an message right before terminating in case something went wrong
|
||||
# ==============================================================================
|
||||
|
||||
if [[ "${S6_STAGE2_EXITED}" -ne 0 ]]; then
|
||||
echo '-----------------------------------------------------------'
|
||||
echo ' Oops! Something went wrong.'
|
||||
echo ' '
|
||||
echo ' We are so sorry, but something went terribly wrong when'
|
||||
echo ' starting or running this add-on.'
|
||||
echo ' '
|
||||
echo ' Be sure to check the log above, line by line, for hints.'
|
||||
echo '-----------------------------------------------------------'
|
||||
bashio::log.red \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.red ' Oops! Something went wrong.'
|
||||
bashio::log.red
|
||||
bashio::log.red ' We are so sorry, but something went terribly wrong when'
|
||||
bashio::log.red ' starting or running this add-on.'
|
||||
bashio::log.red ' '
|
||||
bashio::log.red ' Be sure to check the log above, line by line, for hints.'
|
||||
bashio::log.red \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
|
|
|
@ -1,18 +1,37 @@
|
|||
#!/usr/bin/with-contenv bash
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Base Images
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/base.sh
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
if bashio::supervisor.ping; then
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue " Hass.io Add-on: $(bashio::addon.name)"
|
||||
bashio::log.blue " $(bashio::addon.description)"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
if hass.api.supervisor.ping; then
|
||||
echo '-----------------------------------------------------------'
|
||||
echo " Hass.io Add-on: $(hass.addon.name) v$(hass.addon.version)"
|
||||
echo ''
|
||||
echo " $(hass.addon.description)"
|
||||
echo ''
|
||||
echo " From: $(hass.addon.repository)"
|
||||
echo " By: $(hass.addon.maintainer)"
|
||||
echo '-----------------------------------------------------------'
|
||||
bashio::log.blue " Add-on version: $(bashio::addon.version)"
|
||||
if bashio::addon.update_available; then
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.last_version)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
else
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
fi
|
||||
|
||||
bashio::log.blue " System: $(bashio::host.operating_system)" \
|
||||
" ($(bashio::info.arch) / $(bashio::info.machine))"
|
||||
bashio::log.blue " Home Assistant version: $(bashio::info.homeassistant)"
|
||||
bashio::log.blue " Supervisor version: $(bashio::info.supervisor)"
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
' Please, share the above information when looking for help'
|
||||
bashio::log.blue \
|
||||
' or support in, e.g., GitHub, forums or the Discord chat.'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
|
|
|
@ -1,50 +1,47 @@
|
|||
#!/usr/bin/with-contenv bash
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Base Images
|
||||
# Sets the log level correctly
|
||||
# ==============================================================================
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/base.sh
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
declare log_level
|
||||
|
||||
# Check if the log level configuration option exists
|
||||
if hass.config.exists "log_level"; then
|
||||
if bashio::config.exists log_level; then
|
||||
|
||||
# Find the matching LOG_LEVEL
|
||||
case "$(hass.string.lower "$(hass.config.get 'log_level')")" in
|
||||
case "$(bashio::string.lower "$(bashio::config log_level)")" in
|
||||
all)
|
||||
log_level="${LOG_LEVEL_ALL}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_ALL}"
|
||||
;;
|
||||
trace)
|
||||
log_level="${LOG_LEVEL_TRACE}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_TRACE}"
|
||||
;;
|
||||
debug)
|
||||
log_level="${LOG_LEVEL_DEBUG}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_DEBUG}"
|
||||
;;
|
||||
info)
|
||||
log_level="${LOG_LEVEL_INFO}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_INFO}"
|
||||
;;
|
||||
notice)
|
||||
log_level="${LOG_LEVEL_NOTICE}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_NOTICE}"
|
||||
;;
|
||||
warning)
|
||||
log_level="${LOG_LEVEL_WARNING}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_WARNING}"
|
||||
;;
|
||||
error)
|
||||
log_level="${LOG_LEVEL_ERROR}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_ERROR}"
|
||||
;;
|
||||
fatal)
|
||||
log_level="${LOG_LEVEL_FATAL}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_FATAL}"
|
||||
;;
|
||||
off)
|
||||
log_level="${LOG_LEVEL_OFF}"
|
||||
log_level="${__BASHIO_LOG_LEVEL_OFF}"
|
||||
;;
|
||||
*)
|
||||
hass.die "Unknown log_level: ${log_level}"
|
||||
bashio::exit.nok "Unknown log_level: ${log_level}"
|
||||
esac
|
||||
|
||||
# Save determined log level so S6 can pick it up later
|
||||
echo "${log_level}" > /var/run/s6/container_environment/LOG_LEVEL
|
||||
echo "Log level is set to ${LOG_LEVELS[$log_level]}"
|
||||
bashio::log.blue "Log level is set to ${__BASHIO_LOG_LEVELS[$log_level]}"
|
||||
fi
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/with-contenv bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Base Images
|
||||
# Displays a notice when there is an update available for this add-on
|
||||
# ==============================================================================
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/base.sh
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
if hass.api.supervisor.ping; then
|
||||
if hass.addon.update_available; then
|
||||
hass.log.warning 'There is an update available for this add-on!'
|
||||
hass.log.notice "Current installed version: $(hass.addon.version)"
|
||||
hass.log.notice "Latest version: $(hass.addon.last_version)"
|
||||
hass.log.info 'Please consider updating this add-on.'
|
||||
else
|
||||
hass.log.info 'You are running the latest version of this add-on'
|
||||
fi
|
||||
fi
|
|
@ -1,269 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# This is an bash function library for Hass.io 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.
|
||||
# ==============================================================================
|
||||
set -o errexit # Exit script when a command exits with non-zero status
|
||||
set -o errtrace # Exit on error inside any functions or sub-shells
|
||||
set -o nounset # Exit script on use of an undefined variable
|
||||
set -o pipefail # Return exit status of the last command in the pipe that failed
|
||||
|
||||
# ==============================================================================
|
||||
# GLOBALS
|
||||
# ==============================================================================
|
||||
readonly EX_OK=0 # Successful termination
|
||||
readonly EX_NOK=1 # Termination with errors
|
||||
|
||||
# Stores the location of this library
|
||||
readonly __LIB_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
|
||||
# ==============================================================================
|
||||
# MODULES
|
||||
# ==============================================================================
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/addon.sh
|
||||
source "${__LIB_DIR}/modules/addon.sh"
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api.sh
|
||||
source "${__LIB_DIR}/modules/api.sh"
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/config.sh
|
||||
source "${__LIB_DIR}/modules/config.sh"
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/jq.sh
|
||||
source "${__LIB_DIR}/modules/jq.sh"
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/log.sh
|
||||
source "${__LIB_DIR}/modules/log.sh"
|
||||
#shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/string.sh
|
||||
source "${__LIB_DIR}/modules/string.sh"
|
||||
|
||||
# ==============================================================================
|
||||
# MISC FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Exit the script with an optional error messge
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Error message (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.die() {
|
||||
local message=${1:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if hass.has_value "${message}"; then
|
||||
hass.log.fatal "${message}"
|
||||
fi
|
||||
|
||||
exit "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Exit the script when given value is false, with an optional error messge
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Value to check if false
|
||||
# $2 Error message (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.die_if_false() {
|
||||
local value=${1:-}
|
||||
local message=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if hass.false "${value}"; then
|
||||
hass.die "${message}"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Exit the script when given value is true, with an optional error messge
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Value to check if true
|
||||
# $2 Error message (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.die_if_true() {
|
||||
local value=${1:-}
|
||||
local message=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if hass.true "${value}"; then
|
||||
hass.die "${message}"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check whether or not a directory exists
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Path to directory
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.directory_exists() {
|
||||
local directory=${1}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ -d "${directory}" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check whether or not a file exists
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Path to file
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.file_exists() {
|
||||
local file=${1}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ -f "${file}" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check whether or not a device exists
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Path to device
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.device_exists() {
|
||||
local device=${1}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ -d "${device}" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a give value is true
|
||||
#
|
||||
# Arguments:
|
||||
# $1 value
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.true() {
|
||||
local value=${1:-null}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ "${value}" = "true" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a give value is false
|
||||
#
|
||||
# Arguments:
|
||||
# $1 value
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.false() {
|
||||
local value=${1:-null}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ "${value}" = "false" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Runs a command, while supressing all output
|
||||
#
|
||||
# Arguments:
|
||||
# $1 command
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.quietly() {
|
||||
local command=$*
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
${command} > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a global variable is defined
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Name of the variable
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.defined() {
|
||||
local variable=${1}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
[[ "${!variable-X}" = "${!variable-Y}" ]]
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a value has actual value
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Value
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.has_value() {
|
||||
local value=${1}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ -n "${value}" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if we are currently running in debug mode, based on the log module
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.debug() {
|
||||
if [[ "${LOG_LEVEL_DEBUG}" -gt "${LOG_LEVEL}" ]]; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides basic functions for reading the current add-on configuration.
|
||||
# For more advances options, use the hass.addons.* functions
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Name of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.name() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.addons.info.name "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the slug of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Slug of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.slug() {
|
||||
local hostname
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hostname=$(hostname)
|
||||
echo "${hostname/-/_}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the description of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Description of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.description() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.addons.info.description "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of the repository of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Name of the repository
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.repository() {
|
||||
local slug
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
slug=$(hass.api.addons.info.repository "$(hass.addon.slug)")
|
||||
hass.api.addons.repositories.info.name "${slug}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the maintainer of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Maintainer of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.maintainer() {
|
||||
local slug
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
slug=$(hass.api.addons.info.repository "$(hass.addon.slug)")
|
||||
hass.api.addons.repositories.info.maintainer "${slug}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Version of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.version() {
|
||||
hass.api.addons.info.version "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Latest version of the current Add-on running
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.last_version() {
|
||||
hass.api.addons.info.last_version "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Restarts the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.restart() {
|
||||
hass.api.addons.restart "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Stops the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.stop() {
|
||||
hass.api.addons.stop "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.update() {
|
||||
hass.api.addons.update "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Rebuilds the current running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.rebuild() {
|
||||
hass.api.addons.rebuild "$(hass.addon.slug)"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check if there is an update available for the running add-on
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.addon.update_available() {
|
||||
hass.api.addons.update_available "$(hass.addon.slug)"
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# GLOBALS
|
||||
# ==============================================================================
|
||||
readonly HASS_API_ENDPOINT='http://hassio'
|
||||
|
||||
# ==============================================================================
|
||||
# MODULES
|
||||
# ==============================================================================
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/addons.sh
|
||||
source "${__LIB_DIR}/modules/api/addons.sh"
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/hardware.sh
|
||||
source "${__LIB_DIR}/modules/api/hardware.sh"
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/homeassistant.sh
|
||||
source "${__LIB_DIR}/modules/api/homeassistant.sh"
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/host.sh
|
||||
source "${__LIB_DIR}/modules/api/host.sh"
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/snapshots.sh
|
||||
source "${__LIB_DIR}/modules/api/snapshots.sh"
|
||||
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/supervisor.sh
|
||||
source "${__LIB_DIR}/modules/api/supervisor.sh"
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Makes a call to the Hass.io API
|
||||
#
|
||||
# Arguments:
|
||||
# $1 HTTP Method (GET/POST)
|
||||
# $2 API Resource requested
|
||||
# $3 Whether or not this resource returns raw data instead of json (optional)
|
||||
# $4 jq filter command (optional)
|
||||
# Returns:
|
||||
# Mixed content
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.call() {
|
||||
local method=${1}
|
||||
local resource=${2}
|
||||
local raw=${3:-false}
|
||||
local filter=${4:-}
|
||||
local auth_header='X-HASSIO-KEY;'
|
||||
local response
|
||||
local status
|
||||
local result
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
|
||||
if [[ ! -z "${HASSIO_TOKEN:-}" ]]; then
|
||||
auth_header="X-HASSIO-KEY: ${HASSIO_TOKEN}"
|
||||
fi
|
||||
|
||||
if ! response=$(curl --silent --show-error \
|
||||
--write-out '\n%{http_code}' --request "${method}" \
|
||||
-H "${auth_header}" \
|
||||
"${HASS_API_ENDPOINT}${resource}"
|
||||
); then
|
||||
hass.log.debug "${response}"
|
||||
hass.log.error "Something went wrong contacting the API"
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
status=${response##*$'\n'}
|
||||
response=${response%$status}
|
||||
|
||||
hass.log.debug "Requested API resource: ${HASS_API_ENDPOINT}${resource}"
|
||||
hass.log.debug "API HTTP Response code: ${status}"
|
||||
hass.log.debug "API Response: ${response}"
|
||||
|
||||
if [[ "${status}" -eq 401 ]]; then
|
||||
hass.log.error "Unable to authenticate with the API, permission denied"
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ "${status}" -eq 404 ]]; then
|
||||
hass.log.error "Requested resource ${resource} was not found"
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ "${status}" -eq 405 ]]; then
|
||||
hass.log.error "Requested resource ${resource} was called using an" \
|
||||
"unallowed method."
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ $(hass.jq "${response}" ".result") = "error" ]]; then
|
||||
hass.log.error "Got unexpected response from the API:" \
|
||||
"$(hass.jq "${response}" '.message // empty')"
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ "${status}" -ne 200 ]]; then
|
||||
hass.log.error "Unknown HTTP error occured"
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ "${raw}" = "true" ]]; then
|
||||
echo "${response}"
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
result=$(hass.jq "${response}" 'if .data == {} then empty else .data end')
|
||||
|
||||
if hass.has_value "${filter}"; then
|
||||
hass.log.debug "Filtering response using: ${filter}"
|
||||
result=$(hass.jq "${result}" "${filter}")
|
||||
fi
|
||||
|
||||
echo "${result}"
|
||||
return "${EX_OK}"
|
||||
}
|
|
@ -1,889 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Addons
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available Hass.io addons
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON addon objects
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.list() {
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /addons false ".addons"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all installed Hass.io add-on repositories
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON repository objects
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /addons false ".repositories"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Gives all available information for a repository
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Repository slug
|
||||
# $2 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON repository object or the filtered result
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories.info() {
|
||||
local repository=${1}
|
||||
local filter=${2:-}
|
||||
local repositories
|
||||
local result
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
repositories=$(hass.api.addons.repositories)
|
||||
result=$(hass.jq "${repositories}" \
|
||||
".[] | select(.slug==\"${repository}\")")
|
||||
|
||||
if hass.has_value "${filter}"; then
|
||||
hass.log.debug "Filtering response using: ${filter}"
|
||||
result=$(hass.jq "${result}" "${filter}")
|
||||
fi
|
||||
|
||||
echo "${result}"
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of a repository
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Repository slug
|
||||
# Returns:
|
||||
# Name of the repository
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories.info.name() {
|
||||
local repository=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.repositories.info "${repository}" ".name"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of a repository
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Repository slug
|
||||
# Returns:
|
||||
# Name of the repository
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories.info.source() {
|
||||
local repository=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.repositories.info "${repository}" ".source"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the URL of a repository
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Repository slug
|
||||
# Returns:
|
||||
# URL to the source of the repository
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories.info.url() {
|
||||
local repository=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.repositories.info "${repository}" ".url"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the maintainer of a repository
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Repository slug
|
||||
# Returns:
|
||||
# Maintainer of the repository
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.repositories.info.maintainer() {
|
||||
local repository=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.repositories.info "${repository}" ".maintainer"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Reload the list of addons and version from remote repositories
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.reload() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /addons/reload
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Gives all available information for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# $2 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON repository object or the filtered result
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info() {
|
||||
local addon=${1}
|
||||
local filter=${2:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET "/addons/${addon}/info" false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Name of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.name() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".name"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the description of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Description of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.description() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".description"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the long description of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Description of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.long_description() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".long_description"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not auto update is enabled for this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not auto update is enabled for this add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.auto_update() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".auto_update // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the URL of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# URL of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.url() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".url"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not the add-on is running deattached
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not the add-on is running deattached
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.detached() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".detached // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the repository slug of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Respository slug of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.repository() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".repository"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Version of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.version() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Latest version of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.last_version() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".last_version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the current state of an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# The current state of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.state() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".state"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the current boot setting of this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Boot setting of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.boot() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".boot"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on is being build locally
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on is being build locally
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.build() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".build // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns options for this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# JSON ojbect
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.boot() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".options[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of ports which are exposed on the host network for this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# List of network ports
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.network() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".network"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on runs on the host network
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on is running on the host network
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.host_network() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".host_network // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on has IPC access
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on has IPC access
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.host_ipc() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".host_ipc // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on has DBus access to the host
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on has DBus access
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.host_dbus() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".host_dbus // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the privileges the add-on has on to the hardware / system.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# List of privileges
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.privileged() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".privileged // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the current seccomp state of this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Seccomp state: disable, default or profile
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.seccomp() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".seccomp"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the current apparmor state of this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Seccomp state: disable, default or profile
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.apparmor() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".apparmor"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list devices made available to the add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# List of devices
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.devices() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".devices"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns if UART was made available to the add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on as automatic UART enabled
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.auto_uart() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".auto_uart // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on has a icon available
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on has a icon available
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.icon() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".icon // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on has a logo available
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on has a logo available
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.logo() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".logo // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on has a changelog available
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on has a changelog available
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.changelog() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".changelog // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on can access the Hass.io API
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on can access the Hass.io API
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.hassio_api() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".hassio_api // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on can access the Home Assistant API
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on can access the Home Assistant API
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.homeassistant_api() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".homeassistant_api // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on can use the STDIN on the Hass.io API
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on can use the STDIN
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.stdin() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".stdin // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# A URL for web interface of this add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# The webui URL of the add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.webui() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".webui // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on can access GPIO
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on can access GPIO
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.gpio() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".gpio // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not this add-on can access an audio device
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Whether or not this add-on can access an audio device
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.audio() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".audio // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the available audio input device for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# the available audio input device for an add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.audio_input() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".audio_input // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the available audio output device for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# the available audio output device for an add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.audio_output() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".audio_output // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the available services for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# The available services for this add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.services() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".services // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the available discovery items for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# The available discovery items for this add-on
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.info.discovery() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.info "${addon}" ".discovery // empty"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install an add-on onto your Hass.io instance
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.install() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/install"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uninstall an add-on from your Hass.io instance
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.uninstall() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/uninstall"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Starts an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.start() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/start"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Stops an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stop() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/stop"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Restarts an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.restart() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/restart"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.update() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/update"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Rebuilds an add-on locally
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.rebuild() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/addons/${addon}/rebuild"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the logs created by an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# The logs in text format
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.logs() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET "/addons/${addon}/logs" true
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if there is an update available for an add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.update_available() {
|
||||
local addon=${1}
|
||||
local version
|
||||
local last_version
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
|
||||
version=$(hass.api.addons.info.version "${addon}")
|
||||
last_version=$(hass.api.addons.info.last_version "${addon}")
|
||||
|
||||
if [[ "${version}" = "${last_version}" ]]; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available stats about add-ons
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# $2 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats() {
|
||||
local addon=${1}
|
||||
local filter=${2:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET GET "/addons/${addon}/logs" false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns CPU usage from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in percent
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.cpu_percent() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".cpu_percent"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory usage from add-on
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.memory_usage() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".memory_usage"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory limit from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.memory_limit() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".memory_limit"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns outgoing network usage from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.network_tx() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".network_tx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns incoming network usage from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Bytes
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.network_rx() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".network_rx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk read usage from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.blk_read() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".blk_read"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk write usage from add-on
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Add-on slug
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.addons.stats.blk_write() {
|
||||
local addon=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.addons.stats "${addon}" ".blk_write"
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Hardware
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available hardware on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object with hardware
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /hardware/info false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available serial devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info.serial() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.hardware.info ".serial[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available input devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info.input() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.hardware.info ".input[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available disk devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info.disk() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.hardware.info ".disk[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available disk devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info.gpio() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.hardware.info ".gpio[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available audio hardware devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.info.audio() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.hardware.info ".audio[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of available audio devices on the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.hardware.audio() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /hardware/audio false ".audio[]"
|
||||
}
|
|
@ -1,323 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Home Assistant
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available information about the Home Assistant instance
|
||||
#
|
||||
# Arguments:
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /homeassistant/info false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Latest version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.last_version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".last_version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the Docker image of Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Docker image
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.image() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".image"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not a custom version of Home Assistant is installed
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Whether or not a custom Home Assistant is installed
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.custom() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".custom // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not Home Assistant starts at device boot
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Whether or not Home Assistant starts at boot
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.boot() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".boot // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the port number on which Home Assistant is running
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Port number
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.port() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".port"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not Home Assistant is running on SSL
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Whether or not Home Assistant runs on SSL
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.ssl() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".ssl // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not Home Assistant is monitored by Watchdog
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Whether or not Home Assistant is monitored by Watchdog
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.watchdog() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".watchdog // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the Home Assistant start up time
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Time in seconds
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.info.startup_time() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.info ".startup_time"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates Home Assistant to the latest version
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.update() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /homeassistant/update
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Restarts Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.restart() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /homeassistant/restart
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Stops Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stop() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /homeassistant/stop
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Starts Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.start() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /homeassistant/start
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks/validates your Home Assistant configuration
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.check() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /homeassistant/check
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the logs created by Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# The logs in text format
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.logs() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /homeassistant/logs true
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available stats about Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /homeassistant/stats false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns CPU usage from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in percent
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.cpu_percent() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".cpu_percent"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory usage from Home Assistant
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.memory_usage() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".memory_usage"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory limit from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.memory_limit() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".memory_limit"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns outgoing network usage from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.network_tx() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".network_tx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns incoming network usage from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Bytes
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.network_rx() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".network_rx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk read usage from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.blk_read() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".blk_read"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk write usage from Home Assistant
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.homeassistant.stats.blk_write() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.homeassistant.stats ".blk_write"
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Host
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available information about the host system
|
||||
#
|
||||
# Arguments:
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /host/info false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the hostname of the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Hostname
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.hostname() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".hostname"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of exposed features by the host
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# List of features
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.features() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".features[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the OS of the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# OS
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.operating_system() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".operating_system"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the kernel of the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# OS
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.kernel() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".kernel"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the chassis of the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# OS
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.chassis() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".chassis"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the type of the host
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Type of host
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.type() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".type"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the stability channel / deployment of the system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.deployment() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".deployment"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of the software running on the host
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of the software for the host
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Latest version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.info.last_version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.host.info ".last_version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Reboots the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.reboot() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /host/reboot
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Shuts down the host system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.shutdown() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /host/shutdown
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates the host system to the latest version
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.update() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /host/update
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Reload the host controller
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.host.reload() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /host/reload
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Snapshots
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available snapshots
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.list() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /snapshots false ".snapshots[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Reload the lists of available snapshots
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.reload() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /snapshots/reload
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Create a new full snapshot
|
||||
#
|
||||
# Currently only support full, passwordless snapshotting.
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.new.full() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /snapshots/new/full
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available information about a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Slug of the snapshot to get detailed information for
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info() {
|
||||
local snapshot=${1}
|
||||
local filter=${2:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET "/snapshots/${snapshot}/info" false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the slug of a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# Name
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.slug() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".slug"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the name of a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# Name
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.name() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".name"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the date of a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# Date
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.date() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".date"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the size of a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# Size in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.size() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".size"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns if the snapshot is protected
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# True if it is protected, false otherwise.
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.size() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".protected // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the Home Assistant version installed when this snapshot was created.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# Version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.homeassistant() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.snapshots.info "${snapshot}" ".homeassistant"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of installed addons when this snapshot was created
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# JSON Object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.addons() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.supervisor.info ".addons[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of installed add-on repositories when this snapshot was created
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# List of URL's
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.info.repositories() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.supervisor.info ".repositories[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Removes a snapshot
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.remove() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/snapshots/${snapshot}/remove"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Restores a full snapshot.
|
||||
#
|
||||
# Currently only support full, passwordless restore.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Snapshot slug
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.snapshots.restore.full() {
|
||||
local snapshot=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call POST "/snapshots/${snapshot}/restore/full"
|
||||
}
|
|
@ -1,281 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides access to the API functions of Hass.io: Supervisor
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check to see if the Supervisor is still alive
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.ping() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /supervisor/ping
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available information about the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /supervisor/info false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the version of the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the latest version of the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Latest version
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.last_version() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".last_version"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns whether or not the Supervisor is on the beta channel
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Whether or not the Supervisor is on the beta channel
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.beta_channel() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".beta_channel // false"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the architecture of the system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Architecture
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.arch() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".arch"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the current timezone of the system
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Architecture
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.timezone() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".timezone"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the time to wait after boot in seconds
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Second to wait for boot
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.wait_boot() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".wait_boot"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of all current installed add-ons
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.addons() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".addons[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a list of all activated repositories
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# List of URL's
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.info.addons_repositories() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.info ".addons_repositories[]"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Updates the Supervisor to the latest version
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.update() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /supervisor/update
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Reloads the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.reload() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call POST /supervisor/reload
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the logs created by the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# The logs in text format
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.logs() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.call GET /supervisor/logs true
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# List all available stats about the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# $1 jq Filter to apply on the result (optional)
|
||||
# Returns:
|
||||
# JSON object
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats() {
|
||||
local filter=${1:-}
|
||||
hass.log.trace "${FUNCNAME[0]}" "$@"
|
||||
hass.api.call GET /supervisor/stats false "${filter}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns CPU usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in percent
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.cpu_percent() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".cpu_percent"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.memory_usage() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".memory_usage"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns memory limit from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.memory_limit() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".memory_limit"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns outgoing network usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Mb
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.network_tx() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".network_tx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns incoming network usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Bytes
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.network_rx() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".network_rx"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk read usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.blk_read() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".blk_read"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns disk write usage from the Supervisor
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Usage in Blocks
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.api.supervisor.stats.blk_write() {
|
||||
hass.log.trace "${FUNCNAME[0]}"
|
||||
hass.api.supervisor.stats ".blk_write"
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides functions for reading the add-on configuration
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# GLOBALS
|
||||
# ==============================================================================
|
||||
readonly ADDON_CONFIG_PATH=/data/options.json
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Fetches a configuration value from the add-on config file
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Key of the config option
|
||||
# Returns:
|
||||
# Value of the key in the configuration file
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.config.get() {
|
||||
local key=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! hass.config.exists "${key}"; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
if hass.jq.is_string "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
hass.jq "${ADDON_CONFIG_PATH}" ".${key} // empty"
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
if hass.jq.is_boolean "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
hass.jq "${ADDON_CONFIG_PATH}" ".${key} // false"
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
if hass.jq.is_array "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
if hass.jq.has_value "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
hass.jq "${ADDON_CONFIG_PATH}" ".${key}[]"
|
||||
fi
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
if hass.jq.is_object "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
if hass.jq.has_value "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
hass.jq "${ADDON_CONFIG_PATH}" ".${key}{}"
|
||||
fi
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
if hass.jq.is_number "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
hass.jq "${ADDON_CONFIG_PATH}" ".${key}"
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a configuration option exists in the config file
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Key of the config option
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.config.exists() {
|
||||
local key=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! hass.jq.exists "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a configuration option has an actual value
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Key of the config option
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.config.has_value() {
|
||||
local key=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! hass.jq.has_value "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a configuration option is true
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Key of the config option
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.config.true() {
|
||||
local key=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! hass.jq.is_boolean "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ $(hass.config.get "${key}") = "true" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if a configuration option is false
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Key of the config option
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.config.false() {
|
||||
local key=${1}
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! hass.jq.is_boolean "${ADDON_CONFIG_PATH}" ".${key}"; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
if [[ $(hass.config.get "${key}") = "false" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
return "${EX_NOK}"
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides helper function to the jq json query tool
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute a json query
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# jq result
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ -f "${data}" ]]; then
|
||||
jq --raw-output "$filter" "${data}"
|
||||
else
|
||||
jq --raw-output "$filter" <<< "${data}"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if variable exists (optionally after filtering)
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.exists() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if [[ $(hass.jq "${data}" "${filter}") = "null" ]]; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if data exists (optionally after filtering)
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.has_value() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
local value
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
value=$(hass.jq "${data}" \
|
||||
"${filter} | if (. == {} or . == []) then empty else . end // empty")
|
||||
|
||||
if ! hass.has_value "${value}"; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is of a specific type
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter
|
||||
# $3 type (boolean, string, number, array, object, null)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is() {
|
||||
local data=${1}
|
||||
local filter=${2}
|
||||
local type=${3}
|
||||
local value
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
value=$(hass.jq "${data}" \
|
||||
"${filter} | if type==\"${type}\" then true else false end")
|
||||
|
||||
if [[ "${value}" = "false" ]]; then
|
||||
return "${EX_NOK}"
|
||||
fi
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is a boolean
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is_boolean() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
hass.jq.is "${data}" "${filter}" "boolean"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is a string
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is_string() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
hass.jq.is "${data}" "${filter}" "string"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is an object
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is_object() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
hass.jq.is "${data}" "${filter}" "object"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is a number
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is_number() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
hass.jq.is "${data}" "${filter}" "number"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if resulting data is an array
|
||||
#
|
||||
# Arguments:
|
||||
# $1 JSON string or path to a JSON file
|
||||
# $2 jq filter (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.jq.is_array() {
|
||||
local data=${1}
|
||||
local filter=${2:-}
|
||||
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
hass.jq.is "${data}" "${filter}" "array"
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides functions for simple logging
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# GLOBALS
|
||||
# ==============================================================================
|
||||
readonly LOG_LEVEL_ALL=8
|
||||
readonly LOG_LEVEL_DEBUG=6
|
||||
readonly LOG_LEVEL_ERROR=2
|
||||
readonly LOG_LEVEL_FATAL=1
|
||||
readonly LOG_LEVEL_INFO=5
|
||||
readonly LOG_LEVEL_NOTICE=4
|
||||
readonly LOG_LEVEL_OFF=0
|
||||
readonly LOG_LEVEL_TRACE=7
|
||||
readonly LOG_LEVEL_WARNING=3
|
||||
readonly -A LOG_LEVELS=(
|
||||
[${LOG_LEVEL_OFF}]="OFF"
|
||||
[${LOG_LEVEL_FATAL}]="FATAL"
|
||||
[${LOG_LEVEL_ERROR}]="ERROR"
|
||||
[${LOG_LEVEL_WARNING}]="WARNING"
|
||||
[${LOG_LEVEL_NOTICE}]="NOTICE"
|
||||
[${LOG_LEVEL_INFO}]="INFO"
|
||||
[${LOG_LEVEL_DEBUG}]="DEBUG"
|
||||
[${LOG_LEVEL_TRACE}]="TRACE"
|
||||
[${LOG_LEVEL_ALL}]="ALL"
|
||||
)
|
||||
readonly LOG_FORMAT_DEFAULT="[{TIMESTAMP}] {LEVEL} ----> {MESSAGE}"
|
||||
readonly LOG_TIMESTAMP_DEFAULT="%T%z"
|
||||
|
||||
declare LOG_FORMAT=${LOG_FORMAT:-${LOG_FORMAT_DEFAULT}}
|
||||
declare LOG_LEVEL=${LOG_LEVEL:-${LOG_LEVEL_INFO}}
|
||||
declare LOG_TIMESTAMP_FORMAT=${LOG_TIMESTAMP_FORMAT:-${LOG_TIMESTAMP_DEFAULT}}
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Log level
|
||||
# $2 Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.log() {
|
||||
local level=${1}
|
||||
local message=${2}
|
||||
local timestamp
|
||||
local output
|
||||
|
||||
if [[ "${level}" -gt "${LOG_LEVEL}" ]]; then
|
||||
return "${EX_OK}"
|
||||
fi
|
||||
|
||||
timestamp=$(date +"${LOG_TIMESTAMP_FORMAT}")
|
||||
|
||||
output="${LOG_FORMAT}"
|
||||
output="${output//\{TIMESTAMP\}/${timestamp}}"
|
||||
output="${output//\{MESSAGE\}/${message}}"
|
||||
output="${output//\{LEVEL\}/${LOG_LEVELS[$level]}}"
|
||||
|
||||
echo "${output}" >&2
|
||||
|
||||
return "${EX_OK}"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ trace level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.trace() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_TRACE}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ debug level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.debug() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_DEBUG}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ info level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.info() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_INFO}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ notice level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.notice() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_NOTICE}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ warning level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.warning() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_WARNING}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ error level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.error() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_ERROR}" "${message}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log a message @ fatal level
|
||||
#
|
||||
# Arguments:
|
||||
# $* Message to display
|
||||
# Returns:
|
||||
# None
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.log.fatal() {
|
||||
local message=$*
|
||||
hass.log.log "${LOG_LEVEL_FATAL}" "${message}"
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bash functions library
|
||||
#
|
||||
# Provides string manupulation functions
|
||||
# ==============================================================================
|
||||
|
||||
# ==============================================================================
|
||||
# FUNCTIONS
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Converts a string to upper case
|
||||
#
|
||||
# Arguments:
|
||||
# $1 String to convert
|
||||
# Returns:
|
||||
# Uppercase string
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.string.upper() {
|
||||
local string="${1}"
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
echo "${string^^}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Converts a string to lower case
|
||||
#
|
||||
# Arguments:
|
||||
# $1 String to convert
|
||||
# Returns:
|
||||
# Lowercase string
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.string.lower() {
|
||||
local string="${1}"
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
echo "${string,,}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns the length of a string
|
||||
#
|
||||
# Arguments:
|
||||
# $1 String to determine the length of
|
||||
# Returns:
|
||||
# Length of the string
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.string.length() {
|
||||
local string="${1}"
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
echo "${#string}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Replaces parts of the string with an other string
|
||||
#
|
||||
# Arguments:
|
||||
# $1 String to make replacements in
|
||||
# $2 String part to replace
|
||||
# $3 String replacement
|
||||
# Returns:
|
||||
# The resulting string
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.string.replace() {
|
||||
local string="${1}"
|
||||
local needle="${2}"
|
||||
local replacement="${3}"
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
echo "${string//${needle}/${replacement}}"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Returns a substring of a string
|
||||
#
|
||||
# stringZ=abcABC123ABCabc
|
||||
# hass.string.substring "${stringZ}" 0 # abcABC123ABCabc
|
||||
# hass.string.substring "${stringZ}" 1 # bcABC123ABCabc
|
||||
# hass.string.substring "${stringZ}" 7 # 23ABCabc
|
||||
# hass.string.substring "${stringZ}" 7 3 # 23AB
|
||||
#
|
||||
# Arguments:
|
||||
# $1 String to return a substring off
|
||||
# $2 Position to start
|
||||
# $3 Length of the substring (optional)
|
||||
# Returns:
|
||||
# The resulting string
|
||||
# ------------------------------------------------------------------------------
|
||||
hass.string.substring() {
|
||||
local string="${1}"
|
||||
local position="${2}"
|
||||
local length="${3:-}"
|
||||
hass.log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if hass.has_value "${length}"; then
|
||||
echo "${string:${position}:${length}}"
|
||||
else
|
||||
echo "${string:${position}}"
|
||||
fi
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue