2022-01-08 10:04:57 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
mynh_system_user_create
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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-01-13 21:34:59 +01:00
|
|
|
ynh_exec_fully_quiet myynh_upgrade_venv_directory
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_exec_fully_quiet myynh_install_homeassistant
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2022-02-21 21:33:31 +01:00
|
|
|
# Install libffi-3.3 if libffi.so.7 is missing (buster)
|
|
|
|
[[ $(ldconfig -p | grep libffi.so.7) ]] || myynh_compile_libffi
|
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
|
|
|
|
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
|
|
|
|
ynh_use_logrotate --logfile="$log_file" --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SET FILE OWNERSHIP / PERMISSIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
myynh_set_permissions
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|