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:00:31 +01:00
parent 15f9493299
commit 8a3629278b
28 changed files with 0 additions and 1510 deletions

View file

@ -1,55 +0,0 @@
---
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.*

View file

@ -1,16 +0,0 @@
## 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)

View file

@ -1,23 +0,0 @@
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 .

View file

@ -1,59 +0,0 @@
#!/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

View file

@ -1,49 +0,0 @@
# 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
View file

@ -1,201 +0,0 @@
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.

View file

@ -1,56 +0,0 @@
<!--
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.11.5~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

View file

@ -1,52 +0,0 @@
# 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.11.5~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

View file

@ -1,23 +0,0 @@
;; 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

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

View file

@ -1,62 +0,0 @@
#!/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

@ -1,148 +0,0 @@
#!/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

@ -1,23 +0,0 @@
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
# Apply default set of integrations
default_config:
# 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

View file

@ -1,14 +0,0 @@
# 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;
}

View file

@ -1,5 +0,0 @@
# 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

View file

@ -1,44 +0,0 @@
[Unit]
Description=Home Assistant
After=network.target
[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
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

View file

View file

@ -1,7 +0,0 @@
* 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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 KiB

View file

@ -1,46 +0,0 @@
{
"name": "Home Assistant",
"id": "homeassistant",
"packaging_format": 1,
"description": {
"en": "Home automation platform",
"fr": "Plateforme domotique"
},
"version": "2021.11.5~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/"
},
"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
}
]
}
}

View file

@ -1,154 +0,0 @@
#
# Common variables & functions
#
# Release to install
VERSION=2021.11.5
# 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"
# 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
# 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
}
# Package dependencies
# usage: myynh_install_dependencies --python="3.8.6"
# | arg: -p, --python= - the python version to install
myynh_install_dependencies () {
# 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 "$@"
# Install main dependencies from apt
ynh_install_app_dependencies "${PKG_DEPENDENCIES}"
# 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 Home Assistant' \
&& pip --cache-dir "$data_path/.cache" install --upgrade $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"
}

View file

@ -1,31 +0,0 @@
#!/bin/bash
# to test the functionnality :
# yunohost backup create -n "homeassistant-test" --apps homeassistant
# yunohost backup delete homeassistant-test
source /usr/share/yunohost/helpers
# manage script failure
ynh_abort_if_errors
# retrieve arguments
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)
# backup source & conf files
ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$data_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="$(dirname "$log_file")"
ynh_print_info --message="Backup of $app completed"

View file

@ -1,45 +0,0 @@
#!/bin/bash
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..." --time --weight=1
old_nginx_conf="/etc/nginx/conf.d/$old_domain.d/$app.conf"
new_nginx_conf="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# manage script failure
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
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
# Change the domain for nginx
if [ $change_domain -eq 1 ]; then
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$old_nginx_conf"
mv "$old_nginx_conf" "$new_nginx_conf"
# Store file checksum for the new config file location
ynh_store_file_checksum --file="$new_nginx_conf"
fi
# reload nginx
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Change of URL completed for $app" --time --last

View file

