diff --git a/generate-rpm-note.sh b/generate-rpm-note.sh index e3d0bdb..b80b6ca 100644 --- a/generate-rpm-note.sh +++ b/generate-rpm-note.sh @@ -1,5 +1,7 @@ #!/bin/bash +readonly=1 + pad_string() { for _ in $(seq "$1"); do printf ' BYTE(0x00)' @@ -28,9 +30,10 @@ write_string() { write_script() { value_len=$(( (${#1} + 3) / 4 * 4 )) + [ -n "$readonly" ] && readonly_attr='(READONLY) ' printf 'SECTIONS\n{\n' - printf ' .note.package (READONLY) : ALIGN(4) {\n' + printf ' .note.package %s: ALIGN(4) {\n' "$readonly_attr" printf ' BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */\n' printf ' BYTE(0x%02x) BYTE(0x%02x) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */\n' \ $((value_len % 256)) $((value_len / 256)) @@ -44,6 +47,11 @@ write_script() { printf 'INSERT AFTER .note.gnu.build-id;\n' } +if [ "$1" == "--readonly=no" ]; then + shift + readonly= +fi + cpe="$(cat /usr/lib/system-release-cpe)" json="$(printf '{"type":"rpm","name":"%s","version":"%s","architecture":"%s","osCpe":"%s"}' "$1" "$2" "$3" "$cpe")" write_script "$json" diff --git a/macros.package-notes-srpm b/macros.package-notes-srpm index 20d9d6f..d44e659 100644 --- a/macros.package-notes-srpm +++ b/macros.package-notes-srpm @@ -2,7 +2,8 @@ # See https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects # for details. %_package_note_file %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.package_note-%{name}-%{version}-%{release}.%{_arch}.ld +%_package_note_readonly 1 %_package_note_flags %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"-Wl,-dT,%{_package_note_file}"]}} -%_generate_package_note_file %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"if [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh ${RPM_PACKAGE_NAME:?} ${RPM_PACKAGE_VERSION:?}-${RPM_PACKAGE_RELEASE:?} ${RPM_ARCH:?} >%{_package_note_file}; fi"]}} +%_generate_package_note_file %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"if [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh %{!?_package_note_readonly:--readonly=no} ${RPM_PACKAGE_NAME:?} ${RPM_PACKAGE_VERSION:?}-${RPM_PACKAGE_RELEASE:?} ${RPM_ARCH:?} >%{_package_note_file}; fi"]}}