#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # DEFINE USEFULL VARS #================================================= log_file="/var/log/$app/$app.log" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= 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" 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" # installation in a virtual environment ynh_script_progression --message="Installing Home Assistant in a virtual environment..." myynh_install_homeassistant #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= # 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 #================================================= 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 #================================================= 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 #================================================= # 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 " #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last