Fix ssh-sentinel
This commit is contained in:
parent
63d71b94ac
commit
a727341b56
26
.ssh-sentinel
Normal file
26
.ssh-sentinel
Normal 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
2
.zshrc
@ -1,4 +1,5 @@
|
||||
local oh_my_zsh="$HOME/.oh-my-zsh"
|
||||
source $HOME/.ssh-sentinel
|
||||
|
||||
if [[ -d "$oh_my_zsh" ]]; then
|
||||
local theme="jispwoso"
|
||||
@ -48,6 +49,7 @@ else
|
||||
export EDITOR="vi"
|
||||
fi
|
||||
|
||||
|
||||
function passgen () {
|
||||
local len="$1"
|
||||
local lower="$2"
|
||||
|
@ -26,6 +26,7 @@ function uninstall {
|
||||
eval $rm "$nvim_dir/autoload"
|
||||
eval $rm "$nvim_dir/init.vim"
|
||||
eval $rm "$HOME/.Xresources"
|
||||
eval $rm "$HOME/.ssh-sentinel"
|
||||
}
|
||||
|
||||
function install {
|
||||
@ -35,6 +36,7 @@ function install {
|
||||
eval $link "$PWD/.emacs.d/themes/" "$emacs_dir/themes"
|
||||
eval $link "$PWD/.zshrc" "$HOME/.zshrc"
|
||||
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/init.vim" "$nvim_dir/init.vim"
|
||||
|
||||
|
@ -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"
|
Loading…
Reference in New Issue
Block a user