mirror of
https://github.com/YunoHost-Apps/homeassistant_ynh.git
synced 2024-09-03 19:26:16 +02:00
Move from SQlite to MySQL
This commit is contained in:
parent
ed6e158f7f
commit
b72ad4ac70
8 changed files with 47 additions and 2 deletions
|
@ -11,6 +11,9 @@ http:
|
||||||
- 127.0.0.1
|
- 127.0.0.1
|
||||||
- ::1
|
- ::1
|
||||||
|
|
||||||
|
recorder:
|
||||||
|
db_url: mysql+pymysql://__DB_USER__:__DB_PWD__@localhost:3306/__DB_NAME__?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4
|
||||||
|
|
||||||
# Apply default set of integrations
|
# Apply default set of integrations
|
||||||
default_config:
|
default_config:
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Home Assistant
|
Description=Home Assistant
|
||||||
After=network.target
|
After=network.target mysql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
VERSION=2021.12.7
|
VERSION=2021.12.7
|
||||||
|
|
||||||
# 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 libmariadbclient-dev libmariadb-dev-compat"
|
||||||
|
|
||||||
# Requirements (Major.Minor.Patch)
|
# 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)
|
# PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.9" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2)
|
||||||
|
@ -135,6 +135,8 @@ myynh_install_homeassistant () {
|
||||||
&& source "$final_path/bin/activate" \
|
&& source "$final_path/bin/activate" \
|
||||||
&& echo 'install last version of wheel' \
|
&& echo 'install last version of wheel' \
|
||||||
&& pip --cache-dir "$data_path/.cache" install --upgrade 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' \
|
&& echo 'install Home Assistant' \
|
||||||
&& pip --cache-dir "$data_path/.cache" install --upgrade $app==$VERSION \
|
&& pip --cache-dir "$data_path/.cache" install --upgrade $app==$VERSION \
|
||||||
"
|
"
|
||||||
|
|
|
@ -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)
|
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
|
||||||
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
||||||
python=$(ynh_app_setting_get --app="$app" --key=python)
|
python=$(ynh_app_setting_get --app="$app" --key=python)
|
||||||
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
|
||||||
# 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..."
|
||||||
|
@ -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="/etc/logrotate.d/$app"
|
||||||
ynh_backup --src_path="$(dirname "$log_file")"
|
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"
|
ynh_print_info --message="Backup of $app completed"
|
||||||
|
|
|
@ -59,6 +59,13 @@ chown -R $app: "$data_path"
|
||||||
ynh_script_progression --message="Installing dependencies..."
|
ynh_script_progression --message="Installing dependencies..."
|
||||||
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
|
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
|
# 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..."
|
||||||
ynh_exec_fully_quiet myynh_install_homeassistant
|
ynh_exec_fully_quiet myynh_install_homeassistant
|
||||||
|
|
|
@ -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)
|
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
|
||||||
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
||||||
python=$(ynh_app_setting_get --app="$app" --key=python)
|
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`
|
# Remove a service from the admin panel, added by `yunohost service add`
|
||||||
if ynh_exec_warn_less yunohost service status "$app" >/dev/null ; then
|
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_script_progression --message="Removing logrotate configuration..."
|
||||||
ynh_remove_logrotate
|
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
|
# remove metapackage and its dependencies
|
||||||
ynh_script_progression --message="Removing dependencies..."
|
ynh_script_progression --message="Removing dependencies..."
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_app_dependencies
|
||||||
|
|
|
@ -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)
|
log_file=$(ynh_app_setting_get --app="$app" --key=log_file)
|
||||||
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
||||||
python=$(ynh_app_setting_get --app="$app" --key=python)
|
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
|
# check domain/path availability
|
||||||
ynh_script_progression --message="Validating recovery parameters..."
|
ynh_script_progression --message="Validating recovery parameters..."
|
||||||
|
@ -53,6 +55,12 @@ ynh_restore_file --origin_path="$(dirname "$log_file")"
|
||||||
ynh_script_progression --message="Restoring the packages dependencies..."
|
ynh_script_progression --message="Restoring the packages dependencies..."
|
||||||
myynh_install_dependencies --python="$python"
|
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
|
# 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.service"
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||||
|
|
|
@ -77,6 +77,20 @@ if [ ! -f "$log_file" ]; then
|
||||||
myynh_create_dir "$(dirname "$log_file")"
|
myynh_create_dir "$(dirname "$log_file")"
|
||||||
touch "$log_file"
|
touch "$log_file"
|
||||||
fi
|
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+pymysql://$db_user:$db_pwd@localhost:3306/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
|
||||||
|
else
|
||||||
|
sed -i "/recorder:/a \ db_url: mysql+pymysql://$db_user:$db_pwd@localhost:3306/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# 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..."
|
||||||
|
|
Loading…
Add table
Reference in a new issue