From 75707f9a6574680cb46a93267b7e9e9ca23e426a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Skj=C3=A6veland=20Larsen?= Date: Wed, 17 Dec 2014 07:53:09 +0100 Subject: [PATCH 1/3] Adding script to enable SSH-agent #193 Adding agent-script to bin-folder and a commented out call in init.bat --- bin/agent.cmd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ vendor/init.bat | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 bin/agent.cmd diff --git a/bin/agent.cmd b/bin/agent.cmd new file mode 100644 index 0000000..c12d329 --- /dev/null +++ b/bin/agent.cmd @@ -0,0 +1,46 @@ +@ECHO OFF + +REM Set default sock file +SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock + +REM Check socket is available +IF NOT EXIST "%TMP%\ssh-agent.sock" GOTO:RUNAGENT + +REM Check if an ssh-agent is running +FOR /f "tokens=*" %%I IN ('ps ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') DO SET VAR=%%I +IF "%VAR%" == "" GOTO:RUNAGENT + +REM Check if socket file is valid +ssh-add -l 1> NUL 2>&1 +IF ERRORLEVEL 1 GOTO:RUNAGENT +GOTO:ADDKEYS + +:RUNAGENT +REM Remove old socket file +rm -f /tmp/ssh-agent.sock + +REM Run ssh-agent and save (last) PID in VAR +SET VAR= +FOR /f "tokens=*" %%J IN ('ssh-agent -a /tmp/ssh-agent.sock') DO FOR /f "tokens=*" %%K IN ('echo %%J ^| grep "SSH_AGENT_PID" ^| sed "s/^SSH_AGENT_PID=\([0-9]\+\); .*/\1/"') DO SET VAR=%%K + +:ADDKEYS +SET SSH_AUTH_PID=%VAR% + +REM Check if ssh keys are known +SET KEYS= +FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa"') DO CALL:CHECKKEY %%I + +REM Add missing ssh keys at once +IF NOT "%KEYS%" == "" ssh-add %KEYS% +GOTO:END + +REM Functions +REM Check if ssh key has to be added +:CHECKKEY +SET VAR= +FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep soldat_rsa') DO SET VAR=%%J +IF "%VAR%" == "" SET KEYS=%KEYS% "%HOME%\.ssh\%1" +GOTO:EOF + +:END +@ECHO ON diff --git a/vendor/init.bat b/vendor/init.bat index 308f932..7734f47 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -44,3 +44,5 @@ @cd /d "%HOME%" ) ) + +:: @call "%CMDER_ROOT%/bin/agent.cmd" From 6106a555fee13dce50eb4b61e568e6822a2382d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Skj=C3=A6veland=20Larsen?= Date: Wed, 17 Dec 2014 19:15:54 +0100 Subject: [PATCH 2/3] Adding info on SSH agent to README.md --- Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Readme.md b/Readme.md index 69fd527..1f44311 100644 --- a/Readme.md +++ b/Readme.md @@ -61,6 +61,12 @@ For example there is one defined for you `alias e.=explorer .` All aliases will be saved in `/config/aliases` file +### SSH Agent + +To start SSH agent simply call `agent`, which is in the `bin` folder. + +If you want to run SSH agent on startup, uncomment the line in `/vendor/init.bat`so it says `@call "%CMDER_ROOT%/bin/agent.cmd"`. + ## Todo 1. Complete PowerShell compatibility. From ad4a2103eaf714799c5b1247b34ad869ba574df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Skj=C3=A6veland=20Larsen?= Date: Thu, 18 Dec 2014 10:28:53 +0100 Subject: [PATCH 3/3] Support %HOME% variables containing spaces --- bin/agent.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/agent.cmd b/bin/agent.cmd index c12d329..4eaa614 100644 --- a/bin/agent.cmd +++ b/bin/agent.cmd @@ -38,8 +38,8 @@ REM Functions REM Check if ssh key has to be added :CHECKKEY SET VAR= -FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep soldat_rsa') DO SET VAR=%%J -IF "%VAR%" == "" SET KEYS=%KEYS% "%HOME%\.ssh\%1" +FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep "%1"') DO SET VAR=%%J +IF "%VAR%" == "" SET KEYS='%HOME%\.ssh\%1' %KEYS% GOTO:EOF :END