Skip to content

Commit a96c582

Browse files
committed
feat(package-firewall): generate complete pacman.conf for aur setup
In addition to the staged mirrorlist fragment, write a self-contained pacman.conf whose [core]/[extra]/[multilib] repos point at the /arch prefix. It drives a no-root dry-run (pacman --config <this> --dbpath <tmp> -Syp <pkg>) and serves as the reference for the /etc/pacman.conf merge.
1 parent 5c2a162 commit a96c582

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

pkg/packagefirewall/config.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func ConfigFiles(eco Ecosystem, opts ConfigOptions) ([]ConfigFile, error) {
112112
Content: archMirrorlist(opts),
113113
Structured: true,
114114
},
115+
{
116+
// A complete, ready-to-use pacman config pointing the official repos
117+
// at the /arch prefix. Usable directly (pacman --config <this> -Syp ...)
118+
// and as the reference for the /etc/pacman.conf merge.
119+
Path: filepath.Join(home, ".config", "vulnetix", "package-firewall", "pacman.conf"),
120+
Content: pacmanConfig(opts),
121+
Structured: true,
122+
},
115123
}, nil
116124
default:
117125
return nil, fmt.Errorf("automatic %s configuration is not implemented yet", eco.DisplayName)
@@ -508,6 +516,31 @@ func archMirrorlist(opts ConfigOptions) string {
508516
}, "\n")
509517
}
510518

519+
// pacmanConfig is a complete pacman configuration whose official repositories
520+
// ([core], [extra], [multilib]) are served through the /arch firewall prefix.
521+
// It is self-contained so it can drive a scoped, no-root test
522+
// (`pacman --config <this> --dbpath <tmp> --cachedir <tmp> -Syp <pkg>`) and also
523+
// serves as the reference for merging the Server lines into /etc/pacman.conf.
524+
func pacmanConfig(opts ConfigOptions) string {
525+
server := withBasicAuth(archBaseURL(opts), opts.OrgID, opts.APIKey) + "/$repo/os/$arch"
526+
repo := func(name string) string {
527+
return strings.Join([]string{"[" + name + "]", "Server = " + server, ""}, "\n")
528+
}
529+
return strings.Join([]string{
530+
"# Vulnetix Package Firewall — pacman config for the Arch official repos.",
531+
"# Scoped test (no root):",
532+
"# pacman --config " + "<this file>" + " --dbpath /tmp/vx-db --cachedir /tmp/vx-cache -Syp <pkg>",
533+
"# Or merge the [core]/[extra]/[multilib] Server lines into /etc/pacman.conf.",
534+
"[options]",
535+
"Architecture = auto",
536+
"SigLevel = Required DatabaseOptional",
537+
"",
538+
repo("core"),
539+
repo("extra"),
540+
repo("multilib"),
541+
}, "\n")
542+
}
543+
511544
func yamlString(s string) string {
512545
return strconv.Quote(s)
513546
}

pkg/packagefirewall/config_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ func TestAURConfig(t *testing.T) {
291291
if err != nil {
292292
t.Fatal(err)
293293
}
294-
if len(files) != 3 {
295-
t.Fatalf("aur files = %d, want 3 (paru.conf + yay config.json + mirrorlist)", len(files))
294+
if len(files) != 4 {
295+
t.Fatalf("aur files = %d, want 4 (paru.conf + yay config.json + mirrorlist + pacman.conf)", len(files))
296296
}
297297

298298
// paru.conf
@@ -367,4 +367,17 @@ func TestAURConfig(t *testing.T) {
367367
if !strings.Contains(files[2].Content, want) {
368368
t.Errorf("mirrorlist missing %q:\n%s", want, files[2].Content)
369369
}
370+
371+
// complete pacman.conf (official repos via /arch)
372+
if files[3].Path != "/home/test/.config/vulnetix/package-firewall/pacman.conf" {
373+
t.Fatalf("pacman.conf path = %q", files[3].Path)
374+
}
375+
for _, want := range []string{
376+
"[core]", "[extra]", "[multilib]",
377+
"Server = https://org-123:secret@packages.vulnetix.com/arch/$repo/os/$arch",
378+
} {
379+
if !strings.Contains(files[3].Content, want) {
380+
t.Errorf("pacman.conf missing %q:\n%s", want, files[3].Content)
381+
}
382+
}
370383
}

pkg/packagefirewall/detect.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func ConfigPaths(eco Ecosystem, home string) []string {
5050
filepath.Join(home, ".config", "paru", "paru.conf"),
5151
filepath.Join(home, ".config", "yay", "config.json"),
5252
filepath.Join(home, ".config", "vulnetix", "package-firewall", "arch-mirrorlist"),
53+
filepath.Join(home, ".config", "vulnetix", "package-firewall", "pacman.conf"),
5354
}
5455
default:
5556
return nil

0 commit comments

Comments
 (0)