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() {
|
weblate_fill_settings() {
|
||||||
settings="$1"
|
local settings="$1"
|
||||||
|
|
||||||
ynh_replace_string "__NAME__" "$app" "$settings"
|
ynh_replace_string "__NAME__" "$app" "$settings"
|
||||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$settings"
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$settings"
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
ynh_abort_if_errors
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -42,8 +40,10 @@ key=$(ynh_string_random 50)
|
||||||
)
|
)
|
||||||
previous_version=$(cat freeze.pip | grep "Weblate==" | sed "s|Weblate==||")
|
previous_version=$(cat freeze.pip | grep "Weblate==" | sed "s|Weblate==||")
|
||||||
|
|
||||||
previous_version_file="../conf/settings_history/settings.$previous_version.py"
|
ynh_secure_remove freeze.pip
|
||||||
test -e "$previous_version_file" || ynh_die "Previous version unknown: $previous_version"
|
|
||||||
|
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
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
@ -133,6 +133,19 @@ then
|
||||||
systemctl stop "uwsgi-app@$app.service"
|
systemctl stop "uwsgi-app@$app.service"
|
||||||
fi
|
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
|
# CHECK THE PATH
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -194,12 +207,6 @@ fi
|
||||||
# PIP INSTALLATION
|
# 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
|
set +o nounset
|
||||||
source "${final_path}/venv/bin/activate"
|
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
|
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")
|
check=$(ynh_check_if_checksum_is_different "$settings")
|
||||||
|
|
||||||
if [[ "$check" -eq 1 ]]
|
if [[ "$check" -eq 1 ]]
|
||||||
then
|
then
|
||||||
echo "Settings.py was modified localy, running diff before using the new default file for $current_version."
|
echo "Settings.py was modified localy, running diff before using the new default file for $current_version."
|
||||||
# generate previous defaults settings
|
# generate previous defaults settings
|
||||||
cp "$previous_version_file" "$old_settings"
|
cp "$previous_version_template" "$old_settings"
|
||||||
weblate_fill_settings "$old_settings"
|
weblate_fill_settings "$old_settings"
|
||||||
|
|
||||||
# store diff between defaults and local settings
|
# store diff between defaults and local settings
|
||||||
diff --unified "$old_settings" "$settings" > "$settings_diff"
|
set +eu
|
||||||
|
diff --unified "$old_settings" "$settings" > "$final_path/settings.${previous_version}_${current_version}.diff"
|
||||||
# generate new defaults settings
|
set -eu
|
||||||
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
|
||||||
weblate_fill_settings "$settings"
|
|
||||||
|
|
||||||
# send diff to the server administrator
|
# send diff to the server administrator
|
||||||
mail_message="
|
mail_message="
|
||||||
Weblate was updated from version $previous_version to $current_version
|
Weblate was updated from version $previous_version to $current_version
|
||||||
This is a MAJOR upgrade, please read this:
|
Please read:
|
||||||
https://docs.weblate.org/en/latest/admin/upgrade.html#upgrade-3
|
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
|
$settings
|
||||||
|
|
||||||
You may have changed your defaults 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:
|
Diff has been created in:
|
||||||
$settings_diff
|
$final_path/settings.${previous_version}_${current_version}.diff
|
||||||
|
|
||||||
Please note secret key is updated, this is normal.
|
Please note secret key is updated, this is normal.
|
||||||
|
|
||||||
|
@ -252,10 +267,13 @@ then
|
||||||
ynh_send_readme_to_admin "$mail_message" root "$admin_mail"
|
ynh_send_readme_to_admin "$mail_message" root "$admin_mail"
|
||||||
else
|
else
|
||||||
echo "Settings.py was not modified, using the new default file for $current_version."
|
echo "Settings.py was not modified, using the new default file for $current_version."
|
||||||
|
fi
|
||||||
|
|
||||||
# generate new defaults settings
|
# generate new defaults settings
|
||||||
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
||||||
weblate_fill_settings "$settings"
|
weblate_fill_settings "$settings"
|
||||||
fi
|
|
||||||
|
ynh_secure_remove "$old_settings"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Run migration scripts
|
# Run migration scripts
|
||||||
|
|
Loading…
Reference in a new issue