58ec8a67f5
Sync with https://github.com/systemd/package-notes/pull/31 On big endian machines we need to swap the first three fields, which are binary and thus need to match endianess. Just use LONG() instead of BYTE sequences.
67 lines
1.7 KiB
Bash
Executable File
67 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
readonly=1
|
|
insert_after=1
|
|
|
|
pad_string() {
|
|
for _ in $(seq "$1"); do
|
|
printf ' BYTE(0x00)'
|
|
done
|
|
}
|
|
|
|
write_string() {
|
|
text="$1"
|
|
prefix="$2"
|
|
label="$3"
|
|
total="$4"
|
|
|
|
printf "%s/* %s: '%s' */" "$prefix" "$label" "$text"
|
|
for i in $(seq ${#text}); do
|
|
if (( i % 4 == 1 )); then
|
|
printf '\n%s' "$prefix"
|
|
else
|
|
printf ' '
|
|
fi
|
|
printf 'BYTE(0x%02x)' "'${text:i-1:1}"
|
|
done
|
|
|
|
pad_string $(( total - ${#text} ))
|
|
printf '\n'
|
|
}
|
|
|
|
write_script() {
|
|
value_len=$(( (${#1} + 3) / 4 * 4 ))
|
|
[ -n "$readonly" ] && readonly_attr='(READONLY) '
|
|
|
|
printf 'SECTIONS\n{\n'
|
|
printf ' .note.package %s: ALIGN(4) {\n' "$readonly_attr"
|
|
# Note that for the binary fields we use the native 4 bytes type, to avoid
|
|
# endianness issues.
|
|
printf ' LONG(0x0004) /* Length of Owner including NUL */\n'
|
|
printf ' LONG(0x%04x) /* Length of Value including NUL */\n' \
|
|
${value_len}
|
|
printf ' LONG(0xcafe1a7e) /* Note ID */\n'
|
|
|
|
printf " BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO' */\n"
|
|
|
|
write_string "$1" ' ' 'Value' "$value_len"
|
|
|
|
printf ' }\n}\n'
|
|
[ -n "$insert_after" ] && printf 'INSERT AFTER .note.gnu.build-id;\n'
|
|
:
|
|
}
|
|
|
|
if [ "$1" == "--readonly=no" ]; then
|
|
shift
|
|
readonly=
|
|
fi
|
|
|
|
if [ "$1" == "--insert-after=no" ]; then
|
|
shift
|
|
insert_after=
|
|
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"
|