1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
This commit is contained in:
ewilly 2022-01-08 10:04:57 +01:00
parent 8a3629278b
commit bbd876be99
31 changed files with 1977 additions and 0 deletions

55
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,55 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!*
- *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
### Describe the bug
*A clear and concise description of what the bug is.*
### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install the_app
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '...'*
3. *Scroll down to '...'*
4. *See error*
### Expected behavior
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

23
.github/workflows/package_linter.yml vendored Normal file
View file

@ -0,0 +1,23 @@
name: YunoHost apps package linter
on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 8 * * *'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 'Clone YunoHost apps package linter'
run: |
git clone --depth=1 https://github.com/YunoHost/package_linter ~/package_linter
- name: 'Run linter'
run: |
~/package_linter/package_linter.py .

59
.github/workflows/updater.sh vendored Normal file
View file

@ -0,0 +1,59 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
# Remove this exit command when you are ready to run this Action
exit 1
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
app=$(cat manifest.json | jq -j '.id')
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
upstream_version=$(curl -Ls https://pypi.org/pypi/$pythonPackage/json | jq -r .info.version)
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $upstream_version"
echo "VERSION=$upstream_version" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV
# Proceed only if the retrieved version is greater than the current one
if ! dpkg --compare-versions "$current_version" "lt" "$upstream_version" ; then
echo "::warning ::No new version available"
exit 0
# Proceed only if a PR for this new version does not already exist
elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$upstream_version ; then
echo "::warning ::A branch already exists for this update"
exit 0
fi
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# Replace new version in _common.sh
sed -i "s/app_version=.*/app_version=$upstream_version/" scripts/_common.sh
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$upstream_version~ynh1\"" manifest.json)" > manifest.json
# No need to update the README, yunohost-bot takes care of it
# The Action will proceed only if the PROCEED environment variable is set to true
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

49
.github/workflows/updater.yml vendored Normal file
View file

@ -0,0 +1,49 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every day at 6:00 UTC
schedule:
- cron: '0 6 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to v$VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update to version ${{ env.VERSION }}
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
base: testing
branch: ci-auto-update-v${{ env.VERSION }}
delete-branch: true
title: 'Upgrade to version ${{ env.VERSION }}'
body: |
Upgrade to v${{ env.VERSION }}
draft: false

201
LICENSE Normal file
View file

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

56
README.md Normal file
View file

