Last active
April 8, 2016 11:31
-
-
Save rk295/081b7779163fb067acf1c43dff18559e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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