1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
homeassistant_ynh/scripts/install

111 lines
3.9 KiB
Text
Raw Permalink Normal View History

2022-01-08 10:04:57 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2023-02-15 12:31:34 +01:00
# DEFINE USEFULL VARS / SETTINGS
2022-01-08 10:04:57 +01:00
#=================================================
log_file="/var/log/$app/$app.log"
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"
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"
2023-02-15 22:38:23 +01:00
chown -R $app: "$data_dir"
2023-02-15 12:31:34 +01:00
# create a directory for the logs of Home Assistant
mkdir -p "$(dirname "$log_file")"
touch "$log_file"
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
#=================================================
2023-02-15 12:31:34 +01:00
# SYSTEM CONFIGURATION
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1
# Create a dedicated NGINX config using the conf/nginx.conf template
2022-01-08 10:04:57 +01:00
ynh_add_nginx_config
2023-02-15 12:31:34 +01:00
# 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"
2022-01-08 10:04:57 +01:00
2023-02-15 12:31:34 +01:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="$log_file"
# Create a dedicated Fail2Ban config
2023-04-08 21:17:38 +02:00
ynh_add_fail2ban_config --logpath="$log_file" --failregex="$failregex"
2023-02-15 12:31:34 +01:00
# Grant sudo permissions to the user to manage his own systemd service
2022-01-08 10:04:57 +01:00
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-15 12:31:34 +01:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
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
2023-02-15 18:15:32 +01:00
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
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
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last