|
Packit Service |
672cf4 |
#!/bin/sh
|
|
Packit Service |
672cf4 |
# Copyright (C) 2013 g10 Code GmbH
|
|
Packit Service |
672cf4 |
#
|
|
Packit Service |
672cf4 |
# This file is free software; as a special exception the author gives
|
|
Packit Service |
672cf4 |
# unlimited permission to copy and/or distribute it, with or without
|
|
Packit Service |
672cf4 |
# modifications, as long as this notice is preserved. This file is
|
|
Packit Service |
672cf4 |
# distributed in the hope that it will be useful, but WITHOUT ANY
|
|
Packit Service |
672cf4 |
# WARRANTY, to the extent permitted by law; without even the implied
|
|
Packit Service |
672cf4 |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if [ -z "$(command -v gpg-connect-agent)" ]; then
|
|
Packit Service |
672cf4 |
echo "gpg-agent not installed and thus not started" >&2
|
|
Packit Service |
672cf4 |
exit 0;
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
GPG_AGENT_INFO=
|
|
Packit Service |
672cf4 |
export GPG_AGENT_INFO
|
|
Packit Service |
672cf4 |
GPG_AGENT=$(which gpg-agent)
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
token=$(echo "gpgme-$(pwd)" | tr ' ' '_')
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if [ "$1" = "--stop" ]; then
|
|
Packit Service |
672cf4 |
if [ "$(gpg-connect-agent --no-autostart getval\ $token /bye 2>/dev/null | head -1)" \
|
|
Packit Service |
672cf4 |
!= "D set" ]; then
|
|
Packit Service |
672cf4 |
echo "gpg-agent not running" >&2
|
|
Packit Service |
672cf4 |
exit 0
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
echo "stopping gpg-agent " >&2
|
|
Packit Service |
672cf4 |
gpg-connect-agent KILLAGENT /bye >/dev/null 2>&1
|
|
Packit Service |
672cf4 |
exit 0
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
# Update 'agent-program' in the configuration files to make sure we
|
|
Packit Service |
672cf4 |
# will always start exactly this agent again if we ever need to.
|
|
Packit Service |
672cf4 |
for F in gpg.conf gpgsm.conf
|
|
Packit Service |
672cf4 |
do
|
|
Packit Service |
672cf4 |
if test -f "$GNUPGHOME/$F"
|
|
Packit Service |
672cf4 |
then
|
|
Packit Service |
672cf4 |
mv "$GNUPGHOME/$F" "$GNUPGHOME/$F~"
|
|
Packit Service |
672cf4 |
sed -e "s#^agent-program.*#agent-program ${GPG_AGENT}|--debug-quick-random#" \
|
|
Packit Service |
672cf4 |
>"$GNUPGHOME/$F" <"$GNUPGHOME/$F~"
|
|
Packit Service |
672cf4 |
rm "$GNUPGHOME/$F~"
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
done
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if [ "$(gpg-connect-agent --no-autostart getval\ $token /bye 2>/dev/null | head -1)" \
|
|
Packit Service |
672cf4 |
= "D set" ]; then
|
|
Packit Service |
672cf4 |
echo "gpg-agent already running" >&2
|
|
Packit Service |
672cf4 |
exit 0
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
echo "starting gpg-agent.." >&2
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
# GnuPG prior to 2.1.12 needs --allow-loopback-pinentry for the
|
|
Packit Service |
672cf4 |
# loopback entry to work. Old versions do not understand this though,
|
|
Packit Service |
672cf4 |
# so we need to be careful.
|
|
Packit Service |
672cf4 |
if "$GPG_AGENT" --gpgconf-test --allow-loopback-pinentry &&
|
|
Packit Service |
672cf4 |
test -f "$GNUPGHOME/gpg-agent.conf" &&
|
|
Packit Service |
672cf4 |
! grep -q allow-loopback-pinentry "$GNUPGHOME/gpg-agent.conf"; then
|
|
Packit Service |
672cf4 |
echo allow-loopback-pinentry >> "$GNUPGHOME/gpg-agent.conf"
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
gpg-connect-agent --agent-program="${GPG_AGENT}|--debug-quick-random" putval\ $token\ set /bye
|
|
Packit Service |
672cf4 |
if [ $? -ne 0 -o "$(gpg-connect-agent getval\ $token /bye 2>/dev/null | head -1)" \
|
|
Packit Service |
672cf4 |
!= "D set" ]; then
|
|
Packit Service |
672cf4 |
echo "error starting gpg-agent" >&2
|
|
Packit Service |
672cf4 |
exit 1
|
|
Packit Service |
672cf4 |
fi
|
|
Packit Service |
672cf4 |
exit 0
|