From 25d43dd82e1f8feb825247bc7e6c7d05abd39f75 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Fri, 28 Jan 2022 20:52:04 +0100 Subject: [PATCH] stages: add the ability to configure pacman repos Without configured repositories the generated pacman.conf isn't super useful. Pacman supports two different ways to configure a repository either with a Server = line or sourced from pacman's mirrorlist. --- stages/org.osbuild.pacman.conf | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/stages/org.osbuild.pacman.conf b/stages/org.osbuild.pacman.conf index e39efd36..e0b28106 100755 --- a/stages/org.osbuild.pacman.conf +++ b/stages/org.osbuild.pacman.conf @@ -15,6 +15,37 @@ SCHEMA = """ "type": "string", "description": "pacman architecture", "default": "x86_64" + }, + "repositories": { + "type": "array", + "items": { + "type": "object", + "oneOf": [ + { "required": ["name", "server"] }, + { "required": ["name", "include"] } + ], + "properties": { + "name": { + "type": "string" + }, + "siglevels": { + "type": "array", + "minLength": 1, + "maxLength": 2, + "items": { + "type": "string", + "enum": ["Required", "Optional", "Never", "TrustAll", "TrustedOnly"] + } + }, + "server": { + "type": "string" + }, + "include": { + "type": "string", + "default": "/etc/pacman.d/mirrorlist" + } + } + } } } """ @@ -22,12 +53,26 @@ SCHEMA = """ def main(tree, options): arch = options.get("architecture", "x86_64") + repositories = options.get("repositories", []) cfg = f""" [options] Architecture = {arch} SigLevel = Required DatabaseOptional LocalFileSigLevel = Optional """ + for repo in repositories: + entry = f"[{repo['name']}]\n" + siglevels = repo.get('siglevels', []) + include = repo.get('include', '/etc/pacman.d/mirrorlist') + if siglevels: + siglevelstr = ' '.join(siglevels) + entry += f"SigLevel = {siglevelstr}\n" + if 'server' in repo: + entry += f"Server = {repo['server']}\n" + if 'include' in repo: + entry += f"Include = {include}\n" + cfg += entry + "\n" + os.makedirs(os.path.join(tree, "etc"), exist_ok=True) cfgpath = os.path.join(tree, "etc", "pacman.conf") with open(cfgpath, "w", encoding="utf-8") as cfgfile: