From ff2fda78dba383c419cfcdede7f868fccc9cc887 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 1 Sep 2018 15:16:50 +0200 Subject: [PATCH] Add 3.1.1 upgrade with two steps upgrade --- conf/settings_history/settings.3.1.1.py | 2 +- hooks/post_app_upgrade | 18 ++++++++++ scripts/upgrade | 48 +++++++++++++++++++++---- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 hooks/post_app_upgrade diff --git a/conf/settings_history/settings.3.1.1.py b/conf/settings_history/settings.3.1.1.py index d405f72..37193f5 100644 --- a/conf/settings_history/settings.3.1.1.py +++ b/conf/settings_history/settings.3.1.1.py @@ -27,7 +27,7 @@ from logging.handlers import SysLogHandler # Django settings for Weblate project. # -DEBUG = FALSE +DEBUG = False ADMINS = ( ('__ADMIN__', '__ADMINMAIL__'), diff --git a/hooks/post_app_upgrade b/hooks/post_app_upgrade new file mode 100644 index 0000000..e397d3c --- /dev/null +++ b/hooks/post_app_upgrade @@ -0,0 +1,18 @@ +#!/bin/bash + +migration311=$(yunohost app setting "$YNH_APP_INSTANCE_NAME" "migration311" --output-as plain --quiet) +mig_type=$(yunohost app setting "$YNH_APP_INSTANCE_NAME" "migration311_type" --output-as plain --quiet) +mig_parm=$(yunohost app setting "$YNH_APP_INSTANCE_NAME" "migration311_parm" --output-as plain --quiet) + +if [[ "$migration311" = "two_steps_upgrade_3.0to3.1-needed" ]] +then + yunohost app setting "$YNH_APP_INSTANCE_NAME" "migration311" --value="two_steps_upgrade_3.0to3.1-progress" --quiet + if [ "$mig_type" = "file" ] + then + yunohost app upgrade "$YNH_APP_INSTANCE_NAME" --file "$mig_parm" + else + yunohost app upgrade "$YNH_APP_INSTANCE_NAME" --url "$mig_parm" + fi + + yunohost app setting "$YNH_APP_INSTANCE_NAME" "migration311" --value="two_steps_upgrade_3.0to3.1-done" --quiet +fi \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 94f8844..c7710e0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,6 +26,7 @@ admin=$(ynh_app_setting_get "$app" admin) admin_mail=$(ynh_user_get_info "$admin" mail) memc_port=$(ynh_app_setting_get "$app" memc_port) github_account=$(ynh_app_setting_get "$app" github_account) +migration311=$(ynh_app_setting_get "$app" migration311) key=$(ynh_string_random) #================================================= @@ -84,7 +85,7 @@ then fi # (<2.20) remove your old sockets! -if [ -e "/etc/systemd/system/uwsgi-app@.socket" ] +if [ -e "/etc/systemd/system/uwsgi-app@$app.socket" ] then systemctl stop "uwsgi-app@$app.socket" yunohost service remove "uwsgi-app@$app.socket" @@ -104,6 +105,34 @@ then ynh_secure_remove "$final_path/bin/" fi +# Weblate requires an update to 3.0 before 3.1 +# the upgrade hook will launch this script again to make sure it works +if [[ -z "$migration311" ]] +then + # $migration311 is not set, version is <3.0 + migration311="two_steps_upgrade_3.0to3.1-needed" + + mig_type=$(cat "/etc/yunohost/apps/$YNH_APP_ID/status.json" | sed -e 's/.*"type":.*"\(.\+\)".*/\1/gi') + + if [ "$mig_type" = "file" ] + then + mig_parm=$(cat "/etc/yunohost/apps/$YNH_APP_ID/status.json" | sed -e 's/.*"path": "\(.\+\)",.*/\1/gi') + else + mig_parm=$(cat "/etc/yunohost/apps/$YNH_APP_ID/status.json" | sed -e 's/.*"url": "\(.\+\)", "type".*/\1/gi') + fi + + ynh_app_setting_set "$app" migration311 "$migration311" + ynh_app_setting_set "$app" migration311_type "$mig_type" + ynh_app_setting_set "$app" migration311_parm "$mig_parm" + current_version="3.0.1" +fi + +# Make sure the uwsgi service is stoped +if [[ -e "/var/run/uwsgi/$app.socket" ]] +then + systemctl stop "uwsgi-app@$app.service" +fi + #================================================= # CHECK THE PATH #================================================= @@ -241,13 +270,18 @@ fi # https://docs.weblate.org/en/latest/admin/upgrade.html#upgrade-3 # https://github.com/WeblateOrg/docker/blob/386aa8d98bb57dfec3707680827d4e4f4d79e3fd/start#L81-L88 - weblate showmigrations --plan > /tmp/migrations.txt - if grep -Fq '[X] auth.0001_initial' /tmp/migrations.txt && grep -Fq '[ ] weblate_auth.0001_initial' /tmp/migrations.txt ; then - ynh_replace_string "AUTH_USER_MODEL" "#AUTH_USER_MODEL" "$settings" - weblate migrate weblate_auth 0001 - ynh_replace_string "#AUTH_USER_MODEL" "AUTH_USER_MODEL" "$settings" + if [[ $current_version = "3.0.1" ]] + then + weblate showmigrations --plan > /tmp/migrations.txt + if grep -Fq '[X] auth.0001_initial' /tmp/migrations.txt && grep -Fq '[ ] weblate_auth.0001_initial' /tmp/migrations.txt ; then + ynh_replace_string "AUTH_USER_MODEL" "#AUTH_USER_MODEL" "$settings" + weblate migrate weblate_auth 0001 + ynh_replace_string "#AUTH_USER_MODEL" "AUTH_USER_MODEL" "$settings" + fi + + ynh_secure_remove /tmp/migrations.txt fi - ynh_secure_remove /tmp/migrations.txt + weblate migrate --noinput weblate collectstatic --noinput