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

90 lines
3.1 KiB
Text
Raw Normal View History

2022-01-08 10:04:57 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Stopping a systemd service..."
2022-01-08 10:04:57 +01:00
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
2023-02-15 12:31:34 +01:00
#=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...)
2022-01-08 10:04:57 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
myynh_install_python --python="$py_required_version"
2022-12-19 12:16:25 +01:00
myynh_upgrade_venv_directory
myynh_install_homeassistant
2022-01-08 10:04:57 +01:00
fi
#=================================================
2023-02-15 12:31:34 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2022-01-08 10:04:57 +01:00
2023-02-15 12:31:34 +01:00
ynh_add_nginx_config
2022-01-08 10:04:57 +01:00
ynh_add_systemd_config
2023-02-15 12:31:34 +01:00
yunohost service add $app --description="Home Assistant server" --log="$log_file"
2022-01-08 10:04:57 +01:00
ynh_use_logrotate --logfile="$log_file" --non-append
2023-04-08 19:20:38 +02:00
ynh_add_fail2ban_config --logpath="$log_file" --failregex="[homeassistant.components.http.ban] Login attempt or request with invalid authentication from <HOST> .* Requested URL: ./auth/"
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...)
#=================================================
# UPDATE A CONFIG FILE
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
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"
2022-01-08 10:04:57 +01:00
2023-02-15 18:15:32 +01:00
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
2022-01-08 10:04:57 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2023-02-12 22:01:31 +01:00
2022-01-08 10:04:57 +01:00
ynh_script_progression --message="Starting a systemd service..."
# start systemd service with --verbose
ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600
# remove --verbose from service
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
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last