raoulh/mc-agent

Improve .bashrc and .bash_profile integration

Opened this issue · 2 comments

There are several issues I encountered with bash integration:

  • The mc-agent-env file was being created with default permissions instead of specific permissions (yes, umask could be changed, but we're talking defaults here)
  • The PID of the agent was being printed during login because pgrep was not redirected to /dev/null
  • The /tmp directory was being littered with agent directories when a logout would terminate the agent

Here is the code snippet I settled on for my .bash_profile:

if ! pgrep -u "$USER" mc-agent > /dev/null; then
    #remove old agent directories
    find /tmp -name 'moolticute-ssh-agent*' -user ${USER} -type d -prune -exec rm -r {} ';' 2>/dev/null
    #create the agent env file with user read/write permissions only
    mc-agent | install -m 600 /dev/stdin ~/.mc-agent-env
fi
#send pgrep output to /dev/null so console isn't littered with random PIDs
if pgrep -u "$USER" mc-agent > /dev/null && grep -q 'SSH_AUTH_SOCK=' ~/.mc-agent-env; then
    # once mc-agent started successfully override gnome-keyring ssh component
    eval "$(<~/.mc-agent-env)"
fi

Hi, could you provide a PR for your changes to https://github.com/raoulh/mc-agent/blob/master/docs/mc-agent.md ?
thanks

Yeah, I'll fork/branch/commit/PR it tomorrow.