From ca91120fdc00ba5c44cd09f9d648f7376be58513 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 3 Jul 2020 07:57:38 -0400 Subject: [PATCH] upgrades: Check that backports is for current release - If backports is for older release, then it can be activated again to upgrade to latest release. (Plan is to make this automatic, but leave the manual option as a fallback.) - Security notice still shown if older backports are enabled. Tests: - On Buster system, change distribution in /etc/apt/sources.list.d/freedombox2.list to stretch-backports. Updates page shows button to activate backports again. Activate and check the source list to confirm that it has buster-backports again. Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- actions/upgrades | 4 ++-- plinth/modules/upgrades/__init__.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/actions/upgrades b/actions/upgrades index 94ed5e93f..1c71988c0 100755 --- a/actions/upgrades +++ b/actions/upgrades @@ -13,7 +13,7 @@ import sys from plinth.action_utils import run_apt_command from plinth.modules.apache.components import check_url -from plinth.modules.upgrades import is_backports_enabled, SOURCES_LIST +from plinth.modules.upgrades import is_backports_current, SOURCES_LIST AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades' LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log' @@ -193,7 +193,7 @@ def _check_and_backports_sources(): if os.path.exists(old_sources_list): os.remove(old_sources_list) - if is_backports_enabled(): + if is_backports_current(): print('Repositories list up-to-date. Skipping update.') return diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index b28e606e3..a7d103146 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -3,6 +3,7 @@ FreedomBox app for upgrades. """ +from aptsources import sourceslist import os import subprocess @@ -143,9 +144,24 @@ def is_backports_enabled(): return os.path.exists(SOURCES_LIST) +def is_backports_current(): + """Return whether backports are enabled for the current release.""" + if not is_backports_enabled: + return False + + dist = subprocess.check_output(['lsb_release', '--codename', '--short' + ]).decode().strip() + '-backports' + sources = sourceslist.SourcesList() + for source in sources: + if source.dist == dist: + return True + + return False + + def can_activate_backports(): """Return whether backports can be activated.""" - if is_backports_enabled(): + if is_backports_current(): return False release = subprocess.check_output(['lsb_release', '--release',