From b2c0452a234a357f9377619e6b0290322aaa4375 Mon Sep 17 00:00:00 2001
From: Kyle Gospodnetich <me@kylegospodneti.ch>
Date: Mon, 17 Jul 2023 10:01:20 -0700
Subject: [PATCH] feat: Add new ublue-os/akmod copr repo fix: Restore steamdeck
 and gcadapter_oc akmods

---
 Containerfile               |  5 +++++
 README.md                   |  2 ++
 build-kmod-gcadapter_oc.sh  | 17 +++++++++++++++++
 build-kmod-steamdeck.sh     | 17 +++++++++++++++++
 ublue-os-akmods-addons.spec | 14 +++++++++++---
 5 files changed, 52 insertions(+), 3 deletions(-)
 create mode 100755 build-kmod-gcadapter_oc.sh
 create mode 100755 build-kmod-steamdeck.sh

diff --git a/Containerfile b/Containerfile
index 546c0a3a..e10d97b6 100644
--- a/Containerfile
+++ b/Containerfile
@@ -9,6 +9,9 @@ COPY build*.sh /tmp
 COPY certs /tmp/certs
 COPY ublue-os-akmods-addons.spec /tmp/ublue-os-akmods-addons/ublue-os-akmods-addons.spec
 
+ADD https://copr.fedorainfracloud.org/coprs/ublue-os/akmods/repo/fedora-${FEDORA_MAJOR_VERSION}/ublue-os-akmods-fedora-${FEDORA_MAJOR_VERSION}.repo \
+    /tmp/ublue-os-akmods-addons/rpmbuild/SOURCES/_copr_ublue-os-akmods.repo
+
 ADD https://negativo17.org/repos/fedora-steam.repo \
     /tmp/ublue-os-akmods-addons/rpmbuild/SOURCES/negativo17-fedora-steam.repo
 
@@ -18,6 +21,8 @@ RUN /tmp/build-ublue-os-akmods-addons.sh
 
 RUN /tmp/build-kmod-v4l2loopback.sh
 RUN /tmp/build-kmod-xpadneo.sh
+RUN /tmp/build-kmod-steamdeck.sh
+RUN /tmp/build-kmod-gcadapter_oc.sh
 
 RUN mkdir -p /var/cache/rpms/{kmods,ublue-os}
 RUN cp /tmp/ublue-os-akmods-addons/rpmbuild/RPMS/noarch/ublue-os-akmods-addons*.rpm \
diff --git a/README.md b/README.md
index 59c4f38e..41bd13e2 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,8 @@ The rpmfusion and extra repos provide dependencies which are required by the kmo
 Feel free to PR more kmod build scripts into this repo!
 
 - ublue-os-akmods-addons - installs extra repos and our kmods signing key; install and import to allow SecureBoot systems to use these kmods
