1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00

Update & Refractor

This commit is contained in:
ewilly 2021-11-20 19:05:14 +01:00
parent 4eaade48e9
commit 7190b587b0
17 changed files with 288 additions and 173 deletions

View file

@ -1,3 +1,8 @@
<!--
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)
@ -5,59 +10,37 @@
*[Lire ce readme en français.](./README_fr.md)*
> *This package allows you to install Home Assistant quickly and simply on a YunoHost server.
> *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 Assistant is free, open-source home automation software designed to be the central control system of a smart home or smart home. Written in Python, its main focus is local control and privacy.
**Shipped version:** 0.117.6
Home automation platform
**Shipped version:** 2021.11.4~ynh1
**Demo:** https://demo.home-assistant.io
## Screenshots
![](https://camo.githubusercontent.com/24b8190f22f6e4277778a4f30a61fce1dd5e95169e6ce149408bbc4a0b9eb0dc/68747470733a2f2f7261772e6769746875622e636f6d2f686f6d652d617373697374616e742f686f6d652d617373697374616e742f6d61737465722f646f63732f73637265656e73686f74732e706e67)
![](./doc/screenshots/screenshot1)
## Demo
## Disclaimers / important information
* [Official demo](https://demo.home-assistant.io/)
* Known limitations:
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes
## Configuration
How to configure this app: From an admin panel
* 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
## Documentation and resources
* Official documentation: https://www.home-assistant.io/docs/
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
## YunoHost specific features
#### Multi-user support
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes
#### Supported architectures
* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/homeassistant%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/homeassistant/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/homeassistant%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/homeassistant/)
## Limitations
* Any known limitations.
## Additional information
* As the pyhton version shipped in Debian stable is not supported, a recent version will be built during the installation process. it may take a while to achive that (15 to 60 minutes)
## Links
* Report a bug: https://github.com/YunoHost-Apps/homeassistant_ynh/issues
* App website: https://www.home-assistant.io/
* Upstream app repository: https://github.com/home-assistant/home-assistant
* YunoHost website: https://yunohost.org/
---
* 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
@ -69,3 +52,5 @@ sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tre
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.11.4~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 +1,23 @@
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
is_public=1 (PUBLIC|public=1|private=0)
; Actions
is_public=1|0
domain="domain.tld"
is_public=1
; Checks
pkg_linter=1
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=b07405d0f885f28764031dd80d27af84a90007b1
upgrade=1 from_commit=4eaade48e9bdccf56a53f09a269b2e5ba7621296
backup_restore=1
multi_instance=0
port_already_use=1
change_url=1
actions=0
config_panel=0
;;; 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,7 +1,7 @@
homeassistant:
auth_providers:
- type: command_line
command: /home/homeassistant/.homeassistant/bin/ynh_ldap-auth.sh
command: __PATH__/bin/ynh_ldap-auth.sh
meta: true
http:
@ -13,3 +13,11 @@ http:
# Apply default set of integrations
default_config:
# Switches
switch:
- platform: command_line
switches:
upgrade_homeassistant:
command_on: "nohup bash -c __PATH__/bin/upgrade_homeassistant.sh $1 > /dev/null 2>&1 &"
friendly_name: Upgrade Home Assistant

View file

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

View file

@ -4,9 +4,41 @@ After=network-online.target
[Service]
Type=simple
User=homeassistant
WorkingDirectory=/home/homeassistant/.homeassistant
ExecStart=/opt/yunohost/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant" --verbose
User=__APP__
WorkingDirectory=__PATH__
ExecStart=/opt/yunohost/__APP__/bin/hass --config "__PATH__" --verbose
StandardOutput=append:/var/log/__APP__.log
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

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

View file

@ -6,15 +6,21 @@
"en": "Home automation platform",
"fr": "Plateforme domotique"
},
"version": "2021.6.5~ynh1",
"version": "2021.11.4~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.0.0"
"yunohost": ">= 4.1.0"
},
"multi_instance": false,
"services": [
@ -24,24 +30,11 @@
"install": [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Home Assistant",
"fr": "Choisissez un domaine pour Home Assistant"
},
"help": {
"en": "Installation in a path is not possible",
"fr": "L'installation sous un chemin de domaine n'est pas possible"
},
"example": "domain.org or homeassistant.domain.org"
"type": "domain"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Should this application be public?",
"fr": "Est-ce que cette application doit être visible publiquement ?"
},
"help": {
"en": "If not public, Smartphone app will not work",
"fr": "Dans le cas contraire, l'application sur Smartphone ne fonctionnera pas"

View file

@ -3,14 +3,14 @@
#
# Release to install
VERSION=2021.6.5
VERSION=2021.11.4
# 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.8" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2)
PY_REQUIRED_VERSION=3.8.7
PY_REQUIRED_VERSION=3.9.2
# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
@ -25,6 +25,18 @@ exec_as() {
fi
}
# 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
@ -125,29 +137,23 @@ myynh_install_dependencies () {
}
# Install/Upgrade Homeassistant in virtual environement
# | arg: -p, --path= - the parent path of cache directory
myynh_install_homeassistant () {
# Declare an array to define the options of this helper.
local legacy_args=u
local -A args_array=( [p]=path= )
local path
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
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 pip' \
&& pip install --upgrade pip \
&& echo 'install last version of wheel' \
&& pip install --upgrade wheel \
&& pip --cache-dir "$path/.cache" install --upgrade wheel \
&& echo 'install Home Assistant' \
&& pip install --upgrade $app==$VERSION \
&& pip --cache-dir "$path/.cache" install --upgrade $app==$VERSION \
"
}
# 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"
}

