Fix ssh-sentinel

This commit is contained in:
Kevin Cotugno 2018-11-21 16:51:14 -08:00
parent 63d71b94ac
commit a727341b56
4 changed files with 30 additions and 29 deletions

26
.ssh-sentinel Normal file
View File

@ -0,0 +1,26 @@
file="$HOME/.ssh-agent"
which ssh-agent &> /dev/null
if (( $? )); then
exit 1
fi
if [[ -n "$SSH_AUTH_SOCK" ]] && [[ -n "$SSH_AGENT_PID" ]]; then
return
fi
if [[ -e $file ]]; then
sockenv=`cat $file | grep SSH_AUTH_SOCK`
pidenv=`cat $file | grep SSH_AGENT_PID`
pid=`printf "$pidenv" | grep -o "[0-9]*"`
ps --pid "$pid" &> /dev/null
if (( ! $? )); then
export "$sockenv"
export "$pidenv"
return
fi
fi
export `ssh-agent -s | grep -oP "^.+(?=; export)" | tee "$file"`
chmod 600 "$file"

2
.zshrc
View File

@ -1,4 +1,5 @@
local oh_my_zsh="$HOME/.oh-my-zsh" local oh_my_zsh="$HOME/.oh-my-zsh"
source $HOME/.ssh-sentinel
if [[ -d "$oh_my_zsh" ]]; then if [[ -d "$oh_my_zsh" ]]; then
local theme="jispwoso" local theme="jispwoso"
@ -48,6 +49,7 @@ else
export EDITOR="vi" export EDITOR="vi"
fi fi
function passgen () { function passgen () {
local len="$1" local len="$1"
local lower="$2" local lower="$2"

View File

@ -26,6 +26,7 @@ function uninstall {
eval $rm "$nvim_dir/autoload" eval $rm "$nvim_dir/autoload"
eval $rm "$nvim_dir/init.vim" eval $rm "$nvim_dir/init.vim"
eval $rm "$HOME/.Xresources" eval $rm "$HOME/.Xresources"
eval $rm "$HOME/.ssh-sentinel"
} }
function install { function install {
@ -35,6 +36,7 @@ function install {
eval $link "$PWD/.emacs.d/themes/" "$emacs_dir/themes" eval $link "$PWD/.emacs.d/themes/" "$emacs_dir/themes"
eval $link "$PWD/.zshrc" "$HOME/.zshrc" eval $link "$PWD/.zshrc" "$HOME/.zshrc"
eval $link "$PWD/.tmux.conf" "$HOME/.tmux.conf" eval $link "$PWD/.tmux.conf" "$HOME/.tmux.conf"
eval $link "$PWD/.ssh-sentinel" "$HOME/.ssh-sentinel"
eval $link "$PWD/.config/nvim/autoload" "$nvim_dir/autoload" eval $link "$PWD/.config/nvim/autoload" "$nvim_dir/autoload"
eval $link "$PWD/.config/nvim/init.vim" "$nvim_dir/init.vim" eval $link "$PWD/.config/nvim/init.vim" "$nvim_dir/init.vim"

View File

@ -1,29 +0,0 @@
#!/usr/bin/env bash
file="$HOME/.ssh-agent"
found=0
which ssh-agent &> /dev/null
if (( $? )); then
exit 1
fi
if [[ -e $file ]]; then
sockenv=`cat $file | grep SSH_AUTH_SOCK`
pidenv=`cat $file | grep SSH_AGENT_PID`
sock=`echo "$sockenv" | grep -oP "(?<=\=)/.*$"`
pid=`echo "$pidenv" | grep -o "[0-9]*"`
proc=`ps ax | grep "^ $pid.*ssh-agent"`
if [[ -S "$sock" && -O "$sock" && -n "$proc" ]]; then
export "$sockenv"
export "$pidenv"
found=1
fi
fi
if (( ! $found )); then
export `ssh-agent -s | grep -oP "^.+(?=; export)" | tee "$file"`
fi
chmod 600 "$file"