2024-04-06 15:20:55 -08:00
|
|
|
#!/usr/bin/bash
|
2023-03-08 10:18:57 -09:00
|
|
|
|
|
|
|
|
set -ouex pipefail
|
|
|
|
|
|
2023-09-27 11:35:14 -08:00
|
|
|
# build list of all packages requested for inclusion
|
2024-04-06 15:20:55 -08:00
|
|
|
INCLUDED_PACKAGES=($(jq -r "[(.all.include | (select(.all != null).all)[]), \
|
|
|
|
|
(.all.include | (select(.\"$BASE_IMAGE_NAME\" != null).\"$BASE_IMAGE_NAME\")[]), \
|
|
|
|
|
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".include | (select(.all != null).all)[]), \
|
|
|
|
|
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".include | (select(.\"$BASE_IMAGE_NAME\" != null).\"$BASE_IMAGE_NAME\")[])] \
|
|
|
|
|
| sort | unique[]" /tmp/packages.json))
|
2023-09-27 11:35:14 -08:00
|
|
|
|
|
|
|
|
# build list of all packages requested for exclusion
|
2024-04-06 15:20:55 -08:00
|
|
|
EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (select(.all != null).all)[]), \
|
|
|
|
|
(.all.exclude | (select(.\"$BASE_IMAGE_NAME\" != null).\"$BASE_IMAGE_NAME\")[]), \
|
|
|
|
|
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (select(.all != null).all)[]), \
|
|
|
|
|
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (select(.\"$BASE_IMAGE_NAME\" != null).\"$BASE_IMAGE_NAME\")[])] \
|
|
|
|
|
| sort | unique[]" /tmp/packages.json))
|
2023-03-08 10:18:57 -09:00
|
|
|
|
2024-09-29 09:34:16 -08:00
|
|
|
# store a list of RPMs installed on the image
|
|
|
|
|
INSTALLED_EXCLUDED_PACKAGES=()
|
|
|
|
|
|
2023-09-27 11:35:14 -08:00
|
|
|
# ensure exclusion list only contains packages already present on image
|
|
|
|
|
if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
|
2024-09-29 09:34:16 -08:00
|
|
|
INSTALLED_EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]}))
|
2023-09-27 11:35:14 -08:00
|
|
|
fi
|
2023-03-08 10:18:57 -09:00
|
|
|
|
2023-09-27 11:35:14 -08:00
|
|
|
# simple case to install where no packages need excluding
|
2024-09-29 09:34:16 -08:00
|
|
|
if [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#INSTALLED_EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then
|
2023-03-08 10:18:57 -09:00
|
|
|
rpm-ostree install \
|
|
|
|
|
${INCLUDED_PACKAGES[@]}
|
2023-09-27 11:35:14 -08:00
|
|
|
|
|
|
|
|
# install/excluded packages both at same time
|
2024-09-29 09:34:16 -08:00
|
|
|
elif [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#INSTALLED_EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
|
2023-09-27 11:35:14 -08:00
|
|
|
rpm-ostree override remove \
|
2024-09-29 09:34:16 -08:00
|
|
|
${INSTALLED_EXCLUDED_PACKAGES[@]} \
|
2023-09-27 11:35:14 -08:00
|
|
|
$(printf -- "--install=%s " ${INCLUDED_PACKAGES[@]})
|
2023-03-08 10:18:57 -09:00
|
|
|
else
|
|
|
|
|
echo "No packages to install."
|
2023-09-24 21:08:24 -08:00
|
|
|
fi
|
2023-03-08 10:18:57 -09:00
|
|
|
|
2023-09-27 11:35:14 -08:00
|
|
|
# check if any excluded packages are still present
|
|
|
|
|
# (this can happen if an included package pulls in a dependency)
|
2023-09-24 21:08:24 -08:00
|
|
|
if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
|
2024-09-29 09:34:16 -08:00
|
|
|
INSTALLED_EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]}))
|
2023-09-24 21:08:24 -08:00
|
|
|
fi
|
2023-09-27 11:35:14 -08:00
|
|
|
|
2024-03-29 12:09:52 -08:00
|
|
|
# remove any excluded packages which are still present on image
|
2024-09-29 09:34:16 -08:00
|
|
|
if [[ "${#INSTALLED_EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
|
2023-09-24 21:08:24 -08:00
|
|
|
rpm-ostree override remove \
|
2024-09-29 09:34:16 -08:00
|
|
|
${INSTALLED_EXCLUDED_PACKAGES[@]}
|
2023-03-08 10:18:57 -09:00
|
|
|
fi
|