From 2843ce923d53403934995d4a6d48120746d68506 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 10 May 2018 22:37:27 +0200 Subject: [PATCH] Have a specific upgrade for nginx-common because some people edit /etc/nginx/nginx.conf --- locales/en.json | 1 + .../data_migrations/0003_migrate_to_stretch.py | 16 ++++++++++++++-- src/yunohost/service.py | 11 +++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/locales/en.json b/locales/en.json index 0f45c7a8b..ff1616c79 100644 --- a/locales/en.json +++ b/locales/en.json @@ -230,6 +230,7 @@ "migration_0003_patching_sources_list": "Patching the sources.lists ...", "migration_0003_main_upgrade": "Starting main upgrade ...", "migration_0003_fail2ban_upgrade": "Starting the fail2ban upgrade ...", + "migration_0003_nginx_upgrade": "Starting the nginx-common upgrade ...", "migration_0003_yunohost_upgrade": "Starting the yunohost package upgrade ... The migration will end, but the actual upgrade will happen right after. After the operation is complete, you might have to re-log on the webadmin.", "migration_0003_not_jessie": "The current debian distribution is not Jessie !", "migration_0003_system_not_fully_up_to_date": "Your system is not fully up to date. Please perform a regular upgrade before running the migration to stretch.", diff --git a/src/yunohost/data_migrations/0003_migrate_to_stretch.py b/src/yunohost/data_migrations/0003_migrate_to_stretch.py index ab4974e2e..a15d786df 100644 --- a/src/yunohost/data_migrations/0003_migrate_to_stretch.py +++ b/src/yunohost/data_migrations/0003_migrate_to_stretch.py @@ -15,7 +15,10 @@ from moulinette.utils.filesystem import read_file from yunohost.tools import Migration from yunohost.app import unstable_apps -from yunohost.service import _run_service_command, service_regen_conf, manually_modified_files +from yunohost.service import (_run_service_command, + service_regen_conf, + manually_modified_files, + manually_modified_files_compared_to_debian_default) from yunohost.utils.filesystem import free_space_in_directory from yunohost.utils.packages import get_installed_version @@ -47,7 +50,7 @@ class MyMigration(Migration): self.apt_update() apps_packages = self.get_apps_equivs_packages() self.unhold(["metronome"]) - self.hold(YUNOHOST_PACKAGES + apps_packages + ["fail2ban"]) + self.hold(YUNOHOST_PACKAGES + apps_packages + ["fail2ban", "nginx-common"]) # Main dist-upgrade logger.warning(m18n.n("migration_0003_main_upgrade")) @@ -68,6 +71,11 @@ class MyMigration(Migration): self.apt_dist_upgrade(conf_flags=["new", "miss", "def"]) _run_service_command("restart", "fail2ban") + # Specific upgrade for nginx-common... + logger.warning(m18n.n("migration_0003_nginx_upgrade")) + self.unhold(["nginx-common"]) + self.apt_dist_upgrade(conf_flags=["new", "def"]) + # Clean the mess os.system("apt autoremove --assume-yes") os.system("apt clean --assume-yes") @@ -129,6 +137,10 @@ class MyMigration(Migration): # Manually modified files ? (c.f. yunohost service regen-conf) modified_files = manually_modified_files() + # We also have a specific check for nginx.conf which some people + # modified and needs to be upgraded... + if "/etc/nginx/nginx.conf" in manually_modified_files_compared_to_debian_default(): + modified_files.append("/etc/nginx/nginx.conf") modified_files = "".join(["\n - "+f for f in modified_files ]) message = m18n.n("migration_0003_general_warning") diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 1852259ad..6c8acfbca 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -793,3 +793,14 @@ def manually_modified_files(): output.append(filename) return output + + +def manually_modified_files_compared_to_debian_default(): + + # from https://serverfault.com/a/90401 + r = subprocess.check_output("dpkg-query -W -f='${Conffiles}\n' '*' \ + | awk 'OFS=\" \"{print $2,$1}' \ + | md5sum -c 2>/dev/null \ + | awk -F': ' '$2 !~ /OK/{print $1}'", shell=True) + return r.strip().split("\n") +