From a19da9d87a0a73a68937c59e4753f177476639a3 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Tue, 16 Nov 2021 15:58:12 +0100 Subject: [PATCH] initial build --- gazpar2mqtt/CHANGELOG.md | 1 + gazpar2mqtt/Dockerfile | 68 ++++++++++++++++++++ gazpar2mqtt/README.md | 42 ++++++++++++ gazpar2mqtt/apparmor.txt | 38 +++++++++++ gazpar2mqtt/config.json | 16 +++++ gazpar2mqtt/icon.png | Bin 0 -> 2289 bytes gazpar2mqtt/logo.png | Bin 0 -> 2289 bytes gazpar2mqtt/rootfs/entrypoint.sh | 13 ++++ gazpar2mqtt/rootfs/scripts/00-aaa.sh | 27 ++++++++ gazpar2mqtt/rootfs/scripts/00-banner.sh | 39 ++++++++++++ gazpar2mqtt/rootfs/scripts/99-run.sh | 78 +++++++++++++++++++++++ gazpar2mqtt/rootfs/templates/config.yaml | 4 ++ 12 files changed, 326 insertions(+) create mode 100644 gazpar2mqtt/CHANGELOG.md create mode 100644 gazpar2mqtt/Dockerfile create mode 100644 gazpar2mqtt/README.md create mode 100644 gazpar2mqtt/apparmor.txt create mode 100644 gazpar2mqtt/config.json create mode 100644 gazpar2mqtt/icon.png create mode 100644 gazpar2mqtt/logo.png create mode 100644 gazpar2mqtt/rootfs/entrypoint.sh create mode 100644 gazpar2mqtt/rootfs/scripts/00-aaa.sh create mode 100644 gazpar2mqtt/rootfs/scripts/00-banner.sh create mode 100644 gazpar2mqtt/rootfs/scripts/99-run.sh create mode 100644 gazpar2mqtt/rootfs/templates/config.yaml diff --git a/gazpar2mqtt/CHANGELOG.md b/gazpar2mqtt/CHANGELOG.md new file mode 100644 index 000000000..68dde260e --- /dev/null +++ b/gazpar2mqtt/CHANGELOG.md @@ -0,0 +1 @@ +- Initial build diff --git a/gazpar2mqtt/Dockerfile b/gazpar2mqtt/Dockerfile new file mode 100644 index 000000000..f504ff101 --- /dev/null +++ b/gazpar2mqtt/Dockerfile @@ -0,0 +1,68 @@ +FROM yukulehe/gazpar2mqtt:latest + +# Base system +ARG BASHIO_VERSION=0.13.1 + +# Copy root filesystem +COPY rootfs / + +RUN \ + ################ + # Install apps # + ################ + apt-get clean \ + && apt-get update \ + && apt-get install -y \ + jq \ + curl \ + yamllint \ + && apt-get clean \ + \ + ################## + # Install bashio # + ################## + && mkdir -p /tmp/bashio \ + && curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" \ + | tar -xzf - --strip 1 -C /tmp/bashio \ + && mv /tmp/bashio/lib /usr/lib/bashio \ + && ln -s /usr/lib/bashio/bashio /usr/bin/bashio \ + && rm -rf /tmp/bashio \ + \ + ################# + # Copy template # + ################# + && mkdir -p /share/gazpar2mqtt \ + && cp -n /templates/config.yaml /share/gazpar2mqtt/ || true + +RUN chmod 777 /entrypoint.sh +ENTRYPOINT [ "/usr/bin/env" ] +CMD ["/entrypoint.sh"] +VOLUME [ "/data" ] +VOLUME [ "/share" ] + +### LABELS +ARG BUILD_ARCH +ARG BUILD_DATE +ARG BUILD_DESCRIPTION +ARG BUILD_NAME +ARG BUILD_REF +ARG BUILD_REPOSITORY +ARG BUILD_VERSION +LABEL \ + io.hass.name="${BUILD_NAME}" \ + io.hass.description="${BUILD_DESCRIPTION}" \ + io.hass.arch="${BUILD_ARCH}" \ + io.hass.type="addon" \ + io.hass.version=${BUILD_VERSION} \ + maintainer="alexbelgium (https://github.com/alexbelgium)" \ + org.opencontainers.image.title="${BUILD_NAME}" \ + org.opencontainers.image.description="${BUILD_DESCRIPTION}" \ + org.opencontainers.image.vendor="Home Assistant Add-ons" \ + org.opencontainers.image.authors="alexbelgium (https://github.com/alexbelgium)" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.url="https://github.com/alexbelgium" \ + org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \ + org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \ + org.opencontainers.image.created=${BUILD_DATE} \ + org.opencontainers.image.revision=${BUILD_REF} \ + org.opencontainers.image.version=${BUILD_VERSION} diff --git a/gazpar2mqtt/README.md b/gazpar2mqtt/README.md new file mode 100644 index 000000000..d81f0c964 --- /dev/null +++ b/gazpar2mqtt/README.md @@ -0,0 +1,42 @@ +# Home assistant add-on: gazpar2mqtt + +[![Donate][donation-badge]](https://www.buymeacoffee.com/alexbelgium) + +[donation-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-%23d32f2f?logo=buy-me-a-coffee&style=flat&logoColor=white + +![Supports + Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] + +_Thanks to everyone having starred my repo! To star it click on the image below, then it will be on top right. Thanks!_ + +[![Stargazers repo roster for @alexbelgium/hassio-addons](https://reporoster.com/stars/alexbelgium/hassio-addons)](https://github.com/alexbelgium/hassio-addons/stargazers) + +## About + +Python script to fetch GRDF data and publish data to a mqtt broker. +See its github for all informations : https://github.com/yukulehe/gazpar2mqtt + +## Configuration + +Configuration is done by customizing the config.yaml that can be found in /config/gazpar2mqtt/config.yaml + +The complete list of options can be seen here : https://github.com/yukulehe/gazpar2mqtt + +## Installation + +The installation of this add-on is pretty straightforward and not different in +comparison to installing any other Hass.io add-on. + +1. [Add my Hass.io add-ons repository][repository] to your Hass.io instance. +1. Install this add-on. +1. Click the `Save` button to store your configuration. +1. Start the add-on. +1. Check the logs of the add-on to see if everything went well. +1. Carefully configure the add-on to your preferences, see the official documentation for for that. + +[smb-shield]: https://img.shields.io/badge/SMB--green?style=plastic.svg +[repository]: https://github.com/alexbelgium/hassio-addons +[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 diff --git a/gazpar2mqtt/apparmor.txt b/gazpar2mqtt/apparmor.txt new file mode 100644 index 000000000..4b9ced9e4 --- /dev/null +++ b/gazpar2mqtt/apparmor.txt @@ -0,0 +1,38 @@ +#include + +profile inadyn_addon flags=(attach_disconnected,mediate_deleted) { + #include + + capability, + file, + mount, + umount, + remount, + capability setgid, + capability setuid, + + +# S6-Overlay + /bin/** ix, + /usr/bin/** ix, + /usr/lib/bashio/** ix, + /etc/s6/** rix, + /run/s6/** rix, + /etc/services.d/** rwix, + /etc/cont-init.d/** rwix, + /etc/cont-finish.d/** rwix, + /init rix, + /var/run/** mrwkl, + /var/run/ mrwkl, + /dev/i2c-1 mrwkl, + + # Data access + /data/** rw, + + # suppress ptrace denials when using 'docker ps' or using 'ps' inside a container + ptrace (trace,read) peer=docker-default, + + # docker daemon confinement requires explict allow rule for signal + signal (receive) set=(kill,term) peer=/usr/bin/docker, + +} diff --git a/gazpar2mqtt/config.json b/gazpar2mqtt/config.json new file mode 100644 index 000000000..11105a45c --- /dev/null +++ b/gazpar2mqtt/config.json @@ -0,0 +1,16 @@ +{ + "arch": ["aarch64", "amd64"], + "description": "fetch GRDF data and publish data to a mqtt broker", + "map": ["config:rw", "share:rw"], + "name": "gazpar2mqtt", + "options": { + "CONFIG_LOCATION": "/share/gazpar2mqtt/config.yaml" + }, + "schema": { + "CONFIG_LOCATION": "str" + }, + "slug": "gazpar2mqtt", + "upstream": "0.3", + "url": "https://github.com/alexbelgium/hassio-addons", + "version": "0.3" +} diff --git a/gazpar2mqtt/icon.png b/gazpar2mqtt/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9e69861380db7da1e55d532314ffae53684c395b GIT binary patch literal 2289 zcmb7_SvV958^@=U$TF0aLFp)KS%*Pd&>+GXL$dGd%veH(6yGO?u|^0plzj;$*(c)| z%ZRcsGqR0w7>vn~B@U-^ac;i5@BcjS|9A0wp7-Ltd2w*qJs_Vr9{>OVniv}(esSTS zIeqe1^ZH*g{)HX5nYH2Z@v%ljogyOFo#-i+Pv$hslb0A5-&gM)?sYS|t($D%jR-(i zyF5JS=wJ&!K6=;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1<*wVkPCUk4I-X2?R{R_;nMlQ0tP;}|2(Wof=msld#DrJ$ZU ze7Egzpz@CkkKCawqt;sgTR=lTq>}ds-YeW*paNgzBH1fCZ&fU-CGR$BrdN^}oA*`x zFOsxIuxPoNgo~w_ZU$mOT){s|{ZP_JuC9WYz%dE>;$WGMMPmyl+h8I>)S7Dv8T&;R zW72z9$na=i>MsLbLt4mheR-=BF?5;QuhT3eA^q1U#x0lotvcc5VKy~#pV_fnMkDZ= zmoQxQxP=36s=ssJhtY_QX{|9UPq}IWJc^K}1cExRKFp)7sP9H5eRP7H^3y)?13i?Q zit!6Dh9FXXb)BMV^X}S33OL@sJA(j6<3a3gn_n)j%J9A zU_@j@uietXCNL#gyH3{J z--u>~Mq$R&3W`6m3;14NAtjg?v{~Y#+H6o=aU@&&tk2V9@4Iao!7Wk8SLl(D46=e+ zCG_8yIPb6(sW^8as@%hl4(#C^MIKY)_FDHH6!E%`ueZlb2}FlSogib5G302?x$Z41 p38c$$^3ojpFNqWXuJ~Uv_JxKWw=EbCKIHzROblTLwRc@({stB?Wkmo0 literal 0 HcmV?d00001 diff --git a/gazpar2mqtt/logo.png b/gazpar2mqtt/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..9e69861380db7da1e55d532314ffae53684c395b GIT binary patch literal 2289 zcmb7_SvV958^@=U$TF0aLFp)KS%*Pd&>+GXL$dGd%veH(6yGO?u|^0plzj;$*(c)| z%ZRcsGqR0w7>vn~B@U-^ac;i5@BcjS|9A0wp7-Ltd2w*qJs_Vr9{>OVniv}(esSTS zIeqe1^ZH*g{)HX5nYH2Z@v%ljogyOFo#-i+Pv$hslb0A5-&gM)?sYS|t($D%jR-(i zyF5JS=wJ&!K6=;nHK$R0XDFs+VScmzw1`1Q{nVee%_AuTsgn1z0686ibRvCo2cVN; z(9)2YM-tFaN0HDa?*}M@3;jzQl_QH&vugnDl#$gD)-J1TqI`4zAhNG#Z@O@8W1CP( zX_;+tXm5Sq8#}eZqHoe~7IoLoOcT4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uC9WYz%dE>;$WGMMPmyl+h8I>)S7Dv8T&;R zW72z9$na=i>MsLbLt4mheR-=BF?5;QuhT3eA^q1U#x0lotvcc5VKy~#pV_fnMkDZ= zmoQxQxP=36s=ssJhtY_QX{|9UPq}IWJc^K}1cExRKFp)7sP9H5eRP7H^3y)?13i?Q zit!6Dh9FXXb)BMV^X}S33OL@sJA(j6<3a3gn_n)j%J9A zU_@j@uietXCNL#gyH3{J z--u>~Mq$R&3W`6m3;14NAtjg?v{~Y#+H6o=aU@&&tk2V9@4Iao!7Wk8SLl(D46=e+ zCG_8yIPb6(sW^8as@%hl4(#C^MIKY)_FDHH6!E%`ueZlb2}FlSogib5G302?x$Z41 p38c$$^3ojpFNqWXuJ~Uv_JxKWw=EbCKIHzROblTLwRc@({stB?Wkmo0 literal 0 HcmV?d00001 diff --git a/gazpar2mqtt/rootfs/entrypoint.sh b/gazpar2mqtt/rootfs/entrypoint.sh new file mode 100644 index 000000000..015dd84c9 --- /dev/null +++ b/gazpar2mqtt/rootfs/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +#!/bin/bash + +echo "Starting scripts :" +for SCRIPTS in scripts/*; do + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" + chown $(id -u):$(id -g) $SCRIPTS + chmod a+x $SCRIPTS + sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS || true + ./$SCRIPTS || echo "$SCRIPTS: exiting $?" +done diff --git a/gazpar2mqtt/rootfs/scripts/00-aaa.sh b/gazpar2mqtt/rootfs/scripts/00-aaa.sh new file mode 100644 index 000000000..c1df9fd74 --- /dev/null +++ b/gazpar2mqtt/rootfs/scripts/00-aaa.sh @@ -0,0 +1,27 @@ +#!/bin/bash +if [ ! -f "/usr/bin/bashio" ]; then + echo "Bashio does not exist, executing script" + + ################ + # Install apps # + ################ + apt-get clean && + apt-get update && + apt-get install -y --no-install-recommends \ + jq \ + curl \ + yamllint + + ################### + # Install bashio # + ################## + BASHIO_VERSION=0.13.1 + mkdir -p /tmp/bashio + curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | + tar -xzf - --strip 1 -C /tmp/bashio + mv /tmp/bashio/lib /usr/lib/bashio + ln -s /usr/lib/bashio/bashio /usr/bin/bashio + rm -rf /tmp/bashio + + echo "Bashio installed" +fi diff --git a/gazpar2mqtt/rootfs/scripts/00-banner.sh b/gazpar2mqtt/rootfs/scripts/00-banner.sh new file mode 100644 index 000000000..52d8a7e60 --- /dev/null +++ b/gazpar2mqtt/rootfs/scripts/00-banner.sh @@ -0,0 +1,39 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: Base Images +# Displays a simple add-on banner on startup +# ============================================================================== +if bashio::supervisor.ping; then + bashio::log.blue \ + '-----------------------------------------------------------' + bashio::log.blue " Add-on: $(bashio::addon.name)" + bashio::log.blue " $(bashio::addon.description)" + bashio::log.blue \ + '-----------------------------------------------------------' + + bashio::log.blue " Add-on version: $(bashio::addon.version)" + if bashio::var.true "$(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.version_latest)" + 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::info.operating_system)" \ + " ($(bashio::info.arch) / $(bashio::info.machine))" + bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)" + bashio::log.blue " Home Assistant Supervisor: $(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.green \ + ' https://github.com/alexbelgium/hassio-addons' + bashio::log.blue \ + '-----------------------------------------------------------' +fi diff --git a/gazpar2mqtt/rootfs/scripts/99-run.sh b/gazpar2mqtt/rootfs/scripts/99-run.sh new file mode 100644 index 000000000..4ba6610d5 --- /dev/null +++ b/gazpar2mqtt/rootfs/scripts/99-run.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bashio + +# Where is the config +CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") + +# Check if config file is there, or create one from template +if [ -f $CONFIGSOURCE ]; then + echo "Using config file found in $CONFIGSOURCE" +else + echo "No config file, creating one from template" + # Create folder + mkdir -p "$(dirname "${CONFIGSOURCE}")" + # Downloading template + TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/gazpar2mqtt/rootfs/templates/config.yaml" + curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE + # Placing template in config + #cp config.yaml "$(dirname "${CONFIGSOURCE}")" + # Need to restart + bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting." + bashio::exit.nok +fi + +# Check if yaml is valid +yamllint -d relaxed --no-warnings $CONFIGSOURCE &>ERROR +if [ $? = 0 ]; then + echo "Config file is a valid yaml" +else + bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list :" + cat ERROR +fi + +# Create symlink +[ -f /data/config.yaml ] && rm /data/config.yaml +ln -s $CONFIGSOURCE /data +echo "Symlink created" + +# Export all yaml entries as env variables +# Helper function +function parse_yaml { + local prefix=$2 || local prefix="" + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') + sed -ne "s|^\($s\):|\1|" \ + -e "s| #.*$||g" \ + -e "s|#.*$||g" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i