d400e6
# Some miscellaneous Fedora-related macros
d400e6
d400e6
# List files matching inclusion globs, excluding files matching exclusion blogs
d400e6
# Optional parameters:
d400e6
#  – -i "<globs>" inclusion globs
d400e6
#  – -x "<globs>" exclusion globs
d400e6
# Globs are space-separated lists of shell globs. Such lists require %{quote:}
d400e6
# use for safe rpm argument passing.
d400e6
# Alternatively, set the following rpm variables before calling the macro:
d400e6
#  – “listfiles_include” inclusion globs
d400e6
#  — “listfiles_exclude” exclusion globs
d400e6
# Arguments passed to the macro without flags will be interpreted as inclusion
d400e6
# globs.
d400e6
%listfiles(i:x:) %{expand:
d400e6
%if %{lua: print(string.len(rpm.expand("%{?-i*}%{?listfiles_include}%*")))}
d400e6
  listfiles_include=$(realpath -e --relative-base=. %{?-i*} %{?listfiles_include} %* | sort -u)
d400e6
  %if  %{lua: print(string.len(rpm.expand("%{?-x*}%{?listfiles_exclude}")))}
d400e6
    while IFS= read -r finc ; do
d400e6
      realpath -qe --relative-base=. %{?-x*} %{?listfiles_exclude} \\
d400e6
        | sort -u | grep -q "${finc}" || echo "${finc}"
d400e6
    done <<< "${listfiles_include}"
d400e6
  %else
d400e6
    echo "${listfiles_include}"
d400e6
  %endif
d400e6
%endif
d400e6
}
d400e6
d400e6
# https://github.com/rpm-software-management/rpm/issues/581
d400e6
# Write the contents of a list of rpm variables to a macro file.
d400e6
# The target file must contain the corresponding anchors.
d400e6
# For example %writevars -f myfile foo bar will replace:
d400e6
#  @@FOO@@ with the rpm evaluation of %{foo} and
d400e6
#  @@BAR@@ with the rpm evaluation of %{bar}
d400e6
# in myfile
d400e6
%writevars(f:) %{lua:
d400e6
local    fedora = require "fedora.common"
d400e6
local macrofile = rpm.expand("%{-f*}")
d400e6
local   rpmvars = {}
d400e6
for i = 1, rpm.expand("%#") do
d400e6
  table.insert(rpmvars, rpm.expand("%" .. i))
d400e6
end
d400e6
fedora.writevars(macrofile,rpmvars)
d400e6
}
d400e6
d400e6
# gpgverify verifies signed sources. There is documentation in the script.
d400e6
%gpgverify(k:s:d:) %{lua:
d400e6
local script = rpm.expand("%{_rpmconfigdir}/redhat/gpgverify ")
d400e6
local keyring = rpm.expand("%{-k*}")
d400e6
local signature = rpm.expand("%{-s*}")
d400e6
local data = rpm.expand("%{-d*}")
d400e6
print(script)
d400e6
if keyring ~= "" then
d400e6
  print(rpm.expand("--keyring='%{SOURCE" .. keyring ..  "}' "))
d400e6
end
d400e6
if signature ~= "" then
d400e6
  print(rpm.expand("--signature='%{SOURCE" .. signature ..  "}' "))
d400e6
end
d400e6
if data ~= "" then
d400e6
  print(rpm.expand("--data='%{SOURCE" .. data ..  "}' "))
d400e6
end
d400e6
}
d400e6
d400e6
# gpgverify verifies signed sources. There is documentation in the script.
d400e6
%gpgverify(k:s:d:) %{lua:
d400e6
local script = rpm.expand("%{_rpmconfigdir}/redhat/gpgverify ")
d400e6
local keyring = rpm.expand("%{-k*}")
d400e6
local signature = rpm.expand("%{-s*}")
d400e6
local data = rpm.expand("%{-d*}")
d400e6
print(script)
d400e6
if keyring ~= "" then
d400e6
  print(rpm.expand("--keyring='%{SOURCE" .. keyring ..  "}' "))
d400e6
end
d400e6
if signature ~= "" then
d400e6
  print(rpm.expand("--signature='%{SOURCE" .. signature ..  "}' "))
d400e6
end
d400e6
if data ~= "" then
d400e6
  print(rpm.expand("--data='%{SOURCE" .. data ..  "}' "))
d400e6
end
d400e6
}