Blame SOURCES/shim.rpmmacros

1a3571
%global debug_package %{nil}
1a3571
%global __brp_mangle_shebangs_exclude_from_file %{expand:%{_builddir}/shim-%{efi_arch}-%{version}-%{release}.%{_target_cpu}-shebangs.txt}
1a3571
%global vendor_token_str %{expand:%%{nil}%%{?vendor_token_name:-t "%{vendor_token_name}"}}
1a3571
%global vendor_cert_str %{expand:%%{!?vendor_cert_nickname:-c "Red Hat Test Certificate"}%%{?vendor_cert_nickname:-c "%%{vendor_cert_nickname}"}}
1a3571
1a3571
%global bootcsvaa64 %{expand:%{SOURCE10}}
1a3571
%global bootcsvia32 %{expand:%{SOURCE11}}
1a3571
%global bootcsvx64 %{expand:%{SOURCE12}}
1a3571
#%%global bootcsvarm %%{expand:%%{SOURCE13}}
1a3571
1a3571
%global shimefiaa64 %{expand:%{SOURCE20}}
1a3571
%global shimefiia32 %{expand:%{SOURCE21}}
1a3571
%global shimefix64 %{expand:%{SOURCE22}}
1a3571
#%%global shimefiarm %%{expand:%%{SOURCE23}
1a3571
e2e98b
%global fbefiaa64 %{expand:%{SOURCE30}}
e2e98b
%global fbefiia32 %{expand:%{SOURCE31}}
e2e98b
%global fbefix64 %{expand:%{SOURCE32}}
e2e98b
#%%global fbefiarm %%{expand:%%{SOURCE33}
e2e98b
e2e98b
%global mmefiaa64 %{expand:%{SOURCE40}}
e2e98b
%global mmefiia32 %{expand:%{SOURCE41}}
e2e98b
%global mmefix64 %{expand:%{SOURCE42}}
e2e98b
#%%global mmefiarm %%{expand:%%{SOURCE43}
e2e98b
f48a18
%global shimveraa64 15-7.el8_1
e2e98b
%global shimveria32 15.5-1.el8
e2e98b
%global shimverx64 15.5-1.el8
1a3571
#%%global shimverarm 15-1.el8
1a3571
1a3571
%global shimdiraa64 %{_datadir}/shim/%{shimveraa64}/aa64
1a3571
%global shimdiria32 %{_datadir}/shim/%{shimveria32}/ia32
1a3571
%global shimdirx64 %{_datadir}/shim/%{shimverx64}/x64
1a3571
#%%global shimdirarm %%{_datadir}/shim/%%{shimverarm}/arm
1a3571
1a3571
%global unsignedaa64 shim-unsigned-aarch64
1a3571
%global unsignedia32 shim-unsigned-ia32
1a3571
%global unsignedx64 shim-unsigned-x64
1a3571
#%%global unsignedarm shim-unsigned-arm
1a3571
1a3571
%global bootcsv %{expand:%{bootcsv%{efi_arch}}}
1a3571
%global bootcsvalt %{expand:%{bootcsv%{?efi_alt_arch}}}
1a3571
%global shimefi %{expand:%{shimefi%{efi_arch}}}
1a3571
%global shimefialt %{expand:%{shimefi%{?efi_alt_arch}}}
1a3571
%global shimver %{expand:%{shimver%{efi_arch}}}
1a3571
%global shimveralt %{expand:%{shimver%{?efi_alt_arch}}}
1a3571
%global shimdir %{expand:%{shimdir%{efi_arch}}}
1a3571
%global shimdiralt %{expand:%{shimdir%{?efi_alt_arch}}}
e2e98b
%global fbefi %{expand:%{fbefi%{efi_arch}}}
e2e98b
%global fbefialt %{expand:%{fbefi%{?efi_alt_arch}}}
e2e98b
%global mmefi %{expand:%{mmefi%{efi_arch}}}
e2e98b
%global mmefialt %{expand:%{mmefi%{?efi_alt_arch}}}
1a3571
1a3571
%global unsignednone shim-unsigned-none
1a3571
%global unsigned %{expand:%%{unsigned%{efi_arch}}}
1a3571
%global unsignedalt %{expand:%%{unsigned%{efi_alt_arch}}}
1a3571
1a3571
%define define_pkg(a:p:)						\
1a3571
%{expand:%%package -n shim-%{-a*}}					\
1a3571
Summary: First-stage UEFI bootloader					\
1a3571
Requires: mokutil >= 1:0.3.0-1						\
1a3571
Requires: efi-filesystem						\
1a3571
Provides: shim-signed-%{-a*} = %{version}-%{release}			\
1a3571
Requires: dbxtool >= 0.6-3						\
1a3571
%{expand:%%if 0%%{-p*}							\
1a3571
Provides: shim = %{version}-%{release}					\
1a3571
Provides: shim-signed = %{version}-%{release}				\
1a3571
Obsoletes: shim-signed < %{version}-%{release}				\
1a3571
Obsoletes: shim < %{version}-%{release}					\
1a3571
%%endif}								\
1a3571
# Shim uses OpenSSL, but cannot use the system copy as the UEFI ABI	\
1a3571
# is not compatible with SysV (there's no red zone under UEFI) and	\
1a3571
# there isn't a POSIX-style C library.					\
1a3571
# BuildRequires: OpenSSL						\
1a3571
Provides: bundled(openssl) = 1.0.2j					\
1a3571
									\
