Last active
April 20, 2022 02:45
Revisions
-
Shoozza revised this gist
Sep 22, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ REM Display version and copyright information :VERSION ECHO,Agent 1.0.0.0 (ssh-agent script for MSYS2) ECHO, ECHO,Copyright (C^) 2014-2021 Gregor A. Cieslak. ECHO, ECHO,License GPLv3+: GNU GPL version 3 or later ^<https://gnu.org/licenses/gpl.html^>. ECHO,This is free software: you are free to change and redistribute it. -
Shoozza revised this gist
Sep 22, 2021 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -83,10 +83,12 @@ IF "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" GOTO:SETDEFAULTSOCK CALL:LOG "[INFO] Checking preexisting ssh-agent sock file" GOTO:CHECKSOCKFILE :SETDEFAULTSOCK SET "SSH_AUTH_SOCK=%DEFAULT_AUTH_SOCK%" CALL:LOG "[INFO] Checking default ssh-agent sock file" :CHECKSOCKFILE REM Check if path to socket file is available FOR /f "tokens=*" %%I IN ('cygpath -w "%SSH_AUTH_SOCK%"') DO SET "VAR=%%I" @@ -95,8 +97,6 @@ IF "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" ( ) ELSE ( IF NOT EXIST "%VAR%" GOTO:SETDEFAULTSOCK ) CALL:LOG "[INFO] Found ssh-agent sock file" REM Check if an ssh-agent is running @@ -232,8 +232,7 @@ CALL:CHECKPROGEXISTS ssh-agent SET "KEYS=" SET /A "KEYCOUNT=0" FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa" "%HOME%\.ssh\*_dsa" "%HOME%\.ssh\*_ecdsa" "%HOME%\.ssh\*_ecdsa_sk" "%HOME%\.ssh\*_ed25519" "%HOME%\.ssh\*_ed25519_sk" 2^> NUL') DO CALL:CHECKKEY %%I IF NOT %KEYCOUNT% == 0 ( IF %KEYCOUNT% == 1 ( ECHO,[OK] found %KEYCOUNT% ssh key @@ -281,4 +280,4 @@ GOTO:EOF REM REM Functions end REM -
Shoozza revised this gist
Sep 22, 2021 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ SETLOCAL GOTO:MAIN REM REM Info functions start REM @@ -162,7 +161,6 @@ IF NOT "%KEYS%" == "" ( CALL:LOG "[INFO] All ssh keys already added" ) CALL:LOG "===========================================" CALL:LOG "[INFO] Done" -
Shoozza revised this gist
Sep 22, 2021 . 1 changed file with 263 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,46 +1,286 @@ @ECHO OFF SETLOCAL GOTO:MAIN REM REM Info functions start REM REM Display version and copyright information :VERSION ECHO,Agent 1.0.0.0 (ssh-agent script for MSYS2) ECHO, ECHO,Copyright (C^) 2017-2021 Gregor A. Cieslak. ECHO, ECHO,License GPLv3+: GNU GPL version 3 or later ^<https://gnu.org/licenses/gpl.html^>. ECHO,This is free software: you are free to change and redistribute it. ECHO,There is NO WARRANTY, to the extent permitted by law. GOTO:EOF REM Display usage information :USAGE ECHO,Adds missing ssh-keys to an instance of ssh-agent. ECHO,Starts a new instance if ssh-agent is not running or sock file is invalid. ECHO,Use with MSYS2 command line tools (https://www.msys2.org/^). ECHO, ECHO,Requirements: ECHO, %%HOME%%\.ssh folder with ssh keys in any of the following formats: ECHO, rsa, dsa, ecdsa, ecdsa_sk, ed25519, ed25519_sk ECHO, MSYS2 installation with following command line tools: ECHO, cygpath, rm, sed, awk, grep, ps, ssh-add, ssh-keygen, ssh-agent ECHO, ECHO,Usage: agent [OPTION] ECHO, ECHO,OPTION: ECHO, -c, --check check requirements ECHO, -h, --help display this help text ECHO, -k, --kill kill all ssh-agent processes ECHO, -v, --verbose verbose mode ECHO, -V --version display version GOTO:EOF REM REM Info functions end REM REM REM Entry point start REM :MAIN REM Parse command line arguments IF NOT "%~2" == "" GOTO:USAGE IF "%~1" == "-h" GOTO:USAGE IF "%~1" == "--help" GOTO:USAGE IF "%~1" == "-k" GOTO:KILLSSHAGENT IF "%~1" == "--kill" GOTO:KILLSSHAGENT IF "%~1" == "-c" GOTO:CHECKREQUIREMENTS IF "%~1" == "--check" GOTO:CHECKREQUIREMENTS IF "%~1" == "-V" GOTO:VERSION IF "%~1" == "--version" GOTO:VERSION REM Check for verbose output SET "VERBOSE=" IF "%~1" == "-v" ( SET "VERBOSE=true" ) ELSE IF "%~1" == "--verbose" ( SET "VERBOSE=true" ) ELSE IF NOT "%~1" == "" GOTO:USAGE CALL:LOG "[INFO] Adding missing ssh keys:" CALL:LOG "-------------------------------------------" REM Set default sock file if missing SET "DEFAULT_AUTH_SOCK=/tmp/ssh-agent.sock" IF "%SSH_AUTH_SOCK%" == "" GOTO:SETDEFAULTSOCK IF "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" GOTO:SETDEFAULTSOCK CALL:LOG "[INFO] Checking preexisting ssh-agent sock file" GOTO:CHECKSOCKFILE :SETDEFAULTSOCK SET "SSH_AUTH_SOCK=%DEFAULT_AUTH_SOCK%" CALL:LOG "[INFO] Checking default ssh-agent sock file" :CHECKSOCKFILE REM Check if path to socket file is available FOR /f "tokens=*" %%I IN ('cygpath -w "%SSH_AUTH_SOCK%"') DO SET "VAR=%%I" IF "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" ( IF NOT EXIST "%VAR%" GOTO:RUNAGENT ) ELSE ( IF NOT EXIST "%VAR%" GOTO:SETDEFAULTSOCK ) CALL:LOG "[INFO] Found ssh-agent sock file" 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 "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" ( IF "%VAR%" == "" GOTO:RUNAGENT ) ELSE ( IF "%VAR%" == "" GOTO:CHECKDEFAULTSOCK ) CALL:LOG "[INFO] Found ssh-agent process" REM Check if socket file is valid ssh-add -l 1> NUL 2>&1 IF ERRORLEVEL 1 ( CALL:LOG "[INFO] Failed to validate sock file" IF "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" ( GOTO:RUNAGENT ) ELSE ( GOTO:SETDEFAULTSOCK ) ) CALL:LOG "[INFO] Found valid sock file" GOTO:ADDKEYS :RUNAGENT CALL:LOG "[INFO] Starting new ssh-agent" REM Don't delete %%SSH_AUTH_SOCK%% - could be set to a dangerous path IF NOT "%SSH_AUTH_SOCK%" == "%DEFAULT_AUTH_SOCK%" GOTO:SKIPDELETESOCK REM Remove old default socket file if available FOR /f "tokens=*" %%I IN ('cygpath -w "%DEFAULT_AUTH_SOCK%"') DO SET "VAR=%%I" IF EXIST "%VAR%" rm -f -- "%DEFAULT_AUTH_SOCK%" SET "SSH_AUTH_SOCK=%DEFAULT_AUTH_SOCK%" :SKIPDELETESOCK REM Run ssh-agent and save (last) PID in VAR SET "VAR=" FOR /f "tokens=*" %%J IN ('ssh-agent -a "%SSH_AUTH_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_AGENT_PID=%VAR%" REM Check if ssh keys are known SET "KEYS=" SET /A "KEYCOUNT=0" FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa" "%HOME%\.ssh\*_dsa" "%HOME%\.ssh\*_ecdsa" "%HOME%\.ssh\*_ecdsa_sk" "%HOME%\.ssh\*_ed25519" "%HOME%\.ssh\*_ed25519_sk" 2^> NUL') DO CALL:CHECKKEY %%I REM Print ssh key count IF %KEYCOUNT% == 1 ( CALL:LOG "[INFO] Found %KEYCOUNT% ssh key" ) ELSE ( CALL:LOG "[INFO] Found %KEYCOUNT% ssh keys" ) REM Add all missing ssh keys IF NOT "%KEYS%" == "" ( CALL:LOG "[INFO] Adding ssh keys" ssh-add %KEYS% ) ELSE ( CALL:LOG "[INFO] All ssh keys already added" ) CALL:LOG "===========================================" CALL:LOG "[INFO] Done" ENDLOCAL & SET "SSH_AGENT_PID=%SSH_AGENT_PID%" & SET "SSH_AUTH_SOCK=%SSH_AUTH_SOCK%" GOTO:EOF REM REM Entry point end REM REM REM Functions start REM REM Check if ssh key has to be added :CHECKKEY SET /A "KEYCOUNT=KEYCOUNT+1" SET "FINGERPRINT=" FOR /f "tokens=*" %%J IN ('ssh-keygen -lf "%HOME%\.ssh\%1" 2^>nul ^| awk "{print $2}"') DO SET "FINGERPRINT=%%J" IF "%FINGERPRINT%" == "" GOTO:EOF SET "VAR=" FOR /f "tokens=*" %%J IN ('ssh-add -l 2^>nul ^| awk "{print $2}" ^| grep "%FINGERPRINT%"') DO SET "VAR=%%J" IF "%VAR%" == "" SET "KEYS='%HOME%\.ssh\%1' %KEYS%" GOTO:EOF REM Output text in verbose mode :LOG IF "%VERBOSE%" == "" GOTO:EOF ECHO,%~1 GOTO:EOF REM Check if required command line tools, folders and ssh keys are available :CHECKREQUIREMENTS SET "FAILED=" ECHO,[INFO] Checking requirements... ECHO,------------------------------------------- CALL:CHECKPROGEXISTS cygpath IF NOT "%FAILED%"=="" GOTO:SKIPTMPPATHCHECK FOR /f "tokens=*" %%I IN ('cygpath -w /tmp') DO SET "TMPPATH=%%I" IF EXIST "%TMPPATH%" ( ECHO,[OK] found /tmp folder ) ELSE ( ECHO,[FAIL] missing /tmp folder SET "FAILED=true" ) :SKIPTMPPATHCHECK IF EXIST "%HOME%\.ssh\" ( ECHO,[OK] found %%HOME%%\.ssh folder ) ELSE ( ECHO,[FAIL] missing %%HOME%%\.ssh folder SET "FAILED=true" ) CALL:CHECKPROGEXISTS rm CALL:CHECKPROGEXISTS sed CALL:CHECKPROGEXISTS awk CALL:CHECKPROGEXISTS grep CALL:CHECKPROGEXISTS ps CALL:CHECKPROGEXISTS ssh-add CALL:CHECKPROGEXISTS ssh-keygen CALL:CHECKPROGEXISTS ssh-agent SET "KEYS=" SET /A "KEYCOUNT=0" FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa" 2^> NUL') DO CALL:CHECKKEY %%I FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_ed25519" 2^> NUL') DO CALL:CHECKKEY %%I IF NOT %KEYCOUNT% == 0 ( IF %KEYCOUNT% == 1 ( ECHO,[OK] found %KEYCOUNT% ssh key ) ELSE ( ECHO,[OK] found %KEYCOUNT% ssh keys ) ) ELSE ( ECHO,[FAIL] missing ssh keys SET "FAILED=true" ) ECHO,=========================================== IF "%FAILED%"=="" ( ECHO,[OK] Success! All requirements are met ) ELSE ( ECHO,[FAIL] Failure! Some requirements are not met! ) GOTO:EOF REM Check if programm is in path :CHECKPROGEXISTS WHERE /q %1 IF ERRORLEVEL 1 ( ECHO,[FAIL] missing %1 in PATH SET "FAILED=true" ) ELSE ( ECHO,[OK] found %1 ) GOTO:EOF REM Kills all ssh-agent processes :KILLSSHAGENT SET /A "KILLCOUNT=0" FOR /f "tokens=*" %%I IN ('ps ^| grep ssh-agent ^| awk "{print $1}"') DO ( IF NOT "%%I" == "" ( KILL %%I SET /A "KILLCOUNT=KILLCOUNT+1" ) ) ECHO,[INFO] killed %KILLCOUNT% ssh-agent processes GOTO:EOF REM REM Functions end REM -
Shoozza revised this gist
Dec 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ REM Check if ssh key has to be added :CHECKKEY SET VAR= 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 -
Shoozza revised this gist
Nov 16, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ REM Functions REM Check if ssh key has to be added :CHECKKEY SET VAR= FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep "%1"') DO SET VAR=%%J IF "%VAR%" == "" SET KEYS=%KEYS% "%HOME%\.ssh\%1" GOTO:EOF -
Shoozza revised this gist
Nov 14, 2014 . 1 changed file with 21 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,37 @@ @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 -
Shoozza revised this gist
Oct 29, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent') DO SET VAR=%%I IF NOT "%VAR%" == "" GOTO:GETPID REM Remove old agent socket rm -f /tmp/ssh-agent.sock REM Start ssh-agent ssh-agent -a /tmp/ssh-agent.sock > NUL -
Shoozza revised this gist
Oct 29, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,9 @@ SET VAR= FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent') DO SET VAR=%%I IF NOT "%VAR%" == "" GOTO:GETPID REM Remove old agent socket rm /tmp/ssh-agent.sock REM Start ssh-agent ssh-agent -a /tmp/ssh-agent.sock > NUL -
Shoozza revised this gist
Oct 28, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent') DO SET VAR=%%I IF NOT "%VAR%" == "" GOTO:GETPID REM Start ssh-agent ssh-agent -a /tmp/ssh-agent.sock > NUL :GETPID REM Get SSH_AUTH_SOCK and SSH_AGENT_PID from running ssh-agent -
Shoozza revised this gist
Oct 28, 2014 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,7 @@ FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent') DO SET VAR=%%I IF NOT "%VAR%" == "" GOTO:GETPID REM Start ssh-agent ssh-agent -a /tmp/ssh-agent.sock :GETPID REM Get SSH_AUTH_SOCK and SSH_AGENT_PID from running ssh-agent -
Shoozza revised this gist
Oct 28, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,10 @@ REM ssh-agent already running? SET VAR= FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent') DO SET VAR=%%I IF NOT "%VAR%" == "" GOTO:GETPID REM Start ssh-agent ssh-agent -a /tmp/ssh-agent.sock | grep -v echo | sed -e "s/^/@set /" | sed -e "s/;.*$//" - > call.cmd CALL call.cmd DEL call.cmd @@ -14,7 +14,7 @@ GOTO:CHECKS :GETPID REM Get SSH_AUTH_SOCK and SSH_AGENT_PID from running ssh-agent SET VAR= FOR /f "tokens=*" %%I IN ('ps x ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') DO SET VAR=%%I SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock SET SSH_AGENT_PID=%VAR% @@ -32,7 +32,7 @@ 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 -
Shoozza created this gist
Oct 28, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ @ECHO OFF REM ssh-agent already running? SET VAR= for /f "tokens=*" %%i in ('ps x ^| grep ssh-agent') do set VAR=%%i IF NOT "%VAR%" == "" GOTO:GETPID REM start ssh-agent ssh-agent -a /tmp/ssh-agent.sock | grep -v echo | sed -e "s/^/@set /" | sed -e "s/;.*$//" - > call.cmd CALL call.cmd DEL call.cmd GOTO:CHECKS :GETPID REM Get SSH_AUTH_SOCK and SSH_AGENT_PID from running ssh-agent SET VAR= for /f "tokens=*" %%i in ('ps x ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') do set VAR=%%i SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock SET SSH_AGENT_PID=%VAR% :CHECKS 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