Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftydinar authored Dec 22, 2024
1 parent 0b9c68f commit 380606e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 75 deletions.
102 changes: 38 additions & 64 deletions modules/dnf/dnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,43 @@ 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 .["install-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"
get_json_array REPOS 'try .["repos"][]' "${1}"
if [[ ${#REPOS[@]} -gt 0 ]]; then
echo "Adding repositories"
# Substitute %OS_VERSION% & remove newlines/whitespaces from all repo entries
for i in "${!REPOS[@]}"; do
repo="${REPOS[$i]}"
repo="${repo//%OS_VERSION%/${OS_VERSION}}"
# Extract copr repo array element properly here without JSON brackets
if [[ "${repo}" == "{\"copr\":\""*"\"}" ]]; then
REPOS[$i]="$(echo "copr: $(echo "${repo}" | jq -r '.copr')")"
else
REPOS[$i]="${repo//[$'\t\r\n ']}"
fi
REPOS[$i]="${repo//[$'\t\r\n ']}"
fi
done
# dnf config-manager & dnf copr don't support adding multiple repositories at once, hence why for/done loop is used
for repo in "${REPOS[@]}"; do
if [[ "${repo}" =~ ^https?:\/\/.* ]]; then
echo "Adding repository URL: '${repo}'"
dnf config-manager addrepo --from-repofile="${repo}"
dnf -y config-manager addrepo --from-repofile="${repo}"
elif [[ "${repo}" == *".repo" ]] && [[ -f "${CONFIG_DIRECTORY}/dnf/${repo}" ]]; then
echo "Adding repository file: '${repo}'"
dnf config-manager addrepo --from-repofile="${repo}"
elif [[ "${repo}" == "copr: "* ]]; then
echo "Adding COPR repository: '${repo#copr: }'"
dnf copr enable "${repo#copr: }"
dnf -y config-manager addrepo --from-repofile="${repo}"
elif [[ "${repo}" == "COPR "* ]]; then
echo "Adding COPR repository: '${repo#COPR }'"
dnf -y copr enable "${repo#COPR }"
fi
done
fi

get_json_array KEYS 'try .["keys"][]' "$1"
# Install RPM keys if they are provided
get_json_array KEYS 'try .["keys"][]' "${1}"
if [[ ${#KEYS[@]} -gt 0 ]]; then
echo "Adding keys"
for KEY in "${KEYS[@]}"; do
Expand All @@ -56,12 +62,12 @@ if [[ ${#KEYS[@]} -gt 0 ]]; then
fi

# Create symlinks to fix packages that create directories in /opt
get_json_array OPTFIX 'try .["optfix"][]' "$1"
get_json_array OPTFIX 'try .["optfix"][]' "${1}"
if [[ ${#OPTFIX[@]} -gt 0 ]]; then
echo "Creating symlinks to fix packages that install to /opt"
# Create symlink for /opt to /var/opt since it is not created in the image yet
mkdir -p "/var/opt"
ln -s "/var/opt" "/opt"
ln -snf "/var/opt" "/opt"
# Create symlinks for each directory specified in recipe.yml
for OPTPKG in "${OPTFIX[@]}"; do
OPTPKG="${OPTPKG%\"}"
Expand All @@ -72,15 +78,14 @@ if [[ ${#OPTFIX[@]} -gt 0 ]]; then
done
fi

get_json_array INSTALL_PKGS 'try .["install"][]' "$1"
get_json_array REMOVE_PKGS 'try .["remove"][]' "$1"
get_json_array INSTALL_PKGS 'try .["install"][]' "${1}"
get_json_array REMOVE_PKGS 'try .["remove"][]' "${1}"

CLASSIC_INSTALL=false
HTTPS_INSTALL=false
LOCAL_INSTALL=false

# Install and remove RPM packages
# Sort classic, URL & local packages
# Sort classic, URL & local install packages
if [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
for i in "${!INSTALL_PKGS[@]}"; do
PKG="${INSTALL_PKGS[$i]}"
Expand All @@ -98,6 +103,7 @@ if [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
done
fi

# Function to inform the user about which type of packages is he installing
echo_rpm_install() {
if ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
echo "Installing: ${CLASSIC_PKGS[*]}"
Expand All @@ -121,85 +127,53 @@ echo_rpm_install() {
fi
}

# Remove & install RPM packages
if [[ ${#INSTALL_PKGS[@]} -gt 0 && ${#REMOVE_PKGS[@]} -gt 0 ]]; then
echo "Installing & Removing RPMs"
echo_rpm_install
echo "Removing & Installing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
# Doing both actions in one command allows for replacing required packages with alternatives
# When --install= flag is used, URLs & local packages are not supported
if ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}" $(printf -- "--install=%s " "${CLASSIC_PKGS[@]}")
elif ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}" $(printf -- "--install=%s " "${CLASSIC_PKGS[@]}")
rpm-ostree install "${HTTPS_PKGS[@]}"
elif ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}" $(printf -- "--install=%s " "${CLASSIC_PKGS[@]}")
rpm-ostree install "${LOCAL_PKGS[@]}"
elif ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}" $(printf -- "--install=%s " "${CLASSIC_PKGS[@]}")
rpm-ostree install "${HTTPS_PKGS[@]}" "${LOCAL_PKGS[@]}"
elif ! ${CLASSIC_INSTALL} && ! ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}"
rpm-ostree install "${LOCAL_PKGS[@]}"
elif ! ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ! ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}"
rpm-ostree install "${HTTPS_PKGS[@]}"
elif ! ${CLASSIC_INSTALL} && ${HTTPS_INSTALL} && ${LOCAL_INSTALL}; then
rpm-ostree override remove "${REMOVE_PKGS[@]}"
rpm-ostree install "${HTTPS_PKGS[@]}" "${LOCAL_PKGS[@]}"
fi
echo_rpm_install
dnf -y "${WEAK_DEPS_FLAG}" remove "${REMOVE_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" install --refresh "${INSTALL_PKGS[@]}"
elif [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
echo "Installing RPMs"
echo_rpm_install
rpm-ostree install "${INSTALL_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" install --refresh "${INSTALL_PKGS[@]}"
elif [[ ${#REMOVE_PKGS[@]} -gt 0 ]]; then
echo "Removing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
rpm-ostree override remove "${REMOVE_PKGS[@]}"
dnf -y "${WEAK_DEPS_FLAG}" remove "${REMOVE_PKGS[@]}"
fi

get_json_array REPLACE 'try .["replace"][]' "$1"

# Override-replace RPM packages
# Replace RPM packages from any repository
if [[ ${#REPLACE[@]} -gt 0 ]]; then
for REPLACEMENT in "${REPLACE[@]}"; do

# Get repository
REPO=$(echo "${REPLACEMENT}" | jq -r 'try .["from-repo"]')
REPO="${REPO//%OS_VERSION%/${OS_VERSION}}"
REPO="${REPO//[$'\t\r\n ']}"

# Ensure repository is provided
if [[ "${REPO}" == "null" ]]; then
echo "Error: Key 'from-repo' was declared, but repository URL was not provided."
exit 1
fi

# Get info from repository URL
MAINTAINER=$(awk -F'/' '{print $5}' <<< "${REPO}")
REPO_NAME=$(awk -F'/' '{print $6}' <<< "${REPO}")
FILE_NAME=$(awk -F'/' '{print $9}' <<< "${REPO}" | sed 's/\?.*//') # Remove params after '?'

# Get packages to replace
get_json_array PACKAGES 'try .["packages"][]' "${REPLACEMENT}"
REPLACE_STR="$(echo "${PACKAGES[*]}" | tr -d '\n')"

# Ensure packages are provided
if [[ ${#PACKAGES[@]} == 0 ]]; then
echo "Error: No packages were provided for repository '${REPO_NAME}'."
echo "Error: No packages were provided for repository '${REPO}'."
exit 1
fi

echo "Replacing packages from COPR repository: '${REPO_NAME}' owned by '${MAINTAINER}'"
echo "Replacing packages from repository: '${REPO}'"
echo "Replacing: ${REPLACE_STR}"

REPO_URL="${REPO//[$'\t\r\n ']}"

echo "Downloading repo file ${REPO_URL}"
curl -fLs --create-dirs -O "${REPO_URL}" --output-dir "/etc/yum.repos.d/"
echo "Downloaded repo file ${REPO_URL}"

rpm-ostree override replace --experimental --from "repo=copr:copr.fedorainfracloud.org:${MAINTAINER}:${REPO_NAME}" ${REPLACE_STR}
rm "/etc/yum.repos.d/${FILE_NAME}"
dnf -y "${WEAK_DEPS_FLAG}" distro-sync --refresh --repo "${REPO}" "${PACKEGES[@]}"

done
fi
fi
22 changes: 11 additions & 11 deletions recipes/module-recipes/dnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ modules:
- type: dnf
source: local
repos:
- copr: kylegospo/rom-properties
- copr: fiftydinar/gnome-randr-rust
- copr: elxreno/zsync
- copr: decathorpe/miniaturo
- copr: hyperreal/better_fonts
- copr: secureblue/hardened-chromium
- COPR kylegospo/rom-properties
- COPR fiftydinar/gnome-randr-rust
- COPR elxreno/zsync
- COPR decathorpe/miniaturo
- COPR hyperreal/better_fonts
- COPR secureblue/hardened-chromium
remove:
- tuned
- tuned-ppd
Expand Down Expand Up @@ -47,8 +47,8 @@ modules:
# Workaround needed dependency faad2 for dr14_t.meter package
- type: script
snippets:
- "rpm-ostree install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm"
- "rpm-ostree install faad2"
- "rpm-ostree uninstall rpmfusion-free-release"
- "curl -fLs --create-dirs -O https://copr.fedorainfracloud.org/coprs/sassam/dr14_tmeter/repo/fedora-$(rpm -E %fedora)/sassam-dr14_tmeter-fedora-$(rpm -E %fedora).repo --output-dir /etc/yum.repos.d/"
- "rpm-ostree install dr14_t.meter"
- "dnf -y install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm"
- "dnf -y install faad2"
- "dnf -y uninstall rpmfusion-free-release"
- "dnf -y copr enable sassam/dr14_tmeter"
- "dnf -y install dr14_t.meter"

0 comments on commit 380606e

Please sign in to comment.