From 3b0ab1b90efa30612fb5c72e92c376343649ff26 Mon Sep 17 00:00:00 2001 From: Benjamin Sherman Date: Tue, 26 Mar 2024 23:42:42 -0500 Subject: [PATCH] refactor: combine asus and surface builds with nvidia This is a WIP commit which shows has the first steps of asus/surface main images mostly working in a Containerfile and skipping main/main. The nvidia parts will be built in a second target. Github workflows have not yet been touched. --- Containerfile | 51 +++++++++---- asus/packages.json | 14 ++++ install.sh | 89 ++++++++++++++++++----- main/.gitkeep | 0 nvidia/install.sh | 45 ++++++++++++ post-install.sh => nvidia/post-install.sh | 0 packages.sh | 53 ++++++++++++++ surface/packages.json | 12 +++ 8 files changed, 231 insertions(+), 33 deletions(-) create mode 100644 asus/packages.json create mode 100644 main/.gitkeep create mode 100755 nvidia/install.sh rename post-install.sh => nvidia/post-install.sh (100%) create mode 100755 packages.sh create mode 100644 surface/packages.json diff --git a/Containerfile b/Containerfile index c88b753..be4b83a 100644 --- a/Containerfile +++ b/Containerfile @@ -1,26 +1,51 @@ ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}" -ARG BASE_IMAGE="ghcr.io/ublue-os/${IMAGE_NAME}-main" +ARG SOURCE_IMAGE="${SOURCE_IMAGE:-silverblue-main}" +ARG SOURCE_ORG="${SOURCE_ORG:-ublue-os}" +ARG BASE_IMAGE="ghcr.io/${SOURCE_ORG}/${SOURCE_IMAGE}" ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" -FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS nvidia +FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS main +ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" +ARG HWE_FLAVOR="{HWE_FLAVOR:-main}" ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}" -ARG IMAGE_VENDOR="ublue-os" -ARG IMAGE_FLAVOR="${IMAGE_FLAVOR:-nvidia}" +ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}" +ARG RPMFUSION_MIRROR="" + +COPY *.sh /tmp/ +COPY ${HWE_FLAVOR}/ /tmp/ + +RUN mkdir -p /var/lib/alternatives && \ + IMAGE_FLAVOR=main /tmp/image-info.sh && \ + /tmp/install.sh && \ + mv /var/lib/alternatives /staged-alternatives && \ + rm -rf /tmp/* /var/* && \ + ostree container commit && \ + mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \ + mkdir -p /tmp /var/tmp && \ + chmod -R 1777 /tmp /var/tmp + +FROM main AS nvidia + ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" +ARG HWE_FLAVOR="{HWE_FLAVOR:-main}" +ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}" +ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}" ARG NVIDIA_MAJOR_VERSION="${NVIDIA_MAJOR_VERSION:-550}" ARG RPMFUSION_MIRROR="" -COPY image-info.sh /tmp/image-info.sh -COPY install.sh /tmp/install.sh -COPY post-install.sh /tmp/post-install.sh +COPY --from=ghcr.io/ublue-os/akmods-nvidia:${HWE_FLAVOR}-${FEDORA_MAJOR_VERSION}-${NVIDIA_MAJOR_VERSION} /rpms /tmp/akmods-rpms -COPY --from=ghcr.io/ublue-os/akmods-nvidia:main-${FEDORA_MAJOR_VERSION}-${NVIDIA_MAJOR_VERSION} /rpms /tmp/akmods-rpms +COPY image-info.sh /tmp/ +COPY nvidia/*.sh /tmp/ -RUN /tmp/image-info.sh && \ +RUN mkdir -p /var/lib/alternatives && \ + IMAGE_FLAVOR=nvidia /tmp/image-info.sh && \ /tmp/install.sh && \ /tmp/post-install.sh && \ - rm -rf /tmp/* /var/* - -RUN ostree container commit && \ - mkdir -p /var/tmp && chmod -R 1777 /tmp /var/tmp + mv /var/lib/alternatives /staged-alternatives && \ + rm -rf /tmp/* /var/* && \ + ostree container commit && \ + mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \ + mkdir -p /tmp /var/tmp && \ + chmod -R 1777 /tmp /var/tmp diff --git a/asus/packages.json b/asus/packages.json new file mode 100644 index 0000000..24d9703 --- /dev/null +++ b/asus/packages.json @@ -0,0 +1,14 @@ +{ + "all": { + "include": { + "all": [ + "asusctl", + "asusctl-rog-gui", + "fprintd" + ] + }, + "exclude": { + "all": [] + } + } +} diff --git a/install.sh b/install.sh index 9cb0f4c..bf7b73a 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,12 @@ -#!/bin/sh +#!/bin/bash set -ouex pipefail -if [[ "${FEDORA_MAJOR_VERSION}" -le 38 ]]; then - sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-{cisco-openh264,modular,updates-modular}.repo -else - sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-cisco-openh264.repo +RELEASE="$(rpm -E %fedora)" + +if [ "${HWE_FLAVOR}" = "main" ]; then + # HWE_FLAVOR is main, no need to do anything + exit 0 fi if [ -n "${RPMFUSION_MIRROR}" ]; then @@ -19,27 +20,75 @@ if [ -n "${RPMFUSION_MIRROR}" ]; then fi fi -rpm-ostree install \ - /tmp/akmods-rpms/ublue-os/ublue-os-nvidia-addons-*.rpm +# do HWE specific things +if [ "${HWE_FLAVOR}" = "asus" ]; then + echo "install.sh: steps for HWE_FLAVOR: ${HWE_FLAVOR}" + # Install Asus kernel + wget https://copr.fedorainfracloud.org/coprs/lukenukem/asus-linux/repo/fedora-${RELEASE}/lukenukem-asus-linux-fedora-${RELEASE}.repo -O /etc/yum.repos.d/_copr_lukenukem-asus-linux.repo + wget https://copr.fedorainfracloud.org/coprs/lukenukem/asus-kernel/repo/fedora-${RELEASE}/lukenukem-asus-kernel-fedora-${RELEASE}repo -O /etc/yum.repos.d/_copr_lukenukem-asus-kernel.repo + rpm-ostree cliwrap install-to-root / + rpm-ostree override replace \ + --experimental \ + --from repo=copr:copr.fedorainfracloud.org:lukenukem:asus-kernel \ + kernel \ + kernel-core \ + kernel-modules \ + kernel-modules-core \ + kernel-modules-extra + git clone https://gitlab.com/asus-linux/firmware.git --depth 1 /tmp/asus-firmware + cp -rf /tmp/asus-firmware/* /usr/lib/firmware/ + rm -rf /tmp/asus-firmware +elif [ "${HWE_FLAVOR}" = "surface" ]; then + echo "install.sh: steps for HWE_FLAVOR: ${HWE_FLAVOR}" + # Install Surface kernel + wget https://pkg.surfacelinux.com/fedora/linux-surface.repo -P /etc/yum.repos.d + wget https://github.com/linux-surface/linux-surface/releases/download/silverblue-20201215-1/kernel-20201215-1.x86_64.rpm -O /tmp/surface-kernel.rpm + rpm-ostree cliwrap install-to-root / + rpm-ostree override replace /tmp/surface-kernel.rpm \ + --remove kernel-core \ + --remove kernel-modules \ + --remove kernel-modules-extra \ + --remove libwacom \ + --remove libwacom-data \ + --install kernel-surface \ + --install iptsd \ + --install libwacom-surface \ + --install libwacom-surface-data +else + echo "install.sh: steps for unexpected HWE_FLAVOR: ${HWE_FLAVOR}" +fi -source /tmp/akmods-rpms/kmods/nvidia-vars.${NVIDIA_MAJOR_VERSION} +# copy any shared sys files +if [ -d "/tmp/system_files/shared" ]; then + rsync -rvK /tmp/system_files/shared/ / +fi -if [[ "${IMAGE_NAME}" == "kinoite" ]]; then - VARIANT_PKGS="supergfxctl-plasmoid supergfxctl" -elif [[ "${IMAGE_NAME}" == "silverblue" ]]; then - VARIANT_PKGS="gnome-shell-extension-supergfxctl-gex supergfxctl" -else - VARIANT_PKGS="" +# copy any flavor specific files, eg silverblue +if [ -d "/tmp/system_files/${IMAGE_NAME}" ]; then + rsync -rvK /tmp/system_files/"${IMAGE_NAME}"/ / fi -rpm-ostree install \ - xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-{,cuda-,devel-,kmodsrc-,power-}${NVIDIA_FULL_VERSION} \ - xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-libs.i686 \ - nvidia-container-toolkit nvidia-vaapi-driver ${VARIANT_PKGS} \ - /tmp/akmods-rpms/kmods/kmod-${NVIDIA_PACKAGE_NAME}-${KERNEL_VERSION}-${NVIDIA_AKMOD_VERSION}.fc${RELEASE}.rpm +# install any packages from packages.json +if [ -f "/tmp/packages.json" ]; then + /tmp/packages.sh /tmp/packages.json +fi + +# do HWE specific post-install things +if [ "${HWE_FLAVOR}" = "asus" ]; then + echo "install.sh: post-install for: ${HWE_FLAVOR}" +elif [ "${HWE_FLAVOR}" = "surface" ]; then + echo "install.sh: post-install for: ${HWE_FLAVOR}" + if grep -q "silverblue" <<< "${IMAGE_NAME}"; then + systemctl enable dconf-update + fi + systemctl enable fprintd + systemctl enable surface-hardware-setup +else + echo "install.sh: post-install for unexpected HWE_FLAVOR: ${HWE_FLAVOR}" +fi if [ -n "${RPMFUSION_MIRROR}" ]; then # reset forced use of single rpmfusion mirror echo "Revert from single rpmfusion mirror: ${RPMFUSION_MIRROR}" rename -v .repo.bak .repo /etc/yum.repos.d/rpmfusion-*repo.bak -fi +fi \ No newline at end of file diff --git a/main/.gitkeep b/main/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/nvidia/install.sh b/nvidia/install.sh new file mode 100755 index 0000000..9cb0f4c --- /dev/null +++ b/nvidia/install.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +set -ouex pipefail + +if [[ "${FEDORA_MAJOR_VERSION}" -le 38 ]]; then + sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-{cisco-openh264,modular,updates-modular}.repo +else + sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-cisco-openh264.repo +fi + +if [ -n "${RPMFUSION_MIRROR}" ]; then + # force use of single rpmfusion mirror + echo "Using single rpmfusion mirror: ${RPMFUSION_MIRROR}" + sed -i.bak "s%^metalink=%#metalink=%" /etc/yum.repos.d/rpmfusion-*.repo + sed -i "s%^#baseurl=http://download1.rpmfusion.org%baseurl=${RPMFUSION_MIRROR}%" /etc/yum.repos.d/rpmfusion-*.repo + # after F40 launches, bump to 41 + if [[ "${FEDORA_MAJOR_VERSION}" -ge 40 ]]; then + sed -i "s%free/fedora/releases%free/fedora/development%" /etc/yum.repos.d/rpmfusion-*.repo + fi +fi + +rpm-ostree install \ + /tmp/akmods-rpms/ublue-os/ublue-os-nvidia-addons-*.rpm + +source /tmp/akmods-rpms/kmods/nvidia-vars.${NVIDIA_MAJOR_VERSION} + +if [[ "${IMAGE_NAME}" == "kinoite" ]]; then + VARIANT_PKGS="supergfxctl-plasmoid supergfxctl" +elif [[ "${IMAGE_NAME}" == "silverblue" ]]; then + VARIANT_PKGS="gnome-shell-extension-supergfxctl-gex supergfxctl" +else + VARIANT_PKGS="" +fi + +rpm-ostree install \ + xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-{,cuda-,devel-,kmodsrc-,power-}${NVIDIA_FULL_VERSION} \ + xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-libs.i686 \ + nvidia-container-toolkit nvidia-vaapi-driver ${VARIANT_PKGS} \ + /tmp/akmods-rpms/kmods/kmod-${NVIDIA_PACKAGE_NAME}-${KERNEL_VERSION}-${NVIDIA_AKMOD_VERSION}.fc${RELEASE}.rpm + +if [ -n "${RPMFUSION_MIRROR}" ]; then + # reset forced use of single rpmfusion mirror + echo "Revert from single rpmfusion mirror: ${RPMFUSION_MIRROR}" + rename -v .repo.bak .repo /etc/yum.repos.d/rpmfusion-*repo.bak +fi diff --git a/post-install.sh b/nvidia/post-install.sh similarity index 100% rename from post-install.sh rename to nvidia/post-install.sh diff --git a/packages.sh b/packages.sh new file mode 100755 index 0000000..c75e27f --- /dev/null +++ b/packages.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -ouex pipefail + +RELEASE="$(rpm -E %fedora)" + +# build list of all packages requested for inclusion +INCLUDED_PACKAGES=($(jq -r "[(.all.include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ + (select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_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(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_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 + +# 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 | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \ + (select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_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 diff --git a/surface/packages.json b/surface/packages.json new file mode 100644 index 0000000..ba83fee --- /dev/null +++ b/surface/packages.json @@ -0,0 +1,12 @@ +{ + "all": { + "include": { + "all": [ + "fprintd" + ] + }, + "exclude": { + "all": [] + } + } +}