2
  7   !ˆl–Ðz¾” ”Ò~êq@ŠãmÜmõ1hß�þ\‘¦–q¹ZÇ$o¶@?Õ„¯º/ÔÂÒ ?÷     !#!/bin/sh

set -e
unset GREP_OPTIONS GPGHOMEDIR CURRENTTRAP
export IFS="$(printf "\n\b")"

MASTER_KEYRING=''
eval "$(apt-config shell MASTER_KEYRING APT::Key::MasterKeyring)"
ARCHIVE_KEYRING=''
eval "$(apt-config shell ARCHIVE_KEYRING APT::Key::ArchiveKeyring)"
REMOVED_KEYS=''
eval "$(apt-config shell REMOVED_KEYS APT::Key::RemovedKeys)"
ARCHIVE_KEYRING_URI=''
eval "$(apt-config shell ARCHIVE_KEYRING_URI APT::Key::ArchiveKeyringURI)"

aptkey_echo() { echo "$@"; }

find_gpgv_status_fd() {
   while [ -n "$1" ]; do
	if [ "$1" = '--status-fd' ]; then
		shift
		echo "$1"
		break
	fi
	shift
   done
}
GPGSTATUSFD="$(find_gpgv_status_fd "$@")"

apt_warn() {
    if [ -z "$GPGHOMEDIR" ]; then
	echo >&2 'W:' "$@"
    else
	echo 'W:' "$@" > "${GPGHOMEDIR}/aptwarnings.log"
    fi
    if [ -n "$GPGSTATUSFD" ]; then
	echo >&${GPGSTATUSFD} '[APTKEY:] WARNING' "$@"
    fi
}
apt_error() {
    if [ -z "$GPGHOMEDIR" ]; then
	echo >&2 'E:' "$@"
    else
	echo 'E:' "$@" > "${GPGHOMEDIR}/aptwarnings.log"
    fi
    if [ -n "$GPGSTATUSFD" ]; then
	echo >&${GPGSTATUSFD} '[APTKEY:] ERROR' "$@"
    fi
}

cleanup_gpg_home() {
    if [ -z "$GPGHOMEDIR" ]; then return; fi
    if [ -s "$GPGHOMEDIR/aptwarnings.log" ]; then
	cat >&2 "$GPGHOMEDIR/aptwarnings.log"
    fi
    if command_available 'gpgconf'; then
	GNUPGHOME="${GPGHOMEDIR}" gpgconf --kill all >/dev/null 2>&1 || true
    fi
    rm -rf "$GPGHOMEDIR"
}

# gpg needs (in different versions more or less) files to function correctly,
# so we give it its own homedir and generate some valid content for it later on
create_gpg_home() {
    # for cases in which we want to cache a homedir due to expensive setup
    if [ -n "$GPGHOMEDIR" ]; then
	return
    fi
    if [ -n "$TMPDIR" ]; then
	# tmpdir is a directory and current user has rwx access to it
	# same tests as in apt-pkg/contrib/fileutl.cc GetTempDir()
	if [ ! -d "$TMPDIR" ] || [ ! -r "$TMPDIR" ] || [ ! -w "$TMPDIR" ] || [ ! -x "$TMPDIR" ]; then
	    unset TMPDIR
	fi
    fi
    GPGHOMEDIR="$(mktemp --directory --tmpdir 'apt-key-gpghome.XXXXXXXXXX')"
    CURRENTTRAP="${CURRENTTRAP} cleanup_gpg_home;"
    trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
    if [ -z "$GPGHOMEDIR" ]; then
	apt_error "Could not create temporary gpg home directory in $TMPDIR (wrong permissions?)"
	exit 28
    fi
    chmod 700 "$GPGHOMEDIR"
}

requires_root() {
	if [ "$(id -u)" -ne 0 ]; then
		apt_error "This command can only be used by root."
		exit 1
	fi
}

command_available() {
    if [ -x "$1" ]; then return 0; fi
    command -v "$1" >/dev/null # required by policy, see #747320
}

escape_shell() {
    echo "$@" | sed -e "s#'#'\"'\"'#g"
}

get_fingerprints_of_keyring() {
    aptkey_execute "$GPG_SH" --keyring "$1" --with-colons --fingerprint | while read publine; do
	# search for a public key
	if [ "${publine%%:*}" != 'pub' ]; then continue; fi
	# search for the associated fingerprint (should be the very next line)
	while read fprline; do
	   if [ "${fprline%%:*}" = 'sub' ]; then break; # should never happen
	   elif [ "${fprline%%:*}" != 'fpr' ]; then continue; fi
	   echo "$fprline" | cut -d':' -f 10
	done
	# order in the keyring shouldn't be important
    done | sort
}

add_keys_with_verify_against_master_keyring() {
    ADD_KEYRING="$1"
    MASTER="$2"

    if [ ! -f "$ADD_KEYRING" ]; then
	apt_error "Keyring '$ADD_KEYRING' to be added not found"
	return
    fi
    if [ ! -f "$MASTER" ]; then
	apt_error "Master-Keyring '$MASTER' not found"
	return
    fi

    # when adding new keys, make sure that the archive-master-keyring
    # is honored. so:
    #   all keys that are exported must have a valid signature
    #   from a key in the $distro-master-keyring
    add_keys="$(get_fingerprints_of_keyring "$ADD_KEYRING")"
    all_add_keys="$(aptkey_execute "$GPG_SH" --keyring "$ADD_KEYRING" --with-colons --list-keys | grep ^[ps]ub | cut -d: -f5)"
    master_keys="$(aptkey_execute "$GPG_SH" --keyring "$MASTER" --with-colons --list-keys | grep ^pub | cut -d: -f5)"

    # ensure there