mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
Fix upgrade for locally modified settings files
This commit is contained in:
parent
63f95130ac
commit
2a88486fa9
2 changed files with 43 additions and 25 deletions
|
@ -82,7 +82,7 @@ ynh_remove_uwsgi_service () {
|
|||
|
||||
|
||||
weblate_fill_settings() {
|
||||
settings="$1"
|
||||
local settings="$1"
|
||||
|
||||
ynh_replace_string "__NAME__" "$app" "$settings"
|
||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$settings"
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
@ -42,8 +40,10 @@ key=$(ynh_string_random 50)
|
|||
)
|
||||
previous_version=$(cat freeze.pip | grep "Weblate==" | sed "s|Weblate==||")
|
||||
|
||||
previous_version_file="../conf/settings_history/settings.$previous_version.py"
|
||||
test -e "$previous_version_file" || ynh_die "Previous version unknown: $previous_version"
|
||||
ynh_secure_remove freeze.pip
|
||||
|
||||
previous_version_template="../conf/settings_history/settings.$previous_version.py"
|
||||
test -e "$previous_version_template" || ynh_die "Previous version unknown: $previous_version"
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
|
@ -133,6 +133,19 @@ then
|
|||
systemctl stop "uwsgi-app@$app.service"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
@ -194,12 +207,6 @@ fi
|
|||
# PIP INSTALLATION
|
||||
#=================================================
|
||||
|
||||
# save old settings file
|
||||
cp "$settings" "$final_path/settings.$previous_version.old.py"
|
||||
|
||||
old_settings="./settings.$previous_version.old.py"
|
||||
settings_diff="$final_path/settings.${previous_version}_${current_version}.diff"
|
||||
|
||||
(
|
||||
set +o nounset
|
||||
source "${final_path}/venv/bin/activate"
|
||||
|
@ -213,36 +220,44 @@ settings_diff="$final_path/settings.${previous_version}_${current_version}.diff"
|
|||
pip install django_sendmail_backend
|
||||
)
|
||||
|
||||
#=================================================
|
||||
# CONFIG FILE UPGRADE
|
||||
#=================================================
|
||||
|
||||
# save old settings file
|
||||
|
||||
old_settings="$final_path/settings.$previous_version.old.py"
|
||||
|
||||
cp "$settings" "$old_settings"
|
||||
|
||||
check=$(ynh_check_if_checksum_is_different "$settings")
|
||||
|
||||
if [[ "$check" -eq 1 ]]
|
||||
then
|
||||
echo "Settings.py was modified localy, running diff before using the new default file for $current_version."
|
||||
# generate previous defaults settings
|
||||
cp "$previous_version_file" "$old_settings"
|
||||
cp "$previous_version_template" "$old_settings"
|
||||
weblate_fill_settings "$old_settings"
|
||||
|
||||
# store diff between defaults and local settings
|
||||
diff --unified "$old_settings" "$settings" > "$settings_diff"
|
||||
|
||||
# generate new defaults settings
|
||||
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
||||
weblate_fill_settings "$settings"
|
||||
set +eu
|
||||
diff --unified "$old_settings" "$settings" > "$final_path/settings.${previous_version}_${current_version}.diff"
|
||||
set -eu
|
||||
|
||||
# send diff to the server administrator
|
||||
mail_message="
|
||||
Weblate was updated from version $previous_version to $current_version
|
||||
This is a MAJOR upgrade, please read this:
|
||||
https://docs.weblate.org/en/latest/admin/upgrade.html#upgrade-3
|
||||
Please read:
|
||||
https://docs.weblate.org/en/latest/admin/upgrade.html
|
||||
|
||||
A new settings.py has been created in:
|
||||
A new settings.py has been created:
|
||||
$settings
|
||||
|
||||
You may have changed your defaults settings.
|
||||
To help you to apply it again, here is a diff file with every changes you did.
|
||||
To help you, here is a diff file with every changes you did.
|
||||
|
||||
Diff has been created in:
|
||||
$settings_diff
|
||||
$final_path/settings.${previous_version}_${current_version}.diff
|
||||
|
||||
Please note secret key is updated, this is normal.
|
||||
|
||||
|
@ -252,10 +267,13 @@ then
|
|||
ynh_send_readme_to_admin "$mail_message" root "$admin_mail"
|
||||
else
|
||||
echo "Settings.py was not modified, using the new default file for $current_version."
|
||||
fi
|
||||
|
||||
# generate new defaults settings
|
||||
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
||||
weblate_fill_settings "$settings"
|
||||
fi
|
||||
|
||||
ynh_secure_remove "$old_settings"
|
||||
|
||||
#=================================================
|
||||
# Run migration scripts
|
||||
|
|
Loading…
Reference in a new issue