mirror of
https://github.com/YunoHost-Apps/homeassistant_ynh.git
synced 2024-09-03 19:26:16 +02:00
Fix packaging v2
This commit is contained in:
parent
48879441aa
commit
a1258d7b24
6 changed files with 96 additions and 189 deletions
|
@ -19,7 +19,7 @@ cpe = "cpe:2.3:a:home-assistant:home-assistant"
|
|||
|
||||
[integration]
|
||||
yunohost = ">= 11.0.0"
|
||||
architectures = "all"
|
||||
architectures = ["amd64", "arm64"]
|
||||
multi_instance = false
|
||||
ldap = true
|
||||
sso = false
|
||||
|
@ -81,8 +81,23 @@ ram.runtime = "2G"
|
|||
[resources.system_user]
|
||||
|
||||
[resources.install_dir]
|
||||
dir = "/var/www/__APP__"
|
||||
owner = "__APP__:rwx"
|
||||
group = "__APP__:rx"
|
||||
|
||||
[resources.data_dir]
|
||||
dir = "/home/yunohost.app/__APP__"
|
||||
owner = "__APP__:rwx"
|
||||
group = "__APP__:rx"
|
||||
|
||||
[resources.database]
|
||||
type = "mysql"
|
||||
|
||||
[resources.permissions]
|
||||
main.url = "/"
|
||||
|
||||
[resources.apt]
|
||||
packages = "python3, python3-dev, python3-venv, python3-pip, libffi-dev, libssl-dev, libjpeg-dev, zlib1g-dev, autoconf, build-essential, libopenjp2-7, libtiff5, libturbojpeg0, libmariadb-dev, libmariadb-dev-compat, rustc, tk-dev, libncurses5-dev, libncursesw5-dev, libreadline6-dev, libdb5.3-dev, libgdbm-dev, libsqlite3-dev, libbz2-dev, libexpat1-dev, liblzma-dev, wget, tar, libnss3-dev, libreadline-dev"
|
||||
|
||||
[resources.ports]
|
||||
main.default = 8123
|
||||
|
|
|
@ -124,8 +124,17 @@ myynh_install_homeassistant () {
|
|||
# add pip
|
||||
ynh_exec_as $app "$install_dir/bin/python3" -m ensurepip
|
||||
|
||||
# install last version of wheel, pip & mysqlclient
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel pip mysqlclient
|
||||
# install last version of pip
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade pip
|
||||
|
||||
# install last version of wheel
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel
|
||||
|
||||
# install last version of setuptools
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade setuptools
|
||||
|
||||
# install last version of mysqlclient
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade mysqlclient
|
||||
|
||||
# install Home Assistant
|
||||
ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade $app==$app_version
|
||||
|
@ -146,9 +155,9 @@ myynh_set_permissions () {
|
|||
chown -R $app: "$data_dir"
|
||||
chmod 750 "$data_dir"
|
||||
chmod -R o-rwx "$data_dir"
|
||||
chmod -R +x "$data_dir/bin/"
|
||||
[ ! -e "$data_dir/bin/" ] || chmod -R +x "$data_dir/bin/"
|
||||
|
||||
chown -R $app: "$(dirname "$log_file")"
|
||||
[ ! -e "$(dirname "$log_file")" ] || chown -R $app: "$(dirname "$log_file")"
|
||||
|
||||
chown -R root: "/etc/sudoers.d/$app"
|
||||
[ ! -e "/etc/sudoers.d/$app" ] || chown -R root: "/etc/sudoers.d/$app"
|
||||
}
|
||||
|
|
|
@ -10,15 +10,10 @@ source _common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# DEFINE USEFULL VARS
|
||||
# DEFINE USEFULL VARS / SETTINGS
|
||||
#=================================================
|
||||
|
||||
log_file="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
|
||||
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
|
||||
|
||||
#=================================================
|
||||
|
@ -38,28 +33,40 @@ ynh_script_progression --message="Setting up source files..."
|
|||
|
||||
# create a directory for the installation of Home Assistant
|
||||
myynh_create_dir "$install_dir"
|
||||
chown -R $app: "$install_dir"
|
||||
|
||||
# create a directory for the datas of Home Assistant
|
||||
myynh_create_dir "$data_dir/.cache"
|
||||
chown -R $app: "$data_dir"
|
||||
|
||||
# create a directory for the logs of Home Assistant
|
||||
mkdir -p "$(dirname "$log_file")"
|
||||
touch "$log_file"
|
||||
|
||||
# installation in a virtual environment
|
||||
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
||||
myynh_install_homeassistant
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
# SYSTEM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring NGINX web server..."
|
||||
ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config using the conf/nginx.conf template
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
# grant sudo permissions to the user to manage his own systemd service
|
||||
# Create a dedicated service in YunoHost
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate --logfile="$log_file"
|
||||
|
||||
# Create a dedicated Fail2Ban config
|
||||
ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from <HOST>"
|
||||
|
||||
# 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"
|
||||
|
||||
|
@ -69,39 +76,11 @@ ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
|
|||
# ADD A CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||
|
||||
cp -r "../conf/homeassistant_conf_files/." "$data_dir/"
|
||||
ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Adding the dedicated service..."
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring log rotation..."
|
||||
ynh_use_logrotate --logfile="$log_file"
|
||||
|
||||
#=================================================
|
||||
# SET FILE OWNERSHIP / PERMISSIONS
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring files permissions..."
|
||||
myynh_set_permissions
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
@ -117,13 +96,6 @@ ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
|
|||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=$app --action=restart
|
||||
|
||||
#=================================================
|
||||
# SETUP FAIL2BAN
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
|
||||
ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from <HOST>"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
|
|
@ -12,52 +12,25 @@ source _common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||
# REMOVE SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
|
||||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
ynh_remove_systemd_config
|
||||
|
||||
ynh_script_progression --message="Stopping and removing the systemd service..."
|
||||
ynh_remove_systemd_config --service=$app
|
||||
|
||||
#=================================================
|
||||
# REMOVE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removing logrotate configuration..."
|
||||
ynh_remove_logrotate
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removing NGINX web server configuration..."
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE FAIL2BAN CONFIGURATION
|
||||
#=================================================
|
||||
ynh_remove_logrotate
|
||||
|
||||
ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1
|
||||
ynh_remove_fail2ban_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
# REMOVE VARIOUS FILES
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removing various files..."
|
||||
ynh_secure_remove --file="/etc/sudoers.d/$app"
|
||||
|
||||
ynh_secure_remove --file="$(dirname "$log_file")"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -14,13 +14,6 @@
|
|||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring the NGINX configuration..."
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
@ -37,14 +30,35 @@ ynh_restore_file --origin_path="$data_dir" --not_mandatory
|
|||
mkdir -p $data_dir
|
||||
|
||||
#=================================================
|
||||
# RESTORE FAIL2BAN CONFIGURATION
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
||||
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||
# add --verbose to track restart
|
||||
sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service --quiet
|
||||
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||
|
||||
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
|
||||
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_systemd_action --action=restart --service_name=fail2ban
|
||||
|
||||
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
|
||||
ynh_restore_file --origin_path="$(dirname "$log_file")"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
|
@ -54,38 +68,6 @@ ynh_systemd_action --action=restart --service_name=fail2ban
|
|||
ynh_script_progression --message="Restoring Python..." --weight=1
|
||||
myynh_install_python --python="$python"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
||||
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RESTORE VARIOUS FILES
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring various files..."
|
||||
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
|
||||
ynh_restore_file --origin_path="$(dirname "$log_file")"
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring the systemd configuration..."
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||
# add --verbose to track restart
|
||||
sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service --quiet
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoring the logrotate configuration..."
|
||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||
|
||||
#=================================================
|
||||
# IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV.
|
||||
#=================================================
|
||||
|
@ -97,20 +79,6 @@ if [ ! -e "$hass_python_link" ] ; then
|
|||
ln -sfn "$hass_python_new_dest" "$hass_python_link"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SET FILE OWNERSHIP / PERMISSIONS
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring files permissions..."
|
||||
myynh_set_permissions
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
|
|
@ -9,10 +9,6 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
|
@ -24,6 +20,8 @@ upgrade_type=$(ynh_check_app_version_changed)
|
|||
ynh_script_progression --message="Stopping a systemd service..."
|
||||
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...)
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -38,12 +36,23 @@ then
|
|||
fi
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
# REAPPLY SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
||||
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
||||
|
||||
ynh_add_nginx_config
|
||||
|
||||
ynh_add_systemd_config
|
||||
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
ynh_use_logrotate --logfile="$log_file" --non-append
|
||||
|
||||
ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from <HOST>"
|
||||
|
||||
#=================================================
|
||||
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...)
|
||||
#=================================================
|
||||
# UPDATE A CONFIG FILE
|
||||
#=================================================
|
||||
|
@ -52,45 +61,6 @@ ynh_script_progression --message="Updating a configuration file..."
|
|||
cp -r "../conf/homeassistant_conf_files/bin/." "$data_dir/bin/"
|
||||
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrading systemd configuration..."
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# SETUP FAIL2BAN
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
|
||||
# Create a dedicated Fail2Ban config
|
||||
ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from <HOST>"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrading logrotate configuration..."
|
||||
ynh_use_logrotate --logfile="$log_file" --non-append
|
||||
|
||||
#=================================================
|
||||
# SET FILE OWNERSHIP / PERMISSIONS
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring files permissions..."
|
||||
myynh_set_permissions
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue