upgrades: Use only sources file to determine if backports enabled

Tests:
- Build deb and install in buster image. Manually remove backports
  sources file. Security page does not show backports notice. Updates
  page shows button to activate backports.
- Activate backports from updates page. Success message is shown and
  button to activate backports is removed. Security page shows
  backports notice.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2020-07-02 16:48:16 -04:00 committed by Sunil Mohan Adapa
parent 7caed57caf
commit 6b0744c1c7
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 15 additions and 20 deletions

View File

@ -13,6 +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
AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades'
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
@ -192,8 +193,7 @@ def _check_and_backports_sources():
if os.path.exists(old_sources_list):
os.remove(old_sources_list)
sources_list = '/etc/apt/sources.list.d/freedombox2.list'
if os.path.exists(sources_list):
if is_backports_enabled():
print('Repositories list up-to-date. Skipping update.')
return
@ -229,7 +229,7 @@ def _check_and_backports_sources():
return
print(f'{dist}-backports is now available. Adding to sources.')
_add_backports_sources(sources_list, protocol, dist)
_add_backports_sources(SOURCES_LIST, protocol, dist)
def _add_apt_preferences():

View File

@ -7,12 +7,12 @@
{% load i18n %}
{% block status %}
{% if backports_in_use %}
{% if is_backports_enabled %}
<h3>{% trans "Security Notice" %}</h3>
<p>
{% blocktrans trimmed %}
You are using packages from Debian backports. Please note that these
packages do not have security support from Debian. However, they are
Backports are enabled. Please note that packages from the backports
repository do not have security support from Debian. However, they are
maintained on a best-effort basis by contributors in Debian and
FreedomBox community.
{% endblocktrans %}

View File

@ -9,7 +9,7 @@ from django.utils.translation import ugettext as _
from plinth import action_utils, actions
from plinth.modules import security
from plinth.modules.upgrades import get_backports_in_use
from plinth.modules.upgrades import is_backports_enabled
from .forms import SecurityForm
@ -33,7 +33,7 @@ def index(request):
request, 'security.html', {
'app_info': security.app.info,
'form': form,
'backports_in_use': get_backports_in_use(),
'is_backports_enabled': is_backports_enabled(),
})

View File

@ -3,6 +3,7 @@
FreedomBox app for upgrades.
"""
import os
import subprocess
from django.utils.translation import ugettext_lazy as _
@ -32,6 +33,8 @@ _description = [
app = None
SOURCES_LIST = '/etc/apt/sources.list.d/freedombox2.list'
class UpgradesApp(app_module.App):
"""FreedomBox app for software upgrades."""
@ -135,22 +138,14 @@ def setup_repositories(data):
actions.superuser_run('upgrades', ['setup-repositories'])
def get_backports_in_use():
"""Return whether backports packages are installed."""
# Only freedombox package is set to be installed from backports currently.
output = subprocess.check_output(['apt-cache', 'policy', 'freedombox'])
for line in output.decode().split('\n'):
if 'Installed:' in line:
version = line.strip().split(': ')[1]
if 'bpo' in version:
return True
return False
def is_backports_enabled():
"""Return whether backports are enabled."""
return os.path.exists(SOURCES_LIST)
def can_activate_backports():
"""Return whether backports can be activated."""
if get_backports_in_use():
if is_backports_enabled():
return False
release = subprocess.check_output(['lsb_release', '--release',