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/upgrade

83 lines
2.8 KiB
Text
Raw Normal View History

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-08-12 22:22:59 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
# Cleaning legacy permissions
2020-08-13 20:50:44 +02:00
ynh_script_progression --message="Cleaning legacy permissions..."
2020-08-12 22:22:59 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
if [ -n "$is_public" ]; then
ynh_app_setting_delete --app=$app --key=is_public
ynh_app_setting_delete --app=$app --key=unprotected_uris
fi
2018-09-25 19:03:30 +02:00
# definie useful vars
2018-10-18 05:16:40 +02:00
final_path="/opt/yunohost/$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
# 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..."
myynh_create_dir "/etc/sudoers.d"
2018-12-18 22:36:54 +01:00
cp "../conf/sudoers" "/etc/sudoers.d/$app"
2018-09-25 19:03:30 +02:00
# add required packages
2020-08-13 20:50:44 +02:00
ynh_script_progression --message="Installing dependencies..."
2018-09-25 19:03:30 +02:00
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
# stop systemd service
2020-08-13 20:50:44 +02:00
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app@$app" --action=stop
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..."
2020-08-14 13:25:58 +02:00
exec_as $app -H -s /bin/bash -c " \
2018-09-25 19:03:30 +02:00
echo 'create the virtual environment' \
2020-08-14 13:25:58 +02:00
&& python3 -m venv "$final_path" \
2018-09-25 19:03:30 +02:00
&& echo 'activate the virtual environment' \
2020-08-14 13:25:58 +02:00
&& source "$final_path/bin/activate" \
2018-09-25 19:03:30 +02:00
&& echo 'install a required python package' \
2020-08-14 13:25:58 +02:00
&& python3 -m pip install --upgrade wheel \
2018-09-25 19:03:30 +02:00
&& echo 'install Home Assistant' \
2020-08-14 13:25:58 +02:00
&& pip3 install --upgrade $app==$VERSION \
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..."
ynh_add_systemd_config --service="$app@$app"
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..."
2020-08-13 21:04:43 +02:00
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=1000
2020-08-14 14:26:27 +02:00
# remove --verbose from service
ynh_replace_string " --verbose" "" "/etc/systemd/system/$app@$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
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
# 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