mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 01:12:11 +08:00 
			
		
		
		
	Adding script to enable SSH-agent #193
Adding agent-script to bin-folder and a commented out call in init.bat
This commit is contained in:
		
							
								
								
									
										46
									
								
								bin/agent.cmd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								bin/agent.cmd
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										2
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							| @@ -44,3 +44,5 @@ | |||||||
|         @cd /d "%HOME%" |         @cd /d "%HOME%" | ||||||
|     ) |     ) | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | :: @call "%CMDER_ROOT%/bin/agent.cmd" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user