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

61 lines
1.7 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
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
is_public=$(ynh_app_setting_get $app is_public)
# 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
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
}
fi
# grant sudo permissions to the user to manage his own systemd service
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
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
# stop systemd service
2018-10-18 05:16:40 +02:00
ynh_system_reload --service_name="$app@$app" --action=stop
ynh_system_reload --service_name="$app@$app" --action=disable
2018-09-25 19:03:30 +02:00
# upgrade
exec_as "$app" -H -s /bin/bash -c " \
echo 'create the virtual environment' \
&& python3 -m venv $final_path \
&& echo 'activate the virtual environment' \
&& source $final_path/bin/activate \
&& echo 'install a required python package' \
2018-10-18 05:16:40 +02:00
&& pip install --upgrade wheel \
2018-09-25 19:03:30 +02:00
&& echo 'install Home Assistant' \
2018-10-18 05:16:40 +02:00
&& pip install --upgrade $app \
2018-09-25 19:03:30 +02:00
"
# setup up autostart using systemd
2018-10-18 05:16:40 +02:00
ynh_add_systemd_config "$app@$app"
2018-09-25 19:03:30 +02:00
# enable & restart systemd service
2018-10-18 05:16:40 +02:00
ynh_system_reload --service_name="$app@$app" --action=enable
2018-11-30 05:55:42 +01:00
ynh_check_starting --line_to_match="Home Assistant initialized" --app_log="systemd" --timeout=1000 --service_name="$app@$app"
2018-09-25 19:03:30 +02:00
# create a dedicated nginx config
ynh_add_nginx_config
# reload nginx
2018-10-18 05:16:40 +02:00
ynh_system_reload --service_name=nginx