Skip to content

Commit

Permalink
fix: Go back to removing repo files and clean up negativo repos befor…
Browse files Browse the repository at this point in the history
…e adding them
  • Loading branch information
gmpinder committed Feb 24, 2025
1 parent e86be19 commit 591b517
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 74 deletions.
140 changes: 69 additions & 71 deletions modules/dnf/dnf.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env nu

const NEGATIVO = 'negativo17-multimedia'
const NEGATIVO_URL = 'https://negativo17.org/repos/fedora-multimedia.repo'
const NEGATIVO = 'negativo17'
const NEGATIVO_URL = 'https://negativo17.org/repos/fedora-negativo17.repo'
const RPMFUSION = 'rpmfusion'

# Handle adding/removing repo files and COPR repos.
Expand All @@ -20,10 +20,10 @@ def repos [$repos: record]: nothing -> record {
# Add and remove repos
{
add: [..$add]
disable: [..$remove]
remove: [..$remove]
} => {
let repos = add_repos ($add | default [])
disable_repos ($remove | default [])
remove_repos ($remove | default [])
$repos
}
# Add repos
Expand All @@ -32,7 +32,7 @@ def repos [$repos: record]: nothing -> record {
}
# Remove repos
{ remove: [..$remove] } => {
disable_repos ($remove | default [])
remove_repos ($remove | default [])
[]
}
_ => []
Expand Down Expand Up @@ -90,98 +90,90 @@ def nonfree_repos [repo_type?: string]: nothing -> list<string> {
msg: $"The only valid values are '($NEGATIVO)' and '($RPMFUSION)'"
label: {
text: 'Passed in value'
span: ($repo_type | metadata).span
span: (metadata $repo_type).span
}
}
}
}
}

