From 4920cc46f09fc93ca1a7eab54332b31164f995aa Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Wed, 25 Dec 2024 15:26:31 +0100 Subject: [PATCH] chore: Add separate `copr` array --- modules/dnf/README.md | 2 +- modules/dnf/dnf.sh | 26 ++++++++++++++++---------- modules/dnf/dnf.tsp | 3 +++ modules/dnf/module.yml | 5 +++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/dnf/README.md b/modules/dnf/README.md index 7715ec6..ad353a4 100644 --- a/modules/dnf/README.md +++ b/modules/dnf/README.md @@ -10,7 +10,7 @@ repos: - my-repository.repo # copies in .repo file from files/dnf/my-repository.repo to /etc/yum.repos.d/ ``` -Specific COPR repositories can also be specified in `COPR user/project` format & is prefered over using direct COPR URL. +Specific COPR repositories can also be specified in `user/project` format in `copr:` array. If you use a repo that requires adding custom keys (eg. Brave Browser), you can import the keys by declaring the key URLs under `keys:`. The magic string acts the same as it does in `repos`. diff --git a/modules/dnf/dnf.sh b/modules/dnf/dnf.sh index cb0a37c..98c5bb6 100644 --- a/modules/dnf/dnf.sh +++ b/modules/dnf/dnf.sh @@ -18,14 +18,8 @@ if [[ ${#REPOS[@]} -gt 0 ]]; then repo="${REPOS[$i]}" repo="${repo//%OS_VERSION%/${OS_VERSION}}" REPOS[$i]="${repo//[$'\t\r\n ']}" - # Remove spaces/newlines for all repos other than COPR - if [[ "${repo}" != "COPR "* ]]; then - REPOS[$i]="${repo//[$'\t\r\n ']}" - else - REPOS[$i]="${repo}" - fi done - # dnf config-manager & dnf copr don't support adding multiple repositories at once, hence why for/done loop is used + # dnf config-manager doesn't support adding multiple repositories at once, hence why for/done loop is used for repo in "${REPOS[@]}"; do if [[ "${repo}" =~ ^https?:\/\/.* ]]; then echo "Adding repository URL: '${repo}'" @@ -33,9 +27,21 @@ if [[ ${#REPOS[@]} -gt 0 ]]; then elif [[ "${repo}" == *".repo" ]] && [[ -f "${CONFIG_DIRECTORY}/dnf/${repo}" ]]; then echo "Adding repository file: '${repo##*/}'" dnf -y config-manager addrepo --from-repofile="${CONFIG_DIRECTORY}/dnf/${repo}" - elif [[ "${repo}" == "COPR "* ]]; then - echo "Adding COPR repository: '${repo#COPR }'" - dnf -y copr enable "${repo#COPR }" + fi + done +fi + +# Pull in COPR repos +get_json_array COPR_REPOS 'try .["copr"][]' "${1}" +if [[ ${#COPR_REPOS[@]} -gt 0 ]]; then + echo "Adding COPR repositories" + for repo in "${COPR_REPOS[@]}"; do + if [[ "${repo}" == *"/"* ]]; then + echo "Adding COPR repository: '${repo}'" + dnf copr enable "${repo}" + else + echo "ERROR: You didn't provide COPR repository in proper format, it should be in 'user/project' format." + exit 1 fi done fi diff --git a/modules/dnf/dnf.tsp b/modules/dnf/dnf.tsp index 7084205..349cafc 100644 --- a/modules/dnf/dnf.tsp +++ b/modules/dnf/dnf.tsp @@ -11,6 +11,9 @@ model DnfModule { /** List of links to .repo files to download into /etc/yum.repos.d/. */ repos?: Array; + /** List of COPR project repos to download into /etc/yum.repos.d/. */ + copr?: Array; + /** List of links to key files to import for installing from custom repositories. */ keys?: Array; diff --git a/modules/dnf/module.yml b/modules/dnf/module.yml index c37d028..8b0957e 100644 --- a/modules/dnf/module.yml +++ b/modules/dnf/module.yml @@ -3,9 +3,10 @@ shortdesc: The dnf module offers pseudo-declarative package and repository manag example: | type: dnf repos: - - COPR atim/starship - - COPR trixieua/mutter-patched - https://brave-browser-rpm-release.s3.brave.com/brave-browser.repo + copr: + - atim/starship + - trixieua/mutter-patched keys: - https://brave-browser-rpm-release.s3.brave.com/brave-core.asc optfix: