#!/bin/bash source _common.sh source /usr/share/yunohost/helpers #================================================= # DEFINE USEFULL VARS / SETTINGS #================================================= log_file="/var/log/$app/$app.log" ynh_app_setting_set --key=log_file --value="$log_file" #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= ynh_script_progression "Check Python version & compile the required one if needed..." myynh_install_python --python="$py_required_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression "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 "Installing Home Assistant in a virtual environment..." myynh_install_homeassistant #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression "Adding system configurations related to $app ..." # Create a dedicated NGINX config using the conf/nginx.conf template ynh_config_add_nginx # Create a dedicated systemd config ynh_config_add_systemd # 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_config_add_logrotate "$log_file" # Create a dedicated Fail2Ban config ynh_config_add_fail2ban --logpath="$log_file" --failregex="$failregex" # Grant sudo permissions to the user to manage his own systemd service myynh_create_dir "/etc/sudoers.d" ynh_config_add --template="sudoers" --destination="/etc/sudoers.d/$app" #================================================= # APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression "Adding $app's configuration..." cp -r "../conf/homeassistant_conf_files/." "$data_dir/" ynh_config_add --template="homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" #================================================= # SET FILE OWNERSHIP / PERMISSIONS #================================================= myynh_set_permissions #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." # start systemd service with --verbose ynh_systemctl --service=$app --action=start --wait_until="Home Assistant initialized" --log_path="$log_file" --timeout=3600 # remove --verbose from systemd service ynh_replace --match=" --verbose" --replace="" --file="/etc/systemd/system/$app.service" ynh_store_file_checksum "/etc/systemd/system/$app.service" systemctl daemon-reload ynh_systemctl --service=$app --action=restart #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Installation of $app completed"