diff --git a/plinth/modules/security/templates/security.html b/plinth/modules/security/templates/security.html index 56bd907d1..80ecd8646 100644 --- a/plinth/modules/security/templates/security.html +++ b/plinth/modules/security/templates/security.html @@ -13,7 +13,7 @@ {% trans "Show security report" %} - {% if is_backports_enabled %} + {% if is_backports_requested %}
{% blocktrans trimmed %} diff --git a/plinth/modules/security/views.py b/plinth/modules/security/views.py index 65bcee4de..2270fb746 100644 --- a/plinth/modules/security/views.py +++ b/plinth/modules/security/views.py @@ -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 is_backports_enabled +from plinth.modules.upgrades import is_backports_requested from .forms import SecurityForm @@ -33,7 +33,7 @@ def index(request): request, 'security.html', { 'app_info': security.app.info, 'form': form, - 'is_backports_enabled': is_backports_enabled(), + 'is_backports_requested': is_backports_requested(), }) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index f5808f162..4d733a361 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -3,6 +3,7 @@ FreedomBox app for upgrades. """ +import logging import os import subprocess @@ -42,10 +43,12 @@ _description = [ app = None -BACKPORTS_ENABLED_KEY = 'upgrades_backports_enabled' +BACKPORTS_REQUESTED_KEY = 'upgrades_backports_requested' SOURCES_LIST = '/etc/apt/sources.list.d/freedombox2.list' +logger = logging.getLogger(__name__) + class UpgradesApp(app_module.App): """FreedomBox app for software upgrades.""" @@ -139,7 +142,7 @@ def disable(): def setup_repositories(data): """Setup apt backport repositories.""" - if is_backports_enabled(): + if is_backports_requested(): command = ['setup-repositories'] if cfg.develop: command += ['--develop'] @@ -147,11 +150,22 @@ def setup_repositories(data): actions.superuser_run('upgrades', command) -def is_backports_enabled(): - """Return whether backports are enabled.""" +def is_backports_requested(): + """Return whether user has chosen to activate backports.""" from plinth import kvstore - return kvstore.get_default(BACKPORTS_ENABLED_KEY, - os.path.exists(SOURCES_LIST)) + return kvstore.get_default(BACKPORTS_REQUESTED_KEY, False) + + +def set_backports_requested(requested): + """Set whether user has chosen to activate backports.""" + from plinth import kvstore + kvstore.set(BACKPORTS_REQUESTED_KEY, requested) + logger.info('Backports requested - %s', requested) + + +def is_backports_enabled(): + """Return whether backports are enabled in the system configuration.""" + return os.path.exists(SOURCES_LIST) def get_current_release(): @@ -180,9 +194,6 @@ def is_backports_current(): def can_activate_backports(): """Return whether backports can be activated.""" - if is_backports_current(): - return False - release, _ = get_current_release() if release == 'unstable' or (release == 'testing' and not cfg.develop): return False diff --git a/plinth/modules/upgrades/forms.py b/plinth/modules/upgrades/forms.py index 5a92aa70c..db4263ef4 100644 --- a/plinth/modules/upgrades/forms.py +++ b/plinth/modules/upgrades/forms.py @@ -18,4 +18,4 @@ class BackportsFirstbootForm(forms.Form): """Form to configure backports during first boot wizard.""" backports_enabled = forms.BooleanField( label=_('Activate frequent feature updates (recommended)'), - required=False) + required=False, initial=True) diff --git a/plinth/modules/upgrades/templates/upgrades_configure.html b/plinth/modules/upgrades/templates/upgrades_configure.html index 94262751c..f8c7ecf3b 100644 --- a/plinth/modules/upgrades/templates/upgrades_configure.html +++ b/plinth/modules/upgrades/templates/upgrades_configure.html @@ -10,12 +10,12 @@ {% block extra_content %}
- {% if can_activate_backports %} + {% if can_activate_backports and not is_backports_requested %} {% blocktrans trimmed %} Frequent feature updates can be activated. Activating them is recommended. {% endblocktrans %} - {% elif is_backports_enabled %} + {% elif can_activate_backports and is_backports_requested %} {% blocktrans trimmed %} Frequent feature updates are enabled. {% endblocktrans %} @@ -27,7 +27,7 @@ {% endif %}
- {% if can_activate_backports or is_backports_enabled %} + {% if can_activate_backports %} {% blocktrans trimmed %} Frequent feature updates allow a very limited set of software, including {{box_name}} service, to be updated to receive newer features regularly @@ -38,7 +38,7 @@ {% endblocktrans %} {% endif %}
- {% if can_activate_backports %} + {% if can_activate_backports and not is_backports_requested %}