2022-01-08 10:04:57 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEFINE USEFULL VARS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
|
|
|
log_file="/var/log/$app/$app.log"
|
|
|
|
path_url="/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
|
|
|
[ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path "
|
|
|
|
ynh_webpath_register --app=$app --domain="$domain" --path_url="$path_url"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value="$domain"
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value="$final_path"
|
|
|
|
ynh_app_setting_set --app=$app --key=data_path --value="$data_path"
|
|
|
|
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
|
|
|
|
ynh_app_setting_set --app=$app --key=path_url --value="$path_url"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Finding an available port..."
|
|
|
|
|
|
|
|
port=$(ynh_find_port 8123)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value="$port"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2022-02-21 21:33:31 +01:00
|
|
|
|
|
|
|
# Install libffi-3.3 if libffi.so.7 is missing (buster)
|
|
|
|
[[ $(ldconfig -p | grep libffi.so.7) ]] || myynh_compile_libffi
|
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
myynh_install_python --python="$py_required_version"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
mynh_system_user_create
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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 "$final_path"
|
|
|
|
chown -R $app: "$final_path"
|
|
|
|
|
|
|
|
# create a directory for the datas of Home Assistant
|
|
|
|
myynh_create_dir "$data_path/.cache"
|
|
|
|
chown -R $app: "$data_path"
|
|
|
|
|
|
|
|
# installation in a virtual environment
|
|
|
|
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
|
|
|
ynh_exec_fully_quiet 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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
|
|
|
|
ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_path/configuration.yaml"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# setup up systemd service
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
myynh_set_permissions
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
# add service in admin panel
|
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
|
|
|
|
#=================================================
|
|
|
|
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 SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
|
|
|
|
[ $is_public -eq 1 ] && ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|