Skip to content

Instantly share code, notes, and snippets.

@rk295
Last active April 8, 2016 11:31
Show Gist options
  • Save rk295/081b7779163fb067acf1c43dff18559e to your computer and use it in GitHub Desktop.
Save rk295/081b7779163fb067acf1c43dff18559e to your computer and use it in GitHub Desktop.
run_gpg() {
# cache for 30 mins (1800sec)
gpg-agent --daemon --default-cache-ttl=1800 --write-env-file "${HOME}/.gpg-agent-info"
GPG_AGENT_PID=$(cat ${HOME}/.gpg-agent-info | awk -F: '{print $2}')
echo "${GPG_AGENT_PID})"
}
# GPG Keys
if which gpg-agent > /dev/null 2>&1 ; then
if [[ -e "${HOME}/.gpg-agent-info" ]] ; then
GPG_AGENT_PID=$(cat ${HOME}/.gpg-agent-info | awk -F: '{print $2}')
proc_list=$(ps -u "$LOGNAME" -o pid,name | grep gpg-agent | grep "$GPG_AGENT_PID")
if [[ -z $proc_list ]] ; then
echo -n "gpg-agent: not running, starting ("
run_gpg
else
echo -n "gpg-agent: running ($GPG_AGENT_PID) "
fi
else
run_gpg
fi
if [ -f "${HOME}/.gpg-agent-info" ]; then
echo -n " including environment"
. "${HOME}/.gpg-agent-info"
export GPG_AGENT_INFO
else
echo -n " failed to load environment"
fi
echo ""
else
echo "gpg-agent not found, might want to fix that"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment