2022-01-08 10:04:57 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
cp -r "../conf/homeassistant_conf_files/bin/." "$data_dir/bin/"
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2022-01-08 10:04:57 +01:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2023-01-31 11:14:50 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
|
2023-01-31 11:14:50 +01:00
|
|
|
# Create a dedicated Fail2Ban config
|
|
|
|
ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from <HOST>"
|
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_use_logrotate --logfile="$log_file" --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SET FILE OWNERSHIP / PERMISSIONS
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Configuring files permissions..."
|
2022-01-08 10:04:57 +01:00
|
|
|
myynh_set_permissions
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2022-05-07 21:27:08 +02:00
|
|
|
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
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
|