@ -1,109 +0,0 @@
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
# manage script failure
ynh_clean_setup () {
ynh_clean_check_starting
}
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
# definie useful vars
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
log_file="/var/log/$app/$app.log"
path_url="/"
# check domain/path availability
ynh_script_progression --message="Validating installation parameters..."
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
# find a free port & open it
ynh_script_progression --message="Looking for a free port and opening it..."
port=$(ynh_find_port 8123)
ynh_exec_fully_quiet yunohost firewall allow TCP "$port"
# save app settings
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
ynh_app_setting_set --app="$app" --key=port --value="$port"
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"
# create a dedicated system user
ynh_script_progression --message="Creating dedicated user, rights and folders..."
ynh_system_user_create --username="$app"
# create a directory for the installation of Home Assistant
myynh_create_dir "$final_path"
chown -R $app: "$final_path"
# create a directory with its log file
myynh_create_dir "$(dirname "$log_file")"
touch "$log_file"
# create a directory for the datas of Home Assistant
myynh_create_dir "$data_path/.cache"
chown -R $app: "$data_path"
# build (if needed) & install Pyhton
ynh_script_progression --message="Installing dependencies..."
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
ynh_exec_fully_quiet myynh_install_homeassistant
# set default configuration files and move all homeassistant_conf_files
ynh_script_progression --message="Configuring the installation..."
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_path/configuration.yaml"
# 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"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_add_systemd_config
# add service in admin panel
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# set permissions
myynh_set_permissions
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
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
# enable logrotate
ynh_use_logrotate --logfile="$log_file"
# create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..."
ynh_add_nginx_config
# reload nginx
ynh_systemd_action --service_name=nginx --action=reload
# unprotect app access if public (needed for Android app to work)
ynh_script_progression --message="Configuring permissions..."
[ $is_public -eq 1 ] && ynh_permission_update --permission="main" --add="visitors"
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -1,66 +0,0 @@
#!/bin/bash
# to test the functionnality :
# yunohost app remove homeassistant --purge
source _common.sh
source /usr/share/yunohost/helpers
# retrieve arguments
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)
# Remove a service from the admin panel, added by `yunohost service add`
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
# remove systemd service
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config --service="$app"
# remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate
# remove metapackage and its dependencies
ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies
# remove the app directory securely
ynh_script_progression --message="Removing app main directory..."
ynh_secure_remove --file="$final_path"
# remove a directory securely if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ] ; then
ynh_script_progression --message="Removing app data directory..."
ynh_secure_remove --file="$data_path"
fi
# remove the dedicated nginx config
ynh_script_progression --message="Removing NGINX web server configuration..."
ynh_remove_nginx_config
# close 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
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")"
# delete a system user
ynh_script_progression --message="Removing the dedicated system user..."
ynh_system_user_delete --username="$app"
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -1,86 +0,0 @@
#!/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"
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# manage script failure
ynh_clean_setup () {
ynh_clean_check_starting
}
ynh_abort_if_errors
# retrieve arguments
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)
# check domain/path availability
ynh_script_progression --message="Validating recovery parameters..."
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
# restore port
ynh_script_progression --message="Restoring the port and opening it..."
ynh_exec_warn_less yunohost firewall allow TCP $port
# restore dedicated system user
ynh_script_progression --message="Restoring dedicated user and rights folders..."
ynh_system_user_create --username="$app"
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
# restore source
ynh_script_progression --message="Restoring the app..."
ynh_restore_file --origin_path="$final_path"
# restore data
ynh_script_progression --message="Restoring the data..."
ynh_restore_file --origin_path="$data_path"
# restore log
ynh_script_progression --message="Restoring the app..."
ynh_restore_file --origin_path="$(dirname "$log_file")"
# add required packages
ynh_script_progression --message="Restoring the packages dependencies..."
myynh_install_dependencies --python="$python"
# restore the systemd service
ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
# add service in admin panel
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# set permissions
myynh_set_permissions
# restart the app
ynh_script_progression --message="Starting the Home Assistant server..."
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app.service"
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=900
# remove --verbose from service and restart
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
# restore logrotate
ynh_script_progression --message="Restoring logrotate..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
# restore nginx
ynh_script_progression --message="Restoring nginx web server..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Recovery of $app completed" --last

View file

@ -1,124 +0,0 @@
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
# manage script failure
ynh_clean_setup () {
ynh_clean_check_starting
}
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=port)
# definie useful vars
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
# use prior backup and restore on error only if backup feature exists on installed instance
ynh_script_progression --message="Creating backup in case of failure..."
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_restore_upgradebackup
ynh_clean_check_starting
}
fi
# build (if needed) & install Pyhton
ynh_script_progression --message="Installing dependencies..."
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# stop systemd service
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app" --action=stop --line_match="Stopped Home Assistant" --log_path="$log_file" --timeout=300
# migrate to new app architecture
ynh_script_progression --message="If needed, migrating to new app architecture..."
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
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
ynh_exec_fully_quiet myynh_install_homeassistant
# update script in bin
ynh_script_progression --message="Updating YunoHost script used by homeassitant..."
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/bin/"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_add_systemd_config
# grant sudo permissions to the user to manage his own systemd service
ynh_script_progression --message="Creating dedicated user, rights and folders..."
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
# add service in admin panel
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# set permissions
myynh_set_permissions
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
systemctl daemon-reload
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
# enable logrotate
ynh_use_logrotate --logfile="$log_file" --nonappend
# create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..."
ynh_add_nginx_config
# reload nginx
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Installation of $app completed" --last