View file

@ -14,7 +14,7 @@ domain=$(ynh_app_setting_get --app="$app" --key=domain)
# definie useful vars
final_path="/opt/yunohost/$app"
home_path="/home/$app"
data_path="/home/yunohost.app/$app"
ynh_print_info --message="Storing the python version in settings..."
# store python version
@ -24,7 +24,7 @@ ynh_app_setting_set --app="$app" --key=python --value="$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="$home_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@$app.service"

View file

@ -16,8 +16,7 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
# definie useful vars
final_path="/opt/yunohost/$app"
home_path="/home/$app"
data_path="/home/$app/.$app"
data_path="/home/yunohost.app/$app"
path_url="/"
# check domain/path availability
@ -38,39 +37,47 @@ ynh_exec_fully_quiet yunohost firewall allow TCP "$port"
# create a dedicated system user
ynh_script_progression --message="Creating dedicated user, rights and folders..."
ynh_system_user_create --username="$app"
## grant sudo permissions to the user to manage his own systemd service
# grant sudo permissions to the user to manage his own systemd service
myynh_create_dir "/etc/sudoers.d"
cp "../conf/sudoers" "/etc/sudoers.d/$app"
## create a directory for the installation of Home Assistant
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
# create a directory for the installation of Home Assistant
myynh_create_dir "$final_path"
chown $app: "$final_path"
## create a directory for the datas of Home Assistant
myynh_create_dir "$data_path"
chown -R $app: "$home_path"
# create a directory for the datas of Home Assistant
myynh_create_dir "$data_path/.$app"
myynh_create_dir "$data_path/.cache"
chown -R $app: "$data_path"
# build (if needed) & install Pyhton
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
myynh_install_homeassistant
ynh_exec_fully_quiet myynh_install_homeassistant --path="$data_path"
# set default configuration files and move all homeassistant_conf_files
ynh_script_progression --message="Configuring the installation..."
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/homeassistant_conf_files/configuration.yaml"
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
chown -R $app: "$data_path"
chmod -R +x "$data_path/bin/"
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/homeassistant_conf_files/configuration.yaml"
cp -r "../conf/homeassistant_conf_files/." "$data_path/.$app/"
chown -R $app: "$data_path/.$app"
chmod -R +x "$data_path/.$app/bin/"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app"
## add service in admin panel
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
@ -78,12 +85,13 @@ systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/home-assistant.log"
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log"
# create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..."
ynh_add_nginx_config
## reload nginx
# reload nginx
ynh_systemd_action --service_name=nginx --action=reload
# unprotect app access if public (needed for Android app to work)

View file

