2011-06-30 11:07:54 -04:00
|
|
|
#!/bin/bash -e
|
2010-09-15 23:40:35 -04:00
|
|
|
#
|
|
|
|
# pacman-key - manages pacman's keyring
|
|
|
|
# Based on apt-key, from Debian
|
|
|
|
# @configure_input@
|
|
|
|
#
|
2011-06-04 10:18:33 -04:00
|
|
|
# Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2010-09-15 23:40:35 -04:00
|
|
|
#
|
|
|
|
# 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# gettext initialization
|
2011-06-23 22:21:51 -04:00
|
|
|
export TEXTDOMAIN='pacman-scripts'
|
2010-09-15 23:40:35 -04:00
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
|
|
|
myver="@PACKAGE_VERSION@"
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
# Options
|
|
|
|
ADD=0
|
|
|
|
DELETE=0
|
|
|
|
EXPORT=0
|
|
|
|
FINGER=0
|
|
|
|
LIST=0
|
|
|
|
RECEIVE=0
|
|
|
|
RELOAD=0
|
|
|
|
TRUST=0
|
|
|
|
UPDATEDB=0
|
|
|
|
|
2011-06-09 06:43:25 -04:00
|
|
|
m4_include(library/output_format.sh)
|
2010-09-15 23:40:35 -04:00
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
m4_include(library/parse_options.sh)
|
|
|
|
|
2010-09-15 23:40:35 -04:00
|
|
|
usage() {
|
|
|
|
printf "pacman-key (pacman) %s\n" ${myver}
|
|
|
|
echo
|
2011-07-05 13:05:08 -04:00
|
|
|
printf "$(gettext "Usage: %s [options]")\n" $(basename $0)
|
2010-09-15 23:40:35 -04:00
|
|
|
echo
|
2011-07-05 14:01:14 -04:00
|
|
|
printf "$(gettext "Manage pacman\'s list of trusted keys")\n"
|
2010-09-15 23:40:35 -04:00
|
|
|
echo
|
2011-07-05 13:05:08 -04:00
|
|
|
echo "$(gettext "Options:")"
|
2011-03-23 02:24:28 -04:00
|
|
|
echo "$(gettext " -a, --add [<file(s)>] Add the specified keys (empty for stdin)")"
|
2011-07-05 13:34:04 -04:00
|
|
|
echo "$(gettext " -d, --delete <keyid(s)> Remove the specified keyids")"
|
2011-03-23 02:24:28 -04:00
|
|
|
echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")"
|
|
|
|
echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")"
|
2011-04-21 09:59:05 -04:00
|
|
|
echo "$(gettext " -h, --help Show this help message and exit")"
|
2011-03-23 02:24:28 -04:00
|
|
|
echo "$(gettext " -l, --list List keys")"
|
|
|
|
echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")"
|
|
|
|
echo "$(gettext " -t, --trust <keyid(s)> Set the trust level of the given keyids")"
|
|
|
|
echo "$(gettext " -u, --updatedb Update the trustdb of pacman")"
|
|
|
|
echo "$(gettext " -V, --version Show program version")"
|
2011-07-05 13:05:08 -04:00
|
|
|
echo "$(gettext " --config <file> Use an alternate config file")"
|
|
|
|
printf "$(gettext " (instead of '%s')")\n" "@sysconfdir@/pacman.conf"
|
|
|
|
echo "$(gettext " --gpgdir <dir> Set an alternate directory for gnupg")"
|
|
|
|
printf "$(gettext " (instead of '%s')")\n" "@sysconfdir@/pacman.d/gnupg"
|
|
|
|
echo "$(gettext " --reload Reload the default keys")"
|
2010-09-15 23:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
version() {
|
|
|
|
printf "pacman-key (pacman) %s\n" "${myver}"
|
|
|
|
printf "$(gettext "\
|
2011-03-23 02:24:28 -04:00
|
|
|
Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
|
2010-09-15 23:40:35 -04:00
|
|
|
This is free software; see the source for copying conditions.\n\
|
|
|
|
There is NO WARRANTY, to the extent permitted by law.\n")"
|
|
|
|
}
|
|
|
|
|
2011-04-21 09:59:07 -04:00
|
|
|
# Read provided file and search for values matching the given key
|
|
|
|
# The contents of the file are expected to be in this format: key = value
|
|
|
|
# 'key', 'equal sign' and 'value' can be surrounded by random whitespace
|
|
|
|
# Usage: get_from "$file" "$key" # returns the value for the first matching key in the file
|
|
|
|
get_from() {
|
2011-06-08 02:48:56 -04:00
|
|
|
while read key _ value; do
|
|
|
|
if [[ $key = $2 ]]; then
|
|
|
|
echo "$value"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done < "$1"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
}
|
|
|
|
|
2010-09-15 23:40:35 -04:00
|
|
|
reload_keyring() {
|
|
|
|
local PACMAN_SHARE_DIR='@prefix@/share/pacman'
|
|
|
|
local GPG_NOKEYRING="gpg --batch --quiet --ignore-time-conflict --no-options --no-default-keyring --homedir ${PACMAN_KEYRING_DIR}"
|
|
|
|
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
# Variable used for iterating on keyrings
|
|
|
|
local key
|
|
|
|
local key_id
|
|
|
|
|
|
|
|
# Keyring with keys to be added to the keyring
|
2010-09-15 23:40:35 -04:00
|
|
|
local ADDED_KEYS="${PACMAN_SHARE_DIR}/addedkeys.gpg"
|
|
|
|
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
# Keyring with keys that were deprecated and will eventually be deleted
|
|
|
|
local DEPRECATED_KEYS="${PACMAN_SHARE_DIR}/deprecatedkeys.gpg"
|
|
|
|
|
|
|
|
# List of keys removed from the keyring. This file is not a keyring, unlike the others.
|
|
|
|
# It is a textual list of values that gpg recogniezes as identifiers for keys.
|
2010-09-15 23:40:35 -04:00
|
|
|
local REMOVED_KEYS="${PACMAN_SHARE_DIR}/removedkeys"
|
|
|
|
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
# Verify signatures of related files, if they exist
|
2010-09-15 23:40:35 -04:00
|
|
|
if [[ -r "${ADDED_KEYS}" ]]; then
|
|
|
|
msg "$(gettext "Verifying official keys file signature...")"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
if ! ${GPG_PACMAN} --quiet --batch --verify "${ADDED_KEYS}.sig" 1>/dev/null; then
|
2010-09-15 23:40:35 -04:00
|
|
|
error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}"
|
|
|
|
exit 1
|
|
|
|
fi
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
2010-09-15 23:40:35 -04:00
|
|
|
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
if [[ -r "${DEPRECATED_KEYS}" ]]; then
|
|
|
|
msg "$(gettext "Verifying deprecated keys file signature...")"
|
|
|
|
if ! ${GPG_PACMAN} --quiet --batch --verify "${DEPRECATED_KEYS}.sig" 1>/dev/null; then
|
|
|
|
error "$(gettext "The signature of file %s is not valid.")" "${DEPRECATED_KEYS}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-09-15 23:40:35 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -r "${REMOVED_KEYS}" ]]; then
|
|
|
|
msg "$(gettext "Verifying deleted keys file signature...")"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
if ! ${GPG_PACMAN} --quiet --batch --verify "${REMOVED_KEYS}.sig"; then
|
2010-09-15 23:40:35 -04:00
|
|
|
error "$(gettext "The signature of file %s is not valid.")" "${REMOVED_KEYS}"
|
|
|
|
exit 1
|
|
|
|
fi
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Read the key ids to an array. The conversion from whatever is inside the file
|
|
|
|
# to key ids is important, because key ids are the only guarantee of identification
|
|
|
|
# for the keys.
|
|
|
|
local -A removed_ids
|
|
|
|
if [[ -r "${REMOVED_KEYS}" ]]; then
|
|
|
|
while read key; do
|
|
|
|
local key_values name
|
|
|
|
key_values=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5,10 --output-delimiter=' ')
|
|
|
|
if [[ -n $key_values ]]; then
|
|
|
|
# The first word is the key_id
|
|
|
|
key_id=${key_values%% *}
|
|
|
|
# the rest if the name of the owner
|
|
|
|
name=${key_values#* }
|
|
|
|
if [[ -n ${key_id} ]]; then
|
|
|
|
# Mark this key to be deleted
|
|
|
|
removed_ids[$key_id]="$name"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < "${REMOVED_KEYS}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# List of keys that must be kept installed, even if in the list of keys to be removed
|
2011-04-21 09:59:07 -04:00
|
|
|
local HOLD_KEYS=$(get_from "$CONFIG" "HoldKeys")
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
|
|
|
|
# Remove the keys that must be kept from the set of keys that should be removed
|
|
|
|
if [[ -n ${HOLD_KEYS} ]]; then
|
|
|
|
for key in ${HOLD_KEYS}; do
|
|
|
|
key_id=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5)
|
|
|
|
if [[ -n "${removed_ids[$key_id]}" ]]; then
|
|
|
|
unset removed_ids[$key_id]
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add keys from the current set of keys from pacman-keyring package. The web of trust will
|
|
|
|
# be updated automatically.
|
|
|
|
if [[ -r "${ADDED_KEYS}" ]]; then
|
|
|
|
msg "$(gettext "Appending official keys...")"
|
|
|
|
local add_keys=$(${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5)
|
|
|
|
for key_id in ${add_keys}; do
|
|
|
|
# There is no point in adding a key that will be deleted right after
|
|
|
|
if [[ -z "${removed_ids[$key_id]}" ]]; then
|
|
|
|
${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -r "${DEPRECATED_KEYS}" ]]; then
|
|
|
|
msg "$(gettext "Appending deprecated keys...")"
|
|
|
|
local add_keys=$(${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5)
|
|
|
|
for key_id in ${add_keys}; do
|
|
|
|
# There is no point in adding a key that will be deleted right after
|
|
|
|
if [[ -z "${removed_ids[$key_id]}" ]]; then
|
|
|
|
${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2010-09-15 23:40:35 -04:00
|
|
|
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
# Remove the keys not marked to keep
|
|
|
|
if (( ${#removed_ids[@]} > 0 )); then
|
2010-09-15 23:40:35 -04:00
|
|
|
msg "$(gettext "Removing deleted keys from keyring...")"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
for key_id in "${!removed_ids[@]}"; do
|
|
|
|
echo " removing key $key_id - ${removed_ids[$key_id]}"
|
|
|
|
${GPG_PACMAN} --quiet --batch --yes --delete-key "${key_id}"
|
2010-09-15 23:40:35 -04:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update trustdb, just to be sure
|
|
|
|
msg "$(gettext "Updating trust database...")"
|
|
|
|
${GPG_PACMAN} --batch --check-trustdb
|
|
|
|
}
|
|
|
|
|
|
|
|
# PROGRAM START
|
|
|
|
if ! type gettext &>/dev/null; then
|
|
|
|
gettext() {
|
|
|
|
echo "$@"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
OPT_SHORT="a::d:e:f::hlr:t:uV"
|
2011-07-05 13:34:04 -04:00
|
|
|
OPT_LONG="add::,config:,delete:,export:,finger::,gpgdir:,help,list"
|
2011-07-05 13:05:08 -04:00
|
|
|
OPT_LONG+=",receive:,reload,trust:,updatedb,version"
|
|
|
|
if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
|
|
|
|
echo; usage; exit 1 # E_INVALID_OPTION;
|
|
|
|
fi
|
|
|
|
eval set -- "$OPT_TEMP"
|
|
|
|
unset OPT_SHORT OPT_LONG OPT_TEMP
|
|
|
|
|
|
|
|
if [[ $1 == "--" ]]; then
|
|
|
|
usage;
|
|
|
|
exit 0;
|
2010-09-15 23:40:35 -04:00
|
|
|
fi
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
while true; do
|
2010-09-15 23:40:35 -04:00
|
|
|
case "$1" in
|
2011-07-05 13:05:08 -04:00
|
|
|
-a|--add) ADD=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYFILES=($1) ;;
|
|
|
|
--config) shift; CONFIG=$1 ;;
|
2011-07-05 13:34:04 -04:00
|
|
|
-d|--delete) DELETE=1; shift; KEYIDS=($1) ;;
|
2011-07-05 13:05:08 -04:00
|
|
|
-e|--export) EXPORT=1; shift; KEYIDS=($1) ;;
|
|
|
|
-f|--finger) FINGER=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
|
|
|
--gpgdir) shift; PACMAN_KEYRING_DIR=$1 ;;
|
|
|
|
-l|--list) LIST=1 ;;
|
|
|
|
-r|--receive) RECEIVE=1; shift; KEYSERVER="${1[0]}"; KEYIDS=("${1[@]:1}") ;;
|
|
|
|
--reload) RELOAD=1 ;;
|
|
|
|
-t|--trust) TRUST=1; shift; KEYIDS=($1) ;;
|
|
|
|
-u|--updatedb) UPDATEDB=1 ;;
|
|
|
|
|
|
|
|
-h|--help) usage; exit 0 ;;
|
|
|
|
-V|--version) version; exit 0 ;;
|
|
|
|
|
|
|
|
--) OPT_IND=0; shift; break;;
|
|
|
|
*) usage; exit 1 ;;
|
2010-09-15 23:40:35 -04:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
|
|
|
|
if ! type -p gpg >/dev/null; then
|
|
|
|
error "$(gettext "Cannot find the %s binary required for all %s operations.")" "gpg" "pacman-key"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-07-05 13:27:23 -04:00
|
|
|
if (( (ADD || DELETE || RECEIVE || RELOAD || TRUST || UPDATEDB) && EUID != 0 )); then
|
2011-07-05 13:05:08 -04:00
|
|
|
error "$(gettext "%s needs to be run as root for this operation.")" "pacman-key"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFIG=${CONFIG:-@sysconfdir@/pacman.conf}
|
2010-09-15 23:40:35 -04:00
|
|
|
if [[ ! -r "${CONFIG}" ]]; then
|
2011-07-05 13:05:08 -04:00
|
|
|
error "$(gettext "%s configuation file '%s' not found.")" "pacman" "$CONFIG"
|
2010-09-15 23:40:35 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
# Get GPGDIR from pacman.conf iff not specified on command line
|
|
|
|
if [[ -z PACMAN_KEYRING_DIR && GPGDIR=$(get_from "$CONFIG" "GPGDir") == 0 ]]; then
|
2010-09-15 23:40:35 -04:00
|
|
|
PACMAN_KEYRING_DIR="${GPGDIR}"
|
|
|
|
fi
|
2011-07-05 13:05:08 -04:00
|
|
|
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-@sysconfdir@/pacman.d/gnupg}
|
2011-03-27 12:14:15 -04:00
|
|
|
|
|
|
|
# Try to create $PACMAN_KEYRING_DIR if non-existent
|
|
|
|
# Check for simple existence rather than for a directory as someone may want
|
|
|
|
# to use a symlink here
|
|
|
|
[[ -e ${PACMAN_KEYRING_DIR} ]] || mkdir -p -m 755 "${PACMAN_KEYRING_DIR}"
|
2010-09-15 23:40:35 -04:00
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning"
|
|
|
|
|
|
|
|
|
|
|
|
(( ADD )) && ${GPG_PACMAN} --quiet --batch --import "${KEYFILES[@]}"
|
|
|
|
(( DELETE )) && ${GPG_PACMAN} --quiet --batch --delete-key --yes "${KEYIDS[@]}"
|
|
|
|
(( EXPORT )) && ${GPG_PACMAN} --armor --export "${KEYIDS[@]}"
|
|
|
|
(( FINGER )) && ${GPG_PACMAN} --batch --fingerprint "${KEYIDS[@]}"
|
|
|
|
(( LIST )) && ${GPG_PACMAN} --batch --list-sigs "${KEYIDS[@]}"
|
|
|
|
(( RELOAD )) && reload_keyring
|
|
|
|
(( UPDATEDB )) && ${GPG_PACMAN} --batch --check-trustdb
|
|
|
|
|
|
|
|
if (( RECEIVE )); then
|
|
|
|
if [[ -z ${KEYIDS[@]} ]]; then
|
|
|
|
error "$(gettext "You need to specify the keyserver and at least one key identifier")"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
${GPG_PACMAN} --keyserver "$KEYSERVER" --recv-keys "${KEYIDS[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( TRUST )); then
|
|
|
|
for key in ${KEYIDS[@]}; do
|
2010-09-15 23:40:35 -04:00
|
|
|
# Verify if the key exists in pacman's keyring
|
2011-07-05 13:05:08 -04:00
|
|
|
if ${GPG_PACMAN} --list-keys "$key" > /dev/null 2>&1; then
|
|
|
|
${GPG_PACMAN} --edit-key "$key"
|
2010-09-15 23:40:35 -04:00
|
|
|
else
|
2011-07-05 13:05:08 -04:00
|
|
|
error "$(gettext "The key identified by %s does not exist")" "$key"
|
2010-09-15 23:40:35 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
2011-07-05 13:05:08 -04:00
|
|
|
fi
|
2011-06-08 02:48:56 -04:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|