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

Refractor

This commit is contained in:
ewilly 2021-11-16 21:13:56 +01:00
parent 4eaade48e9
commit b7fa83f99b
16 changed files with 196 additions and 129 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 # 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) [![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)
@ -9,55 +14,33 @@
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview ## 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.3~ynh1
**Demo:** https://demo.home-assistant.io
## Screenshots ## Screenshots
![](https://camo.githubusercontent.com/24b8190f22f6e4277778a4f30a61fce1dd5e95169e6ce149408bbc4a0b9eb0dc/68747470733a2f2f7261772e6769746875622e636f6d2f686f6d652d617373697374616e742f686f6d652d617373697374616e742f6d61737465722f646f63732f73637265656e73686f74732e706e67) ![](./doc/screenshots/screenshot1)
## Demo ## Disclaimers / important information
* [Official demo](https://demo.home-assistant.io/)
## Configuration
How to configure this app: From an admin panel
## Documentation
* 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
* Known limitations:
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No * Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
* Can the app be used by multiple users? Yes * 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/) * Additional informations:
* 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/) * 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)
## Limitations ## Documentation and resources
* 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
* 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 * 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/
---
## Developer info ## Developer info
@ -69,3 +52,5 @@ sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tre
or or
sudo yunohost app upgrade homeassistant -u https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug 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.3~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,7 +1,7 @@
homeassistant: homeassistant:
auth_providers: auth_providers:
- type: command_line - type: command_line
command: /home/homeassistant/.homeassistant/bin/ynh_ldap-auth.sh command: __PATH__/bin/ynh_ldap-auth.sh
meta: true meta: true
http: http:
@ -13,3 +13,11 @@ http:
# Apply default set of integrations # Apply default set of integrations
default_config: 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 # Grant sudo permissions to the user to manage his own systemd service
homeassistant ALL=(ALL) NOPASSWD: /bin/systemctl stop homeassistant@homeassistant.service __NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl stop __NAME__@__NAME__.service
homeassistant ALL=(ALL) NOPASSWD: /bin/systemctl start homeassistant@homeassistant.service __NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl start __NAME__@__NAME__.service
homeassistant ALL=(ALL) NOPASSWD: /bin/systemctl restart homeassistant@homeassistant.service __NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl restart __NAME__@__NAME__.service
homeassistant ALL=(ALL) NOPASSWD: /bin/systemctl status homeassistant@homeassistant.service __NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl status __NAME__@__NAME__.service

View file

@ -5,8 +5,8 @@ After=network-online.target
[Service] [Service]
Type=simple Type=simple
User=homeassistant User=homeassistant
WorkingDirectory=/home/homeassistant/.homeassistant WorkingDirectory=__PATH__
ExecStart=/opt/yunohost/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant" --verbose ExecStart=/opt/yunohost/homeassistant/bin/hass --config "__PATH__" --verbose
[Install] [Install]
WantedBy=multi-user.target 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", "en": "Home automation platform",
"fr": "Plateforme domotique" "fr": "Plateforme domotique"
}, },
"version": "2021.6.5~ynh1", "version": "2021.11.4~ynh1",
"url": "https://github.com/home-assistant/home-assistant", "url": "https://github.com/home-assistant/home-assistant",
"license": "Apache-2.0", "upstream": {
"license": "Apache License 2.0",
"website": "https://www.home-assistant.io",
"demo": "https://demo.home-assistant.io",
"admindoc": "https://www.home-assistant.io/docs/"
},
"license": "Apache License 2.0",
"maintainer": { "maintainer": {
"name": "ewilly", "name": "ewilly",
"email": "ewilly@ewilly.fr" "email": "ewilly@ewilly.fr"
}, },
"requirements": { "requirements": {
"yunohost": ">= 4.0.0" "yunohost": ">= 4.1.0"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
@ -24,28 +30,11 @@
"install": [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "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"
}, },
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "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"
},
"default": true "default": true
} }
] ]

