mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
backports: Add buster-backports to apt sources list
Fixes freedombox-team/freedom-maker#149 Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
b1c8c22b92
commit
3d38b8a686
116
actions/backports
Executable file
116
actions/backports
Executable file
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- mode: python -*-
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Script to check for availability of buster-backports and create an
|
||||
apt sources list for backports if available.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import requests
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
BUSTER_BACKPORTS_RELEASE_FILE_URL = "http://cdn-fastly.deb.debian.org/debian/dists/buster-backports/Release"
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('enable', help='Enable buster backports check')
|
||||
subparsers.add_parser('disable', help='Disable buster backports check')
|
||||
subparsers.add_parser('check-backports',
|
||||
help='Check whether buster backports are available')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def add_buster_backports_sources():
|
||||
backports_list = '/etc/apt/sources.list.d/freedombox-backports.list'
|
||||
|
||||
conf = \
|
||||
"""deb http://deb.debian.org/debian buster-backports main
|
||||
deb-src http://deb.debian.org/debian buster-backports main
|
||||
"""
|
||||
|
||||
components = {"main"}
|
||||
|
||||
# Use tor+http if download over tor is enabled in sources.list
|
||||
with open('/etc/apt/sources.list', 'r') as sources_list:
|
||||
sources = sources_list.readlines()
|
||||
for line in sources:
|
||||
if not line.startswith("#") and "tor+http" in line:
|
||||
conf = conf.replace("http", "tor+http")
|
||||
# Check for contrib and nonfree components
|
||||
if "contrib" in line:
|
||||
components.add("contrib")
|
||||
if "nonfree" in line:
|
||||
components.add("nonfree")
|
||||
break
|
||||
|
||||
conf = conf.replace("main", " ".join(components))
|
||||
|
||||
if not os.path.exists(backports_list):
|
||||
try:
|
||||
with open(backports_list, 'w') as file_handle:
|
||||
file_handle.write(conf)
|
||||
except PermissionError:
|
||||
print(("Failed adding sources list for buster-backports."
|
||||
"Try running as a superuser."))
|
||||
|
||||
|
||||
def subcommand_check_backports(_):
|
||||
"""Check whether buster backports is available.
|
||||
Add a sources file if it's available.
|
||||
"""
|
||||
response = requests.get(BUSTER_BACKPORTS_RELEASE_FILE_URL)
|
||||
|
||||
if response.status_code == 404:
|
||||
print("Release file for Buster backports is not available yet.")
|
||||
else:
|
||||
print("Buster backports is now available. Adding to sources...")
|
||||
add_buster_backports_sources()
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Enable systemd service for the daily job buster-backports-check."""
|
||||
action_utils.service_enable('buster-backports-check.timer')
|
||||
action_utils.service_start('buster-backports-check.timer')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Disable systemd service for the daily job buster-backports-check."""
|
||||
action_utils.service_stop('buster-backports-check.timer')
|
||||
action_utils.service_disable('buster-backports-check.timer')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
3
data/etc/apt/preferences.d/freedombox.pref
Normal file
3
data/etc/apt/preferences.d/freedombox.pref
Normal file
@ -0,0 +1,3 @@
|
||||
Package: freedombox
|
||||
Pin: release a=buster-backports
|
||||
Pin-Priority: 800
|
||||
2
data/etc/plinth/modules-enabled/backports
Normal file
2
data/etc/plinth/modules-enabled/backports
Normal file
@ -0,0 +1,2 @@
|
||||
plinth.modules.backports
|
||||
|
||||
24
data/lib/systemd/system/buster-backports-check.service
Normal file
24
data/lib/systemd/system/buster-backports-check.service
Normal file
@ -0,0 +1,24 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
[Unit]
|
||||
Description=Service to check for buster backports and enable them
|
||||
ConditionPathExists=!/etc/apt/sources.list.d/freedombox-backports.list
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/share/plinth/actions/backports check-backports
|
||||
|
||||
27
data/lib/systemd/system/buster-backports-check.timer
Normal file
27
data/lib/systemd/system/buster-backports-check.timer
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
[Unit]
|
||||
Description=Daily check of whether buster backports are available yet
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
AccuracySec=12h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
4
debian/postrm
vendored
4
debian/postrm
vendored
@ -9,6 +9,10 @@ purge)
|
||||
|
||||
# Remove legacy directory too
|
||||
rm -rf /var/log/plinth
|
||||
|
||||
if [ -e '/etc/apt/sources.list.d/freedombox-backports.list' ]; then
|
||||
rm /etc/apt/sources.list.d/freedombox-backports.list
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
30
plinth/modules/backports/__init__.py
Normal file
30
plinth/modules/backports/__init__.py
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
FreedomBox app to manage Debian backports.
|
||||
"""
|
||||
|
||||
from plinth import actions
|
||||
|
||||
is_essential = True
|
||||
|
||||
version = 1
|
||||
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Configure the module."""
|
||||
helper.call('post', actions.superuser_run, 'backports', ['enable'])
|
||||
21
plinth/modules/backports/urls.py
Normal file
21
plinth/modules/backports/urls.py
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
URLs for the Backports module.
|
||||
"""
|
||||
|
||||
urlpatterns = []
|
||||
@ -84,7 +84,7 @@ class Transaction(object):
|
||||
self.package_names)
|
||||
else:
|
||||
self._run_apt_command(['install', self.module_name] +
|
||||
self.package_names)
|
||||
self.package_names)
|
||||
except subprocess.CalledProcessError as exception:
|
||||
logger.exception('Error installing package: %s', exception)
|
||||
raise
|
||||
|
||||
3
setup.py
3
setup.py
@ -238,6 +238,8 @@ setuptools.setup(
|
||||
glob.glob('data/etc/apache2/includes/*.conf')),
|
||||
('/etc/apt/apt.conf.d',
|
||||
glob.glob('data/etc/apt/apt.conf.d/60unattended-upgrades')),
|
||||
('/etc/apt/preferences.d',
|
||||
glob.glob('data/etc/apt/preferences.d/freedombox.pref')),
|
||||
('/etc/avahi/services/',
|
||||
glob.glob('data/etc/avahi/services/*.service')),
|
||||
('/etc/ikiwiki', glob.glob('data/etc/ikiwiki/*.setup')),
|
||||
@ -247,6 +249,7 @@ setuptools.setup(
|
||||
'data/etc/sudoers.d/plinth'
|
||||
]), ('/lib/systemd/system',
|
||||
glob.glob('data/lib/systemd/system/*.service')),
|
||||
('/lib/systemd/system', glob.glob('data/lib/systemd/system/*.timer')),
|
||||
('/etc/mediawiki',
|
||||
glob.glob('data/etc/mediawiki/*.php')), ('/etc/update-motd.d/', [
|
||||
'data/etc/update-motd.d/50-freedombox'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user