2018-09-25 19:03:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# manage script failure
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
# retrieve arguments
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-11-16 15:10:12 +01:00
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
port=$(ynh_app_setting_get --app="$app" --key=port)
|
2020-08-12 22:22:59 +02:00
|
|
|
|
2018-09-25 19:03:30 +02:00
|
|
|
# definie useful vars
|
2018-10-18 05:16:40 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
2021-11-20 19:05:14 +01:00
|
|
|
data_path="/home/yunohost.app/$app"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# use prior backup and restore on error only if backup feature exists on installed instance
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_script_progression --message="Creating backup in case of failure..."
|
2018-09-25 19:03:30 +02:00
|
|
|
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
|
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_restore_upgradebackup
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_clean_check_starting
|
2018-09-25 19:03:30 +02:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2021-11-20 19:05:14 +01:00
|
|
|
# move $data_path to new directory
|
|
|
|
ynh_script_progression --message="Moving existing datas to new location..."
|
|
|
|
if [ ! -d "$data_path" ] ; then
|
|
|
|
mv "/""home""/$app" "$data_path"
|
|
|
|
ynh_replace_string --match_string="/home/homeassistant/.homeassistant" --replace_string="$data_path/.$app" --target_file="$data_path/.$app/configuration.yaml"
|
|
|
|
chown -R $app: "$data_path"
|
|
|
|
fi
|
|
|
|
|
2018-12-18 07:30:30 +01:00
|
|
|
# grant sudo permissions to the user to manage his own systemd service
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_script_progression --message="Creating dedicated user, rights and folders..."
|
2021-11-20 19:05:14 +01:00
|
|
|
ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
|
2018-12-18 07:30:30 +01:00
|
|
|
|
2020-11-14 14:10:51 +01:00
|
|
|
# build (if needed) & install Pyhton
|
2021-01-18 21:12:47 +01:00
|
|
|
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# stop systemd service
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_script_progression --message="Stoping service..."
|
2021-11-21 21:25:39 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=stop --line_match="Stopped Home Assistant" --log_path="systemd" --timeout=300
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-08-13 20:50:44 +02:00
|
|
|
# installation in a virtual environment
|
|
|
|
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
2021-11-20 19:05:14 +01:00
|
|
|
ynh_exec_fully_quiet myynh_install_homeassistant --path="$data_path"
|
2020-11-14 14:10:51 +01:00
|
|
|
|
2020-08-27 21:06:09 +02:00
|
|
|
# update script in bin
|
2021-01-05 15:18:56 +01:00
|
|
|
ynh_script_progression --message="Updating YunoHost script used by homeassitant..."
|
2021-11-20 19:05:14 +01:00
|
|
|
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/.$app/bin/"
|
|
|
|
chown -R $app: "$data_path/.$app/bin"
|
|
|
|
chmod -R +x "$data_path/.$app/bin/"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-08-13 20:50:44 +02:00
|
|
|
# setup up systemd service
|
|
|
|
ynh_script_progression --message="Adding the dedicated service..."
|
2021-11-20 19:05:14 +01:00
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/systemd.service"
|
2021-11-21 21:25:39 +01:00
|
|
|
ynh_add_systemd_config --service="$app"
|
2021-11-20 19:05:14 +01:00
|
|
|
|
|
|
|
# add service in admin panel
|
2021-11-21 21:25:39 +01:00
|
|
|
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-08-13 20:50:44 +02:00
|
|
|
# start systemd service
|
|
|
|
ynh_script_progression --message="Starting the Home Assistant server..."
|
2021-11-20 19:05:14 +01:00
|
|
|
systemctl daemon-reload
|
2021-11-21 21:25:39 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
|
2021-11-20 19:05:14 +01:00
|
|
|
|
2020-08-14 14:26:27 +02:00
|
|
|
# remove --verbose from service
|
2021-11-21 21:25:39 +01:00
|
|
|
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"
|
2020-08-14 14:26:27 +02:00
|
|
|
systemctl daemon-reload
|
2021-11-21 21:25:39 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=restart
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2021-02-20 09:53:53 +01:00
|
|
|
# enable logrotate
|
2021-11-20 19:05:14 +01:00
|
|
|
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log" --nonappend
|
2021-02-20 09:53:53 +01:00
|
|
|
|
2018-09-25 19:03:30 +02:00
|
|
|
# create a dedicated nginx config
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_add_nginx_config
|
2021-11-20 19:05:14 +01:00
|
|
|
|
2018-09-25 19:03:30 +02:00
|
|
|
# reload nginx
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|