commit 9042ef24bc34974d207c7062741cdb2c2c6d0a9a Author: root Date: Wed Sep 25 13:57:35 2024 +0200 . diff --git a/hassio-addons/.devcontainer/devcontainer.json b/hassio-addons/.devcontainer/devcontainer.json new file mode 100644 index 0000000..032f121 --- /dev/null +++ b/hassio-addons/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +{ + "containerEnv": { + "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" + }, + "extensions": [ + "timonwong.shellcheck", + "esbenp.prettier-vscode" + ], + "image": "ghcr.io/home-assistant/devcontainer:addons", + "name": "Example Home Assistant add-on repository", + "postStartCommand": ".devcontainer/setup.sh", + "runArgs": [ + "-e", + "GIT_EDITOR=code --wait", + "--privileged" + ], + "settings": { + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true, + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + } + } +} diff --git a/hassio-addons/.devcontainer/setup.sh b/hassio-addons/.devcontainer/setup.sh new file mode 100755 index 0000000..3f1eebd --- /dev/null +++ b/hassio-addons/.devcontainer/setup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Install pre-commit +sudo apt install -y pre-commit +pre-commit install diff --git a/hassio-addons/.github/dependabot.yaml b/hassio-addons/.github/dependabot.yaml new file mode 100644 index 0000000..83b26ea --- /dev/null +++ b/hassio-addons/.github/dependabot.yaml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: weekly + time: "06:00" diff --git a/hassio-addons/.github/workflows/builder.yaml b/hassio-addons/.github/workflows/builder.yaml new file mode 100644 index 0000000..7cb5b75 --- /dev/null +++ b/hassio-addons/.github/workflows/builder.yaml @@ -0,0 +1,113 @@ +name: Builder + +env: + BUILD_ARGS: "--test" + MONITORED_FILES: "build.yaml config.yaml Dockerfile rootfs" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + init: + runs-on: ubuntu-latest + name: Initialize builds + outputs: + changed_addons: ${{ steps.changed_addons.outputs.addons }} + changed: ${{ steps.changed_addons.outputs.changed }} + steps: + - name: Check out the repository + uses: actions/checkout@v3.5.2 + + - name: Get changed files + id: changed_files + uses: jitterbit/get-changed-files@v1 + + - name: Find add-on directories + id: addons + uses: home-assistant/actions/helpers/find-addons@master + + - name: Get changed add-ons + id: changed_addons + run: | + declare -a changed_addons + for addon in ${{ steps.addons.outputs.addons }}; do + if [[ "${{ steps.changed_files.outputs.all }}" =~ $addon ]]; then + for file in ${{ env.MONITORED_FILES }}; do + if [[ "${{ steps.changed_files.outputs.all }}" =~ $addon/$file ]]; then + if [[ ! "${changed_addons[@]}" =~ $addon ]]; then + changed_addons+=("\"${addon}\","); + fi + fi + done + fi + done + + changed=$(echo ${changed_addons[@]} | rev | cut -c 2- | rev) + + if [[ -n ${changed} ]]; then + echo "Changed add-ons: $changed"; + echo "::set-output name=changed::true"; + echo "::set-output name=addons::[$changed]"; + else + echo "No add-on had any monitored files changed (${{ env.MONITORED_FILES }})"; + fi + build: + needs: init + runs-on: ubuntu-latest + if: needs.init.outputs.changed == 'true' + name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on + strategy: + matrix: + addon: ${{ fromJson(needs.init.outputs.changed_addons) }} + arch: ["aarch64", "amd64", "armhf", "armv7", "i386"] + + steps: + - name: Check out repository + uses: actions/checkout@v3.5.2 + + - name: Get information + id: info + uses: home-assistant/actions/helpers/info@master + with: + path: "./${{ matrix.addon }}" + + - name: Check if add-on should be built + id: check + run: | + if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then + echo "::set-output name=build_arch::true"; + echo "::set-output name=image::$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)"; + if [[ -z "${{ github.head_ref }}" ]] && [[ "${{ github.event_name }}" == "push" ]]; then + echo "BUILD_ARGS=" >> $GITHUB_ENV; + fi + else + echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build"; + echo "::set-output name=build_arch::false"; + fi + + - name: Login to GitHub Container Registry + if: env.BUILD_ARGS != '--test' + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build ${{ matrix.addon }} add-on + if: steps.check.outputs.build_arch == 'true' + uses: home-assistant/builder@2023.03.0 + with: + args: | + ${{ env.BUILD_ARGS }} \ + --${{ matrix.arch }} \ + --target /data/${{ matrix.addon }} \ + --image "${{ steps.check.outputs.image }}" \ + --docker-hub "ghcr.io/${{ github.repository_owner }}" \ + --addon + env: + CAS_API_KEY: ${{ secrets.CAS_API_KEY }} diff --git a/hassio-addons/.github/workflows/lint.yaml b/hassio-addons/.github/workflows/lint.yaml new file mode 100644 index 0000000..d99a004 --- /dev/null +++ b/hassio-addons/.github/workflows/lint.yaml @@ -0,0 +1,41 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: "0 0 * * *" + +jobs: + find: + name: Find add-ons + runs-on: ubuntu-latest + outputs: + addons: ${{ steps.addons.outputs.addons_list }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v3.5.2 + + - name: 🔍 Find add-on directories + id: addons + uses: home-assistant/actions/helpers/find-addons@master + + lint: + name: Lint add-on ${{ matrix.path }} + runs-on: ubuntu-latest + needs: find + strategy: + matrix: + path: ${{ fromJson(needs.find.outputs.addons) }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v3.5.2 + + - name: 🚀 Run Home Assistant Add-on Lint + uses: frenck/action-addon-linter@v2.12 + with: + path: "./${{ matrix.path }}" diff --git a/hassio-addons/.pre-commit-config.yaml b/hassio-addons/.pre-commit-config.yaml new file mode 100644 index 0000000..d668a50 --- /dev/null +++ b/hassio-addons/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +fail_fast: false +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-added-large-files + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: destroyed-symlinks + - id: detect-private-key + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=auto"] + - id: pretty-format-json + args: [--autofix, --indent, "4"] + - id: trailing-whitespace diff --git a/hassio-addons/LICENSE b/hassio-addons/LICENSE new file mode 100644 index 0000000..32ee9c8 --- /dev/null +++ b/hassio-addons/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Ezlo Picori + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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. diff --git a/hassio-addons/README.md b/hassio-addons/README.md new file mode 100644 index 0000000..545fed4 --- /dev/null +++ b/hassio-addons/README.md @@ -0,0 +1,9 @@ +# Ezlo's custom Home Assistant addons + +This repository defines a few custom addons for Home Assistant. Notably: + +- [Backup S3](./backup-s3): automatically synchronizes your home-assistant backups with a S3-compatible storage backend. +- [PostgreSQL](./postgres): provides a PostgreSQL instance, strongly inspired by the [official MariaDB](https://github.com/home-assistant/addons/tree/master/mariadb) addon. +- [Kresus](./kresus): sets-up a [Kresus](https://kresus.org/) instance which is a personal finances management software. + +These addons are published under [MIT license](./LICENSE). diff --git a/hassio-addons/backup-s3/CHANGELOG.md b/hassio-addons/backup-s3/CHANGELOG.md new file mode 100644 index 0000000..5945142 --- /dev/null +++ b/hassio-addons/backup-s3/CHANGELOG.md @@ -0,0 +1,11 @@ +## 3.1.0 + +- Prevent service restart +- Rename configuration keys + +## 3.0.0 + +- Update run script to bashio +- Add proper translations for configuration items +- Sign addon with Codenotary +- Enable Apparmor in complain mode diff --git a/hassio-addons/backup-s3/Dockerfile b/hassio-addons/backup-s3/Dockerfile new file mode 100644 index 0000000..edce5fd --- /dev/null +++ b/hassio-addons/backup-s3/Dockerfile @@ -0,0 +1,12 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +ENV LANG C.UTF-8 + +# add aws-cli and deps +RUN apk add --no-cache py3-pip && \ + pip3 install --no-cache-dir awscli awscli-plugin-endpoint + +# Copy root filesystem +COPY rootfs / +WORKDIR / diff --git a/hassio-addons/backup-s3/README.md b/hassio-addons/backup-s3/README.md new file mode 100644 index 0000000..a19df22 --- /dev/null +++ b/hassio-addons/backup-s3/README.md @@ -0,0 +1,66 @@ +# Home Assistant Add-on: S3 Backup + +Add-on for uploading hass.io snapshots to AWS S3. + +## Installation + +Under the Add-on Store tab in the Hass.io Supervisor view in HA add this repo as an add-on repository: `https://github.com/ezlo-picori/hassio-addons`. + +Install, then set the config variables that you obtained from setting up the S3 storage: + +```yaml +awskey: `access key id` +awssecret: `secret access key` +awsendpoint: `URL to S3 endpoint` +bucketname: `AWS S3 bucket name` +``` + +## Usage + +To sync your HASSIO backup folder with AWS just click START in this add-on. It will keep a synced cloud-copy, so any purged backup files will not be kept in your bucket either. + +You could automate this using Automation: + +``` +# backups +- alias: Make snapshot + trigger: + platform: time + at: '3:00:00' + condition: + condition: time + weekday: + - mon + action: + service: hassio.snapshot_full + data_template: + name: Automated Backup {{ now().strftime('%Y-%m-%d') }} + +- alias: Upload to S3 + trigger: + platform: time + at: '4:00:00' + condition: + condition: time + weekday: + - mon + action: + service: hassio.addon_start + data: + addon: b2ddf90b_backup_s3 +``` + +The automation above first makes a snapshot at 3am, and then at 3.30am uploads to S3. + +## Help and Debug + +Please post an issue on this repo with your full log. + +## Credits + +This addon was subject to many forks since its original development. +Original project was developed by [rrostt]/[hassio-backup-s3](https://github.com/rrostt/hassio-backup-s3). It has been forked by [jperquin] and then by [mikebell] whose fork served as a basis for the current addon version. + +[jperquin]: https://github.com/jperquin +[mikebell]: https://github.com/mikebell +[rrostt]: https://github.com/rrostt diff --git a/hassio-addons/backup-s3/apparmor.txt b/hassio-addons/backup-s3/apparmor.txt new file mode 100644 index 0000000..8915d2c --- /dev/null +++ b/hassio-addons/backup-s3/apparmor.txt @@ -0,0 +1,30 @@ +#include + +profile example flags=(attach_disconnected,mediate_deleted,complain) { + #include + + # Capabilities + file, + signal (send) set=(kill,term,int,hup,cont), + + # S6-Overlay + /init ix, + /bin/** ix, + /usr/bin/** ix, + /run/{s6,s6-rc*,service}/** ix, + /package/** ix, + /command/** ix, + /etc/services.d/** rwix, + /etc/cont-init.d/** rwix, + /etc/cont-finish.d/** rwix, + /run/{,**} rwk, + /dev/tty rw, + + # Bashio + /usr/lib/bashio/** ix, + /tmp/** rwk, + + # Access to options.json and other files within your addon + /data/** r, + +} diff --git a/hassio-addons/backup-s3/build.yaml b/hassio-addons/backup-s3/build.yaml new file mode 100644 index 0000000..51f6ba7 --- /dev/null +++ b/hassio-addons/backup-s3/build.yaml @@ -0,0 +1,14 @@ +build_from: + aarch64: "ghcr.io/home-assistant/aarch64-base:3.16" + amd64: "ghcr.io/home-assistant/amd64-base:3.16" + armhf: "ghcr.io/home-assistant/armhf-base:3.16" + armv7: "ghcr.io/home-assistant/armv7-base:3.16" + i386: "ghcr.io/home-assistant/i386-base:3.16" +labels: + org.opencontainers.image.title: "Ezlo's add-on: S3 Backup" + org.opencontainers.image.description: "Addon for backup synchronization to S3 storage" + org.opencontainers.image.source: "https://github.com/ezlo-picori/hassio-addons" + org.opencontainers.image.licenses: "MIT License" +codenotary: + signer: ezlo@protonmail.com + base_image: notary@home-assistant.io diff --git a/hassio-addons/backup-s3/config.yaml b/hassio-addons/backup-s3/config.yaml new file mode 100644 index 0000000..a70996b --- /dev/null +++ b/hassio-addons/backup-s3/config.yaml @@ -0,0 +1,27 @@ +name: Backup S3 +version: 3.1.3 +slug: backup_s3 +codenotary: ezlo@protonmail.com +description: Synchronize your Home-Assistant backups to S3 bucket +url: "https://github.com/ezlo-picori/hassio-addons/tree/main/backup-s3" +arch: + - armhf + - armv7 + - aarch64 + - amd64 + - i386 +image: "ghcr.io/ezlo-picori/haos-addon-backup_s3-{arch}" +init: false +startup: once +options: + s3keyid: "" + s3secret: "" + s3endpoint: "" + bucketname: "" +schema: + s3keyid: str + s3secret: password + s3endpoint: str + bucketname: str +map: + - backup:ro diff --git a/hassio-addons/backup-s3/icon.png b/hassio-addons/backup-s3/icon.png new file mode 100644 index 0000000..316b3ec Binary files /dev/null and b/hassio-addons/backup-s3/icon.png differ diff --git a/hassio-addons/backup-s3/rootfs/etc/services.d/backup/finish b/hassio-addons/backup-s3/rootfs/etc/services.d/backup/finish new file mode 100755 index 0000000..ebdcd39 --- /dev/null +++ b/hassio-addons/backup-s3/rootfs/etc/services.d/backup/finish @@ -0,0 +1,13 @@ +#!/usr/bin/env bashio + +declare APP_EXIT_CODE=${1} + +echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode + +if [[ "${APP_EXIT_CODE}" -eq 0 ]] +then + bashio::log.info "Service ran successfully. Stopping the add-on." +else + bashio::log.warning "Error raised by backup service (error code: ${APP_EXIT_CODE}). Stopping the add-on." +fi +exec /run/s6/basedir/bin/halt diff --git a/hassio-addons/backup-s3/rootfs/etc/services.d/backup/run b/hassio-addons/backup-s3/rootfs/etc/services.d/backup/run new file mode 100755 index 0000000..a6c0238 --- /dev/null +++ b/hassio-addons/backup-s3/rootfs/etc/services.d/backup/run @@ -0,0 +1,23 @@ +#!/usr/bin/with-contenv bashio + +bashio::log.info "Setting AWS CLI options." + +BUCKET="$(bashio::config 'bucketname')" +ENDPOINT="$(bashio::config 's3endpoint')" +KEY="$(bashio::config 's3keyid')" +SECRET="$(bashio::config 's3secret')" + +aws configure set aws_access_key_id "${KEY}" +aws configure set aws_secret_access_key "${SECRET}" +aws configure set plugins.endpoint awscli_plugin_endpoint + +bashio::log.info "Starting backup synchronisation to S3 bucket ${BUCKET} on endpoint ${ENDPOINT}." + +if aws s3 sync /backup "s3://${BUCKET}/" --no-progress --delete --endpoint-url "${ENDPOINT}" +then + bashio::log.info "Synchronization succeeded." + exit 0 +else + bashio::log.warning "Synchronization failed." + exit 1 +fi diff --git a/hassio-addons/backup-s3/translations/en.yaml b/hassio-addons/backup-s3/translations/en.yaml new file mode 100644 index 0000000..ed0e869 --- /dev/null +++ b/hassio-addons/backup-s3/translations/en.yaml @@ -0,0 +1,17 @@ +configuration: + awskey: + s3keyid: "S3 Key" + description: >- + Access Key ID for your S3 storage backend. + s3secret: + name: "S3 Secret" + description: >- + Secret Access Key for your S3 storage backend. + s3endpoint: + name: "S3 Endpoint" + description: >- + Endpoint URL end the S3 backend. + bucketname: + name: "S3 Bucket" + description: >- + Name of the bucket used for backup synchronization. diff --git a/hassio-addons/kresus/CHANGELOG.md b/hassio-addons/kresus/CHANGELOG.md new file mode 100644 index 0000000..1e4983e --- /dev/null +++ b/hassio-addons/kresus/CHANGELOG.md @@ -0,0 +1,37 @@ +## 0.6.2 + +- Update woob dependencies install method + +## 0.6.1 + +- Remove support for i386 architecture + +## 0.6.0 + +- Bump Kresus to 0.19.0 + +## 0.5.1 + +- Fix AppArmor profile + +## 0.5.0 + +- Attempt using `alpine:edge` as base image + +## 0.4.2 + +- Fix AppArmor profile + +## 0.4.1 + +- Reinstall py3-lxml by default + +## 0.4.0 + +- Remove python dependencies from Dockerfile to prevent + incompatibility with woob requirements + +## 0.3.0 + +- Use `s6-setuidgid` instead of `su-exec` +- Set AppArmor in complain mode diff --git a/hassio-addons/kresus/DOCS.md b/hassio-addons/kresus/DOCS.md new file mode 100644 index 0000000..a6484b0 --- /dev/null +++ b/hassio-addons/kresus/DOCS.md @@ -0,0 +1,54 @@ +# Home Assistant Custom Add-on: Kresus + +[Kresus](https://kresus.org/) is an open-source self-hostable Personal Finance Manager. +It automatically retrieves your daily bank transactions, lets you categorize them and manage your monthly budgets. + +It relies on [woob](https://gitlab.com/woob/woob) to fetch data from your bank website. + +## Installation + +Kresus requires a PostgreSQL database to store data. +If you do not already have a PostgreSQL database installed, you may consider the [PostgreSQL addon](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres). + +The installation of Kresus add-on is quite straightforward and do not differ from the standard installation process for Home-Assistant add-ons: + +1. Click the Home Assistant My button below to open the add-on on your Home + Assistant instance. + + [![Open this add-on in your Home Assistant instance.][addon-badge]][addon] + +1. Click the "Install" button to install the add-on. +1. Start the "Kresus" add-on. +1. Check the logs of the "Kresus" add-on to see if everything + went well. A working installation should indicate `Server is ready, let's start the show!` +1. Click the "OPEN WEB UI" button to open Kresus UI. + +## Configuration + +The only configuration configurations required are the database connection options. +If you used the [PostgreSQL add-on](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres) configured with following options: + +```yaml +databases: + - kresus_db +logins: + - password: CHANGEME_kr3sus-p@ssword_CHANGEME + username: kresus_user +rights: + - database: kresus_db + username: kresus_user +``` + +then you may configure kresus with these options: + +```yaml +postgres_hostname: homeassistant.local +postgres_port: 5432 +postgres_user: kresus_user +postgres_password: CHANGEME_kr3sus-p@ssword_CHANGEME +postgres_database: kresus_db +``` + +## Authors & contributors + +The original setup of this repository is by [Ezlo Picori](https://github.com/ezlo-picori). diff --git a/hassio-addons/kresus/Dockerfile b/hassio-addons/kresus/Dockerfile new file mode 100644 index 0000000..733a82b --- /dev/null +++ b/hassio-addons/kresus/Dockerfile @@ -0,0 +1,107 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +# Default ENV +ENV \ + LANG="C.UTF-8" \ + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ + S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ + S6_CMD_WAIT_FOR_SERVICES=1 \ + S6_SERVICES_READYTIME=50 + +# Set shell +SHELL ["/bin/ash", "-o", "pipefail", "-c"] + +# Build Args +ARG \ + BASHIO_VERSION \ + TEMPIO_VERSION \ + S6_OVERLAY_VERSION \ + JEMALLOC_VERSION \ + QEMU_CPU + +# Base system +WORKDIR /usr/src +ARG BUILD_ARCH + +RUN \ + set -x \ + && apk add --no-cache \ + bash \ + bind-tools \ + ca-certificates \ + curl \ + jq \ + tzdata \ + xz \ + \ + && apk add --no-cache --virtual .build-deps \ + build-base \ + autoconf \ + git \ + \ + && if [ "${BUILD_ARCH}" = "armv7" ]; then \ + export S6_ARCH="arm"; \ + elif [ "${BUILD_ARCH}" = "i386" ]; then \ + export S6_ARCH="i686"; \ + elif [ "${BUILD_ARCH}" = "amd64" ]; then \ + export S6_ARCH="x86_64"; \ + else \ + export S6_ARCH="${BUILD_ARCH}"; \ + fi \ + \ + && curl -L -f -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz" \ + | tar Jxvf - -C / \ + && curl -L -f -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" \ + | tar Jxvf - -C / \ + && curl -L -f -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz" \ + | tar Jxvf - -C / \ + && curl -L -f -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz" \ + | tar Jxvf - -C / \ + && mkdir -p /etc/fix-attrs.d \ + && mkdir -p /etc/services.d \ + \ + && git clone "https://github.com/jemalloc/jemalloc" /usr/src/jemalloc \ + && cd /usr/src/jemalloc \ + && git checkout ${JEMALLOC_VERSION} \ + && ./autogen.sh \ + && make -j "$(nproc)" \ + && make install \ + \ + && mkdir -p /usr/src/bashio \ + && curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" \ + | tar -xzf - --strip 1 -C /usr/src/bashio \ + && mv /usr/src/bashio/lib /usr/lib/bashio \ + && ln -s /usr/lib/bashio/bashio /usr/bin/bashio \ + \ + && curl -L -f -s -o /usr/bin/tempio \ + "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}" \ + && chmod a+x /usr/bin/tempio \ + \ + && apk del .build-deps \ + && rm -rf /usr/src/* + +# S6-Overlay +WORKDIR / +ENTRYPOINT ["/init"] + +# Copy root filesystem +COPY rootfs / + +# Setup base +RUN apk add --no-cache \ + gcc g++ gpgv jpeg-dev pwgen python3-dev py3-lxml py3-pip \ + py3-wheel make nodejs npm zlib-dev && \ + npm install --omit=dev -g kresus@0.19.0 && \ + addgroup kresus && \ + adduser -G kresus -D -H kresus && \ + mkdir -p /woob && \ + chown kresus:kresus /woob && \ + chown -R kresus:kresus /etc/kresus && \ + chmod 0400 /etc/kresus/config.ini && \ + chmod 0755 /etc/kresus + +ENV KRESUS_DIR="/data/kresus" +ENV KRESUS_USER="kresus" + +WORKDIR / diff --git a/hassio-addons/kresus/README.md b/hassio-addons/kresus/README.md new file mode 100644 index 0000000..d20aef7 --- /dev/null +++ b/hassio-addons/kresus/README.md @@ -0,0 +1,25 @@ +# Home Assistant Add-on: Kresus + +Open source personal accounting solution. + +![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] + +## About + +[Kresus][kresus] is a free solution for personal accounting management. +It automatically retrieves your daily bank transactions, lets you categorize them +and manage your monthly budgets. + +![Kresus Preview][screenshot] + +[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 +[i386-shield]: https://img.shields.io/badge/i386-no-red.svg +[screenshot]: https://kresus.org/images/pages/view-all-accounts.png +[kresus]: https://kresus.org/ diff --git a/hassio-addons/kresus/apparmor.txt b/hassio-addons/kresus/apparmor.txt new file mode 100644 index 0000000..44f634b --- /dev/null +++ b/hassio-addons/kresus/apparmor.txt @@ -0,0 +1,72 @@ +include + +profile kresus flags=(attach_disconnected,mediate_deleted) { + #include + + # Capabilities + file, + signal (send) set=(kill,term,int,hup,cont), + capability chown, + capability fowner, + capability kill, + + # S6-Overlay + /init ix, + /bin/** ix, + /usr/bin/** ix, + /run/{s6,s6-rc*,service}/** ix, + /package/** ix, + /command/** ix, + /etc/services.d/** rwix, + /etc/cont-init.d/** rwix, + /etc/cont-finish.d/** rwix, + /run/{,**} rwk, + /dev/tty rw, + + # Access to options.json and other files within your addon + /data/options.json r, + /data/kresus/{,**} rw, + + /package/admin/s6-2.11.2.0/command/s6-applyuidgid cx -> s6setuidgid, + profile s6setuidgid flags=(attach_disconnected,mediate_deleted) { + #include + capability setuid, + capability setgid, + + signal (receive) set=("cont","kill","term"), + + # Generic accesses + /package/admin/s6-2.11.2.0/command/s6-applyuidgid rm, + + /bin/{bash,busybox} ix, + /dev/{null,tty} rw, + /etc/{group,hosts,os-release,passwd,resolv.conf,ssl/**} r, + /package/admin/** rmix, + /run/s6/container_environment** r, + /tmp/.bashio/{,**} rw, + /usr/bin/{curl,jq,ssl_client} rix, + /usr/lib/bashio/bashio ix, + /lib/** rmix, + /tmp/pip-install-** rw, + + # Kresus specific accesses + /data/kresus_salt r, + /data/kresus/{,**} rw, + /etc/kresus/config.ini r, + /woob/ r, + /woob/** lrw, + /woob/.py-deps/** lrwix, + + /usr/bin/{,**} r, + /usr/bin/git ix, + /usr/bin/gpgv ix, + /usr/bin/node ix, + /usr/bin/python3.11 ix, + /usr/bin/pip3 rix, + /usr/libexec/git-core/** ix, + /usr/libexec/kresus/** rix, + /usr/local/lib/node_modules/** rm, + /usr/local/lib/node_modules/kresus/bin/kresus.js rix, + /usr/share/** r, + } +} diff --git a/hassio-addons/kresus/build.yaml b/hassio-addons/kresus/build.yaml new file mode 100644 index 0000000..a953b79 --- /dev/null +++ b/hassio-addons/kresus/build.yaml @@ -0,0 +1,18 @@ +build_from: + aarch64: "arm64v8/alpine:edge" + armv7: "arm32v7/alpine:edge" + armhf: "arm32v6/alpine:edge" + amd64: "alpine:edge" +labels: + org.opencontainers.image.title: "Home Assistant Add-on: Kresus" + org.opencontainers.image.description: "Kresus addon" + org.opencontainers.image.source: "https://github.com/ezlo-picori/hassio-addons" + org.opencontainers.image.licenses: "MIT License" + io.hass.base.name: alpine +codenotary: + signer: ezlo@protonmail.com +args: + BASHIO_VERSION: 0.14.3 + TEMPIO_VERSION: 2021.09.0 + S6_OVERLAY_VERSION: 3.1.3.0 + JEMALLOC_VERSION: 5.3.0 diff --git a/hassio-addons/kresus/config.yaml b/hassio-addons/kresus/config.yaml new file mode 100644 index 0000000..0a9d78a --- /dev/null +++ b/hassio-addons/kresus/config.yaml @@ -0,0 +1,33 @@ +name: Kresus +version: "0.6.2" +slug: kresus +codenotary: ezlo@protonmail.com +url: "https://github.com/ezlo-picori/hassio-addons/tree/main/kresus" +description: Open source personal accounting management +arch: + - armhf + - armv7 + - aarch64 + - amd64 +image: "ghcr.io/ezlo-picori/haos-addon-kresus-{arch}" +init: false +options: + postgres_hostname: homeassistant.local + postgres_port: 5432 + postgres_user: kresus + postgres_password: null + postgres_database: kresus +panel_icon: mdi:piggy-bank-outline +ports: + 9876/tcp: 9876 +ports_description: + 9876/tcp: "The port to access kresus web server." +schema: + postgres_hostname: str + postgres_port: int + postgres_user: str + postgres_password: password + postgres_database: str + http_basicauth: str? +startup: system +timeout: 20 diff --git a/hassio-addons/kresus/icon.png b/hassio-addons/kresus/icon.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/hassio-addons/kresus/icon.png differ diff --git a/hassio-addons/kresus/logo.png b/hassio-addons/kresus/logo.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/hassio-addons/kresus/logo.png differ diff --git a/hassio-addons/kresus/rootfs/etc/kresus/config.ini b/hassio-addons/kresus/rootfs/etc/kresus/config.ini new file mode 100644 index 0000000..defb96e --- /dev/null +++ b/hassio-addons/kresus/rootfs/etc/kresus/config.ini @@ -0,0 +1,270 @@ +; Hi there! This is the configuration file for +; Kresus. Please make sure to read all the options before setting up +; Kresus for the first time. +; +[kresus] + +; This is where Kresus stores additional data, as the latest bank +; scrapping modules. It should be writeable by the user which launches +; the Kresus executable. +; Can be removed; defaults to HOME_DIR/.kresus. +; Overriden by the KRESUS_DIR environment variable, if it's set. +; Example: +; datadir=/home/ben/.kresus +datadir= + +; A user id obtained from using the "kresus create-user" command. +; This allows sharing a single database with several users. If your +; instance is only planned to host a single user, you can keep it +; disabled, and Kresus will know how to automatically generate a new +; user. +; Overriden by the KRESUS_USER_ID environment variable, if it's set. +; Example: +; userid=1 +userid= + +; This is the port that Kresus will run on. It is recommended not +; to expose it on port 80 directly but to use a reverse-proxy +; configuration like Nginx, Caddy or Apache. +; Can be removed; defaults to 9876. +; Overriden by the PORT environment variable, if it's set. +; Example: +; port=9876 +port= + +; The host on which the Kresus server will listen to. +; Can be removed; defaults to 127.0.0.1. +; Overriden by the HOST environment variable, if it's set. +; Example: +; host=127.0.0.1 +host= + +; The executable version of Python that is going to get used when +; interacting with Python scripts. This can be python or python3. +; Can be removed; defaults to python3. +; Overriden by the KRESUS_PYTHON_EXEC environment variable, if it's set. +; Example: +; python_exec=python3 +python_exec= + +; The directory prefix in the URL, if Kresus is to be served from a +; subdirectory. For instance, if your website is hosted at example.com +; and the url prefix is "money", then Kresus will be reachable at +; example.com/money. By default, it's '', meaning that Kresus has its own +; subdomain. +; Can be removed; defaults to "". +; Overriden by the KRESUS_URL_PREFIX environment variable, if it's set. +; Example: +; url_prefix=/money +url_prefix= + +; A salt value used in encryption algorithms (used for instance to +; encrypt/decrypt exports). It should be a random string value with +; at least 16 characters if you decide to provide it. +; Overriden by the KRESUS_SALT environment variable, if it's set. +; Example: +; salt=gj4J89fkjf4h29aDi0f{}fu4389sejk`9osk` +salt= + +; Set this to true if you want to use this instance only in demo +; mode, and to never allow users to link their personal accounts. +; +; WARNING! Switching this on and off may trigger data loss. Note that it +; is still possible to try Kresus in demo mode, even if this is not set +; to true. Setting this to true will *force* demo mode, and prevent users +; from leaving this mode. +; Can be removed; defaults to false. +; Overriden by the KRESUS_FORCE_DEMO_MODE environment variable, if it's set. +; Example: +; force_demo_mode=true +force_demo_mode= + +; If set to a string, will enable HTTP Basic Auth, by splitting the +; string on a colon, i.e. ":" +; Overriden by the KRESUS_AUTH environment variable, if it's set. +; Example: +; auth=foo:bar +auth= + +[woob] + +; The directory in which Woob core is stored. If empty, indicates +; that woob is already in the PYTHON_PATH (e.g. installed at the global +; level) +; Overriden by the KRESUS_WOOB_DIR environment variable, if it's set. +; Example: +; srcdir=/home/ben/code/woob +srcdir= + +; Path to a file containing a valid Woob's source list directory. +; If empty (the default), indicates that Kresus will generate its own +; source list file and will store it in +; KRESUS_DIR/woob-data/sources.list. +; Overriden by the KRESUS_WOOB_SOURCES_LIST environment variable, if it's set. +; Example: +; sources_list=/home/ben/code/woob/sources.list +sources_list= + +[email] + +; The transport method you want to use. Can be either: +; * "sendmail": relies on sendmail executable to be available on your +; system and only sendmail-specific parameters are used, +; +; * "smtp": you should provide proper SMTP credentials to use, in the +; dedicated configuration entries. +; +; If empty, no emails will be sent by Kresus. +; Overriden by the KRESUS_EMAIL_TRANSPORT environment variable, if it's set. +; Example: +; transport=smtp +transport= + +; The path to the sendmail executable to use. If empty, indicates +; that the default sendmail executable will be used. +; Overriden by the KRESUS_EMAIL_SENDMAIL_BIN environment variable, if it's set. +; Example: +; sendmail_bin=/usr/bin/sendmail +sendmail_bin= + +; The email address from which email alerts will be sent. Make sure +; that your domain DNS is correctly configured and that you've done +; what's needed to prevent email alerts from landing in the spam folder. +; Overriden by the KRESUS_EMAIL_FROM environment variable, if it's set. +; Example: +; from=kresus@domain.tld +from= + +; The network address (ipv4, ipv6 or FQDN) of the SMTP server. +; Overriden by the KRESUS_EMAIL_HOST environment variable, if it's set. +; Example: +; host=mail.domain.tld +host= + +; The port to which the SMTP server listens. Default values tend to +; be: 25 (server to server), or 587 (clients to server), or 465 +; (nonstandard). +; Overriden by the KRESUS_EMAIL_PORT environment variable, if it's set. +; Example: +; port=465 +port= + +; The username used during authentication to the SMTP server. If +; empty, indicates an anonymous connection will be used. +; Overriden by the KRESUS_EMAIL_USER environment variable, if it's set. +; Example: +; user=login +user= + +; The password used during authentication to the SMTP server. If +; empty, indicates no password will be used. +; Overriden by the KRESUS_EMAIL_PASSWORD environment variable, if it's set. +; Example: +; password=hunter2 +password= + +; If set to true, will force using a TLS connection. By default, +; emails are sent with STARTTLS, i.e. using TLS if available. +; Can be removed; defaults to false. +; Overriden by the KRESUS_EMAIL_FORCE_TLS environment variable, if it's set. +; Example: +; force_tls=false +force_tls= + +; If set to false, will allow self-signed TLS certificates. +; Can be removed; defaults to true. +; Overriden by the KRESUS_EMAIL_REJECT_UNAUTHORIZED_TLS environment variable, if it's set. +; Example: +; reject_unauthorized_tls=true +reject_unauthorized_tls= + +[notifications] + +; The baseurl from which apprise-api will be called for +; notifications to be sent. +; See https://github.com/caronc/apprise-api#installation for +; installation +; Overriden by the KRESUS_APPRISE_API_BASE_URL environment variable, if it's set. +; Example: +; appriseApiBaseUrl=http://localhost:8000/ +appriseApiBaseUrl= + +[logs] + +; The path to the log file to use. If empty, defaults to kresus.log +; in datadir. +; Overriden by the KRESUS_LOG_FILE environment variable, if it's set. +; Example: +; log_file=/var/log/kresus.log +log_file= + +[db] + +; Database type supported by Kresus, to choose among: +; - postgres +; - sqlite +; +; It must be set by the user. PostgreSQL is recommended and strongly supported; your experience with other databases might vary. +; +; Note using sqlite is *strongly discouraged* because it can't properly handle certain kinds of database migrations. It is only intended for development purposes. +; Overriden by the KRESUS_DB_TYPE environment variable, if it's set. +; Example: +; type=sqlite +type= + +; Logging level for the SQL queries. Possible values are: +; +; - all: will log every SQL query, including queries causing errors. +; - error (default value): will only log SQL queries resulting in errors. This is useful for debugging purposes. +; - none: nothing will be logged. +; Can be removed; defaults to error. +; Overriden by the KRESUS_DB_LOG environment variable, if it's set. +; Example: +; log=error +log= + +; Path to the sqlite database file. Make sure that the user running +; Kresus has the right permissions to write into this file. Required only for +; sqlite. +; Overriden by the KRESUS_DB_SQLITE_PATH environment variable, if it's set. +; Example: +; sqlite_path=/tmp/dev.sqlite +sqlite_path= + +; Path to a directory containing a Unix socket to connect to the +; database, or host address of the database server. Required for postgres. +; +; If using a Unix socket, the socket file's name will be inferred from the +; standard postgres name and the port number. +; Can be removed; defaults to localhost for postgres. +; Overriden by the KRESUS_DB_HOST environment variable, if it's set. +; Example: +; host=localhost +host= + +; Port of the database server. Required for postgres, even when +; using a Unix socket (the port is used to compute the socket's file name). +; Can be removed; defaults to 5432 for postgres. +; Overriden by the KRESUS_DB_PORT environment variable, if it's set. +; Example: +; port=5432 +port= + +; Username to connect to the database server. Required for postgres. +; Overriden by the KRESUS_DB_USERNAME environment variable, if it's set. +; Example: +; username=benjamin +username= + +; Password to connect to the database server. Required for postgres. +; Overriden by the KRESUS_DB_PASSWORD environment variable, if it's set. +; Example: +; password=hunter2 +password= + +; Database name to use. Required for postgres. +; Can be removed; defaults to kresus. +; Overriden by the KRESUS_DB_NAME environment variable, if it's set. +; Example: +; name=kresus +name= diff --git a/hassio-addons/kresus/rootfs/etc/services.d/kresus/finish b/hassio-addons/kresus/rootfs/etc/services.d/kresus/finish new file mode 100755 index 0000000..230d179 --- /dev/null +++ b/hassio-addons/kresus/rootfs/etc/services.d/kresus/finish @@ -0,0 +1,15 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Take down the S6 supervision tree when example fails +# s6-overlay docs: https://github.com/just-containers/s6-overlay +# ============================================================================== + +declare APP_EXIT_CODE=${1} + +if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then + bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}" + echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode + exec /run/s6/basedir/bin/halt +fi + +bashio::log.info "Service restart after closing" diff --git a/hassio-addons/kresus/rootfs/etc/services.d/kresus/run b/hassio-addons/kresus/rootfs/etc/services.d/kresus/run new file mode 100755 index 0000000..d8bcbce --- /dev/null +++ b/hassio-addons/kresus/rootfs/etc/services.d/kresus/run @@ -0,0 +1,25 @@ +#!/usr/bin/with-contenv bashio + +# ============================================================================== +# Init data directory +# ============================================================================== +if ! bashio::fs.directory_exists "${KRESUS_DIR}"; then + bashio::log.info "Create data directory \"${KRESUS_DIR}\"" + mkdir "${KRESUS_DIR}" + chown "${KRESUS_USER}:${KRESUS_USER}" "${KRESUS_DIR}" + chmod 0700 "${KRESUS_DIR}" +fi + +# ============================================================================== +# Generate Kresus salt once +# ============================================================================== +if ! bashio::fs.file_exists "/data/kresus_salt"; then + pwgen 32 1 > /data/kresus_salt + chown "${KRESUS_USER}:${KRESUS_USER}" /data/kresus_salt + chmod 400 /data/kresus_salt +fi + +# ============================================================================== +# Start service as unprivileged user +# ============================================================================== +exec s6-setuidgid "${KRESUS_USER}" /usr/libexec/kresus/start.sh diff --git a/hassio-addons/kresus/rootfs/usr/libexec/kresus/start.sh b/hassio-addons/kresus/rootfs/usr/libexec/kresus/start.sh new file mode 100755 index 0000000..a03d20d --- /dev/null +++ b/hassio-addons/kresus/rootfs/usr/libexec/kresus/start.sh @@ -0,0 +1,55 @@ +#!/usr/bin/with-contenv bashio +WOOB_DIR="/woob" +KRESUS_INI_FILE="/etc/kresus/config.ini" + +# ============================================================================== +# Pull latest Woob version +# ============================================================================== +cd "${WOOB_DIR}" || bashio::exit.nok + +bashio::log.info "Clear woob install" +rm -rf {,.[!.],..?}* + +bashio::log.info "Add clean woob install" +wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 + +bashio::log.info "Updating Woob dependencies..." +pip3 install --no-cache-dir --prefix .py-deps . +PYTHONPATH=$(python3 -c "import sys, os; print(os.sep.join(['$(pwd)', '.py-deps', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages']))") +export PYTHONPATH +bashio::log.info "Done updating Woob dependencies." + +# ============================================================================== +# Set-up environment variables +# ============================================================================== + +# Basic Kresus options +export PORT=9876 +export HOST=0.0.0.0 +export KRESUS_PYTHON_EXEC=python3 +export KRESUS_WOOB_DIR="${WOOB_DIR}" + +KRESUS_SALT="$(cat /data/kresus_salt)" +export KRESUS_SALT + +# Kresus Basic auth +if bashio::config.has_value 'http_basicauth'; then + KRESUS_AUTH="$(bashio::config 'http_basicauth')" + export KRESUS_AUTH +fi + +# Kresus database +export KRESUS_DB_TYPE="postgres" + +KRESUS_DB_HOST="$(bashio::config 'postgres_hostname')" +KRESUS_DB_PORT="$(bashio::config 'postgres_port')" +KRESUS_DB_USERNAME="$(bashio::config 'postgres_user')" +KRESUS_DB_PASSWORD="$(bashio::config 'postgres_password')" +KRESUS_DB_NAME="$(bashio::config 'postgres_database')" +export KRESUS_DB_HOST KRESUS_DB_PORT KRESUS_DB_USERNAME \ + KRESUS_DB_PASSWORD KRESUS_DB_NAME + +# ============================================================================== +# Start Kresus +# ============================================================================== +kresus -c ${KRESUS_INI_FILE} diff --git a/hassio-addons/kresus/translations/en.yaml b/hassio-addons/kresus/translations/en.yaml new file mode 100644 index 0000000..a9aa6a8 --- /dev/null +++ b/hassio-addons/kresus/translations/en.yaml @@ -0,0 +1,27 @@ +configuration: + postgres_hostname: + name: "DB hostname" + description: >- + Hostname of the PostgreSQL database. + postgres_port: + name: "DB port" + description: >- + Port of the PostgreSQL database. + postgres_user: + name: "DB user" + description: >- + User to connect to the database. + postgres_password: + name: "DB password" + description: >- + Password of the database user. + postgres_database: + name: "DB database" + description: >- + Name of the kresus database. + http_basicauth: + name: "Authentication" + description: >- + Logins for HTTP basic auth authentication ("login:passwd" format, optional). +network: + 9876/tcp: Port to access kresus web server. diff --git a/hassio-addons/postgres/CHANGELOG.md b/hassio-addons/postgres/CHANGELOG.md new file mode 100644 index 0000000..e8a6217 --- /dev/null +++ b/hassio-addons/postgres/CHANGELOG.md @@ -0,0 +1,13 @@ +## 0.5.1 + +- Fix detection of existing users + +## 0.5.0 + +- Enforce apparmor +- Do not stop on pg_checksums failure +- Simplify script by setting PGDATA environment variable + +## 0.4.0 + +- Initial test without su-exec diff --git a/hassio-addons/postgres/DOCS.md b/hassio-addons/postgres/DOCS.md new file mode 100644 index 0000000..4fd9a7c --- /dev/null +++ b/hassio-addons/postgres/DOCS.md @@ -0,0 +1,76 @@ +# Home Assistant Add-on: PostgreSQL + +[PostgreSQL](https://www.postgresql.org/) is an open-source relational SQL database. +It can be used as a backend for [Kresus](https://github.com/ezlo-picori/hassio-addons/tree/main/kresus), Nextcloud or even as your Home-Assistant recorder. + +## Installation + +The installation of this add-on is pretty straightforward and not different in +comparison to installing any other Home Assistant add-on. + +1. Click the Home Assistant My button below to open the add-on on your Home + Assistant instance. + + [![Open this add-on in your Home Assistant instance.][addon-badge]][addon] + +1. Click the "Install" button to install the add-on. +1. Change the configuration (see next section) +1. Start the "PostgreSQL" add-on. +1. Check the logs of the add-on to see if everything went well. +1. Enjoy the add-on! + +## Configuration + +The configuration of the PostgreSQL add-on matches that of the official [MariaDB add-on](https://github.com/home-assistant/addons/tree/master/mariadb). + +Example add-on configuration: + +```yaml +databases: + - homeassistant +logins: + - username: homeassistant + password: PASSWORD + - username: read_only_user + password: PASSWORD +rights: + - username: homeassistant + database: homeassistant + - username: read_only_user + database: homeassistant + privileges: + - SELECT +``` + +### Option: `databases` (required) + +Database name, e.g., `homeassistant`. Multiple are allowed. + +### Option: `logins` (required) + +This section defines a create user definition in PostgreSQL. + +### Option: `logins.username` (required) + +Database user login, e.g., `homeassistant`. + +### Option: `logins.password` (required) + +Password for user login. This should be strong and unique. + +### Option: `rights` (required) + +This section grant privileges to users in MariaDB. + +### Option: `rights.username` (required) + +This should be the same user name defined in `logins` -> `username`. + +### Option: `rights.database` (required) + +This should be the same database defined in `databases`. + +### Option: `rights.privileges` (optional) + +A list of privileges to grant to this user from grant like `SELECT` and `CREATE`. +If omitted, grants `ALL PRIVILEGES` to the user. diff --git a/hassio-addons/postgres/Dockerfile b/hassio-addons/postgres/Dockerfile new file mode 100644 index 0000000..de90840 --- /dev/null +++ b/hassio-addons/postgres/Dockerfile @@ -0,0 +1,16 @@ +# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-dockerfile +ARG BUILD_FROM +FROM $BUILD_FROM + +# Setup base +RUN apk add --no-cache \ + postgresql14 && \ + mkdir /run/postgresql && \ + chown postgres:postgres /run/postgresql + +# Copy root filesystem +COPY rootfs / + +ENV PGDATA=/data/databases + +WORKDIR / diff --git a/hassio-addons/postgres/README.md b/hassio-addons/postgres/README.md new file mode 100644 index 0000000..daafc7c --- /dev/null +++ b/hassio-addons/postgres/README.md @@ -0,0 +1,19 @@ +# Home Assistant Add-on: PostgreSQL + +PostgreSQL database in Home-Assistant. + +![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] + +## About + +You can use this add-on to install the PostgreSQL database and easily define databases, users and their permissions. + +[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 +[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg diff --git a/hassio-addons/postgres/apparmor.txt b/hassio-addons/postgres/apparmor.txt new file mode 100644 index 0000000..8ea49e7 --- /dev/null +++ b/hassio-addons/postgres/apparmor.txt @@ -0,0 +1,51 @@ +include + +profile b2ddf90b_postgres flags=(attach_disconnected,mediate_deleted) { + #include + + # Capabilities + file, + signal (send) set=(kill,term,int,hup,cont), + capability chown, + capability kill, + + # S6-Overlay + /init ix, + /bin/** ix, + /usr/bin/** ix, + /run/{s6,s6-rc*,service}/** ix, + /package/** ix, + /command/** ix, + /etc/services.d/** rwix, + /etc/cont-init.d/** rwix, + /etc/cont-finish.d/** rwix, + /run/{,**} rwk, + /dev/tty rw, + + # Access to options.json and other files within your addon + /data/options.json r, + + /package/admin/s6-2.11.1.2/command/s6-applyuidgid cx -> s6setuidgid, + profile s6setuidgid flags=(attach_disconnected,mediate_deleted) { + #include + capability setuid, + capability setgid, + + signal (receive) set=("cont","kill","term"), + + /bin/{bash,busybox} ix, + /data/databases/{,**} lrw, + /dev/{null,tty} rw, + /dev/shm/PostgreSQL.* rw, + /etc/{hosts,passwd,resolv.conf,ssl/*} r, + /package/admin/** rmix, + /run/postgresql/* rw, + /run/s6/container_environment** r, + /tmp/.bashio/{,**} rw, + /usr/bin/{curl,jq} rix, + /usr/libexec/postgres{ql14,}/** rix, + /usr/lib/** rm, + /usr/lib/bashio/bashio ix, + /usr/share/{icu,postgresql14,zoneinfo}/** r, + } +} diff --git a/hassio-addons/postgres/build.yaml b/hassio-addons/postgres/build.yaml new file mode 100644 index 0000000..40a28be --- /dev/null +++ b/hassio-addons/postgres/build.yaml @@ -0,0 +1,14 @@ +build_from: + aarch64: "ghcr.io/home-assistant/aarch64-base:3.16" + amd64: "ghcr.io/home-assistant/amd64-base:3.16" + armhf: "ghcr.io/home-assistant/armhf-base:3.16" + armv7: "ghcr.io/home-assistant/armv7-base:3.16" + i386: "ghcr.io/home-assistant/i386-base:3.16" +labels: + org.opencontainers.image.title: "Home Assistant Add-on: PostgreSQL" + org.opencontainers.image.description: "PostgreSQL database addon" + org.opencontainers.image.source: "https://github.com/ezlo-picori/hassio-addons" + org.opencontainers.image.licenses: "MIT License" +codenotary: + signer: ezlo@protonmail.com + base_image: notary@home-assistant.io diff --git a/hassio-addons/postgres/config.yaml b/hassio-addons/postgres/config.yaml new file mode 100644 index 0000000..f3b7f95 --- /dev/null +++ b/hassio-addons/postgres/config.yaml @@ -0,0 +1,42 @@ +name: PostgreSQL +version: 0.5.1 +slug: postgres +codenotary: ezlo@protonmail.com +url: "https://github.com/ezlo-picori/hassio-addons/tree/main/postgres" +description: PostgreSQL database +arch: + - armhf + - armv7 + - aarch64 + - amd64 + - i386 +image: "ghcr.io/ezlo-picori/haos-addon-postgres-{arch}" +init: false +options: + databases: + - homeassistant + logins: + - password: null + username: homeassistant + rights: + - database: homeassistant + username: homeassistant +ports: + 5432/tcp: 5432 +ports_description: + 5432/tcp: "The port to access the database engine." +schema: + databases: + - str + logins: + - username: str + password: password + rights: + - database: str + privileges: + - "list(ALTER|CREATE|CREATE ROUTINE|CREATE TEMPORARY TABLES|\ + CREATE VIEW|DELETE|DELETE HISTORY|DROP|EVENT|GRANT OPTION|INDEX|\ + INSERT|LOCK TABLES|SELECT|SHOW VIEW|TRIGGER|UPDATE)?" + username: str +startup: system +timeout: 20 diff --git a/hassio-addons/postgres/icon.png b/hassio-addons/postgres/icon.png new file mode 100644 index 0000000..7f9cb7b Binary files /dev/null and b/hassio-addons/postgres/icon.png differ diff --git a/hassio-addons/postgres/logo.png b/hassio-addons/postgres/logo.png new file mode 100644 index 0000000..d404139 Binary files /dev/null and b/hassio-addons/postgres/logo.png differ diff --git a/hassio-addons/postgres/rootfs/etc/services.d/postgresql/finish b/hassio-addons/postgres/rootfs/etc/services.d/postgresql/finish new file mode 100755 index 0000000..230d179 --- /dev/null +++ b/hassio-addons/postgres/rootfs/etc/services.d/postgresql/finish @@ -0,0 +1,15 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Take down the S6 supervision tree when example fails +# s6-overlay docs: https://github.com/just-containers/s6-overlay +# ============================================================================== + +declare APP_EXIT_CODE=${1} + +if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then + bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}" + echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode + exec /run/s6/basedir/bin/halt +fi + +bashio::log.info "Service restart after closing" diff --git a/hassio-addons/postgres/rootfs/etc/services.d/postgresql/run b/hassio-addons/postgres/rootfs/etc/services.d/postgresql/run new file mode 100755 index 0000000..b73f71d --- /dev/null +++ b/hassio-addons/postgres/rootfs/etc/services.d/postgresql/run @@ -0,0 +1,15 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Start PostgreSQL service +# ============================================================================== + +if ! bashio::fs.directory_exists "${PGDATA}"; then + bashio::log.info "Create database directory \"${PGDATA}\"" + mkdir "${PGDATA}" + chown postgres:postgres "${PGDATA}" + + exec s6-setuidgid postgres /usr/libexec/postgres/initdb.sh +else + bashio::log.info "Using existing postgres initial system" + exec s6-setuidgid postgres /usr/libexec/postgres/checkdb.sh +fi diff --git a/hassio-addons/postgres/rootfs/usr/libexec/postgres/checkdb.sh b/hassio-addons/postgres/rootfs/usr/libexec/postgres/checkdb.sh new file mode 100755 index 0000000..3ee75bd --- /dev/null +++ b/hassio-addons/postgres/rootfs/usr/libexec/postgres/checkdb.sh @@ -0,0 +1,12 @@ +#!/usr/bin/with-contenv bashio +# ======================================================= +# 1 - Check database checksums in PGDATA directory +# 2 - Delegate execution to database start procedure +# ======================================================= + +# Initialize database +bashio::log.info "Checking data integrity" +pg_checksums --check || bashio::log.warning "Error raised when checking data integrity, still trying to start the database." + +# Delegate execution to start script +/usr/libexec/postgres/start.sh diff --git a/hassio-addons/postgres/rootfs/usr/libexec/postgres/config.sh b/hassio-addons/postgres/rootfs/usr/libexec/postgres/config.sh new file mode 100755 index 0000000..ed89452 --- /dev/null +++ b/hassio-addons/postgres/rootfs/usr/libexec/postgres/config.sh @@ -0,0 +1,49 @@ +#!/usr/bin/with-contenv bashio +# ======================================================= +# 1 - Create missing databases +# 2 - Initialize users +# 3 - Initialize permissions +# 4 - Delegate execution to monitoring +# ======================================================= + +# Init databases +bashio::log.info "Ensure databases exists" +for database in $(bashio::config "databases"); do + if psql "${database}" -c '' &> /dev/null; then + bashio::log.info "Database ${database} already defined" + else + bashio::log.info "Create database ${database}" + psql -c "CREATE DATABASE ${database};" 2> /dev/null || true + fi +done + +# Init logins +bashio::log.info "Ensure users exists and are updated" +for login in $(bashio::config "logins|keys"); do + USERNAME=$(bashio::config "logins[${login}].username") + PASSWORD=$(bashio::config "logins[${login}].password") + + if ! psql -U "${USERNAME}" -d "postgres" -c '' &> /dev/null; then + bashio::log.info "Create user ${USERNAME}" + psql -c "CREATE USER ${USERNAME};" + fi + bashio::log.info "Set password of user ${USERNAME}" + psql -c "ALTER USER ${USERNAME} WITH PASSWORD '${PASSWORD}';" +done + +# Init rights +bashio::log.info "Init/Update rights" +for right in $(bashio::config "rights|keys"); do + USERNAME=$(bashio::config "rights[${right}].username") + DATABASE=$(bashio::config "rights[${right}].database") + + if bashio::config.exists "rights[${right}].privileges"; then + PRIVILEGES=$(bashio::config "rights[${right}].privileges") + bashio::log.info "Granting ${PRIVILEGES} to ${USERNAME} on ${DATABASE}" + psql -c "REVOKE ALL PRIVILEGES ON DATABASE ${DATABASE} FROM ${USERNAME};" 2> /dev/null || true + psql -c "GRANT ${PRIVILEGES} ON DATABASE ${DATABASE} TO ${USERNAME};" 2> /dev/null || true + else + bashio::log.info "Granting all privileges to ${USERNAME} on ${DATABASE}" + psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DATABASE} TO ${USERNAME};" 2> /dev/null || true + fi +done diff --git a/hassio-addons/postgres/rootfs/usr/libexec/postgres/initdb.sh b/hassio-addons/postgres/rootfs/usr/libexec/postgres/initdb.sh new file mode 100755 index 0000000..49a6c2f --- /dev/null +++ b/hassio-addons/postgres/rootfs/usr/libexec/postgres/initdb.sh @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bashio +# ======================================================= +# 1 - Initialize the database in PGDATA directory +# 2 - Delegate execution to database start procedure +# ======================================================= + +# Initialize database +bashio::log.info "Create a new postgres initial system" +initdb --data-checksums > /dev/null +echo "host all all 0.0.0.0/0 scram-sha-256" >> "${PGDATA}/pg_hba.conf" +echo "listen_addresses='*'" >> "${PGDATA}/postgresql.conf" + +# Delegate execution to start script +/usr/libexec/postgres/start.sh diff --git a/hassio-addons/postgres/rootfs/usr/libexec/postgres/start.sh b/hassio-addons/postgres/rootfs/usr/libexec/postgres/start.sh new file mode 100755 index 0000000..3d384ed --- /dev/null +++ b/hassio-addons/postgres/rootfs/usr/libexec/postgres/start.sh @@ -0,0 +1,32 @@ +#!/usr/bin/with-contenv bashio +# ======================================================= +# 1 - Start the PostgreSQL database +# 2 - Trap stop signals to properly stop the database +# 3 - Delegate execution to configuration application +# ======================================================= + +# Start the database +bashio::log.info "Starting PostgreSQL..." +postgres & +POSTGRES_PID=$! + +# Wait until DB is running +while ! psql -c '' 2> /dev/null; do + sleep 1 +done +bashio::log.info "PostgreSQL database started." + +# Register stop +function stop_postgres() { + pg_ctl stop -m smart + # Successful exit, avoid wait exit status to propagate + exit 0 +} +trap "stop_postgres" SIGTERM SIGHUP + +# Apply database configuration +/usr/libexec/postgres/config.sh + +# Wait for process to end +bashio::log.info "Waiting for PostgreSQL termination..." +wait "${POSTGRES_PID}" diff --git a/hassio-addons/postgres/translations/en.yaml b/hassio-addons/postgres/translations/en.yaml new file mode 100644 index 0000000..0a999ee --- /dev/null +++ b/hassio-addons/postgres/translations/en.yaml @@ -0,0 +1,12 @@ +configuration: + databases: + name: Databases + description: Database names. + logins: + name: Logins + description: This section defines a create user definition in PostgreSQL. + rights: + name: Rights + description: This section grant privileges to users in PostgreSQL. +network: + 5432/tcp: The port to access the database engine. diff --git a/hassio-addons/repository.yaml b/hassio-addons/repository.yaml new file mode 100644 index 0000000..d7e78d8 --- /dev/null +++ b/hassio-addons/repository.yaml @@ -0,0 +1,3 @@ +name: Ezlo's custom Home Assistant addons +url: "https://github.com/ezlo-picori/hassio-addons" +maintainer: Ezlo Picori diff --git a/kresus-mrraph-test/CHANGELOG.md b/kresus-mrraph-test/CHANGELOG.md new file mode 100644 index 0000000..1e4983e --- /dev/null +++ b/kresus-mrraph-test/CHANGELOG.md @@ -0,0 +1,37 @@ +## 0.6.2 + +- Update woob dependencies install method + +## 0.6.1 + +- Remove support for i386 architecture + +## 0.6.0 + +- Bump Kresus to 0.19.0 + +## 0.5.1 + +- Fix AppArmor profile + +## 0.5.0 + +- Attempt using `alpine:edge` as base image + +## 0.4.2 + +- Fix AppArmor profile + +## 0.4.1 + +- Reinstall py3-lxml by default + +## 0.4.0 + +- Remove python dependencies from Dockerfile to prevent + incompatibility with woob requirements + +## 0.3.0 + +- Use `s6-setuidgid` instead of `su-exec` +- Set AppArmor in complain mode diff --git a/kresus-mrraph-test/DOCS.md b/kresus-mrraph-test/DOCS.md new file mode 100644 index 0000000..a6484b0 --- /dev/null +++ b/kresus-mrraph-test/DOCS.md @@ -0,0 +1,54 @@ +# Home Assistant Custom Add-on: Kresus + +[Kresus](https://kresus.org/) is an open-source self-hostable Personal Finance Manager. +It automatically retrieves your daily bank transactions, lets you categorize them and manage your monthly budgets. + +It relies on [woob](https://gitlab.com/woob/woob) to fetch data from your bank website. + +## Installation + +Kresus requires a PostgreSQL database to store data. +If you do not already have a PostgreSQL database installed, you may consider the [PostgreSQL addon](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres). + +The installation of Kresus add-on is quite straightforward and do not differ from the standard installation process for Home-Assistant add-ons: + +1. Click the Home Assistant My button below to open the add-on on your Home + Assistant instance. + + [![Open this add-on in your Home Assistant instance.][addon-badge]][addon] + +1. Click the "Install" button to install the add-on. +1. Start the "Kresus" add-on. +1. Check the logs of the "Kresus" add-on to see if everything + went well. A working installation should indicate `Server is ready, let's start the show!` +1. Click the "OPEN WEB UI" button to open Kresus UI. + +## Configuration + +The only configuration configurations required are the database connection options. +If you used the [PostgreSQL add-on](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres) configured with following options: + +```yaml +databases: + - kresus_db +logins: + - password: CHANGEME_kr3sus-p@ssword_CHANGEME + username: kresus_user +rights: + - database: kresus_db + username: kresus_user +``` + +then you may configure kresus with these options: + +```yaml +postgres_hostname: homeassistant.local +postgres_port: 5432 +postgres_user: kresus_user +postgres_password: CHANGEME_kr3sus-p@ssword_CHANGEME +postgres_database: kresus_db +``` + +## Authors & contributors + +The original setup of this repository is by [Ezlo Picori](https://github.com/ezlo-picori). diff --git a/kresus-mrraph-test/Dockerfile b/kresus-mrraph-test/Dockerfile new file mode 100644 index 0000000..ff92201 --- /dev/null +++ b/kresus-mrraph-test/Dockerfile @@ -0,0 +1,39 @@ +FROM node:lts-bookworm-slim + +ENV LANG="C.UTF-8" + +# Install Weboob OS-level dependencies. +RUN apt-get update \ +&& apt-get install -y git python3 python3-dev libffi-dev \ + libxml2-dev libxslt-dev libyaml-dev libtiff-dev libjpeg-dev zlib1g-dev \ + libfreetype6-dev libwebp-dev build-essential gcc g++ wget mupdf-tools \ + python3-pip \ + && rm -rf /var/lib/apt/lists/ + +# Install Weboob python dependencies +RUN mkdir /tmp/install && cd /tmp/install +#RUN $(which pip) install --upgrade setuptools +RUN pip install html2text simplejson BeautifulSoup PyExecJS pdfminer python-jose +RUN rm -rf /tmp/install + +# Setup kresus layout. +RUN useradd -d /home/kreseus -m -s /bin/bash -U user && \ + mkdir -p /data/kreseus && \ + mkdir -p /data/weboob && \ + npm install -g --production kresus; + +# Run server. +ENV HOST 0.0.0.0 +ENV KRESUS_DIR /data/kreseus +ENV KRESUS_WEBOOB_DIR /data/weboob +ENV NODE_ENV production + +EXPOSE 9876 + +COPY ./config.example.ini /opt/config.ini +RUN chmod -x /opt/config.ini +COPY ./docker/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["kresus --config /opt/config.ini"] diff --git a/kresus-mrraph-test/README.md b/kresus-mrraph-test/README.md new file mode 100644 index 0000000..d20aef7 --- /dev/null +++ b/kresus-mrraph-test/README.md @@ -0,0 +1,25 @@ +# Home Assistant Add-on: Kresus + +Open source personal accounting solution. + +![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] + +## About + +[Kresus][kresus] is a free solution for personal accounting management. +It automatically retrieves your daily bank transactions, lets you categorize them +and manage your monthly budgets. + +![Kresus Preview][screenshot] + +[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 +[i386-shield]: https://img.shields.io/badge/i386-no-red.svg +[screenshot]: https://kresus.org/images/pages/view-all-accounts.png +[kresus]: https://kresus.org/ diff --git a/kresus-mrraph-test/build.yaml b/kresus-mrraph-test/build.yaml new file mode 100644 index 0000000..f5f795f --- /dev/null +++ b/kresus-mrraph-test/build.yaml @@ -0,0 +1,12 @@ +build_from: + aarch64: "node:lts-bookworm-slim" +labels: + org.opencontainers.image.title: "Home Assistant Add-on: Kresus Local TEST" + org.opencontainers.image.description: "Kresus Local TEST addon" + org.opencontainers.image.licenses: "MIT License" + io.hass.base.name: alpine +args: + BASHIO_VERSION: 0.14.3 + TEMPIO_VERSION: 2021.09.0 + S6_OVERLAY_VERSION: 3.1.3.0 + JEMALLOC_VERSION: 5.3.0 diff --git a/kresus-mrraph-test/config.yaml b/kresus-mrraph-test/config.yaml new file mode 100644 index 0000000..fb5bc81 --- /dev/null +++ b/kresus-mrraph-test/config.yaml @@ -0,0 +1,30 @@ +name: Kresus Local TEST +version: "0.6.2" +slug: kresuslocaltest +description: Open source personal accounting management +arch: + - armhf + - armv7 + - aarch64 + - amd64 +init: false +options: + postgres_hostname: homeassistant.local + postgres_port: 5432 + postgres_user: kresus + postgres_password: null + postgres_database: kresus +panel_icon: mdi:piggy-bank-outline +ports: + 9876/tcp: 9876 +ports_description: + 9876/tcp: "The port to access kresus web server." +schema: + postgres_hostname: str + postgres_port: int + postgres_user: str + postgres_password: password + postgres_database: str + http_basicauth: str? +startup: system +timeout: 20 diff --git a/kresus-mrraph-test/icon.png b/kresus-mrraph-test/icon.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/kresus-mrraph-test/icon.png differ diff --git a/kresus-mrraph-test/logo.png b/kresus-mrraph-test/logo.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/kresus-mrraph-test/logo.png differ diff --git a/kresus-mrraph-test/requirements.txt b/kresus-mrraph-test/requirements.txt new file mode 100644 index 0000000..40ff3e1 --- /dev/null +++ b/kresus-mrraph-test/requirements.txt @@ -0,0 +1 @@ +python-jose \ No newline at end of file diff --git a/kresus-mrraph-test/start.sh b/kresus-mrraph-test/start.sh new file mode 100755 index 0000000..77715b5 --- /dev/null +++ b/kresus-mrraph-test/start.sh @@ -0,0 +1,56 @@ +#!/usr/bin/with-contenv bashio +bashio::log.info "Custom Start script" +WOOB_DIR="/woob" +KRESUS_INI_FILE="/etc/kresus/config.ini" + +# ============================================================================== +# Pull latest Woob version +# ============================================================================== +cd "${WOOB_DIR}" || bashio::exit.nok + +#bashio::log.info "Clear woob install" +#rm -rf {,.[!.],..?}* + +#bashio::log.info "Add clean woob install" +#wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 + +#bashio::log.info "Updating Woob dependencies..." +#pip3 install --no-cache-dir --prefix .py-deps . +PYTHONPATH=$(python3 -c "import sys, os; print(os.sep.join(['$(pwd)', '.py-deps', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages']))") +export PYTHONPATH +bashio::log.info "Done updating Woob dependencies." + +# ============================================================================== +# Set-up environment variables +# ============================================================================== + +# Basic Kresus options +export PORT=9876 +export HOST=0.0.0.0 +export KRESUS_PYTHON_EXEC=python3 +export KRESUS_WOOB_DIR="${WOOB_DIR}" + +KRESUS_SALT="$(cat /data/kresus_salt)" +export KRESUS_SALT + +# Kresus Basic auth +if bashio::config.has_value 'http_basicauth'; then + KRESUS_AUTH="$(bashio::config 'http_basicauth')" + export KRESUS_AUTH +fi + +# Kresus database +export KRESUS_DB_TYPE="postgres" + +KRESUS_DB_HOST="$(bashio::config 'postgres_hostname')" +KRESUS_DB_PORT="$(bashio::config 'postgres_port')" +KRESUS_DB_USERNAME="$(bashio::config 'postgres_user')" +KRESUS_DB_PASSWORD="$(bashio::config 'postgres_password')" +KRESUS_DB_NAME="$(bashio::config 'postgres_database')" +export KRESUS_DB_HOST KRESUS_DB_PORT KRESUS_DB_USERNAME \ + KRESUS_DB_PASSWORD KRESUS_DB_NAME + +# ============================================================================== +# Start Kresus +# ============================================================================== +kresus -c ${KRESUS_INI_FILE} diff --git a/kresus-mrraph-test/start.sh.ori b/kresus-mrraph-test/start.sh.ori new file mode 100755 index 0000000..a03d20d --- /dev/null +++ b/kresus-mrraph-test/start.sh.ori @@ -0,0 +1,55 @@ +#!/usr/bin/with-contenv bashio +WOOB_DIR="/woob" +KRESUS_INI_FILE="/etc/kresus/config.ini" + +# ============================================================================== +# Pull latest Woob version +# ============================================================================== +cd "${WOOB_DIR}" || bashio::exit.nok + +bashio::log.info "Clear woob install" +rm -rf {,.[!.],..?}* + +bashio::log.info "Add clean woob install" +wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 + +bashio::log.info "Updating Woob dependencies..." +pip3 install --no-cache-dir --prefix .py-deps . +PYTHONPATH=$(python3 -c "import sys, os; print(os.sep.join(['$(pwd)', '.py-deps', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages']))") +export PYTHONPATH +bashio::log.info "Done updating Woob dependencies." + +# ============================================================================== +# Set-up environment variables +# ============================================================================== + +# Basic Kresus options +export PORT=9876 +export HOST=0.0.0.0 +export KRESUS_PYTHON_EXEC=python3 +export KRESUS_WOOB_DIR="${WOOB_DIR}" + +KRESUS_SALT="$(cat /data/kresus_salt)" +export KRESUS_SALT + +# Kresus Basic auth +if bashio::config.has_value 'http_basicauth'; then + KRESUS_AUTH="$(bashio::config 'http_basicauth')" + export KRESUS_AUTH +fi + +# Kresus database +export KRESUS_DB_TYPE="postgres" + +KRESUS_DB_HOST="$(bashio::config 'postgres_hostname')" +KRESUS_DB_PORT="$(bashio::config 'postgres_port')" +KRESUS_DB_USERNAME="$(bashio::config 'postgres_user')" +KRESUS_DB_PASSWORD="$(bashio::config 'postgres_password')" +KRESUS_DB_NAME="$(bashio::config 'postgres_database')" +export KRESUS_DB_HOST KRESUS_DB_PORT KRESUS_DB_USERNAME \ + KRESUS_DB_PASSWORD KRESUS_DB_NAME + +# ============================================================================== +# Start Kresus +# ============================================================================== +kresus -c ${KRESUS_INI_FILE} diff --git a/kresus-mrraph-test/translations/en.yaml b/kresus-mrraph-test/translations/en.yaml new file mode 100644 index 0000000..a9aa6a8 --- /dev/null +++ b/kresus-mrraph-test/translations/en.yaml @@ -0,0 +1,27 @@ +configuration: + postgres_hostname: + name: "DB hostname" + description: >- + Hostname of the PostgreSQL database. + postgres_port: + name: "DB port" + description: >- + Port of the PostgreSQL database. + postgres_user: + name: "DB user" + description: >- + User to connect to the database. + postgres_password: + name: "DB password" + description: >- + Password of the database user. + postgres_database: + name: "DB database" + description: >- + Name of the kresus database. + http_basicauth: + name: "Authentication" + description: >- + Logins for HTTP basic auth authentication ("login:passwd" format, optional). +network: + 9876/tcp: Port to access kresus web server. diff --git a/kresus-mrraph/CHANGELOG.md b/kresus-mrraph/CHANGELOG.md new file mode 100644 index 0000000..1e4983e --- /dev/null +++ b/kresus-mrraph/CHANGELOG.md @@ -0,0 +1,37 @@ +## 0.6.2 + +- Update woob dependencies install method + +## 0.6.1 + +- Remove support for i386 architecture + +## 0.6.0 + +- Bump Kresus to 0.19.0 + +## 0.5.1 + +- Fix AppArmor profile + +## 0.5.0 + +- Attempt using `alpine:edge` as base image + +## 0.4.2 + +- Fix AppArmor profile + +## 0.4.1 + +- Reinstall py3-lxml by default + +## 0.4.0 + +- Remove python dependencies from Dockerfile to prevent + incompatibility with woob requirements + +## 0.3.0 + +- Use `s6-setuidgid` instead of `su-exec` +- Set AppArmor in complain mode diff --git a/kresus-mrraph/DOCS.md b/kresus-mrraph/DOCS.md new file mode 100644 index 0000000..a6484b0 --- /dev/null +++ b/kresus-mrraph/DOCS.md @@ -0,0 +1,54 @@ +# Home Assistant Custom Add-on: Kresus + +[Kresus](https://kresus.org/) is an open-source self-hostable Personal Finance Manager. +It automatically retrieves your daily bank transactions, lets you categorize them and manage your monthly budgets. + +It relies on [woob](https://gitlab.com/woob/woob) to fetch data from your bank website. + +## Installation + +Kresus requires a PostgreSQL database to store data. +If you do not already have a PostgreSQL database installed, you may consider the [PostgreSQL addon](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres). + +The installation of Kresus add-on is quite straightforward and do not differ from the standard installation process for Home-Assistant add-ons: + +1. Click the Home Assistant My button below to open the add-on on your Home + Assistant instance. + + [![Open this add-on in your Home Assistant instance.][addon-badge]][addon] + +1. Click the "Install" button to install the add-on. +1. Start the "Kresus" add-on. +1. Check the logs of the "Kresus" add-on to see if everything + went well. A working installation should indicate `Server is ready, let's start the show!` +1. Click the "OPEN WEB UI" button to open Kresus UI. + +## Configuration + +The only configuration configurations required are the database connection options. +If you used the [PostgreSQL add-on](https://github.com/ezlo-picori/hassio-addons/tree/main/postgres) configured with following options: + +```yaml +databases: + - kresus_db +logins: + - password: CHANGEME_kr3sus-p@ssword_CHANGEME + username: kresus_user +rights: + - database: kresus_db + username: kresus_user +``` + +then you may configure kresus with these options: + +```yaml +postgres_hostname: homeassistant.local +postgres_port: 5432 +postgres_user: kresus_user +postgres_password: CHANGEME_kr3sus-p@ssword_CHANGEME +postgres_database: kresus_db +``` + +## Authors & contributors + +The original setup of this repository is by [Ezlo Picori](https://github.com/ezlo-picori). diff --git a/kresus-mrraph/Dockerfile b/kresus-mrraph/Dockerfile new file mode 100644 index 0000000..54acad6 --- /dev/null +++ b/kresus-mrraph/Dockerfile @@ -0,0 +1,19 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +COPY requirements.txt /requirements.txt +COPY start.sh /usr/libexec/kresus/start.sh + +# Addintional Python Libs +RUN pip install -r /requirements.txt && \ + npm install --omit=dev -g kresus@0.20.0 && \ + cd /woob && \ + rm -rf {,.[!.],..?}* && \ + wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 && \ + pip3 install --no-cache-dir --prefix .py-deps . && \ + chown -R kresus:kresus /woob && \ + chown -R kresus:kresus /etc/kresus && \ + chown -R kresus:kresus .py-deps woob .ci .gitlab modules tests tools woob.egg-info man weboob icons docs && \ + chmod 0400 /etc/kresus/config.ini && \ + chmod 0755 /etc/kresus && \ + rm -rf {,.[!.],..?}* \ No newline at end of file diff --git a/kresus-mrraph/README.md b/kresus-mrraph/README.md new file mode 100644 index 0000000..d20aef7 --- /dev/null +++ b/kresus-mrraph/README.md @@ -0,0 +1,25 @@ +# Home Assistant Add-on: Kresus + +Open source personal accounting solution. + +![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] + +## About + +[Kresus][kresus] is a free solution for personal accounting management. +It automatically retrieves your daily bank transactions, lets you categorize them +and manage your monthly budgets. + +![Kresus Preview][screenshot] + +[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 +[i386-shield]: https://img.shields.io/badge/i386-no-red.svg +[screenshot]: https://kresus.org/images/pages/view-all-accounts.png +[kresus]: https://kresus.org/ diff --git a/kresus-mrraph/build.yaml b/kresus-mrraph/build.yaml new file mode 100644 index 0000000..2da25fa --- /dev/null +++ b/kresus-mrraph/build.yaml @@ -0,0 +1,12 @@ +build_from: + aarch64: "ghcr.io/ezlo-picori/haos-addon-kresus-aarch64:latest" +labels: + org.opencontainers.image.title: "Home Assistant Add-on: Kresus Local" + org.opencontainers.image.description: "Kresus Local addon" + org.opencontainers.image.licenses: "MIT License" + io.hass.base.name: alpine +args: + BASHIO_VERSION: 0.14.3 + TEMPIO_VERSION: 2021.09.0 + S6_OVERLAY_VERSION: 3.1.3.0 + JEMALLOC_VERSION: 5.3.0 diff --git a/kresus-mrraph/config.yaml b/kresus-mrraph/config.yaml new file mode 100644 index 0000000..3c4dc02 --- /dev/null +++ b/kresus-mrraph/config.yaml @@ -0,0 +1,30 @@ +name: Kresus Local +version: "0.6.2" +slug: kresuslocal +description: Open source personal accounting management +arch: + - armhf + - armv7 + - aarch64 + - amd64 +init: false +options: + postgres_hostname: homeassistant.local + postgres_port: 5432 + postgres_user: kresus + postgres_password: null + postgres_database: kresus +panel_icon: mdi:piggy-bank-outline +ports: + 9876/tcp: 9876 +ports_description: + 9876/tcp: "The port to access kresus web server." +schema: + postgres_hostname: str + postgres_port: int + postgres_user: str + postgres_password: password + postgres_database: str + http_basicauth: str? +startup: system +timeout: 20 diff --git a/kresus-mrraph/icon.png b/kresus-mrraph/icon.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/kresus-mrraph/icon.png differ diff --git a/kresus-mrraph/logo.png b/kresus-mrraph/logo.png new file mode 100644 index 0000000..df04d0d Binary files /dev/null and b/kresus-mrraph/logo.png differ diff --git a/kresus-mrraph/requirements.txt b/kresus-mrraph/requirements.txt new file mode 100644 index 0000000..40ff3e1 --- /dev/null +++ b/kresus-mrraph/requirements.txt @@ -0,0 +1 @@ +python-jose \ No newline at end of file diff --git a/kresus-mrraph/start.sh b/kresus-mrraph/start.sh new file mode 100755 index 0000000..77715b5 --- /dev/null +++ b/kresus-mrraph/start.sh @@ -0,0 +1,56 @@ +#!/usr/bin/with-contenv bashio +bashio::log.info "Custom Start script" +WOOB_DIR="/woob" +KRESUS_INI_FILE="/etc/kresus/config.ini" + +# ============================================================================== +# Pull latest Woob version +# ============================================================================== +cd "${WOOB_DIR}" || bashio::exit.nok + +#bashio::log.info "Clear woob install" +#rm -rf {,.[!.],..?}* + +#bashio::log.info "Add clean woob install" +#wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 + +#bashio::log.info "Updating Woob dependencies..." +#pip3 install --no-cache-dir --prefix .py-deps . +PYTHONPATH=$(python3 -c "import sys, os; print(os.sep.join(['$(pwd)', '.py-deps', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages']))") +export PYTHONPATH +bashio::log.info "Done updating Woob dependencies." + +# ============================================================================== +# Set-up environment variables +# ============================================================================== + +# Basic Kresus options +export PORT=9876 +export HOST=0.0.0.0 +export KRESUS_PYTHON_EXEC=python3 +export KRESUS_WOOB_DIR="${WOOB_DIR}" + +KRESUS_SALT="$(cat /data/kresus_salt)" +export KRESUS_SALT + +# Kresus Basic auth +if bashio::config.has_value 'http_basicauth'; then + KRESUS_AUTH="$(bashio::config 'http_basicauth')" + export KRESUS_AUTH +fi + +# Kresus database +export KRESUS_DB_TYPE="postgres" + +KRESUS_DB_HOST="$(bashio::config 'postgres_hostname')" +KRESUS_DB_PORT="$(bashio::config 'postgres_port')" +KRESUS_DB_USERNAME="$(bashio::config 'postgres_user')" +KRESUS_DB_PASSWORD="$(bashio::config 'postgres_password')" +KRESUS_DB_NAME="$(bashio::config 'postgres_database')" +export KRESUS_DB_HOST KRESUS_DB_PORT KRESUS_DB_USERNAME \ + KRESUS_DB_PASSWORD KRESUS_DB_NAME + +# ============================================================================== +# Start Kresus +# ============================================================================== +kresus -c ${KRESUS_INI_FILE} diff --git a/kresus-mrraph/start.sh.ori b/kresus-mrraph/start.sh.ori new file mode 100755 index 0000000..a03d20d --- /dev/null +++ b/kresus-mrraph/start.sh.ori @@ -0,0 +1,55 @@ +#!/usr/bin/with-contenv bashio +WOOB_DIR="/woob" +KRESUS_INI_FILE="/etc/kresus/config.ini" + +# ============================================================================== +# Pull latest Woob version +# ============================================================================== +cd "${WOOB_DIR}" || bashio::exit.nok + +bashio::log.info "Clear woob install" +rm -rf {,.[!.],..?}* + +bashio::log.info "Add clean woob install" +wget -qO- https://gitlab.com/woob/woob/-/archive/master/woob-master.tar.gz | tar xz --strip-components=1 + +bashio::log.info "Updating Woob dependencies..." +pip3 install --no-cache-dir --prefix .py-deps . +PYTHONPATH=$(python3 -c "import sys, os; print(os.sep.join(['$(pwd)', '.py-deps', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages']))") +export PYTHONPATH +bashio::log.info "Done updating Woob dependencies." + +# ============================================================================== +# Set-up environment variables +# ============================================================================== + +# Basic Kresus options +export PORT=9876 +export HOST=0.0.0.0 +export KRESUS_PYTHON_EXEC=python3 +export KRESUS_WOOB_DIR="${WOOB_DIR}" + +KRESUS_SALT="$(cat /data/kresus_salt)" +export KRESUS_SALT + +# Kresus Basic auth +if bashio::config.has_value 'http_basicauth'; then + KRESUS_AUTH="$(bashio::config 'http_basicauth')" + export KRESUS_AUTH +fi + +# Kresus database +export KRESUS_DB_TYPE="postgres" + +KRESUS_DB_HOST="$(bashio::config 'postgres_hostname')" +KRESUS_DB_PORT="$(bashio::config 'postgres_port')" +KRESUS_DB_USERNAME="$(bashio::config 'postgres_user')" +KRESUS_DB_PASSWORD="$(bashio::config 'postgres_password')" +KRESUS_DB_NAME="$(bashio::config 'postgres_database')" +export KRESUS_DB_HOST KRESUS_DB_PORT KRESUS_DB_USERNAME \ + KRESUS_DB_PASSWORD KRESUS_DB_NAME + +# ============================================================================== +# Start Kresus +# ============================================================================== +kresus -c ${KRESUS_INI_FILE} diff --git a/kresus-mrraph/translations/en.yaml b/kresus-mrraph/translations/en.yaml new file mode 100644 index 0000000..a9aa6a8 --- /dev/null +++ b/kresus-mrraph/translations/en.yaml @@ -0,0 +1,27 @@ +configuration: + postgres_hostname: + name: "DB hostname" + description: >- + Hostname of the PostgreSQL database. + postgres_port: + name: "DB port" + description: >- + Port of the PostgreSQL database. + postgres_user: + name: "DB user" + description: >- + User to connect to the database. + postgres_password: + name: "DB password" + description: >- + Password of the database user. + postgres_database: + name: "DB database" + description: >- + Name of the kresus database. + http_basicauth: + name: "Authentication" + description: >- + Logins for HTTP basic auth authentication ("login:passwd" format, optional). +network: + 9876/tcp: Port to access kresus web server.