mirror-ublue-os-akmods/build_files/zfs/dual-sign-zfs.sh
m2 00880e48db
refactor: implement local builds (#356)
* refactor: implement local builds

This has a long way to go. But at least want to get the branch published.

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* disable all workflows while iterating

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* cleanup fetch-kernel.sh

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* enable local builds

Still need to generate tags. Removal of most of the suffix Containerfiles.

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add tags, images.yaml

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* use anchors more!

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* start on workflows

No Testing and Pushing in yet.

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* update workflows

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* more workflow modifications

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* don't cache during PRs

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix base64 decode

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix path name

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* name file

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* quotes?

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try again.

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try again

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* quote the env?

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* tell base64 to read from stdin

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* update workflows

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try different way for getting json file

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix conditional

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try github.workspace

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* just hardcode it

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* typo

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* main doesn't have zfs....

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* One button build

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* remove common from centos builds

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* handle defaults

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix package naming?

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* don't have ./

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try using swap instead

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* path names

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* remove dnf remove

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* missing decleration

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try allow-erasing instead

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try reinstalling instead

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* Add testing via multistage build

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add missing args

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* correct test tag name

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix VARS_KERNEL_VERSION now that the package is no longer messed up

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* always have json point to cache location

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* use a reusable cache workflow

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* Names

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* put generate workflow in justfile

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add startpoint for multiarch

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* change the names

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* dynamic names for generating workflow

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* start appeasing the linter

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* fix kernel version detection

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* try again

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* filter for arch

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* move system76 to common

Appease the linter

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* permissions

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* more permissions

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* move system76 back

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add arch to tags

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add push/sign/manifest

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* silly names

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* remove secureboot just recipe, it's internal to fetch-kernel.sh

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add CI=1 to scripts for debug output

* update warning for workflow within justfile

* remove for now

* Update dual-sign-check.sh

* Update Containerfile.in

* Update dual-sign-check.sh

* Add cosign fix

* Fix signing in push as well

* fix: hardcode internel kcwd for fetch-kernel.sh

* pass CI into fetch kernel, use cache version instead of get version for fetch kernel step

* split out bazzite workflow

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* rename name of reusable build

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* additional adds to manifest

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* allow workflow dispatch for cache/akmods build

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* add comments to Justfile

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* split mega workflow by flavors

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* Build Badges and README

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* appease the linter

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

* tiny AKMODS_VERSION string update

* fix manifest recipe

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>

---------

Signed-off-by: m2 <69128853+m2Giles@users.noreply.github.com>
Co-authored-by: Benjamin Sherman <benjamin@holyarmy.org>
2025-07-07 20:09:34 -04:00

66 lines
3.1 KiB
Bash
Executable file

#!/usr/bin/bash
set "${CI:+-x}" -euo pipefail
if [[ "${DUAL_SIGN}" != "true" ]]; then
echo "Not Dual Signing..."
exit 0
fi
KERNEL="$(rpm -q "${KERNEL_NAME}" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
SIGNING_KEY_1="/tmp/certs/signing_key_1.pem"
SIGNING_KEY_2="/tmp/certs/signing_key_2.pem"
PUBLIC_CHAIN="/tmp/certs/public_key_chain.pem"
ln -s / /tmp/buildroot
dnf install -y /var/cache/rpms/kmods/zfs/*.rpm pv
modinfo /usr/lib/modules/"${KERNEL}"/extra/zfs/spl.ko
for module in /usr/lib/modules/"${KERNEL}"/extra/zfs/*.ko*; do
module_basename=${module:0:-3}
module_suffix=${module: -3}
if [[ "$module_suffix" == ".xz" ]]; then
xz --decompress "$module"
openssl cms -sign -signer "${SIGNING_KEY_1}" -signer "${SIGNING_KEY_2}" -binary -in "$module_basename" -outform DER -out "${module_basename}.cms" -nocerts -noattr -nosmimecap
/usr/src/kernels/"${KERNEL}"/scripts/sign-file -s "${module_basename}.cms" sha256 "${PUBLIC_CHAIN}" "${module_basename}"
/tmp/dual-sign-check.sh "${KERNEL}" "${module_basename}" "${PUBLIC_CHAIN}"
xz -C crc32 -f "${module_basename}"
elif [[ "$module_suffix" == ".gz" ]]; then
gzip -d "$module"
openssl cms -sign -signer "${SIGNING_KEY_1}" -signer "${SIGNING_KEY_2}" -binary -in "$module_basename" -outform DER -out "${module_basename}.cms" -nocerts -noattr -nosmimecap
/usr/src/kernels/"${KERNEL}"/scripts/sign-file -s "${module_basename}.cms" sha256 "${PUBLIC_CHAIN}" "${module_basename}"
/tmp/dual-sign-check.sh "${KERNEL}" "${module_basename}" "${PUBLIC_CHAIN}"
gzip -9f "${module_basename}"
else
openssl cms -sign -signer "${SIGNING_KEY_1}" -signer "${SIGNING_KEY_2}" -binary -in "$module" -outform DER -out "${module}.cms" -nocerts -noattr -nosmimecap
/usr/src/kernels/"${KERNEL}"/scripts/sign-file -s "${module}.cms" sha256 "${PUBLIC_CHAIN}" "${module}"
/tmp/dual-sign-check.sh "${KERNEL}" "${module}" "${PUBLIC_CHAIN}"
fi
done
find /var/cache/rpms/kmods/zfs -type f -name "\kmod-*.rpm" | grep -v debug | grep -v devel
RPMPATH=$(find /var/cache/rpms/kmods/zfs -type f -name "\kmod-*.rpm" | grep -v debug | grep -v devel)
RPM=$(basename "${RPMPATH/\.rpm/}")
rpmrebuild --additional=--buildroot=/tmp/buildroot --batch "${RPM}"
rm -rf /usr/lib/modules/"${KERNEL}"/extra
pushd /root/rpmbuild/RPMS/"$(uname -m)"/
mapfile -t RPMPATHS < <(find . -type f -name "\kmod-*.rpm")
for RPMPATH in "${RPMPATHS[@]}"; do
RPM=$(basename "${RPMPATH/\.rpm/}")
if [[ ! "$RPM" =~ ${KERNEL} ]]; then
RENAME=${RPM%"$(rpm -q --queryformat="%{VERSION}" kernel)"*}
RENAME+=$KERNEL
RENAME+=${RPM#*"$(rpm -E %dist)"}
RPM_RENAME="$(dirname "$RPMPATH")/$RENAME.rpm"
RPM_RENAME="$(dirname "$RPMPATH")/$RENAME.rpm"
mv "$RPMPATH" "$RPM_RENAME"
fi
done
# Reinstall KMODs for initial check that they were signed
mapfile -t kmods < <(ls -1 ./kmod-*.rpm)
dnf reinstall -y --allowerasing "${kmods[@]}"
popd
for module in /usr/lib/modules/"${KERNEL}"/extra/*/*.ko*; do
if ! modinfo "${module}"; then
exit 1
fi
done
mv -f /root/rpmbuild/RPMS/"$(uname -m)"/kmod-*.rpm /var/cache/rpms/kmods/zfs/