# Enable rpmfusion repos
#
# See https://rpmfusion.org/Configuration
def enable_rpmfusion []: nothing -> nothing {
const CISCO_REPO = 'fedora-cisco-openh264'

print $'(ansi green)Enabling rpmfusion repos(ansi reset)'

mut repos = []

if (^rpm -q rpmfusion-free-release | complete).exit_code != 0 {
try {
^dnf5 -y install $'https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-($env.OS_VERSION).noarch.rpm'
} catch {
exit 1
}
$repos = $repos | append $'https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-($env.OS_VERSION).noarch.rpm'
}

if (^rpm -q rpmfusion-nonfree-release | complete).exit_code != 0 {
try {
^dnf5 -y install $'https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-($env.OS_VERSION).noarch.rpm'
} catch {
exit 1
}
$repos = $repos | append $'https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-($env.OS_VERSION).noarch.rpm'
}

if (^rpm -q rpmfusion-free-release-tainted | complete).exit_code != 0 {
try {
^dnf5 -y install rpmfusion-free-release-tainted
} catch {
exit 1
}
}
install_pkgs { packages: $repos }

if (^rpm -q rpmfusion-nonfree-release-tainted | complete).exit_code != 0 {
try {
^dnf5 -y install rpmfusion-nonfree-release-tainted
} catch {
exit 1
}
print $"(ansi green)Enabling '(ansi cyan)($CISCO_REPO)(ansi green)' repo for RPMFusion compatibility(ansi reset)"
try {
^dnf5 config-manager setopt $'($CISCO_REPO).enabled=1'
} catch {
exit 1
}
}

# Disable rpmfusion repos
def disable_rpmfusion []: nothing -> nothing {
print $'(ansi green)Removing rpmfusion repos(ansi reset)'

mut repos = []

if (^rpm -q rpmfusion-free-release | complete).exit_code == 0 {
try {
^dnf5 -y remove rpmfusion-free-release
} catch {
exit 1
}
$repos = $repos | append 'rpmfusion-free-release'
}

if (^rpm -q rpmfusion-nonfree-release | complete).exit_code == 0 {
try {
^dnf5 -y remove rpmfusion-nonfree-release
} catch {
exit 1
}
$repos = $repos | append 'rpmfusion-nonfree-release'
}

if (^rpm -q rpmfusion-free-release-tainted | complete).exit_code == 0 {
try {
^dnf5 -y remove rpmfusion-free-release-tainted
} catch {
exit 1
}
}

if (^rpm -q rpmfusion-nonfree-release-tainted | complete).exit_code == 0 {
try {
^dnf5 -y remove rpmfusion-nonfree-release-tainted
} catch {
exit 1
}
}
remove_pkgs { packages: $repos }
}

def negativo_repo_path []: nothing -> path {
[/ etc yum.repos.d ($NEGATIVO_URL | path basename)] | path join
def negativo_repo_list []: nothing -> list<path> {
try {
^dnf5 -y repo list --all --json | from json
} catch {
exit 1
}
| find negativo17
| get id
| ansi strip
| par-each {|repo|
try {
^dnf5 -y repo info $repo --all --json | from json
} catch {
exit 1
}
}
| flatten
| get id
| uniq
}

# Enable negativo17-multimedia repos
def enable_negativo []: nothing -> nothing {
print $'(ansi green)Enabling negativo17 repos(ansi reset)'

if not (negativo_repo_path | path exists) {
add_repos [$NEGATIVO_URL]
let current_repo_list = negativo_repo_list

if ($current_repo_list | is-not-empty) {
print $'(ansi green)Cleaning up existing negativo17 repos(ansi reset)'
remove_repos $current_repo_list
}
add_repos [$NEGATIVO_URL]

try {
^dnf5 repo list --all --json
Expand All @@ -207,9 +199,7 @@ def enable_negativo []: nothing -> nothing {
def disable_negativo []: nothing -> nothing {
print $'(ansi green)Disabling negativo17 repos(ansi reset)'

if (negativo_repo_path | path exists) {
rm -f (negativo_repo_path)
}
remove_repos (negativo_repo_list)
}

# Adds a list of repo files for `dnf` to use
Expand Down Expand Up @@ -250,7 +240,7 @@ def add_repos [$repos: list]: nothing -> list<string> {
}

try {
^dnf5 -y config-manager addrepo --from-repofile $repo
^dnf5 -y config-manager addrepo --overwrite --from-repofile $repo
} catch {
exit 1
}
Expand Down Expand Up @@ -302,7 +292,7 @@ def add_repos [$repos: list]: nothing -> list<string> {
}

# Remove a list of repos. The list must be the IDs of the repos.
def disable_repos [$repos: list]: nothing -> nothing {
def remove_repos [$repos: list]: nothing -> nothing {
if ($repos | is-not-empty) {
print $'(ansi green)Removing repositories:(ansi reset)'
let repos = $repos | str trim
Expand All @@ -311,14 +301,21 @@ def disable_repos [$repos: list]: nothing -> nothing {
print $'- (ansi cyan)($in)(ansi reset)'
}

for $repo in $repos {
print $'Disabling repo ($repo)'
try {
^dnf5 config-manager setopt $'($repo).enabled=0'
} catch {
exit 1
$repos
| par-each {|repo|
try {
^dnf5 -y repo info $repo --all --json | from json
} catch {
exit 1
}
}
| flatten
| get repo_file_path
| uniq
| each {|file|
print $"Removing repo file '(ansi cyan)($file)(ansi reset)'"
rm -f $file
}
}
}
}

Expand Down Expand Up @@ -785,7 +782,7 @@ def main [config: string]: nothing -> nothing {

if $should_cleanup {
print $'(ansi green)Cleaning up added repos(ansi reset)'
disable_repos $cleanup_repos.files
remove_repos $cleanup_repos.files
disable_coprs $cleanup_repos.copr

match $config.repos.nonfree? {
Expand All @@ -797,5 +794,6 @@ def main [config: string]: nothing -> nothing {
}
_ => {},
}
print $'(ansi green)Finished cleaning up repos(ansi reset)'
}
}
2 changes: 1 addition & 1 deletion modules/dnf/dnf.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ model Repo {
* However, only one can be enabled at a time so if one
* is enabled, the other will be disabled if it is already enabled.
*/
nonfree?: "negativo17-multimedia" | "rpmfusion";
nonfree?: "negativo17" | "rpmfusion";
}

model RepoFiles {
Expand Down
4 changes: 2 additions & 2 deletions modules/dnf/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ example: |
- trixieua/mutter-patched
keys: # Add keys for repos
- https://brave-browser-rpm-release.s3.brave.com/brave-core.asc
nonfree: rpmfusion # Enable either the `rpmfusion` or `negativo17-multimedia` repo
nonfree: rpmfusion # Enable either the `rpmfusion` or `negativo17` repos
# Performs symlinking for `/opt/` to allow certain packages to install
optfix:
- Tabby # needed because tabby installs into `/opt/Tabby/`
Expand Down Expand Up @@ -78,7 +78,7 @@ example: |
add:
- https://pkgs.tailscale.com/stable/fedora/tailscale.repo
# Remove repos by specifying the repo ID
disable:
remove:
- docker-ce-stable
copr:
# Enable COPR repos like the examples above
Expand Down

0 comments on commit 591b517

Please sign in to comment.