feat(rpm-ostree): Add support for installing local repos & RPMs

I also made installing packages more efficient, as rpm-ostree can install from URL, local RPM & classic RPM package at the same time, so there is no need to keep packages installing separately from URLs as it is now.

I also made logs more informative for install section, so classic RPMs, local RPMs & URL RPMs are printed separately.
This commit is contained in:
fiftydinar 2024-07-31 18:26:19 +02:00
parent 32bbddc245
commit d9d7d0968e
3 changed files with 62 additions and 15 deletions

View file

@ -4,12 +4,24 @@ The [`rpm-ostree`](https://coreos.github.io/rpm-ostree/) module offers pseudo-de
The module first downloads the repository files from repositories declared under `repos:` into `/etc/yum.repos.d/`. The magic string `%OS_VERSION%` is substituted with the current VERSION_ID (major Fedora version), which can be used, for example, for pulling correct versions of repositories from [Fedora's Copr](https://copr.fedorainfracloud.org/).
You can also have local repos inserted in this file location (make the directory if it doesn't exist):
```
files/rpm-ostree/my-repository.repo
files/rpm-ostree/my-image/my-2nd-repository.repo
```
If you use a repo that requires adding custom keys (eg. Brave Browser), you can import the keys by declaring the key URLs under `keys:`. The magic string acts the same as it does in `repos`.
Then the module installs the packages declared under `install:` using `rpm-ostree install`, it removes the packages declared under `remove:` using `rpm-ostree override remove`. If there are packages declared under both `install:` and `remove:` a hybrid command `rpm-ostree remove <packages> --install <packages>` is used, which should allow you to switch required packages for other ones.
Installing RPM packages directly from a `http(s)` url that points to the RPM file is also supported, you can just put the URLs under `install:` and they'll be installed along with the other packages. The magic string `%OS_VERSION%` is substituted with the current VERSION_ID (major Fedora version) like with the `repos:` property.
Installing local RPM packages from the file location is supported. You can insert those RPMs in this file location (make the directory if it doesn't exist):
```
files/rpm-ostree/my-package.rpm
files/rpm-ostree/my-image/somepackage.rpm
```
The module can also replace base RPM packages with packages from COPR repo. Under `replace:`, the module finds every pair of keys `- from-repo:` and `packages:`. (Multiple pairs are supported.) The module downloads the COPR repository file declared by `- from-repo:` into `/etc/yum.repos.d/`, and from that repository replaces packages declared under `packages:` using the command `rpm-ostree override replace`. The COPR repository file is then deleted. The magic string `%OS_VERSION%` is substituted with the current VERSION_ID (major Fedora version) as already said above. At the moment, only COPR repo is supported.
:::note

View file

@ -5,6 +5,7 @@ example: |
repos:
- https://copr.fedorainfracloud.org/coprs/atim/starship/repo/fedora-%OS_VERSION%/atim-starship-fedora-%OS_VERSION%.repo # when including COPR repos, use the %OS_VERSION% magic string
- https://brave-browser-rpm-release.s3.brave.com/brave-browser.repo
- my-local-repository.repo # local repo located in `files/rpm-ostree/my-local-repository.repo`
keys:
- https://brave-browser-rpm-release.s3.brave.com/brave-core.asc
optfix:
@ -16,9 +17,11 @@ example: |
remove:
- firefox
- firefox-langpacks
- my-local-package.rpm # local package located in `files/rpm-ostree/my-local-package.rpm`
- some-folder/my-local-package-2.rpm # local package located in `files/rpm-ostree/some-folder/my-local-package-2.rpm`
replace:
- from-repo: https://copr.fedorainfracloud.org/coprs/trixieua/mutter-patched/repo/fedora-%OS_VERSION%/trixieua-mutter-patched-fedora-%OS_VERSION%.repo
packages:
- mutter
- mutter-common
- gdm
- gdm

View file

@ -8,8 +8,12 @@ get_yaml_array REPOS '.repos[]' "$1"
if [[ ${#REPOS[@]} -gt 0 ]]; then
echo "Adding repositories"
for REPO in "${REPOS[@]}"; do
REPO="${REPO//%OS_VERSION%/${OS_VERSION}}"
curl --output-dir "/etc/yum.repos.d/" -O "${REPO//[$'\t\r\n ']}"
REPO="${REPO//%OS_VERSION%/${OS_VERSION}}"
if [[ "${REPO}" =~ ^https?:\/\/.* ]]; then
curl --output-dir "/etc/yum.repos.d/" -O "${REPO//[$'\t\r\n ']}"
elif [[ ! "${REPO}" =~ ^https?:\/\/.* ]] && [[ "${REPO}" == *".repo" ]] && [[ -f "${CONFIG_DIRECTORY}/rpm-ostree/${REPO}" ]]; then
cp "${CONFIG_DIRECTORY}/rpm-ostree/${REPO}" "/etc/yum.repos.d/${REPO}"
fi
done
fi
@ -43,16 +47,22 @@ fi
get_yaml_array INSTALL '.install[]' "$1"
get_yaml_array REMOVE '.remove[]' "$1"
# Install and remove RPM packages
# Sort classic, URL & local packages
if [[ ${#INSTALL[@]} -gt 0 ]]; then
for PKG in "${INSTALL[@]}"; do
if [[ "$PKG" =~ ^https?:\/\/.* ]]; then
REPLACED_PKG="${PKG//%OS_VERSION%/${OS_VERSION}}"
echo "Installing directly from URL: ${REPLACED_PKG}"
rpm-ostree install "$REPLACED_PKG"
INSTALL=( "${INSTALL[@]/$PKG}" ) # delete URL from install array
fi
done
fi
if [[ "$PKG" =~ ^https?:\/\/.* ]]; then
VERSION_SUBSTITUTED_PKG="${PKG//%OS_VERSION%/${OS_VERSION}}"
HTTPS_INSTALL=true
HTTPS_PKG+=("${VERSION_SUBSTITUTED_PKG}")
elif [[ ! "$PKG" =~ ^https?:\/\/.* ]] && [[ -f "${CONFIG_DIRECTORY}/rpm-ostree/${PKG}" ]]; then
LOCAL_INSTALL=true
LOCAL_PKG+=("${PKG}")
else
CLASSIC_INSTALL=true
CLASSIC_PKG+=("${PKG}")
fi
done
# The installation is done with some wordsplitting hacks
# because of errors when doing array destructuring at the installation step.
@ -60,16 +70,38 @@ fi
INSTALL_STR=$(echo "${INSTALL[*]}" | tr -d '\n')
REMOVE_STR=$(echo "${REMOVE[*]}" | tr -d '\n')
# Install and remove RPM packages
echo_rpm_install() {
if ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
echo "Installing: ${CLASSIC_PKG[*]}"
elif ! ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
echo "Installing package(s) directly from URL: ${HTTPS_PKG[*]}"
elif ! ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
echo "Installing local package(s): ${LOCAL_PKG[*]}"
elif ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
echo "Installing: ${CLASSIC_PKG[*]}"
echo "Installing package(s) directly from URL: ${HTTPS_PKG[*]}"
elif ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
echo "Installing: ${CLASSIC_PKG[*]}"
echo "Installing local package(s): ${LOCAL_PKG[*]}"
elif ! ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
echo "Installing package(s) directly from URL: ${HTTPS_PKG[*]}"
echo "Installing local package(s): ${LOCAL_PKG[*]}"
elif ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
echo "Installing: ${CLASSIC_PKG[*]}"
echo "Installing package(s) directly from URL: ${HTTPS_PKG[*]}"
echo "Installing local package(s): ${LOCAL_PKG[*]}"
fi
}
if [[ ${#INSTALL[@]} -gt 0 && ${#REMOVE[@]} -gt 0 ]]; then
echo "Installing & Removing RPMs"
echo "Installing: ${INSTALL_STR[*]}"
echo_rpm_install
echo "Removing: ${REMOVE_STR[*]}"
# Doing both actions in one command allows for replacing required packages with alternatives
rpm-ostree override remove $REMOVE_STR $(printf -- "--install=%s " $INSTALL_STR)
elif [[ ${#INSTALL[@]} -gt 0 ]]; then
echo "Installing RPMs"
echo "Installing: ${INSTALL_STR[*]}"
echo_rpm_install
rpm-ostree install $INSTALL_STR
elif [[ ${#REMOVE[@]} -gt 0 ]]; then
echo "Removing RPMs"
@ -108,7 +140,7 @@ if [[ ${#REPLACE[@]} -gt 0 ]]; then
exit 1
fi
echo "Replacing packages from repository: '${REPO_NAME}' owned by '${MAINTAINER}'"
echo "Replacing packages from COPR repository: '${REPO_NAME}' owned by '${MAINTAINER}'"
echo "Replacing: ${REPLACE_STR}"
curl --output-dir "/etc/yum.repos.d/" -O "${REPO//[$'\t\r\n ']}"