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

Merge pull request #43 from YunoHost-Apps/testing2

Testing2
This commit is contained in:
ewilly 2022-01-05 22:02:34 +01:00 committed by GitHub
commit f1ff3212f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 80 additions and 19 deletions

View file

@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
Home automation platform
**Shipped version:** 2021.12.7~ynh1
**Shipped version:** 2021.12.8~ynh1
**Demo:** https://demo.home-assistant.io

View file

@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
Plateforme domotique
**Version incluse :** 2021.12.7~ynh1
**Version incluse :** 2021.12.8~ynh1
**Démo :** https://demo.home-assistant.io

View file

@ -11,9 +11,17 @@ http:
- 127.0.0.1
- ::1
recorder:
db_url: mysql://__DB_USER__:__DB_PWD__@127.0.0.1/__DB_NAME__?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4
# Apply default set of integrations
default_config:
# Linked yaml files
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Switches
switch:
- platform: command_line

View file

@ -1,6 +1,6 @@
[Unit]
Description=Home Assistant
After=network.target
After=network.target mysql.service
[Service]
Type=simple
@ -20,7 +20,7 @@ PrivateTmp=yes
#CANT BE ACTIVATED FOR __APP__ #RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
DevicePolicy=closed
#CANT BE ACTIVATED FOR __APP__ (see issue #40) #DevicePolicy=closed
ProtectSystem=full
ProtectControlGroups=yes
ProtectKernelModules=yes

View file

@ -6,7 +6,7 @@
"en": "Home automation platform",
"fr": "Plateforme domotique"
},
"version": "2021.12.7~ynh1",
"version": "2021.12.8~ynh1",
"url": "https://github.com/home-assistant/home-assistant",
"upstream": {
"license": "Apache-2.0",

View file

@ -3,18 +3,25 @@
#
# Release to install
VERSION=2021.12.7
VERSION=2021.12.8
# Package dependencies
PKG_DEPENDENCIES="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5"
PKG_DEPENDENCIES="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0 libmariadbclient-dev libmariadb-dev-compat"
# Requirements (Major.Minor.Patch)
# PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.9" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2)
# Pyhton 3.9.2 will be shiped with bullseye
PY_REQUIRED_VERSION=3.9.2
# System groups allowed to homeassistant user
USER_GROUPS="dialout gpio i2c"
# Create homeassistant user
mynh_user_create () {
USER_GROUPS=""
[ $(getent group dialout) ] && USER_GROUPS="${USER_GROUPS} dialout"
[ $(getent group gpio) ] && USER_GROUPS="${USER_GROUPS} gpio"
[ $(getent group i2c) ] && USER_GROUPS="${USER_GROUPS} i2c"
ynh_system_user_create --username="$app" --groups="$USER_GROUPS"
}
# Check if directory/file already exists (path in argument)
myynh_check_path () {
@ -135,6 +142,8 @@ myynh_install_homeassistant () {
&& source "$final_path/bin/activate" \
&& echo 'install last version of wheel' \
&& pip --cache-dir "$data_path/.cache" install --upgrade wheel \
&& echo 'install last version of mysqlclient' \
&& pip --cache-dir "$data_path/.cache" install --upgrade mysqlclient \
&& echo 'install Home Assistant' \
&& pip --cache-dir "$data_path/.cache" install --upgrade $app==$VERSION \
"

View file

@ -17,6 +17,7 @@ data_path=$(ynh_app_setting_get --app="$app" --key=data_path)
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
python=$(ynh_app_setting_get --app="$app" --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
# backup source & conf files
ynh_print_info --message="Declaring files to be backed up..."
@ -28,4 +29,8 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="$(dirname "$log_file")"
# backup the MySQL database
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
ynh_print_info --message="Backup of $app completed"

View file

@ -41,7 +41,7 @@ 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" --groups="$USER_GROUPS"
mynh_user_create
# create a directory for the installation of Home Assistant
myynh_create_dir "$final_path"
@ -59,6 +59,13 @@ chown -R $app: "$data_path"
ynh_script_progression --message="Installing dependencies..."
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# create a MySQL database
ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
ynh_exec_fully_quiet myynh_install_homeassistant

View file

@ -14,6 +14,8 @@ data_path=$(ynh_app_setting_get --app="$app" --key=data_path)
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
python=$(ynh_app_setting_get --app="$app" --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
# Remove a service from the admin panel, added by `yunohost service add`
if ynh_exec_warn_less yunohost service status "$app" >/dev/null ; then
@ -29,6 +31,10 @@ ynh_remove_systemd_config --service="$app"
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate
# remove the MySQL database
ynh_script_progression --message="Removing the MySQL database..."
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
# remove metapackage and its dependencies
ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies

View file

@ -23,6 +23,8 @@ data_path=$(ynh_app_setting_get --app="$app" --key=data_path)
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
python=$(ynh_app_setting_get --app="$app" --key=python)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
# check domain/path availability
ynh_script_progression --message="Validating recovery parameters..."
@ -34,9 +36,13 @@ 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" --groups="$USER_GROUPS"
mynh_user_create
ynh_restore_file --origin_path="/etc/sudoers.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"
# restore source
ynh_script_progression --message="Restoring the app..."
ynh_restore_file --origin_path="$final_path"
@ -53,6 +59,12 @@ ynh_restore_file --origin_path="$(dirname "$log_file")"
ynh_script_progression --message="Restoring the packages dependencies..."
myynh_install_dependencies --python="$python"
# restore the MySQL database
ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
# restore the systemd service
ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
@ -69,18 +81,17 @@ 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
#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"
# reload nginx
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Recovery of $app completed" --last
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -77,6 +77,20 @@ if [ ! -f "$log_file" ]; then
myynh_create_dir "$(dirname "$log_file")"
touch "$log_file"
fi
if [ -z $(ynh_app_setting_get --app="$app" --key=db_name) ]; then
# create a MySQL database
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app="$app" --key=mysqlpwd)
if [ -z $(sed -n "/recorder:/=" configuration.yaml) ]; then
sed -i "$ a recorder:" "$data_path/configuration.yaml"
sed -i "$ a \ db_url: mysql://$db_user:$db_pwd@127.0.0.1/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
else
sed -i "/recorder:/a \ db_url: mysql://$db_user:$db_pwd@127.0.0.1/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
fi
fi
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
@ -92,6 +106,7 @@ 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..."
mynh_user_create
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
# add service in admin panel