mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
7caed57caf
commit
6b0744c1c7
@ -13,6 +13,7 @@ import sys
|
|||||||
|
|
||||||
from plinth.action_utils import run_apt_command
|
from plinth.action_utils import run_apt_command
|
||||||
from plinth.modules.apache.components import check_url
|
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'
|
AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades'
|
||||||
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
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):
|
if os.path.exists(old_sources_list):
|
||||||
os.remove(old_sources_list)
|
os.remove(old_sources_list)
|
||||||
|
|
||||||
sources_list = '/etc/apt/sources.list.d/freedombox2.list'
|
if is_backports_enabled():
|
||||||
if os.path.exists(sources_list):
|
|
||||||
print('Repositories list up-to-date. Skipping update.')
|
print('Repositories list up-to-date. Skipping update.')
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ def _check_and_backports_sources():
|
|||||||
return
|
return
|
||||||
|
|
||||||
print(f'{dist}-backports is now available. Adding to sources.')
|
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():
|
def _add_apt_preferences():
|
||||||
|
|||||||
@ -7,12 +7,12 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block status %}
|
{% block status %}
|
||||||
{% if backports_in_use %}
|
{% if is_backports_enabled %}
|
||||||
<h3>{% trans "Security Notice" %}</h3>
|
<h3>{% trans "Security Notice" %}</h3>
|
||||||
<p>
|
<p>
|
||||||
{% blocktrans trimmed %}
|
{% blocktrans trimmed %}
|
||||||
You are using packages from Debian backports. Please note that these
|
Backports are enabled. Please note that packages from the backports
|
||||||
packages do not have security support from Debian. However, they are
|
repository do not have security support from Debian. However, they are
|
||||||
maintained on a best-effort basis by contributors in Debian and
|
maintained on a best-effort basis by contributors in Debian and
|
||||||
FreedomBox community.
|
FreedomBox community.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from django.utils.translation import ugettext as _
|
|||||||
|
|
||||||
from plinth import action_utils, actions
|
from plinth import action_utils, actions
|
||||||
from plinth.modules import security
|
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
|
from .forms import SecurityForm
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ def index(request):
|
|||||||
request, 'security.html', {
|
request, 'security.html', {
|
||||||
'app_info': security.app.info,
|
'app_info': security.app.info,
|
||||||
'form': form,
|
'form': form,
|
||||||
'backports_in_use': get_backports_in_use(),
|
'is_backports_enabled': is_backports_enabled(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
FreedomBox app for upgrades.
|
FreedomBox app for upgrades.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@ -32,6 +33,8 @@ _description = [
|
|||||||
|
|
||||||
app = None
|
app = None
|
||||||
|
|
||||||
|
SOURCES_LIST = '/etc/apt/sources.list.d/freedombox2.list'
|
||||||
|
|
||||||
|
|
||||||
class UpgradesApp(app_module.App):
|
class UpgradesApp(app_module.App):
|
||||||
"""FreedomBox app for software upgrades."""
|
"""FreedomBox app for software upgrades."""
|
||||||
@ -135,22 +138,14 @@ def setup_repositories(data):
|
|||||||
actions.superuser_run('upgrades', ['setup-repositories'])
|
actions.superuser_run('upgrades', ['setup-repositories'])
|
||||||
|
|
||||||
|
|
||||||
def get_backports_in_use():
|
def is_backports_enabled():
|
||||||
"""Return whether backports packages are installed."""
|
"""Return whether backports are enabled."""
|
||||||
# Only freedombox package is set to be installed from backports currently.
|
return os.path.exists(SOURCES_LIST)
|
||||||
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 can_activate_backports():
|
def can_activate_backports():
|
||||||
"""Return whether backports can be activated."""
|
"""Return whether backports can be activated."""
|
||||||
if get_backports_in_use():
|
if is_backports_enabled():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
release = subprocess.check_output(['lsb_release', '--release',
|
release = subprocess.check_output(['lsb_release', '--release',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user