2022-01-08 10:04:57 +01:00
|
|
|
#!/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
|
|
|
|
#=================================================
|
2023-02-12 22:01:31 +01:00
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
|
|
|
|
|
|
|
|
#=================================================
|
2023-02-12 22:01:31 +01:00
|
|
|
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
|
2022-01-08 10:04:57 +01:00
|
|
|
#=================================================
|
2023-02-12 22:01:31 +01:00
|
|
|
# CHECK PYTHON VERSION AND COMPILE IF NEEDED
|
2022-01-08 10:04:57 +01:00
|
|
|
#=================================================
|
2022-02-21 21:33:31 +01:00
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Check Python version & compile the required one if needed..." --weight=1
|
2022-01-08 10:04:57 +01:00
|
|
|
myynh_install_python --python="$py_required_version"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2023-02-12 22:01:31 +01:00
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
|
|
|
|
# create a directory for the installation of Home Assistant
|
2023-02-12 22:01:31 +01:00
|
|
|
myynh_create_dir "$install_dir"
|
|
|
|
chown -R $app: "$install_dir"
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
# create a directory for the datas of Home Assistant
|
2023-02-12 22:01:31 +01:00
|
|
|
myynh_create_dir "$data_dir/.cache"
|
|
|
|
chown -R $app: "$data_dir"
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
# installation in a virtual environment
|
|
|
|
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
2022-12-19 12:16:25 +01:00
|
|
|
myynh_install_homeassistant
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2022-01-08 10:04:57 +01:00
|
|
|
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"
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
#=================================================
|
|
|
|
# APP INITIAL CONFIGURATION
|
2022-01-08 10:04:57 +01:00
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
cp -r "../conf/homeassistant_conf_files/." "$data_dir/"
|
|
|
|
ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml"
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Adding the dedicated service..."
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2022-01-08 10:04:57 +01:00
|
|
|
ynh_use_logrotate --logfile="$log_file"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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 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
|
|
|
|
|
2023-01-31 11:14:50 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-12 22:01:31 +01:00
|
|
|
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
|
2023-01-31 11:14:50 +01:00
|
|
|
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
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|