@ -0,0 +1,56 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# Home Assistant for YunoHost
[![Integration level](https://dash.yunohost.org/integration/homeassistant.svg)](https://dash.yunohost.org/appci/app/homeassistant) ![](https://ci-apps.yunohost.org/ci/badges/homeassistant.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/homeassistant.maintain.svg)
[![Install Home Assistant with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=homeassistant)
*[Lire ce readme en français.](./README_fr.md)*
> *This package allows you to install Home Assistant quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview
Home automation platform
**Shipped version:** 2021.12.8~ynh1
**Demo:** https://demo.home-assistant.io
## Screenshots
![](./doc/screenshots/screenshot1)
## Disclaimers / important information
* Known limitations:
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes
* Additional informations:
* As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes)
## Documentation and resources
* Official app website: https://www.home-assistant.io
* Official admin documentation: https://www.home-assistant.io/docs/
* YunoHost documentation for this app: https://yunohost.org/app_homeassistant
* Report a bug: https://github.com/YunoHost-Apps/homeassistant_ynh/issues
## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
or
sudo yunohost app upgrade homeassistant -u https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
```
**More info regarding app packaging:** https://yunohost.org/packaging_apps

52
README_fr.md Normal file
View file

@ -0,0 +1,52 @@
# Home Assistant pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/homeassistant.svg)](https://dash.yunohost.org/appci/app/homeassistant) ![](https://ci-apps.yunohost.org/ci/badges/homeassistant.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/homeassistant.maintain.svg)
[![Installer Home Assistant avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=homeassistant)
*[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer Home Assistant rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
## Vue d'ensemble
Plateforme domotique
**Version incluse :** 2021.12.8~ynh1
**Démo :** https://demo.home-assistant.io
## Captures d'écran
![](./doc/screenshots/screenshot1)
## Avertissements / informations importantes
* Known limitations:
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes
* Additional informations:
* As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes)
## Documentations et ressources
* Site officiel de l'app : https://www.home-assistant.io
* Documentation officielle de l'admin : https://www.home-assistant.io/docs/
* Documentation YunoHost pour cette app : https://yunohost.org/app_homeassistant
* Signaler un bug : https://github.com/YunoHost-Apps/homeassistant_ynh/issues
## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
```
sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
ou
sudo yunohost app upgrade homeassistant -u https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps

23
check_process Normal file
View file

@ -0,0 +1,23 @@
;; Test complet
; Manifest
domain="domain.tld"
is_public=1
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=4eaade48e9bdccf56a53f09a269b2e5ba7621296
backup_restore=1
multi_instance=0
port_already_use=1
change_url=1
;;; Options
Notification=all
;;; Upgrade options
; commit=4eaade48e9bdccf56a53f09a269b2e5ba7621296
name= Update to 2021.6.5 on 21/06/2021
manifest_arg=domain=DOMAIN&is_public=1&

View file

@ -0,0 +1,12 @@
{
"version": 4,
"key": "onboarding",
"data": {
"done": [
"user",
"core_config",
"analytics",
"integration"
]
}
}

View file

@ -0,0 +1,62 @@
#!/bin/bash
#
# upgrade_homeassistant.sh - Simple shell script to upgrade homeassistant installed in a python environnement
#
# Uncomment to enable debugging to stderr (prints full client output and more)
DEBUG=0
# define usefull variables
app="homeassistant"
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
########## END OF CONFIGURATION ##########
########## SCRIPT CODE FOLLOWS, DON'T TOUCH! ##########
# Log messages to log file.
log() {
echo "$(date)\t$1" >> $LOG_FILE
}
has_sudo() {
local prompt
prompt=$(sudo -nv 2>&1)
if [ $? -eq 0 ]; then
echo "has sudo pass set"
elif echo $prompt | grep -q '^sudo:'; then
echo "has sudo needs pass"
else
echo "can't sudo"
fi
}
# Reset log file.
if [ ! -z "$DEBUG" ]; then
LOG_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/upgrade_homeassistant.log"
[ -f "$LOG_FILE" ] && :> "$LOG_FILE"
fi
# Check User and permissions
[ ! -z "$DEBUG" ] && log "User '$(whoami)' is running that script and '$(has_sudo)'."
# create the virtual environment
MY_PYTHON=$(readlink -e "$final_path/bin/python")
[ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'."
$MY_PYTHON -m venv "$final_path"
# activate the virtual environment
source "$final_path/bin/activate"
# install last version of wheel
pip --cache-dir "$data_path/.cache" install --upgrade wheel
# upgrade homeassistant python package
pip --cache-dir "$data_path/.cache" install --upgrade $app
# restart homeassistant systemd service
sudo systemctl restart $app.service
exit 0

View file

@ -0,0 +1,148 @@
#!/bin/sh
#
# ldap-auth.sh - Simple shell script to authenticate users against LDAP
#
# Uncomment to enable debugging to stderr (prints full client output
# and more).
#DEBUG=1
# Must be one of "curl" and "ldapsearch".
# NOTE:
# - When choosing "curl", make sure "curl --version | grep ldap" outputs
# something. Otherwise, curl was compiled without LDAP support.
# - When choosing "ldapsearch", make sure the ldapwhoami command is
# available as well, as that might be needed in some cases.
CLIENT="ldapsearch"
# Usernames should be validated using a regular expression to be of
# a known format. Special characters will be escaped anyway, but it is
# generally not recommended to allow more than necessary.
# This pattern is set by default. In your config file, you can either
# overwrite it with a different one or use "unset USERNAME_PATTERN" to
# disable validation completely.
USERNAME_PATTERN='^[a-z|A-Z|0-9|_|-|.]+$'
# Adapt to your needs.
SERVER="ldap://127.0.0.1:389"
USERDN="uid=$username,ou=users,dc=yunohost,dc=org"
BASEDN="$USERDN"
SCOPE="base"
FILTER="(&(uid=$username)(objectClass=posixAccount))"
NAME_ATTR="cn"
ATTRS="$ATTRS $NAME_ATTR"
# When the timeout (in seconds) is exceeded (e.g. due to slow networking),
# authentication fails.
TIMEOUT=3
########## END OF CONFIGURATION ##########
########## SCRIPT CODE FOLLOWS, DON'T TOUCH! ##########
# Log messages to log file.
log() {
echo "$(date)\t$1" >> $LOG_FILE
}
# Check permission of ynh user.
ynh_user_app_permission() {
access=$(cat "/etc/ssowat/conf.json" | jq ".permissions.\"homeassistant.main\".users | index(\"$username\")")
[ ! -z "$access" ] && return 1
return 0
}
ldap_auth_ldapsearch() {
common_opts="-o nettimeout=$TIMEOUT -H $SERVER -x"
[ ! -z "$DEBUG" ] && common_opts="-v $common_opts"
output=$(ldapsearch $common_opts -LLL \
-D "$USERDN" -w "$password" \
-s "$SCOPE" -b "$BASEDN" "$FILTER" dn $ATTRS)
[ $? -ne 0 ] && return 1
return 0
}
on_auth_success() {
# print the meta entries for use in HA
if [ ! -z "$NAME_ATTR" ]; then
name=$(echo "$output" | sed -nr "s/^\s*$NAME_ATTR:\s*(.+)\s*\$/\1/Ip")
[ -z "$name" ] || echo "name=$name"
fi
}
# Reset log file.
if [ ! -z "$DEBUG" ]; then
LOG_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/ldap-auth.log"
[ -f "$LOG_FILE" ] && :> "$LOG_FILE"
fi
# Check app access permisssion for the ynh user.
ynh_user_app_permission
if [ $? -eq 0 ]; then
[ ! -z "$DEBUG" ] && log "User '$username' does not have the permission to access these app."
exit 1
else
[ ! -z "$DEBUG" ] && log "User '$username' have the permission to access these app."
fi
# Validate config.
err=0
if [ -z "$SERVER" ] || [ -z "$USERDN" ]; then
[ ! -z "$DEBUG" ] && log "SERVER and USERDN need to be configured."
err=1
fi
if [ -z "$TIMEOUT" ]; then
[ ! -z "$DEBUG" ] && log "TIMEOUT needs to be configured."
err=1
fi
if [ ! -z "$BASEDN" ]; then
if [ -z "$SCOPE" ] || [ -z "$FILTER" ]; then
[ ! -z "$DEBUG" ] && log "BASEDN, SCOPE and FILTER may only be configured together."
err=1
fi
elif [ ! -z "$ATTRS" ]; then
[ ! -z "$DEBUG" ] && log "Configuring ATTRS only makes sense when enabling searching."
err=1
fi
# Check username and password are present and not malformed.
if [ -z "$username" ] || [ -z "$password" ]; then
[ ! -z "$DEBUG" ] && log "Need username and password environment variables."
err=1
elif [ ! -z "$USERNAME_PATTERN" ]; then
username_match=$(echo "$username" | sed -r "s/$USERNAME_PATTERN/x/")
if [ "$username_match" != "x" ]; then
[ ! -z "$DEBUG" ] && log "Username '$username' has an invalid format."
err=1
fi
fi
[ $err -ne 0 ] && exit 2
# Do the authentication.
ldap_auth_ldapsearch
result=$?
entries=0
if [ $result -eq 0 ]; then
entries=$(echo "$output" | grep -cie '^dn\s*:')
[ "$entries" != "1" ] && result=1
fi
if [ ! -z "$DEBUG" ]; then
log "Result: $result"
log "Number of entries: $entries"
log "Client output:"
log "$output"
fi
if [ $result -ne 0 ]; then
[ ! -z "$DEBUG" ] && log "User '$username' failed to authenticate."
type on_auth_failure > /dev/null && on_auth_failure
exit 1
fi
[ ! -z "$DEBUG" ] && log "User '$username' authenticated successfully."
type on_auth_success > /dev/null && on_auth_success
exit 0

View file

@ -0,0 +1,31 @@
homeassistant:
auth_providers:
- type: command_line
command: __DATA_PATH__/bin/ynh_ldap-auth.sh
meta: true
http:
server_port: __PORT__
use_x_forwarded_for: True
trusted_proxies:
- 127.0.0.1
- ::1
recorder:
db_url: mysql://__DB_USER__:__DB_PWD__@127.0.0.1/__DB_NAME__?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4
# Apply default set of integrations
default_config:
# Linked yaml files
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Switches
switch:
- platform: command_line
switches:
upgrade_homeassistant:
command_on: "nohup bash -c __DATA_PATH__/bin/upgrade_homeassistant.sh $1 > /dev/null 2>&1 &"
friendly_name: Upgrade Home Assistant

14
conf/nginx.conf Normal file
View file

@ -0,0 +1,14 @@
# see https://github.com/home-assistant/addons/blob/master/nginx_proxy/data/nginx.conf
location / {
proxy_pass http://localhost:__PORT__;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

5
conf/sudoers Normal file
View file

@ -0,0 +1,5 @@
# Grant sudo permissions to the user to manage his own systemd service
__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl stop __APP__.service
__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl start __APP__.service
__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl restart __APP__.service
__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl status __APP__.service

44
conf/systemd.service Normal file
View file

@ -0,0 +1,44 @@
[Unit]
Description=Home Assistant
After=network.target mysql.service
[Service]
Type=simple
User=__APP__
WorkingDirectory=__DATA_PATH__
ExecStart=__FINALPATH__/bin/hass --config "__DATA_PATH__" --log-file "__LOG_FILE__" --verbose
StandardOutput=append:__LOG_FILE__
StandardError=inherit
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
NoNewPrivileges=yes
PrivateTmp=yes
#CANT BE ACTIVATED FOR __APP__ #PrivateDevices=yes
#CANT BE ACTIVATED FOR __APP__ #RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
#CANT BE ACTIVATED FOR __APP__ (see issue #40) #DevicePolicy=closed
ProtectSystem=full
ProtectControlGroups=yes
ProtectKernelModules=yes
# ProtectKernelTunables=yes
LockPersonality=yes
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap
# Denying access to capabilities that should not be relevant for webapps
# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
[Install]
WantedBy=multi-user.target

0
doc/.gitkeep Normal file
View file

7
doc/DISCLAIMER.md Normal file
View file

@ -0,0 +1,7 @@
* Known limitations:
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes
* Additional informations:
* As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes)

0
doc/screenshots/.gitkeep Normal file
View file

BIN
doc/screenshots/screenshot1 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

47
manifest.json Normal file
View file

@ -0,0 +1,47 @@
{
"name": "Home Assistant",
"id": "homeassistant",
"packaging_format": 1,
"description": {
"en": "Home automation platform",
"fr": "Plateforme domotique"
},
"version": "2021.12.8~ynh1",
"url": "https://github.com/home-assistant/home-assistant",
"upstream": {
"license": "Apache-2.0",
"website": "https://www.home-assistant.io",
"demo": "https://demo.home-assistant.io",
"admindoc": "https://www.home-assistant.io/docs/",
"code": "https://github.com/home-assistant/core"
},
"license": "Apache-2.0",
"maintainer": {
"name": "ewilly",
"email": "ewilly@ewilly.fr"
},
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": false,
"services": [
"nginx"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "is_public",
"type": "boolean",
"help": {
"en": "If not public, Smartphone app will not work",
"fr": "Dans le cas contraire, l'application sur Smartphone ne fonctionnera pas"
},
"default": true
}
]
}
}

183
scripts/_common.sh Normal file
View file

@ -0,0 +1,183 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# Release to install
app_version=2021.12.8
# Package dependencies
pkg_dependencies="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0 libmariadbclient-dev libmariadb-dev-compat"
# Requirements (Major.Minor.Patch)
# PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.9" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2)
# Pyhton 3.9.2 will be shiped with bullseye
py_required_version=3.9.2
#=================================================
# PERSONAL HELPERS
#=================================================
# Create homeassistant user
mynh_system_user_create () {
user_groups=""
[ $(getent group dialout) ] && user_groups="${user_groups} dialout"
[ $(getent group gpio) ] && user_groups="${user_groups} gpio"
[ $(getent group i2c) ] && user_groups="${user_groups} i2c"
ynh_system_user_create --username=$app --groups="$user_groups" --home_dir="$data_path"
}
# Check if directory/file already exists (path in argument)
myynh_check_path () {
[ -z "$1" ] && ynh_die "No argument supplied"
[ ! -e "$1" ] || ynh_die "$1 already exists"
}
# Create directory only if not already exists (path in argument)
myynh_create_dir () {
[ -z "$1" ] && ynh_die "No argument supplied"
[ -d "$1" ] || mkdir -p "$1"
}
# Compare version in arguments
myynh_version_compare () {
# myynh_version_compare A B
# 0 -> A = B
# 1 -> A > B
# 2 -> A < B
if [[ $1 == $2 ]]
then
echo 0; return
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
echo 1; return
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
echo 2; return
fi
done
echo 1; return
}
# Install specific python version
# usage: myynh_install_python --python="3.8.6"
# | arg: -p, --python= - the python version to install
myynh_install_python () {
# Declare an array to define the options of this helper.
local legacy_args=u
local -A args_array=( [p]=python= )
local python
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Check python version from APT
local PY_APT_VERSION=$(python3 --version | cut -d ' ' -f 2)
# Check existing built version of python in /usr/local/bin
if [ -e "/usr/local/bin/python${python:0:3}" ]
then
local PY_BUILT_VERSION=$(/usr/local/bin/python${python:0:3} --version \
| cut -d ' ' -f 2)
else
local PY_BUILT_VERSION=0
fi
# Compare version
if [ $(myynh_version_compare $PY_APT_VERSION $python) -le 1 ]
then
# APT >= Required
ynh_print_info --message="Using provided python3..."
MY_PYTHON="python3"
else
# Either python already built or to build
if [ $(myynh_version_compare $PY_BUILT_VERSION $python) -le 1 ]
then
# Built >= Required
ynh_print_info --message="Using already used python3 built version..."
MY_PYTHON="/usr/local/bin/python${PY_BUILT_VERSION:0:3}"
else
ynh_print_info --message="Installing additional dependencies to build python..."
pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar"
ynh_install_app_dependencies "${pkg_dependencies}"
# APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin
ynh_print_info --message="Building python (may take a while)..."
# Store current direcotry
local MY_DIR=$(pwd)
# Download
wget -O "/tmp/Python-$python.tar.xz" "https://www.python.org/ftp/python/$python/Python-$python.tar.xz" 2>&1
# Extract
cd /tmp
tar xf "Python-$python.tar.xz"
# Install
cd "Python-$python"
./configure --enable-optimizations
ynh_exec_warn_less make -j4
ynh_exec_warn_less make altinstall
# Clean
cd ..
ynh_secure_remove "Python-$python"
ynh_secure_remove "Python-$python.tar.xz"
# Set version
MY_PYTHON="/usr/local/bin/python${python:0:3}"
# Go back to working directory
cd $MY_DIR
fi
fi
# Save python version in settings
ynh_app_setting_set --app=$app --key=python --value="$python"
}
# Install/Upgrade Homeassistant in virtual environement
myynh_install_homeassistant () {
ynh_exec_as $app -H -s /bin/bash -c " \
echo 'create the virtual environment' \
&& $MY_PYTHON -m venv "$final_path" \
&& echo 'activate the virtual environment' \
&& source "$final_path/bin/activate" \
&& echo 'install last version of wheel' \
&& pip --cache-dir "$data_path/.cache" install --upgrade wheel \
&& echo 'install last version of mysqlclient' \
&& pip --cache-dir "$data_path/.cache" install --upgrade mysqlclient \
&& echo 'install Home Assistant' \
&& pip --cache-dir "$data_path/.cache" install --upgrade $app==$app_version \
"
}
# Set permissions
myynh_set_permissions () {
chown -R $app: "$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app: "$data_path"
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chmod -R +x "$data_path/bin/"
chown -R $app: "$(dirname "$log_file")"
chown -R root: "/etc/sudoers.d/$app"
}

92
scripts/backup Normal file
View file

@ -0,0 +1,92 @@
#!/bin/bash
# to test the functionnality :
# yunohost backup create -n "homeassistant-test" --apps homeassistant
# yunohost backup delete homeassistant-test
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
log_file=$(ynh_app_setting_get --app=$app --key=log_file)
path_url=$(ynh_app_setting_get --app=$app --key=path_url)
python=$(ynh_app_setting_get --app=$app --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="$data_path" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="$(dirname "$log_file")"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database=$db_name > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

96
scripts/change_url Normal file
View file

@ -0,0 +1,96 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
old_domain=$YNH_APP_OLD_DOMAIN
new_domain=$YNH_APP_NEW_DOMAIN
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_restore_upgradebackup
}
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action=start --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

195
scripts/install Normal file
View file

@ -0,0 +1,195 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
#=================================================
# DEFINE USEFULL VARS
#=================================================
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
log_file="/var/log/$app/$app.log"
path_url="/"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
[ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path "
ynh_webpath_register --app=$app --domain="$domain" --path_url="$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value="$domain"
ynh_app_setting_set --app=$app --key=final_path --value="$final_path"
ynh_app_setting_set --app=$app --key=data_path --value="$data_path"
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
ynh_app_setting_set --app=$app --key=path_url --value="$path_url"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
port=$(ynh_find_port 8123)
ynh_app_setting_set --app=$app --key=port --value="$port"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
myynh_install_python --python="$py_required_version"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
mynh_system_user_create
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# create a directory for the installation of Home Assistant
myynh_create_dir "$final_path"
chown -R $app: "$final_path"
# create a directory for the datas of Home Assistant
myynh_create_dir "$data_path/.cache"
chown -R $app: "$data_path"
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
ynh_exec_fully_quiet myynh_install_homeassistant
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# grant sudo permissions to the user to manage his own systemd service
myynh_create_dir "/etc/sudoers.d"
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
#=================================================
# ADD A CONFIGURATION
#=================================================
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_path/configuration.yaml"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile="$log_file"
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
# add service in admin panel
yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# start systemd service with --verbose
ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600
# remove --verbose from systemd service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name=$app --action=restart
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
[ $is_public -eq 1 ] && ynh_permission_update --permission="main" --add="visitors"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

130
scripts/remove Normal file
View file

@ -0,0 +1,130 @@
#!/bin/bash
# to test the functionnality :
# yunohost app remove homeassistant --purge
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
log_file=$(ynh_app_setting_get --app=$app --key=log_file)
path_url=$(ynh_app_setting_get --app=$app --key=path_url)
python=$(ynh_app_setting_get --app=$app --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
if ynh_exec_warn_less yunohost service status $app >/dev/null ; then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config --service=$app
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..."
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DATA DIR
#=================================================
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..."
ynh_secure_remove --file="$data_path"
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
# remove sudoers file
ynh_secure_remove --file="/etc/sudoers.d/$app"
# Remove the log files
ynh_secure_remove --file="$(dirname "$log_file")"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

158
scripts/restore Normal file
View file

@ -0,0 +1,158 @@
#!/bin/bash
# to test the functionnality :
# yunohost backup create -n "homeassistant-test" --apps homeassistant
# yunohost app remove homeassistant --purge
# yunohost backup restore "homeassistant-test"
# yunohost backup delete "homeassistant-test"
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
log_file=$(ynh_app_setting_get --app=$app --key=log_file)
path_url=$(ynh_app_setting_get --app=$app --key=path_url)
python=$(ynh_app_setting_get --app=$app --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
[ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
mynh_system_user_create
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..."
ynh_restore_file --origin_path="$data_path" --not_mandatory
mkdir -p $data_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
ynh_install_app_dependencies $pkg_dependencies
myynh_install_python --python="$python"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd="$db_pwd"
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
ynh_restore_file --origin_path="$(dirname "$log_file")"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action=start
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last

219
scripts/upgrade Normal file
View file

@ -0,0 +1,219 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_restore_upgradebackup
}
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# changes introduce in
if [ -z $(ynh_app_setting_get --app=$app --key=final_path) ]
then
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
log_file="/var/log/$app/$app.log"
path_url="/"
ynh_app_setting_set --app=$app --key=final_path --value="$final_path"
ynh_app_setting_set --app=$app --key=data_path --value="$data_path"
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
ynh_app_setting_set --app=$app --key=path_url --value="$path_url"
else
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
log_file=$(ynh_app_setting_get --app=$app --key=log_file)
path_url=$(ynh_app_setting_get --app=$app --key=path_url)
python=$(ynh_app_setting_get --app=$app --key=python)
fi
# changes introduced in 2021.11.5~ynh1
if [ -f "/etc/systemd/system/$app@$app.service" ]
then
# remove old systemd service
if ynh_exec_warn_less yunohost service status "$app@$app" >/dev/null
then
yunohost service remove "$app@$app"
fi
ynh_remove_systemd_config --service="$app@$app"
fi
if [ ! -d "$final_path" ]
then
# move $final_path to new directory
mv "/opt/yunohost/$app" "$final_path"
chown -R $app: "$final_path"
fi
if [ ! -d "$data_path" ]
then
# move $data_path to new directory
mv "/""home""/$app" "$data_path"
find "$data_path/.$app" -maxdepth 1 -mindepth 1 -exec mv {} "$data_path" \;
rmdir "$data_path/.$app"
ynh_replace_string --match_string="/home/homeassistant/.homeassistant" --replace_string="$data_path" --target_file="$data_path/configuration.yaml"
chown -R $app: "$data_path"
fi
if [ ! -f "$log_file" ]
then
# create a directory with its log file
myynh_create_dir "$(dirname "$log_file")"
touch "$log_file"
fi
# changes introduced in 2021.12.8~ynh1
if [ -z $(ynh_app_setting_get --app=$app --key=db_name) ]
then
# create a MySQL database
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
if [ -z $(sed -n "/recorder:/=" "$data_path/configuration.yaml") ]
then
sed -i "$ a recorder:" "$data_path/configuration.yaml"
sed -i "$ a \ db_url: mysql://$db_user:$db_pwd@127.0.0.1/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
else
sed -i "/recorder:/a \ db_url: mysql://$db_user:$db_pwd@127.0.0.1/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
fi
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
mynh_system_user_create
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
myynh_install_python --python="$py_required_version"
ynh_exec_fully_quiet myynh_install_homeassistant
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/bin/"
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_use_logrotate --logfile="$log_file" --non-append
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# start systemd service with --verbose
ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name=$app --action=restart
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last