Skip to content

Commit

Permalink
chore: Add option to enable or disable installation of weak dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftydinar authored Dec 22, 2024
1 parent a4e9ba4 commit 7da24f5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion modules/dnf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ If an RPM is not available in a repository or as an URL, you can also install it
install:
- weird-package.rpm # tries to install files/dnf/weird-package.rpm
```

Additionally, the `dnf` module supports a fix for packages that install into `/opt/`. Installation for packages that install into folder names declared under `optfix:` are fixed using some symlinks. Directory path in `/opt/` for those packages should be provided in recipe, like in Example Configuration.

The module can also replace base RPM packages with packages from any repo. Under `replace:`, the module finds every pair of keys `- from-repo:` and `packages:`. (Multiple pairs are supported.) The module uses `- from-repo:` key to gather the repo for package replacement, then it replaces packages declared under `packages:` using the command `dnf -y distro-sync --refresh --repo "${repo}" "${packages}"`. The magic string `%OS_VERSION%` is substituted with the current VERSION_ID (major Fedora version) as already said above. You need to assure that you provided the repo in `repos:` before using replacement functionality. To gather the repo ID that you need to input, you can use `dnf repo list` command.

:::note
[Removed packages are still present in the underlying ostree repository](https://coreos.github.io/rpm-ostree/administrator-handbook/#removing-a-base-package), what `remove` does is kind of like hiding them from the system, it doesn't free up storage space.
:::

Additionally, the `dnf` module supports a fix for packages that install into `/opt/`. Installation for packages that install into folder names declared under `optfix:` are fixed using some symlinks. Directory path in `/opt/` for those packages should be provided in recipe, like in Example Configuration.
There is also a 'weak-dependencies:' option to enable or disable installation of weak dependencies for every install operation. Weak dependencies are installed by default. Which kind of dependencies are considered weak can be seen [here](https://docs.fedoraproject.org/en-US/packaging-guidelines/WeakDependencies/).
19 changes: 14 additions & 5 deletions modules/dnf/dnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ if ! rpm -q dnf5-plugins &>/dev/null; then
exit 1
fi

# Check if option for weak dependencies is enabled or disabled
WEAK_DEPENDENCIES=$(echo "${1}" | jq -r 'try .["weak-dependencies"]')

if [[ -z "${WEAK_DEPENDENCIES}" ]] || [[ "${WEAK_DEPENDENCIES}" == "null" ]] || [[ "${WEAK_DEPENDENCIES}" == "true" ]]; then
WEAK_DEPS_FLAG="--setopt=install_weak_deps=True"
elif [[ "${WEAK_DEPENDENCIES}" == false ]]; then
WEAK_DEPS_FLAG="--setopt=install_weak_deps=False"
fi

# Pull in repos
get_json_array REPOS 'try .["repos"][]' "${1}"
if [[ ${#REPOS[@]} -gt 0 ]]; then
Expand Down Expand Up @@ -128,16 +137,16 @@ if [[ ${#INSTALL_PKGS[@]} -gt 0 && ${#REMOVE_PKGS[@]} -gt 0 ]]; then
echo "Removing & Installing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
echo_rpm_install
dnf -y remove "${REMOVE_PKGS[@]}"
dnf -y install "${INSTALL_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" remove "${REMOVE_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" install "${INSTALL_PKGS[@]}"
elif [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
echo "Installing RPMs"
echo_rpm_install
dnf -y install "${INSTALL_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" install "${INSTALL_PKGS[@]}"
elif [[ ${#REMOVE_PKGS[@]} -gt 0 ]]; then
echo "Removing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
dnf -y remove "${REMOVE_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" remove "${REMOVE_PKGS[@]}"
fi

get_json_array REPLACE 'try .["replace"][]' "$1"
Expand Down Expand Up @@ -169,7 +178,7 @@ if [[ ${#REPLACE[@]} -gt 0 ]]; then
echo "Replacing packages from repository: '${REPO}'"
echo "Replacing: ${REPLACE_STR}"

dnf -y distro-sync --refresh --repo "${REPO}" "${PACKEGES[@]}"
dnf -y "${WEAK_DEPS_FLAG}" distro-sync --refresh --repo "${REPO}" "${PACKEGES[@]}"

done
fi
3 changes: 3 additions & 0 deletions modules/dnf/dnf.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ model RpmOstreeModule {
/** List of packages to replace using packages from the defined repo. */
packages: Array<string>,
}>;

/** Whether to install weak dependencies during install operation or not. */
"weak-dependencies"?: boolean = true;
}
1 change: 1 addition & 0 deletions modules/dnf/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: dnf
shortdesc: The dnf module offers pseudo-declarative package and repository management using dnf.
example: |
type: dnf
weak-dependencies: true
repos:
- copr: atim/starship
- https://brave-browser-rpm-release.s3.brave.com/brave-browser.repo
Expand Down

0 comments on commit 7da24f5

Please sign in to comment.