#!/bin/sh # SPDX-License-Identifier: 0BSD # Prints a quoted --package-metadata string suitable for being used from an RPM # macro in a way that gets correctly propagated down to the linker. cpe="$(cat /usr/lib/system-release-cpe)" # We need to print the escapes as-is, so single quote echo, but also print the # variables, so do it in multiple lines. # The many quotes are necessary so that the compiler gets: # -Xlinker "--package-metadata={\"type\":\"rpm\",\"name\":\"foo\",\"version\":\"bar\",\"architecture\":\"baz\",\"osCpe\":\"barbaz\"}" # This way the inner quotes make it into the parsed string, and the outer quotes # ensure the { } do not get expanded. -Xlinker instead of -Wl allows to use commas. echo -n '-Xlinker \"--package-metadata={\\\"type\\\":\\\"rpm\\\",\\\"name\\\":\\\"' echo -n "$1" echo -n '\\\",\\\"version\\\":\\\"' echo -n "$2" echo -n '\\\",\\\"architecture\\\":\\\"' echo -n "$3" echo -n '\\\",\\\"osCpe\\\":\\\"' echo -n "$cpe" # Yes, the closing bracket needs to be escaped, otherwise it gets duplicated: # "--package-metadata={\"type\":\"rpm\",\"name\":\"foo\",\"version\":\"bar\",\"architecture\":\"baz\",\"osCpe\":\"barbaz\"}"} echo -n '\\\"\}\"'