1a3571
%{expand:%%description -n shim-%{-a*}}					\
1a3571
Initial UEFI bootloader that handles chaining to a trusted full		\
1a3571
bootloader under secure boot environments. This package contains the	\
1a3571
version signed by the UEFI signing service.				\
1a3571
%{nil}
1a3571
1a3571
# -a <efiarch>
1a3571
# -i <input>
e2e98b
%define hash(a:i:d:)								\
e2e98b
	if [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
e2e98b
		pesign -i %{-i*} -h -P > shim.hash				\
e2e98b
		read file0 hash0 < shim.hash					\
e2e98b
		read file1 hash1 < %{-d*}/shim%{-a*}.hash			\
e2e98b
		if ! [ "$hash0" = "$hash1" ] ; then				\
e2e98b
			echo Invalid signature\! > /dev/stderr			\
e2e98b
			echo $hash0 vs $hash1					\
e2e98b
			exit 1							\
e2e98b
		fi								\
e2e98b
	fi									\
1a3571
	%{nil}
1a3571
1a3571
# -i <input>
1a3571
# -o <output>
1a3571
%define sign(i:o:n:a:c:)									\
1a3571
	%{expand:%%pesign -s -i %{-i*} -o %{-o*} %{-n} %{-n*} %{-a} %{-a*} %{-c} %{-c*}}	\
1a3571
	%{nil}
1a3571
1a3571
# -b <binary prefix>
1a3571
# -a <efiarch>
1a3571
# -i <input>
e2e98b
%define distrosign(b:a:d:)							\
e2e98b
	if [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
e2e98b
		if [ "%{-b*}%{-a*}" = "shim%{efi_arch}" ] ; then		\
e2e98b
			cp -av "%{shimefi}" %{-b*}%{-a*}-unsigned.efi		\
e2e98b
		elif [ "%{-b*}%{-a*}" = "shim%{efi_alt_arch}" ] ; then		\
e2e98b
			cp -av "%{shimefialt}" %{-b*}%{-a*}-unsigned.efi	\
e2e98b
		elif [ "%{-b*}%{-a*}" = "mm%{efi_arch}" ] ; then		\
e2e98b
			cp -av "%{mmefi}" %{-b*}%{-a*}-unsigned.efi		\
e2e98b
		elif [ "%{-b*}%{-a*}" = "mm%{efi_alt_arch}" ] ; then		\
e2e98b
			cp -av "%{mmefialt}" %{-b*}%{-a*}-unsigned.efi		\
e2e98b
		elif [ "%{-b*}%{-a*}" = "fb%{efi_arch}" ] ; then		\
e2e98b
			cp -av "%{fbefi}" %{-b*}%{-a*}-unsigned.efi		\
e2e98b
		elif [ "%{-b*}%{-a*}" = "fb%{efi_alt_arch}" ] ; then		\
e2e98b
			cp -av "%{fbefialt}" %{-b*}%{-a*}-unsigned.efi		\
e2e98b
		fi								\
e2e98b
	else									\
e2e98b
		cp -av %{-d*}/%{-b*}%{-a*}.efi %{-b*}%{-a*}-unsigned.efi	\
e2e98b
	fi									\
e2e98b
	%{expand:%%sign -i %{-b*}%{-a*}-unsigned.efi -o %{-b*}%{-a*}-signed.efi -n redhatsecureboot501 -a %{SOURCE2} -c %{SOURCE1} } \
1a3571
	%{nil}
1a3571
1a3571
# -a <efiarch>
1a3571
# -A <EFIARCH>
1a3571
# -b <1|0> # signed by this builder?
1a3571
# -c <1|0> # signed by UEFI CA?
1a3571
# -i <shimARCH.efi>
e2e98b
# -d /usr/share dir for this build (full path)
1a3571
%define define_build(a:A:b:c:i:d:)					\
1a3571
if [ "%{-c*}" = "yes-temporarily-disabled-20180723" ]; then		\
1a3571
	%{expand:%%hash -i %{-i*} -a %{-a*} -d %{-d*}}			\
1a3571
fi									\
1a3571
cp %{-i*} shim%{-a*}.efi						\
e2e98b
if [ "%{-b*}" = "yes" ] ; then						\
1a3571
	%{expand:%%distrosign -b shim -a %{-a*} -d %{-d*}}		\
1a3571
	mv shim%{-a*}-signed.efi shim%{-a*}-%{efi_vendor}.efi		\
1a3571
fi									\
e2e98b
if [ "%{-c*}" = "no" ] ||						\
e2e98b
   [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
1a3571
	cp shim%{-a*}-%{efi_vendor}.efi shim%{-a*}.efi			\
1a3571
fi									\
1a3571
%{expand:%%distrosign -b mm -a %{-a*} -d %{-d*}}			\
1a3571
mv mm%{-a*}-signed.efi mm%{-a*}.efi					\
1a3571
%{expand:%%distrosign -b fb -a %{-a*} -d %{-d*}}			\
1a3571
mv fb%{-a*}-signed.efi fb%{-a*}.efi					\
1a3571
rm -vf									\\\
1a3571
	mm%{-a*}-unsigned.efi						\\\
1a3571
	fb%{-a*}-unsigned.efi						\\\
1a3571
	shim%{-a*}-unsigned.efi						\
1a3571
%{nil}
1a3571
1a3571
# -a <efiarch>
1a3571
# -A <EFIARCH>
1a3571
# -b <BOOTCSV>
1a3571
%define do_install(a:A:b:)						\
1a3571
install -m 0700 shim%{-a*}.efi						\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_dir}/shim%{-a*}.efi			\
1a3571
install -m 0700 shim%{-a*}-%{efi_vendor}.efi				\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_dir}/shim%{-a*}-%{efi_vendor}.efi	\
1a3571
install -m 0700 mm%{-a*}.efi						\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_dir}/mm%{-a*}.efi			\
1a3571
install -m 0700 %{-b*}							\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_dir}/BOOT%{-A*}.CSV			\
1a3571
install -m 0700 shim%{-a*}.efi						\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_boot}/BOOT%{-A*}.EFI			\
1a3571
install -m 0700 fb%{-a*}.efi						\\\
1a3571
	$RPM_BUILD_ROOT%{efi_esp_boot}/fb%{-a*}.efi			\
