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 Mar 5, 2025
1 parent e86be19 commit e781c4b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 84 deletions.
195 changes: 115 additions & 80 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,17 +301,26 @@ 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
}
}
}
}

# Checks to see if the string passed in is
# a COPR repo string. Will error if it isn't
def check_copr []: string -> string {
let is_copr = ($in | split row / | length) == 2

Expand Down Expand Up @@ -558,23 +557,27 @@ def remove_pkgs [remove: record]: nothing -> nothing {
}

# Build up args to use on `dnf`
def install_args []: record -> list<string> {
def install_args [...filter: string]: record -> list<string> {
let install = $in
| default false skip-unavailable
| default false skip-broken
| default false allow-erasing

mut args = []
let check_filter = {|arg|
let arg_exists = ($arg in $install)
if ($filter | is-empty) {
$arg_exists and ($install | get $arg)
} else {
$arg_exists and ($arg in $filter) and ($install | get $arg)
}
}

if $install.skip-unavailable {
if (do $check_filter 'skip-unavailable') {
$args = $args | append '--skip-unavailable'
}

if $install.skip-broken {
if (do $check_filter 'skip-broken') {
$args = $args | append '--skip-broken'
}

if $install.allow-erasing {
if (do $check_filter 'allow-erasing') {
$args = $args | append '--allowerasing'
}

Expand Down Expand Up @@ -706,6 +709,10 @@ def install_pkgs [install: record]: nothing -> nothing {
# Perform a replace operation for a list of packages that
# you want to replace from a specific repo.
def replace_pkgs [replace_list: list]: nothing -> nothing {
let check = {|item|
'old' in $item and 'new' in $item
}

if ($replace_list | is-not-empty) {
for $replacement in $replace_list {
let replacement = $replacement
Expand All @@ -727,8 +734,35 @@ def replace_pkgs [replace_list: list]: nothing -> nothing {
let from_repo = $replacement
| get from-repo

let swap_packages = $replacement.packages
| filter $check
let sync_packages = $replacement.packages
| filter {
not (do $check $in)
}

print $"(ansi green)Swapping packages from '(ansi cyan)($from_repo)(ansi green)':(ansi reset)"
$swap_packages
| each {
print $'- (ansi cyan)($in.old)(ansi green) -> (ansi cyan)($in.new)(ansi reset)'
}

for $pkg_pair in $swap_packages {
try {
(^dnf5
-y
swap
--refresh
...($replacement | install_args allow-erasing)
$pkg_pair.old
$pkg_pair.new)
} catch {
exit 1
}
}

print $"(ansi green)Replacing packages from '(ansi cyan)($from_repo)(ansi green)':(ansi reset)"
$replacement.packages
$sync_packages
| each {
print $'- (ansi cyan)($in)(ansi reset)'
}
Expand Down Expand Up @@ -785,7 +819,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 +831,6 @@ def main [config: string]: nothing -> nothing {
}
_ => {},
}
print $'(ansi green)Finished cleaning up repos(ansi reset)'
}
}
12 changes: 10 additions & 2 deletions 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 Expand Up @@ -111,11 +111,19 @@ model Replace {
`from-repo`: string;

/** List of packages to replace using packages from the defined repo. */
packages: Array<string>;
packages: Array<string | Swap>;

...InstallCommon;
}

model Swap {
/** The package to be replaced. */
old: string;

/** The package to replace with. */
new: string;
}

model GroupInstall {
/** List of RPM groups to install. */
packages: Array<string>;
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 e781c4b

Please sign in to comment.