-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on making this a nushell module
- Loading branch information
Showing
2 changed files
with
170 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/evn nu | ||
|
||
def add_repos [$repos: list]: nothing -> nothing { | ||
if $repos | is-not-empty { | ||
print $'(ansi green)Adding repositories(ansi reset)' | ||
|
||
for $repo in $repos { | ||
# Substitute %OS_VERSION% & remove newlines/whitespaces from all repo entries | ||
let repo = $repo | str replace '%OS_VERSION%' $env.OS_VERSION | str trim | ||
|
||
let repo = if ($repo | str starts-with 'https://') or ($repo | str starts-with 'http://') { | ||
print $"Adding repository URL: (ansi cyan)'${repo}'(ansi reset)" | ||
$repo | ||
} else if ($repo | str ends-with '.repo') and ($'($envCONFIG_DIRECTORY)/dnf/($repo)' | path exists) { | ||
print $"Adding repository file: (ansi cyan)'($repo)'(ansi reset)" | ||
$'($env.CONFIG_DIRECTORY)/dnf/($repo)' | ||
} else { | ||
return (error make { | ||
msg: $"(ansi red)Urecognized repo (ansi cyan)'($repo)'(ansi reset)" | ||
label: { | ||
span: (metadata $repo).span | ||
text: 'Found in config' | ||
} | ||
}) | ||
} | ||
|
||
try { | ||
^dnf -y config-manager addrepo --from-repofile $'($repo)' | ||
} | ||
} | ||
} | ||
} | ||
|
||
def add_coprs [$copr_repos: list]: nothing -> nothing { | ||
if $copr_repos | is-not-empty { | ||
print $'(ansi green)Adding COPR repositories(ansi reset)' | ||
|
||
for $copr in $copr_repos { | ||
let is_copr = ($copr | split row | length) == 2 | ||
|
||
if not $is_copr { | ||
return (error make { | ||
msg: $"(ansi red)The string '(ansi cyan)($copr)(ansi red)' is not recognized as a COPR repo(ansi reset)" | ||
label: { | ||
span: (metadata $is_copr).span | ||
text: 'Checks if string is a COPR repo' | ||
} | ||
}) | ||
} | ||
|
||
print $"Adding COPR repository: (ansi cyan)'($copr)'(ansi reset)" | ||
try { | ||
^dnf -y copr enable $copr | ||
} | ||
} | ||
} | ||
} | ||
|
||
def main [config: string]: nothing -> nothing { | ||
let config = $config | from json | ||
let has_dnf5 = ^rpm -q dnf5 | complete | ||
|
||
if has_dnf5.exit_code != 0 { | ||
return (error make { | ||
msg: $"(ansi red)ERROR: Main dependency '(ansi cyan)dnf5(ansi red)' is not installed. Install '(ansi cyan)dnf5(ansi red)' before using this module to solve this error.(ansi reset)" | ||
label: { | ||
span: (metadata $has_dn5).span | ||
text: 'Checks for dnf5' | ||
} | ||
}) | ||
} | ||
|
||
add_repos ($config | default [] repos | select repos) | ||
add_coprs ($config | default [] copr | select copr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,99 @@ | ||
import "@typespec/json-schema"; | ||
using TypeSpec.JsonSchema; | ||
|
||
@jsonSchema("/modules/dnf.json") | ||
model DnfModule { | ||
/** The dnf module offers pseudo-declarative package and repository management using dnf. | ||
* https://blue-build.org/reference/modules/dnf/ | ||
*/ | ||
type: "dnf"; | ||
|
||
/** List of links to .repo files to download into /etc/yum.repos.d/. */ | ||
repos?: Array<string>; | ||
|
||
/** List of COPR project repos to download into /etc/yum.repos.d/. */ | ||
copr?: Array<string>; | ||
|
||
/** List of links to key files to import for installing from custom repositories. */ | ||
keys?: Array<string>; | ||
|
||
/** List of folder names under /opt/ to enable for installing into. */ | ||
optfix?: Array<string>; | ||
|
||
/** Configuration of RPM groups removal. */ | ||
"group-remove"?: { | ||
/** List of RPM groups to remove. */ | ||
packages: Array<string>; | ||
}; | ||
|
||
/** Configuration of RPM groups install. */ | ||
"group-install"?: { | ||
/** List of RPM groups to install. */ | ||
packages: Array<string>, | ||
/** Whether to install weak dependencies during the RPM group install or not. */ | ||
"install-weak-dependencies"?: boolean = true, | ||
/** Whether to continue with the RPM group install if there are no packages available in the repository. */ | ||
"skip-unavailable-packages"?: boolean = false, | ||
/** Whether to continue with the RPM group install if there are broken packages. */ | ||
"skip-broken-packages"?: boolean = false, | ||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the RPM group install. */ | ||
"allow-erasing-packages"?: boolean = false; | ||
}; | ||
|
||
/** Configuration of RPM packages removal. */ | ||
"remove"?: { | ||
/** List of RPM packages to remove. */ | ||
packages: Array<string>, | ||
/** Whether to remove unused dependencies during removal operation. */ | ||
"remove-unused-dependencies"?: boolean = true; | ||
}; | ||
|
||
/** Configuration of RPM packages install. */ | ||
"install"?: { | ||
/** List of RPM packages to install. */ | ||
packages: Array<string>, | ||
/** Whether to install weak dependencies during the RPM package install or not. */ | ||
"install-weak-dependencies"?: boolean = true, | ||
/** Whether to continue with the RPM package install if there are no packages available in the repository. */ | ||
"skip-unavailable-packages"?: boolean = false, | ||
/** Whether to continue with the RPM package install if there are broken packages. */ | ||
"skip-broken-packages"?: boolean = false, | ||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the RPM package install. */ | ||
"allow-erasing-packages"?: boolean = false; | ||
}; | ||
|
||
/** List of configurations for replacing packages from another repo. */ | ||
replace?: Array<{ | ||
/** URL to the source COPR repo for the new packages. */ | ||
"from-repo": string, | ||
/** List of packages to replace using packages from the defined repo. */ | ||
packages: Array<string>, | ||
/** Whether to install weak dependencies during the replacement or not. */ | ||
"install-weak-dependencies"?: boolean = true, | ||
/** Whether to continue with the replacement if there are no packages available on the system to replace. */ | ||
"skip-unavailable-packages"?: boolean = false, | ||
/** Whether to continue with the replacement if there are broken packages in the system during the replacement. */ | ||
"skip-broken-packages"?: boolean = false, | ||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the replacement. */ | ||
"allow-erasing-packages"?: boolean = false; | ||
}>; | ||
@jsonSchema("/modules/dnf-latest.json") | ||
model DnfModuleLatest { | ||
...DnfModuleV1; | ||
} | ||
|
||
@jsonSchema("/modules/dnf-v1.json") | ||
model DnfModuleV1 { | ||
/** The dnf module offers pseudo-declarative package and repository management using dnf. | ||
* https://blue-build.org/reference/modules/dnf/ | ||
*/ | ||
type: "dnf"; | ||
|
||
/** List of links to .repo files to download into /etc/yum.repos.d/. */ | ||
repos?: Array<string>; | ||
|
||
/** List of COPR project repos to download into /etc/yum.repos.d/. */ | ||
copr?: Array<string>; | ||
|
||
/** List of links to key files to import for installing from custom repositories. */ | ||
keys?: Array<string>; | ||
|
||
/** List of folder names under /opt/ to enable for installing into. */ | ||
optfix?: Array<string>; | ||
|
||
/** Configuration of RPM groups removal. */ | ||
`group-remove`?: { | ||
/** List of RPM groups to remove. */ | ||
packages: Array<string>; | ||
}; | ||
|
||
/** Configuration of RPM groups install. */ | ||
`group-install`?: { | ||
/** List of RPM groups to install. */ | ||
packages: Array<string>; | ||
|
||
/** Whether to install weak dependencies during the RPM group install or not. */ | ||
`install-weak-dependencies`?: boolean = true; | ||
|
||
/** Whether to continue with the RPM group install if there are no packages available in the repository. */ | ||
`skip-unavailable-packages`?: boolean = false; | ||
|
||
/** Whether to continue with the RPM group install if there are broken packages. */ | ||
`skip-broken-packages`?: boolean = false; | ||
|
||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the RPM group install. */ | ||
`allow-erasing-packages`?: boolean = false; | ||
}; | ||
|
||
/** Configuration of RPM packages removal. */ | ||
remove?: { | ||
/** List of RPM packages to remove. */ | ||
packages: Array<string>; | ||
|
||
/** Whether to remove unused dependencies during removal operation. */ | ||
`remove-unused-dependencies`?: boolean = true; | ||
}; | ||
|
||
/** Configuration of RPM packages install. */ | ||
install?: { | ||
/** List of RPM packages to install. */ | ||
packages: Array<string>; | ||
|
||
/** Whether to install weak dependencies during the RPM package install or not. */ | ||
`install-weak-dependencies`?: boolean = true; | ||
|
||
/** Whether to continue with the RPM package install if there are no packages available in the repository. */ | ||
`skip-unavailable-packages`?: boolean = false; | ||
|
||
/** Whether to continue with the RPM package install if there are broken packages. */ | ||
`skip-broken-packages`?: boolean = false; | ||
|
||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the RPM package install. */ | ||
`allow-erasing-packages`?: boolean = false; | ||
}; | ||
|
||
/** List of configurations for replacing packages from another repo. */ | ||
replace?: Array<{ | ||
/** URL to the source COPR repo for the new packages. */ | ||
`from-repo`: string; | ||
|
||
/** List of packages to replace using packages from the defined repo. */ | ||
packages: Array<string>; | ||
|
||
/** Whether to install weak dependencies during the replacement or not. */ | ||
`install-weak-dependencies`?: boolean = true; | ||
|
||
/** Whether to continue with the replacement if there are no packages available on the system to replace. */ | ||
`skip-unavailable-packages`?: boolean = false; | ||
|
||
/** Whether to continue with the replacement if there are broken packages in the system during the replacement. */ | ||
`skip-broken-packages`?: boolean = false; | ||
|
||
/** Whether to allow erasing (removal) of packages in case of dependency problems during the replacement. */ | ||
`allow-erasing-packages`?: boolean = false; | ||
}>; | ||
} |