1a3571
%nil
1a3571
1a3571
# -a <efiarch>
1a3571
# -A <EFIARCH>
1a3571
%define define_files(a:A:)						\
1a3571
%{expand:%%files -n shim-%{-a*}}					\
1a3571
%{efi_esp_dir}/*%{-a*}*.efi						\
1a3571
%{efi_esp_dir}/BOOT%{-A*}.CSV						\
1a3571
%{efi_esp_boot}/*%{-a*}.efi						\
1a3571
%{efi_esp_boot}/*%{-A*}.EFI						\
1a3571
%{nil}
1a3571
1a3571
%ifarch x86_64
1a3571
%global is_signed yes
1a3571
%global is_alt_signed yes
1a3571
%global provide_legacy_shim 1
1a3571
%endif
1a3571
%ifarch aarch64
1a3571
%global is_signed no
1a3571
%global is_alt_signed no
1a3571
%global provide_legacy_shim 1
1a3571
%endif
1a3571
%ifnarch x86_64 aarch64
1a3571
%global is_signed no
1a3571
%global is_alt_signed no
1a3571
%global provide_legacy_shim 0
1a3571
%endif
1a3571
1a3571
%if ! 0%{?vendor:1}
1a3571
%global vendor nopenopenope
1a3571
%endif
1a3571
1a3571
# vim:filetype=rpmmacros