Skip to content

Commit

Permalink
feat: Add remove-unused-dependencies option for package removal
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftydinar authored Dec 23, 2024
1 parent 7fc5a24 commit 63f745b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
26 changes: 20 additions & 6 deletions modules/dnf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,37 @@ The module can also replace base RPM packages with packages from any repo. Under
[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.
:::

## Package manager behavior options
## `dnf` behavior options

There are several options that can be enabled during the package/group install + removal & during package replace, which modify the behavior of the package manager during those operations.

There are several options that can be enabled during the package/group install & during package replace, which modify the behavior of the package manager during those operations.
Those include:

Install operation:
- `install-weak-dependencies` (`--setopt=install_weak_deps=True/False` flag)
- `skip-unavailable-packages` (`--skip-unavailable` flag)
- `skip-broken-packages` (`--skip-broken` flag)
- `allow-erasing-packages` (`--allowerasing` flag)

### `install-weak-dependencies`
Remove operation:
- `remove-unused-dependencies` (`--no-autoremove` flag)


### `dnf` install/replace behavior options

#### `install-weak-dependencies`
`install-weak-dependencies` option is used to enable or disable installation of weak dependencies for every install & replace operation. By default, this option is true, which means that 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/).

### `skip-unavailable-packages`
#### `skip-unavailable-packages`
`skip-unavailable-packages` option is used to continue or abort install/replace operation if there are no packages available in the repo in install operation, or if they are not available in the system in replace operation. By default, this option is false, which means that install/replace operation aborts in case of unavailable packages.

### `skip-broken-packages`
#### `skip-broken-packages`
`skip-broken-packages` option is used to continue or abort install/replace operation if there are broken packages in the system. By default, this option is false, which means that install/replace operation aborts in case of broken packages.

### `allow-erasing-packages`
#### `allow-erasing-packages`
`allow-erasing-packages` option is used to allow erasing/removing problematic packages if they cause issues in install/replace operation. By default, this option is false, which means that problematic packages won't be removed & operation will be aborted.

### `dnf` package (non-group) removal behavior options

#### `remove-unused-dependencies`
`remove-unused-dependencies` option is used to control the behavior of removing unused dependencies when some main packages are removed. By default, this option is true. Only compatible with removing packages, not compatible with removing RPM groups.
13 changes: 11 additions & 2 deletions modules/dnf/dnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ elif [[ "${ALLOW_ERASING}" == "true" ]]; then
ALLOW_ERASING_FLAG="--allowerasing"
fi

# Get if 'remove-unused-dependencies' is provided for package removal
REMOVE_UNUSED_DEPS=$(echo "${1}" | jq -r 'try .["remove"].["remove-unused-dependencies"]')

if [[ -z "${REMOVE_UNUSED_DEPS}" ]] || [[ "${REMOVE_UNUSED_DEPS}" == "null" ]] || [[ "${REMOVE_UNUSED_DEPS}" == "true" ]]; then
REMOVE_UNUSED_DEPS_FLAG=""
elif [[ "${REMOVE_UNUSED_DEPS}" == "false" ]]; then
REMOVE_UNUSED_DEPS_FLAG="--no-autoremove"
fi

CLASSIC_INSTALL=false
HTTPS_INSTALL=false
LOCAL_INSTALL=false
Expand Down Expand Up @@ -209,7 +218,7 @@ 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 remove "${REMOVE_UNUSED_DEPS_FLAG}" "${REMOVE_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" install --refresh "${SKIP_UNAVAILABLE_FLAG}" "${SKIP_BROKEN_FLAG}" "${ALLOW_ERASING_FLAG}" "${INSTALL_PKGS[@]}"
elif [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
echo "Installing RPMs"
Expand All @@ -218,7 +227,7 @@ elif [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
elif [[ ${#REMOVE_PKGS[@]} -gt 0 ]]; then
echo "Removing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
dnf -y remove "${REMOVE_PKGS[@]}"
dnf -y remove "${REMOVE_UNUSED_DEPS_FLAG}" "${REMOVE_PKGS[@]}"
fi

get_json_array REPLACE 'try .["replace"][]' "$1"
Expand Down
4 changes: 3 additions & 1 deletion modules/dnf/dnf.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ model DnfModule {
/** Configuration of RPM packages removal. */
"remove"?: {
/** List of RPM packages to remove. */
packages?: string;
packages?: string,
/** Whether to remove unused dependencies during removal operation. */
"remove-unused-dependencies"?: boolean = true;
};

/** Configuration of RPM packages install. */
Expand Down

0 comments on commit 63f745b

Please sign in to comment.