Skip to content

Commit

Permalink
Fixed custom rpm-ostree module logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkrai committed Jan 11, 2025
1 parent e708f0e commit bd7b7fa
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions modules/rpm-ostree/rpm-ostree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ if [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
done
fi

# store a list of RPMs installed on the image
INSTALLED_REMOVE_PACKAGES=()

# ensure removal list only contains packages already present on image
if [[ "${#REMOVE_PKGS[@]}" -gt 0 ]]; then
REMOVE_PKGS=($(rpm -qa --queryformat='%{NAME} ' ${REMOVE_PKGS[@]}))
INSTALLED_REMOVE_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${REMOVE_PKGS[@]}))
fi

echo_rpm_install() {
Expand All @@ -110,32 +113,32 @@ echo_rpm_install() {
fi
}

if [[ ${#INSTALL_PKGS[@]} -gt 0 && ${#REMOVE_PKGS[@]} -gt 0 ]]; then
if [[ ${#INSTALL_PKGS[@]} -gt 0 && ${#INSTALLED_REMOVE_PACKAGES[@]} -gt 0 ]]; then
echo "Installing & Removing RPMs"
echo_rpm_install
echo "Removing: ${REMOVE_PKGS[*]}"
echo "Removing: ${INSTALLED_REMOVE_PACKAGES[*]}"
# 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[@]}")
rpm-ostree override remove "${INSTALLED_REMOVE_PACKAGES[@]}" $(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 override remove "${INSTALLED_REMOVE_PACKAGES[@]}" $(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 override remove "${INSTALLED_REMOVE_PACKAGES[@]}" $(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 override remove "${INSTALLED_REMOVE_PACKAGES[@]}" $(printf -- "--install=%s " "${CLASSIC_PKGS[@]}")
rpm-ostree install "${HTTPS_PKGS[@]}" "${LOCAL_PKGS[@]}"
fi
elif [[ ${#INSTALL_PKGS[@]} -gt 0 ]]; then
echo "Installing RPMs"
echo_rpm_install
rpm-ostree install "${INSTALL_PKGS[@]}"
elif [[ ${#REMOVE_PKGS[@]} -gt 0 ]]; then
elif [[ ${#INSTALLED_REMOVE_PACKAGES[@]} -gt 0 ]]; then
echo "Removing RPMs"
echo "Removing: ${REMOVE_PKGS[*]}"
rpm-ostree override remove "${REMOVE_PKGS[@]}"
echo "Removing: ${INSTALLED_REMOVE_PACKAGES[*]}"
rpm-ostree override remove "${INSTALLED_REMOVE_PACKAGES[@]}"
fi

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

0 comments on commit bd7b7fa

Please sign in to comment.