From 8b51355bceb64c2d59fcf52f83f08cc180b0126b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Thu, 19 Oct 2017 11:01:39 +0200 Subject: [PATCH] add new helper ynh_check_if_checksum_is_different --- scripts/_common.sh | 14 ++++++++++ scripts/upgrade | 67 +++++++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 511629f..9755b6f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -24,6 +24,20 @@ weblate_fill_settings() { fi } +ynh_check_if_checksum_is_different() { + local file=$1 + local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' + local checksum_value=$(ynh_app_setting_get $app $checksum_setting_name) + local check=0 + + if ! echo "$checksum_value $file" | sudo md5sum -c --status + then # If the checksum is now different + check=1 + fi + + return "$check" +} + ynh_psql_test_if_first_run() { if [ -f /etc/yunohost/psql ]; then diff --git a/scripts/upgrade b/scripts/upgrade index 99892f3..68bf411 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -131,45 +131,56 @@ fi "${final_path}/venv/bin/pip" install django_sendmail_backend ) -# generate previous defaults settings -cp "$previous_version_file" "$old_settings" -weblate_fill_settings "$old_settings" +check=$(ynh_check_if_checksum_is_different "$settings") -# store diff between defaults and local settings -diff --unified "$old_settings" "$settings" > "$settings_diff" +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" + weblate_fill_settings "$old_settings" -# generate new defaults settings -cp ../conf/settings.py "$settings" -weblate_fill_settings "$settings" + # store diff between defaults and local settings + diff --unified "$old_settings" "$settings" > "$settings_diff" -# send diff to the server administrator -mail_subject="'$app' settings diff from $previous_version to $current_version" -mail_message=" -Weblate was updated from version $previous_version to $current_version + # generate new defaults settings + cp ../conf/settings.py "$settings" + weblate_fill_settings "$settings" -A new settings.py has been created in: -$settings + # send diff to the server administrator + mail_subject="'$app' settings diff from $previous_version to $current_version" + mail_message=" + Weblate was updated from version $previous_version to $current_version -You may have changed your defaults settings. -To help you to apply it again, here is a diff file with every changes you did. + A new settings.py has been created in: + $settings -Please note secret key is updated, this is normal. + You may have changed your defaults settings. + To help you to apply it again, here is a diff file with every changes you did. -For any issue, please file a bug in: https://github.com/YunoHost-Apps/weblate_ynh -" + Please note secret key is updated, this is normal. -echo "$mail_message" | mail -s "$mail_subject" root -u root -a "$settings_diff" + For any issue, please file a bug in: https://github.com/YunoHost-Apps/weblate_ynh + " -# inform weblate's admin -mail_subject="'$app' was updated from $previous_version to $current_version" -mail_message=" -Weblate was updated from version $previous_version to $current_version + echo "$mail_message" | mail -s "$mail_subject" root -u root -a "$settings_diff" -A new settings.py has been created and a diff has been sent to root user. -Your administrator may have to update your settings.py to have a fully working installation. -" + # inform weblate's admin + mail_subject="'$app' was updated from $previous_version to $current_version" + mail_message=" + Weblate was updated from version $previous_version to $current_version -echo "$mail_subject" | mail -s "$mail_subject" "$admin_mail" + A new settings.py has been created and a diff has been sent to root user. + Your administrator may have to update your settings.py to have a fully working installation. + " + + echo "$mail_subject" | mail -s "$mail_subject" "$admin_mail" +else + echo "Settings.py was not modified, using the new default file for $current_version." + # generate new defaults settings + cp ../conf/settings.py "$settings" + weblate_fill_settings "$settings" +fi #================================================= # Run migration scripts