@ -1,6 +1,6 @@
#!/bin/bash
# to test the functionnality :
# yunohost app remove homeassistant
# yunohost app remove homeassistant --purge
source _common.sh
source /usr/share/yunohost/helpers
@ -12,38 +12,52 @@ port=$(ynh_app_setting_get --app=$app --key=port)
# definie useful vars
final_path="/opt/yunohost/$app"
home_path="/home/$app"
# remove metapackage and its dependencies
ynh_remove_app_dependencies
# remove the app directory securely
ynh_secure_remove --file="$final_path"
# remove the dedicated nginx config
ynh_remove_nginx_config
# remove a directory securely
ynh_secure_remove --file="$home_path"
data_path="/home/yunohost.app/$app"
# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status "$app@$app" >/dev/null 2>&1 ; then
yunohost service remove "$app@$app"
if ynh_exec_warn_less yunohost service status "$app@$app" >/dev/null ; then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove "$app@$app"
fi
# remove systemd service
ynh_systemd_action --service_name="$app@$app" --action=stop
ynh_systemd_action --service_name="$app@$app" --action=disable
ynh_secure_remove --file="/etc/systemd/system/$app@$app.service"
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config --service="$app@$app"
# remove logrotate config
# remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate
# close port
ynh_exec_fully_quiet yunohost firewall disallow TCP $port
# remove metapackage and its dependencies
ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies
# delete a system user
ynh_system_user_delete --username="$app"
# 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
# remove sudoers file
ynh_script_progression --message="Removing various files..."
ynh_secure_remove --file="/etc/sudoers.d/$app"
# 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,8 +1,9 @@
#!/bin/bash
# to test the functionnality :
# yunohost backup create -n "homeassistant-test" --apps homeassistant
# yunohost app remove 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
@ -21,58 +22,63 @@ python=$(ynh_app_setting_get --app="$app" --key=python)
# definie useful vars
final_path="/opt/yunohost/$app"
home_path="/home/$app"
data_path="/home/$app/.$app"
data_path="/home/yunohost.app/$app"
path_url="/"
ynh_script_progression --message="Validating recovery parameters..."
# check domain/path availability
ynh_script_progression --message="Validating recovery parameters..."
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
ynh_webpath_available --domain="$domain" --path_url="$path_url" || ynh_die "$domain/$path_url is not available, please use an other domain."
ynh_script_progression --message="Restoring the port and opening it..."
# restore port
ynh_script_progression --message="Restoring the port and opening it..."
ynh_exec_warn_less yunohost firewall allow TCP $port
ynh_script_progression --message="Restoring dedicated user, rights and folders..."
# 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"
chown -R $app: "$final_path"
ynh_script_progression --message="Restoring the data..."
# restore data
ynh_restore_file --origin_path="$home_path"
chown -R $app: "$home_path"
chmod -R +x "$home_path/.homeassistant/bin"
ynh_script_progression --message="Restoring the data..."
ynh_restore_file --origin_path="$data_path"
chown -R $app: "$data_path"
chmod -R +x "$data_path/.$app/bin"
ynh_script_progression --message="Restoring the packages dependencies..."
# 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@$app.service"
# add service in admin panel
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# add service in admin panel
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# restart the app
ynh_script_progression --message="Starting the Home Assistant server..."
# add --verbose to service
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app@$app.service"
# start
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=900
# remove --verbose from service and restart
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart --line_match="Started Home Assistant" --log_path="systemd" --timeout=3600
ynh_systemd_action --service_name="$app@$app" --action=restart
ynh_script_progression --message="Restoring nginx web server..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# restore logrotate
ynh_script_progression --message="Restoring logrotate..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
# reload nginx
# 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_exec_fully_quiet sleep 60s #Only necessary for CI test otherwise curl failed to nginx page
ynh_script_progression --message="Recovery of $app completed" --last

View file

@ -14,17 +14,9 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=port)
# Cleaning legacy permissions
ynh_script_progression --message="Cleaning legacy permissions..."
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
if [ -n "$is_public" ]; then
ynh_app_setting_delete --app="$app" --key=is_public
ynh_app_setting_delete --app="$app" --key=unprotected_uris
fi
# definie useful vars
final_path="/opt/yunohost/$app"
data_path="/home/$app/.$app"
data_path="/home/yunohost.app/$app"
# 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..."
@ -36,37 +28,48 @@ if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
}
fi
# move $data_path to new directory
ynh_script_progression --message="Moving existing datas to new location..."
if [ ! -d "$data_path" ] ; then
mv "/""home""/$app" "$data_path"
ynh_replace_string --match_string="/home/homeassistant/.homeassistant" --replace_string="$data_path/.$app" --target_file="$data_path/.$app/configuration.yaml"
chown -R $app: "$data_path"
fi
# grant sudo permissions to the user to manage his own systemd service
ynh_script_progression --message="Creating dedicated user, rights and folders..."
myynh_create_dir "/etc/sudoers.d"
cp "../conf/sudoers" "/etc/sudoers.d/$app"
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
# build (if needed) & install Pyhton
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# stop systemd service
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app@$app" --action=stop
ynh_systemd_action --service_name="$app@$app" --action=stop --line_match="Stopped Home Assistant" --log_path="/var/log/$app.log" --timeout=300
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
myynh_install_homeassistant
ynh_exec_fully_quiet myynh_install_homeassistant --path="$data_path"
# update script in bin
ynh_script_progression --message="Updating YunoHost script used by homeassitant..."
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/bin/"
chown -R $app: "$data_path/bin"
chmod -R +x "$data_path/bin/"
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/.$app/bin/"
chown -R $app: "$data_path/.$app/bin"
chmod -R +x "$data_path/.$app/bin/"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app"
## add service in admin panel
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# add service in admin panel
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
@ -74,11 +77,12 @@ systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/home-assistant.log" --nonappend
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log" --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