diff --git a/hci/build.sh b/hci/build.sh index b8c10e3..26feb68 100755 --- a/hci/build.sh +++ b/hci/build.sh @@ -4,25 +4,34 @@ set -ouex pipefail RELEASE="$(rpm -E %fedora)" +## install packages.json stuffs +# build list of all packages requested for inclusion INCLUDED_PACKAGES=($(jq -r "[(.all.include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ | sort | unique[]" /tmp/packages.json)) + +# build list of all packages requested for exclusion EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ | sort | unique[]" /tmp/packages.json)) + +# ensure exclusion list only contains packages already present on image if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) fi +# ensure exclusion list only contains packages already present on image +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) +fi + +# simple case to install where no packages need excluding if [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then rpm-ostree install \ ${INCLUDED_PACKAGES[@]} -elif [[ "${#INCLUDED_PACKAGES[@]}" -eq 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then - rpm-ostree override remove \ - ${EXCLUDED_PACKAGES[@]} - +# install/excluded packages both at same time elif [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then rpm-ostree override remove \ ${EXCLUDED_PACKAGES[@]} \ @@ -33,6 +42,22 @@ else fi +# check if any excluded packages are still present +# (this can happen if an included package pulls in a dependency) +EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ + (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ + | sort | unique[]" /tmp/packages.json)) + +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) +fi + +# remove any excluded packages which are still present on image +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + rpm-ostree override remove \ + ${EXCLUDED_PACKAGES[@]} +fi + ## install packages direct from github /tmp/github-release-install.sh trapexit/mergerfs fc.x86_64 diff --git a/main/build.sh b/main/build.sh index 48a43b0..acd60c8 100755 --- a/main/build.sh +++ b/main/build.sh @@ -42,25 +42,33 @@ if [[ "-zfs" == "${ZFS_TAG}" ]]; then fi ## install packages.json stuffs +# build list of all packages requested for inclusion INCLUDED_PACKAGES=($(jq -r "[(.all.include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ | sort | unique[]" /tmp/packages.json)) + +# build list of all packages requested for exclusion EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ | sort | unique[]" /tmp/packages.json)) + +# ensure exclusion list only contains packages already present on image if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) fi +# ensure exclusion list only contains packages already present on image +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) +fi + +# simple case to install where no packages need excluding if [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then rpm-ostree install \ ${INCLUDED_PACKAGES[@]} -elif [[ "${#INCLUDED_PACKAGES[@]}" -eq 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then - rpm-ostree override remove \ - ${EXCLUDED_PACKAGES[@]} - +# install/excluded packages both at same time elif [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then rpm-ostree override remove \ ${EXCLUDED_PACKAGES[@]} \ @@ -70,3 +78,19 @@ else echo "No packages to install." fi + +# check if any excluded packages are still present +# (this can happen if an included package pulls in a dependency) +EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ + (select(.\"$COREOS_VERSION\" != null).\"$COREOS_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \ + | sort | unique[]" /tmp/packages.json)) + +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) +fi + +# remove any excluded packages which are still present on image +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + rpm-ostree override remove \ + ${EXCLUDED_PACKAGES[@]} +fi