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