diff --git a/Containerfile b/Containerfile index 322ae161..ab819706 100644 --- a/Containerfile +++ b/Containerfile @@ -5,31 +5,12 @@ FROM ghcr.io/ublue-os/${SOURCE_IMAGE}-${SOURCE_SUFFIX}:${FEDORA_VERSION} # User files COPY usr /usr +COPY packages.json /tmp/packages.json +COPY build.sh /tmp/build.sh +RUN chmod +x /tmp/build.sh -# install and remove a package -RUN rpm-ostree install \ - virt-manager \ - qemu-kvm \ - libvirt \ - mesa-vulkan-drivers \ - vulkan-loader \ - pipewire-alsa \ - pipewire-libs \ - steam \ - systemd-libs \ - gnome-shell-extension-pop-shell \ - langpacks-en - -RUN rpm-ostree override remove \ - firefox \ - firefox-langpacks \ - gnome-classic-session \ - gnome-shell-extension-launch-new-instance \ - gnome-shell-extension-places-menu \ - gnome-shell-extension-window-list \ - gnome-shell-extension-background-logo \ - gnome-shell-extension-apps-menu \ - toolbox +# Handle packages via packages.json +RUN /tmp/build.sh # Flatpaks RUN mkdir -p /usr/etc/flatpak/remotes.d && \ @@ -49,4 +30,4 @@ RUN rm -f /etc/yum.repos.d/_copr:copr.fedorainfracloud.org:phracek:PyCharm.repo echo "Hidden=true" >> /usr/share/applications/nvtop.desktop && \ ostree container commit && \ mkdir -p /var/tmp && \ - chmod -R 1777 /var/tmp + chmod -R 1777 /var/tmp \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..d1ac32fd --- /dev/null +++ b/build.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -ouex pipefail + +RELEASE="$(rpm -E %fedora)" +PACKAGE_LIST="up" +FEDORA_MAJOR_VERSION=$RELEASE + +# build list of all packages requested for inclusion +INCLUDED_PACKAGES=($(jq -r "[(.all.include | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[]), \ + (select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".include | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[])] \ + | sort | unique[]" /tmp/packages.json)) + +# build list of all packages requested for exclusion +EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[]), \ + (select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[])] \ + | 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 + +# simple case to install where no packages need excluding +if [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then + rpm-ostree install \ + ${INCLUDED_PACKAGES[@]} + +# install/excluded packages both at same time +elif [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + rpm-ostree override remove \ + ${EXCLUDED_PACKAGES[@]} \ + $(printf -- "--install=%s " ${INCLUDED_PACKAGES[@]}) + +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 | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[]), \ + (select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (select(.\"$PACKAGE_LIST\" != null).\"$PACKAGE_LIST\")[])] \ + | sort | unique[]" /tmp/packages.json)) + +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]})) +fi + +# remove any exluded packages which are still present on image +if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then + rpm-ostree override remove \ + ${EXCLUDED_PACKAGES[@]} +fi \ No newline at end of file diff --git a/packages.json b/packages.json new file mode 100644 index 00000000..d5ab4b3e --- /dev/null +++ b/packages.json @@ -0,0 +1,32 @@ +{ + "all": { + "include": { + "up": [ + "virt-manager", + "qemu-kvm", + "libvirt", + "mesa-vulkan-drivers", + "steam", + "pipewire-alsa", + "pipewire-libs", + "vulkan-loader", + "systemd-libs", + "gnome-shell-extension-pop-shell", + "langpacks-en" + ] + }, + "exclude": { + "up": [ + "firefox", + "firefox-langpacks", + "gnome-classic-session", + "gnome-shell-extension-launch-new-instance", + "gnome-shell-extension-places-menu", + "gnome-shell-extension-window-list", + "gnome-shell-extension-background-logo", + "gnome-shell-extension-apps-menu", + "toolbox" + ] + } + } +} \ No newline at end of file