From 637ab05590a8bebd55a5bf59f82856f78220cb69 Mon Sep 17 00:00:00 2001 From: cronekorkn Date: Tue, 1 Aug 2023 12:15:49 +0200 Subject: [PATCH] apt source multiple urls --- bundles/apt/README.md | 8 +++++++- bundles/crystal/metadata.py | 4 +++- bundles/grafana/metadata.py | 4 +++- bundles/icinga2/metadata.py | 9 +++++++-- bundles/icingaweb2/metadata.py | 9 +++++++-- bundles/influxdb2/metadata.py | 4 +++- bundles/openhab/metadata.py | 4 +++- bundles/telegraf/metadata.py | 4 +++- groups/os/debian.py | 8 ++++++-- libs/apt.py | 23 +++++++++++++++++++---- 10 files changed, 61 insertions(+), 16 deletions(-) diff --git a/bundles/apt/README.md b/bundles/apt/README.md index 7027527..012d490 100644 --- a/bundles/apt/README.md +++ b/bundles/apt/README.md @@ -9,7 +9,13 @@ }, 'sources': { 'debian': { - 'urls': 'https://deb.debian.org/debian', + 'types': { # optional, defaults to `{'deb'}`` + 'deb', + 'deb-src', + }, + 'urls': { + 'https://deb.debian.org/debian', + }, 'suites': { # at least one '{codename}', '{codename}-updates', diff --git a/bundles/crystal/metadata.py b/bundles/crystal/metadata.py index dc91eb9..05ba4d3 100644 --- a/bundles/crystal/metadata.py +++ b/bundles/crystal/metadata.py @@ -8,7 +8,9 @@ defaults = { 'sources': { 'crystal': { # https://software.opensuse.org/download.html?project=devel%3Alanguages%3Acrystal&package=crystal - 'url': 'https://download.opensuse.org/repositories/devel:/languages:/crystal/Debian_Testing/', + 'urls': { + 'https://download.opensuse.org/repositories/devel:/languages:/crystal/Debian_Testing/', + }, 'suites': { '/', }, diff --git a/bundles/grafana/metadata.py b/bundles/grafana/metadata.py index 0a95923..12f95ce 100644 --- a/bundles/grafana/metadata.py +++ b/bundles/grafana/metadata.py @@ -9,7 +9,9 @@ defaults = { }, 'sources': { 'grafana': { - 'url': 'https://packages.grafana.com/oss/deb', + 'urls': { + 'https://packages.grafana.com/oss/deb', + }, 'suites': { 'stable', }, diff --git a/bundles/icinga2/metadata.py b/bundles/icinga2/metadata.py index c782940..e945a1a 100644 --- a/bundles/icinga2/metadata.py +++ b/bundles/icinga2/metadata.py @@ -10,8 +10,13 @@ defaults = { }, 'sources': { 'icinga': { - 'types': {'deb', 'deb-src'}, - 'url': 'https://packages.icinga.com/debian', + 'types': { + 'deb', + 'deb-src', + }, + 'urls': { + 'https://packages.icinga.com/debian', + }, 'suites': { 'icinga-{codename}', }, diff --git a/bundles/icingaweb2/metadata.py b/bundles/icingaweb2/metadata.py index 4a2c8a3..7575963 100644 --- a/bundles/icingaweb2/metadata.py +++ b/bundles/icingaweb2/metadata.py @@ -15,8 +15,13 @@ defaults = { }, 'sources': { 'icinga': { - 'types': {'deb', 'deb-src'}, - 'url': 'https://packages.icinga.com/debian', + 'types': { + 'deb', + 'deb-src', + }, + 'urls': { + 'https://packages.icinga.com/debian', + }, 'suites': { 'icinga-{codename}', }, diff --git a/bundles/influxdb2/metadata.py b/bundles/influxdb2/metadata.py index a2b6ef7..4e7aa6c 100644 --- a/bundles/influxdb2/metadata.py +++ b/bundles/influxdb2/metadata.py @@ -8,7 +8,9 @@ defaults = { }, 'sources': { 'influxdata': { - 'url': 'https://repos.influxdata.com/debian', + 'urls': { + 'https://repos.influxdata.com/debian', + }, 'suites': { 'stable', }, diff --git a/bundles/openhab/metadata.py b/bundles/openhab/metadata.py index 40f05bc..91c6977 100644 --- a/bundles/openhab/metadata.py +++ b/bundles/openhab/metadata.py @@ -10,7 +10,9 @@ defaults = { }, 'sources': { 'jfrog': { - 'url': 'https://openhab.jfrog.io/artifactory/openhab-linuxpkg', + 'urls': { + 'https://openhab.jfrog.io/artifactory/openhab-linuxpkg', + }, 'suites': { 'stable', }, diff --git a/bundles/telegraf/metadata.py b/bundles/telegraf/metadata.py index 7de7e60..4d4c421 100644 --- a/bundles/telegraf/metadata.py +++ b/bundles/telegraf/metadata.py @@ -10,7 +10,9 @@ defaults = { }, 'sources': { 'influxdata': { - 'url': 'https://repos.influxdata.com/debian', + 'urls': { + 'https://repos.influxdata.com/debian', + }, 'suites': { 'stable', }, diff --git a/groups/os/debian.py b/groups/os/debian.py index cbdc15e..69bb0d2 100644 --- a/groups/os/debian.py +++ b/groups/os/debian.py @@ -13,7 +13,9 @@ 'apt': { 'sources': { 'debian': { - 'url': 'https://deb.debian.org/debian', + 'urls': { + 'https://deb.debian.org/debian', + }, 'suites': { '{codename}', '{codename}-updates', @@ -27,7 +29,9 @@ 'key': 'debian-{version}', }, 'debian-security': { - 'url': 'https://security.debian.org/', + 'urls': { + 'https://security.debian.org/', + }, 'suites': { '{codename}-security', }, diff --git a/libs/apt.py b/libs/apt.py index 63fca1e..97e2d65 100644 --- a/libs/apt.py +++ b/libs/apt.py @@ -1,6 +1,3 @@ -# https://manpages.debian.org/latest/apt/sources.list.5.de.html -# https://repolib.readthedocs.io/en/latest/deb822-format.html - from re import match from glob import glob from os.path import join, basename, exists @@ -23,6 +20,7 @@ def find_keyfile_extension(node, key_name): raise Exception(f"no keyfile '{formatted_key_name}.(asc|gpg)' found") +# https://manpages.ubuntu.com/manpages/latest/en/man5/apt.conf.5.html def render_apt_conf(section, depth=0): buffer = '' @@ -47,10 +45,27 @@ def render_apt_conf(section, depth=0): +# https://manpages.debian.org/latest/apt/sources.list.5.de.html +# https://repolib.readthedocs.io/en/latest/deb822-format.html def render_source(node, source_name): config = node.metadata.get(f'apt/sources/{source_name}') lines = [] + keys_and_types = { + 'types': (set, list), + 'urls': (set, list), + 'suites': (set, list), + 'components': (set, list), + 'options': dict, + 'key': str, + } + + for key, value in config.items(): + if key not in keys_and_types: + raise Exception(f"{node}: invalid source '{source_name}' conf key: '{key}' (expecting one of: {', '.join(keys_and_types)})") + elif not isinstance(value, keys_and_types[key]): + raise Exception(f"{node}: invalid source '{source_name}' conf value type for '{key}': '{type(value)}' (expecting: '{keys_and_types[key]}')") + # X-Repolib-Name lines.append( f'X-Repolib-Name: ' + source_name @@ -63,7 +78,7 @@ def render_source(node, source_name): # url lines.append( - f'URIs: ' + config['url'] + f'URIs: ' + ' '.join(sorted(config['urls'])) ) # suites