#!/bin/bash
# We need this wrapper for starting local apps which need a running gpg-agent

# Providing gpg-agent in a local-apps-environment

# start only, if we are local
if   [ "$LTSP_CLIENT" != "" ] && ip addr|grep -q $LTSP_CLIENT/24 ; then
        # Invoke GnuPG-Agent the first time we login.
        # Does `~/.gpg-agent-info' exist and points to gpg-agent process accepting signals?
        if test -f $HOME/.gpg-agent-info && \
            kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then
            GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info | cut -c 16-`
#            echo "gpg-agent already running, not starting a second one"
        else
          # No, gpg-agent not available; start gpg-agent
#          echo "no running gpg-agent found. starting"
          gpg-agent --daemon --enable-ssh-support \
          --write-env-file "${HOME}/.gpg-agent-info"
        fi

        # the next script looks for a running gpg-agent and exports the
        # environment variables
        if [ -f "${HOME}/.gpg-agent-info" ]; then
           . "${HOME}/.gpg-agent-info"
           export GPG_AGENT_INFO
           export SSH_AUTH_SOCK
#           echo "connect to running gpg-agent"
        fi
fi

# start pyhoca gui
which pyhoca-gui && pyhoca-gui 