+- [gcadapter_oc](https://github.com/hannesmann/gcadapter-oc-kmod) - kernel module for overclocking the Nintendo Wii U/Mayflash GameCube adapter (akmod from [copr](https://copr.fedorainfracloud.org/coprs/ublue-os/akmods/))
+- [steamdeck](https://lkml.org/lkml/2022/2/5/391) - platform driver for Valve's Steam Deck handheld PC (akmod from [copr](https://copr.fedorainfracloud.org/coprs/ublue-os/akmods/))
 - [v4l2loopback](https://github.com/umlaeute/v4l2loopback) - allows creating "virtual video devices"
 - [xpadneo](https://github.com/atar-axis/xpadneo) - xbox one controller bluetooth driver (akmod from [negativo17 steam repo](https://negativo17.org/steam/)
 
diff --git a/build-kmod-gcadapter_oc.sh b/build-kmod-gcadapter_oc.sh
new file mode 100755
index 00000000..87dcf4de
--- /dev/null
+++ b/build-kmod-gcadapter_oc.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -oeux pipefail
+
+ARCH="$(rpm -E '%_arch')"
+KERNEL="$(rpm -q kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
+RELEASE="$(rpm -E '%fedora')"
+
+wget https://copr.fedorainfracloud.org/coprs/ublue-os/akmods/repo/fedora-${RELEASE}/ublue-os-akmods-fedora-${RELEASE}.repo -O /etc/yum.repos.d/_copr_ublue-os-akmods.repo
+
+rpm-ostree install \
+    akmod-gcadapter_oc-*.fc${RELEASE}.${ARCH}
+akmods --force --kernels "${KERNEL}" --kmod gcadapter_oc
+modinfo /usr/lib/modules/${KERNEL}/extra/gcadapter_oc/gcadapter_oc.ko.xz > /dev/null \
+|| (find /var/cache/akmods/gcadapter_oc/ -name \*.log -print -exec cat {} \; && exit 1)
+
+rm -f /etc/yum.repos.d/_copr_ublue-os-akmods.repo
diff --git a/build-kmod-steamdeck.sh b/build-kmod-steamdeck.sh
new file mode 100755
index 00000000..8b709cf6
--- /dev/null
+++ b/build-kmod-steamdeck.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -oeux pipefail
+
+ARCH="$(rpm -E '%_arch')"
+KERNEL="$(rpm -q kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
+RELEASE="$(rpm -E '%fedora')"
+
+wget https://copr.fedorainfracloud.org/coprs/ublue-os/akmods/repo/fedora-${RELEASE}/ublue-os-akmods-fedora-${RELEASE}.repo -O /etc/yum.repos.d/_copr_ublue-os-akmods.repo
+
+rpm-ostree install \
+    akmod-steamdeck-*.fc${RELEASE}.${ARCH}
+akmods --force --kernels "${KERNEL}" --kmod steamdeck
+modinfo /usr/lib/modules/${KERNEL}/extra/steamdeck/steamdeck.ko.xz > /dev/null \
+|| (find /var/cache/akmods/steamdeck/ -name \*.log -print -exec cat {} \; && exit 1)
+
+rm -f /etc/yum.repos.d/_copr_ublue-os-akmods.repo
diff --git a/ublue-os-akmods-addons.spec b/ublue-os-akmods-addons.spec
index d4e7ef47..d057877a 100644
--- a/ublue-os-akmods-addons.spec
+++ b/ublue-os-akmods-addons.spec
@@ -1,5 +1,5 @@
 Name:           ublue-os-akmods-addons
-Version:        0.2
+Version:        0.3
 Release:        1%{?dist}
 Summary:        Signing key and repos for ublue os akmods
 
@@ -10,7 +10,8 @@ BuildArch:      noarch
 Supplements:    mokutil policycoreutils
 
 Source0:        public_key.der
-Source1:        negativo17-fedora-steam.repo
+Source1:        _copr_ublue-os-akmods.repo
+Source2:        negativo17-fedora-steam.repo
 
 %description
 Adds the signing key for importing with mokutil to enable secure boot for kernel modules and repo files required to install akmod dependencies.
@@ -22,20 +23,27 @@ Adds the signing key for importing with mokutil to enable secure boot for kernel
 %build
 # Have different name for *.der in case kmodgenca is needed for creating more keys
 install -Dm0644 %{SOURCE0} %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/pki/akmods/certs/akmods-ublue.der
-install -Dm0644 %{SOURCE1} %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
+install -Dm0644 %{SOURCE1} %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/_copr_ublue-os-akmods.repo
+install -Dm0644 %{SOURCE2} %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
 
 sed -i 's@enabled=1@enabled=0@g' %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
 
 install -Dm0644 %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/pki/akmods/certs/akmods-ublue.der            %{buildroot}%{_sysconfdir}/pki/akmods/certs/akmods-ublue.der
+install -Dm0644 %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/_copr_ublue-os-akmods.repo    %{buildroot}%{_sysconfdir}/yum.repos.d/_copr_ublue-os-akmods.repo
 install -Dm0644 %{buildroot}%{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo     %{buildroot}%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
 
 %files
 %attr(0644,root,root) %{_datadir}/ublue-os/%{_sysconfdir}/pki/akmods/certs/akmods-ublue.der
+%attr(0644,root,root) %{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/_copr_ublue-os-akmods.repo
 %attr(0644,root,root) %{_datadir}/ublue-os/%{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
 %attr(0644,root,root) %{_sysconfdir}/pki/akmods/certs/akmods-ublue.der
+%attr(0644,root,root) %{_sysconfdir}/yum.repos.d/_copr_ublue-os-akmods.repo
 %attr(0644,root,root) %{_sysconfdir}/yum.repos.d/negativo17-fedora-steam.repo
 
 %changelog
+* Mon Jul 17 2023 Kyle Gospodnetich <me@kylegospodneti.ch> - 0.3
+- Add ublue-os/akmods copr repo for modules not available upstream/elsewhere
+
 * Tue May 30 2023 Benjamin Sherman <benjamin@holyarmy.org> - 0.2
 - Add negativo17 fedora-steam repo to enable xbox controllers