#!/bin/bash
# rpmdev-packager -- guess rpm packager info from various sources
#
# Copyright (c) 2009-2016 Ville Skyttä <ville.skytta@iki.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
version()
{
cat <<EOF
rpmdev-packager version 1.3
Copyright (c) 2009-2015 Ville Skyttä <ville.skytta@iki.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
EOF
}
help()
{
cat <<\EOF
rpmdev-packager guesses rpm packager info from various sources:
$RPM_PACKAGER from environment (full name + email address)
%packager from rpm configuration (full name + email address)
certificates ~/.fedora.cert (email address)
git from git configuration (user.name + user.email)
$MAILTO from environment (email address)
/etc/passwd gecos (full name, username)
EOF
usage
echo ""
echo "Report bugs at <https://bugzilla.redhat.com/>, component rpmdevtools,"
echo "or at <https://pagure.io/rpmdevtools/issues>."
}
usage() {
cat <<EOF
Usage: rpmdev-packager [option]...
Options:
-h, --help Show help message and exit.
-v, --version Print version information and exit.
EOF
}
while [ -n "$1" ] ; do
case "$1" in
-h|--help)
help
exit 0
;;
-v|--version)
version
exit 0
;;
*)
usage
exit 1
;;
esac
done
username="$( id -un )"
fullname="$( getent passwd $username 2>/dev/null | cut -d: -f5 )"
fullname="${fullname%%,*}"
# TODO obsolete, should use kerberos instead? e.g.
# https://pagure.io/rpkg/blob/master/f/pyrpkg/__init__.py#_823
# https://pagure.io/fedora-packager/c/715483c1bbdf5cceaeb63e90410139
certs=(~/.fedora.cert)
# Try $RPM_PACKAGER
packager="$RPM_PACKAGER"
# Try rpm %packager
[ -z "$packager" ] && packager="$( rpm --eval '%packager' )"
[ "$packager" = "%packager" ] && packager=
# Try packager certificates
if [ -z "$packager" ] ; then
for cert in $certs ; do
if [ -f "$cert" ] ; then
packager="$( openssl x509 -noout -email -in "$cert" 2>/dev/null )"
[ -n "$packager" -a -n "$fullname" ] && \
packager="$fullname <$packager>"
[ -n "$packager" ] && break
fi
done
fi
# Try git configuration
if [ -z "$packager" ] ; then
packager="$( git config user.email )"
if [ -n "$packager" ] ; then
gituser="$( git config user.name )"
[ -n "${gituser:-$fullname}" ] && \
packager="${gituser:-$fullname} <$packager>"
fi
fi
# Try $MAILTO
if [ -z "$packager" ] ; then
packager="$MAILTO"
[ -n "$packager" -a -n "$fullname" ] && packager="$fullname <$packager>"
fi
# Try full name
[ -z "$packager" ] && packager="$fullname"
# Fall back to username only
[ -z "$packager" ] && packager="$username"
# Done
[ -n "$packager" ] && echo "$packager"
|