View file

@ -3,14 +3,14 @@
# #
# Release to install # Release to install
VERSION=2021.6.5 VERSION=2021.11.4
# Package dependencies # 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" 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) # 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_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 # Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...] # usage: exec_as USER COMMAND [ARG ...]
@ -25,6 +25,18 @@ exec_as() {
fi 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 # Compare version in arguments
myynh_version_compare () { myynh_version_compare () {
# myynh_version_compare A B # myynh_version_compare A B
@ -132,22 +144,10 @@ myynh_install_homeassistant () {
&& echo 'activate the virtual environment' \ && echo 'activate the virtual environment' \
&& source "$final_path/bin/activate" \ && source "$final_path/bin/activate" \
&& echo 'install last version of pip' \ && echo 'install last version of pip' \
&& pip install --upgrade pip \ && pip --cache-dir "$1/.cache" install --upgrade pip \
&& echo 'install last version of wheel' \ && echo 'install last version of wheel' \
&& pip install --upgrade wheel \ && pip --cache-dir "$1/.cache" install --upgrade wheel \
&& echo 'install Home Assistant' \ && echo 'install Home Assistant' \
&& pip install --upgrade $app==$VERSION \ && pip --cache-dir "$1/.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,13 +14,17 @@ domain=$(ynh_app_setting_get --app="$app" --key=domain)
# definie useful vars # definie useful vars
final_path="/opt/yunohost/$app" final_path="/opt/yunohost/$app"
home_path="/home/$app" home_path="/home/yunohost.app/$app"
ynh_print_info --message="Storing the python version in settings..." ynh_print_info --message="Storing the python version in settings..."
# store python version # store python version
python=$(cat "$final_path/bin/python3" --version | cut -d ' ' -f 2) python=$(cat "$final_path/bin/python3" --version | cut -d ' ' -f 2)
ynh_app_setting_set --app="$app" --key=python --value="$python" ynh_app_setting_set --app="$app" --key=python --value="$python"
# stop systemd service
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app@$app" --action=stop --line_match="Stopped Home Assistant" --log_path="systemd" --timeout=3600
# backup source & conf files # backup source & conf files
ynh_print_info --message="Declaring files to be backed up..." ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$final_path" ynh_backup --src_path="$final_path"
@ -30,4 +34,8 @@ ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app@$app.service" ynh_backup --src_path="/etc/systemd/system/$app@$app.service"
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
# restart systemd service
ynh_script_progression --message="Restarting the Home Assistant server..."
ynh_systemd_action --service_name="$app@$app" --action=restart
ynh_print_info --message="Backup of $app completed" ynh_print_info --message="Backup of $app completed"

View file

@ -16,8 +16,8 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
# definie useful vars # definie useful vars
final_path="/opt/yunohost/$app" final_path="/opt/yunohost/$app"
home_path="/home/$app" home_path="/home/yunohost.app/$app"
data_path="/home/$app/.$app" data_path="$home_path/.$app"
path_url="/" path_url="/"
# check domain/path availability # check domain/path availability
@ -38,13 +38,16 @@ ynh_exec_fully_quiet yunohost firewall allow TCP "$port"
# create a dedicated system user # create a dedicated system user
ynh_script_progression --message="Creating dedicated user, rights and folders..." ynh_script_progression --message="Creating dedicated user, rights and folders..."
ynh_system_user_create --username="$app" 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" myynh_create_dir "/etc/sudoers.d"
cp "../conf/sudoers" "/etc/sudoers.d/$app" ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
## create a directory for the installation of Home Assistant
# create a directory for the installation of Home Assistant
myynh_create_dir "$final_path" myynh_create_dir "$final_path"
chown $app: "$final_path" chown $app: "$final_path"
## create a directory for the datas of Home Assistant
# create a directory for the datas of Home Assistant
myynh_create_dir "$data_path" myynh_create_dir "$data_path"
chown -R $app: "$home_path" chown -R $app: "$home_path"
@ -53,24 +56,28 @@ myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# installation in a virtual environment # installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..." ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
myynh_install_homeassistant myynh_install_homeassistant "$home_path"
# set default configuration files and move all homeassistant_conf_files # set default configuration files and move all homeassistant_conf_files
ynh_script_progression --message="Configuring the installation..." ynh_script_progression --message="Configuring the installation..."
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/homeassistant_conf_files/configuration.yaml" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/homeassistant_conf_files/configuration.yaml"
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path" --target_file="../conf/homeassistant_conf_files/configuration.yaml"
cp -r "../conf/homeassistant_conf_files/." "$data_path/" cp -r "../conf/homeassistant_conf_files/." "$data_path/"
chown -R $app: "$data_path" chown -R $app: "$data_path"
chmod -R +x "$data_path/bin/" chmod -R +x "$data_path/bin/"
# setup up systemd service # setup up systemd service
ynh_script_progression --message="Adding the dedicated service..." ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app" ynh_add_systemd_config --service="$app@$app"
## add service in admin panel ## 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/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service # start systemd service
ynh_script_progression --message="Starting the Home Assistant server..." 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="systemd" --timeout=3600
# remove --verbose from service # remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.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" ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
@ -83,7 +90,8 @@ ynh_use_logrotate --logfile="$data_path/home-assistant.log"
# create a dedicated nginx config # create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..." ynh_script_progression --message="Configuring nginx web server..."
ynh_add_nginx_config ynh_add_nginx_config
## reload nginx
# reload nginx
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
# unprotect app access if public (needed for Android app to work) # unprotect app access if public (needed for Android app to work)

View file

@ -12,11 +12,16 @@ port=$(ynh_app_setting_get --app=$app --key=port)
# definie useful vars # definie useful vars
final_path="/opt/yunohost/$app" final_path="/opt/yunohost/$app"
home_path="/home/$app" home_path="/home/yunohost.app/$app"
# remove metapackage and its dependencies # remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
# remove systemd service
ynh_systemd_action --service_name="$app@$app" --action=stop --line_match="Stopped Home Assistant" --log_path="systemd" --timeout=3600
ynh_systemd_action --service_name="$app@$app" --action=disable
ynh_secure_remove --file="/etc/systemd/system/$app@$app.service"
# remove the app directory securely # remove the app directory securely
ynh_secure_remove --file="$final_path" ynh_secure_remove --file="$final_path"
@ -31,11 +36,6 @@ if yunohost service status "$app@$app" >/dev/null 2>&1 ; then
yunohost service remove "$app@$app" yunohost service remove "$app@$app"
fi 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"
# remove logrotate config # remove logrotate config
ynh_remove_logrotate ynh_remove_logrotate

View file

@ -21,58 +21,63 @@ python=$(ynh_app_setting_get --app="$app" --key=python)
# definie useful vars # definie useful vars
final_path="/opt/yunohost/$app" final_path="/opt/yunohost/$app"
home_path="/home/$app" home_path="/home/yunohost.app/$app"
data_path="/home/$app/.$app" data_path="$home_path/.$app"
path_url="/" path_url="/"
ynh_script_progression --message="Validating recovery parameters..."
# check domain/path availability # check domain/path availability
ynh_script_progression --message="Validating recovery parameters..."
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder" [ ! -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 # restore port
ynh_script_progression --message="Restoring the port and opening it..."
ynh_exec_warn_less yunohost firewall allow TCP $port ynh_exec_warn_less yunohost firewall allow TCP $port
ynh_script_progression --message="Restoring dedicated user, rights and folders..."
# restore dedicated system user # restore dedicated system user
ynh_script_progression --message="Restoring dedicated user and rights folders..."
ynh_system_user_create --username="$app" ynh_system_user_create --username="$app"
ynh_restore_file --origin_path="/etc/sudoers.d/$app" ynh_restore_file --origin_path="/etc/sudoers.d/$app"
# restore source # restore source
ynh_script_progression --message="Restoring the app..."
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path"
chown -R $app: "$final_path" chown -R $app: "$final_path"
ynh_script_progression --message="Restoring the data..."
# restore data # restore data
ynh_script_progression --message="Restoring the data..."
ynh_restore_file --origin_path="$home_path" ynh_restore_file --origin_path="$home_path"
chown -R $app: "$home_path" chown -R $app: "$home_path"
chmod -R +x "$home_path/.homeassistant/bin" chmod -R +x "$data_path/bin"
ynh_script_progression --message="Restoring the packages dependencies..."
# add required packages # add required packages
ynh_script_progression --message="Restoring the packages dependencies..."
myynh_install_dependencies --python="$python" myynh_install_dependencies --python="$python"
# restore the systemd service
ynh_script_progression --message="Restoring the dedicated service..." ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
# add service in admin panel # 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/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# restart the app
ynh_script_progression --message="Starting the Home Assistant server..." 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" 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="systemd" --timeout=3600
# remove --verbose from service and restart # remove --verbose from service and restart
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.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"
systemctl daemon-reload 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 # restore logrotate
ynh_script_progression --message="Restoring logrotate..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app" 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_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Recovery of $app completed" --last ynh_script_progression --message="Recovery of $app completed" --last

View file

@ -14,17 +14,10 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=port) 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 # definie useful vars
final_path="/opt/yunohost/$app" final_path="/opt/yunohost/$app"
data_path="/home/$app/.$app" home_path="/home/yunohost.app/$app"
data_path="$home_path/.$app"
# use prior backup and restore on error only if backup feature exists on installed instance # 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..." ynh_script_progression --message="Creating backup in case of failure..."
@ -36,21 +29,28 @@ if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
} }
fi fi
# move $home_path to new directory
ynh_script_progression --message="Moving existing datas to new location..."
if [ ! -d "$home_path" ] ; then
mv "/home/$app" "$home_path"
ynh_replace_string --match_string="/home/homeassistant/.homeassistant" --replace_string="$data_path" --target_file="$data_path/configuration.yaml"
chown -R $app: "$home_path"
fi
# grant sudo permissions to the user to manage his own systemd service # grant sudo permissions to the user to manage his own systemd service
ynh_script_progression --message="Creating dedicated user, rights and folders..." ynh_script_progression --message="Creating dedicated user, rights and folders..."
myynh_create_dir "/etc/sudoers.d" ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
cp "../conf/sudoers" "/etc/sudoers.d/$app"
# build (if needed) & install Pyhton # build (if needed) & install Pyhton
myynh_install_dependencies --python="$PY_REQUIRED_VERSION" myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# stop systemd service # stop systemd service
ynh_script_progression --message="Stoping 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="systemd" --timeout=3600
# installation in a virtual environment # installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..." ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
myynh_install_homeassistant myynh_install_homeassistant "$home_path"
# update script in bin # update script in bin
ynh_script_progression --message="Updating YunoHost script used by homeassitant..." ynh_script_progression --message="Updating YunoHost script used by homeassitant..."
@ -60,13 +60,17 @@ chmod -R +x "$data_path/bin/"
# setup up systemd service # setup up systemd service
ynh_script_progression --message="Adding the dedicated service..." ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app" ynh_add_systemd_config --service="$app@$app"
## add service in admin panel
# 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/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service # start systemd service
ynh_script_progression --message="Starting the Home Assistant server..." ynh_script_progression --message="Starting the Home Assistant server..."
systemctl daemon-reload
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="systemd" --timeout=3600
# remove --verbose from service # remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.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" ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
@ -79,6 +83,7 @@ ynh_use_logrotate --logfile="$data_path/home-assistant.log" --nonappend
# create a dedicated nginx config # create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..." ynh_script_progression --message="Configuring nginx web server..."
ynh_add_nginx_config ynh_add_nginx_config
# reload nginx # reload nginx
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload