#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # DEFINE USEFULL VARS / SETTINGS #================================================= log_file="/var/log/$app/$app.log" ynh_app_setting_set --app=$app --key=log_file --value="$log_file" #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= ynh_script_progression --message="Check Python version & compile the required one if needed..." --weight=1 myynh_install_python --python="$py_required_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." # create a directory for the installation of Home Assistant myynh_create_dir "$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 #================================================= # SYSTEM CONFIGURATION #================================================= 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 # Create a dedicated systemd config ynh_add_systemd_config # 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 " # 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" #================================================= # APP INITIAL CONFIGURATION #================================================= # 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" #================================================= # SET FILE OWNERSHIP / PERMISSIONS #================================================= myynh_set_permissions #================================================= # 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 systemd 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="Installation of $app completed" --last