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
|
|
|
|
|
2018-12-18 07:30:30 +01:00
|
|
|
# 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-12-18 07:30:30 +01:00
|
|
|
|
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
|