From e5ec13f592837a982a9e2ad8829d49f2fb3bffc2 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 5 Jun 2025 22:35:02 -0400 Subject: [PATCH] modules: misc: Add a class to install a copr repo --- modules/misc/main.mcl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/misc/main.mcl b/modules/misc/main.mcl index 07cf29a1..79c0b4da 100644 --- a/modules/misc/main.mcl +++ b/modules/misc/main.mcl @@ -27,12 +27,14 @@ # additional permission if he deems it necessary to achieve the goals of this # additional permission. +import "fmt" import "golang" import "golang/strings" as golang_strings import "iter" import "local" import "net" import "os" +import "strings" import "world/collect" # ssh_keygen creates an ssh key pair in the user's home directory if the private @@ -359,3 +361,27 @@ class systemd_daemon_reload($name) { ifshell => "/usr/bin/bash", } } + +# Instead of running `dnf copr enable purpleidea/foo` you can use +# `purpleidea/foo` as the $name here to accomplish the same thing. +class copr_enable($name) { + # example: sudo dnf copr enable gsauthof/dracut-sshd + # /etc/yum.repos.d/_copr:copr.fedorainfracloud.org:gsauthof:dracut-sshd.repo + $sp = strings.split($name, "/") + $user = $sp[0] + $repo = $sp[1] + $p = fmt.printf("/etc/yum.repos.d/_copr:copr.fedorainfracloud.org:%s:%s.repo", $user, $repo) + + # TODO: If we wanted to be more thorough, we could template the file + # instead or running this copr enable command. + exec "dnf-copr-enable-${name}" { + cmd => "/usr/bin/dnf", + args => [ + "copr", + "enable", + "${name}", + ], + creates => $p, + user => "root", + } +}