codekingpro/portable-devtools
115k
1@REM Do not use "echo off" to not affect any child calls.2 3@REM Enable extensions, the `verify` call is a trick from the setlocal help4@VERIFY other 2>nul5@SETLOCAL EnableDelayedExpansion6@IF ERRORLEVEL 1 (7 @ECHO Unable to enable extensions8 @GOTO failure9)10 11@REM Start the ssh-agent if needed by git12@FOR %%i IN ("git.exe") DO @SET GIT=%%~$PATH:i13@IF EXIST "%GIT%" @(14 @REM Get the ssh-agent executable15 @FOR %%i IN ("ssh-agent.exe") DO @SET SSH_AGENT=%%~$PATH:i16 @IF NOT EXIST "%SSH_AGENT%" @(17 @FOR %%s IN ("%GIT%") DO @SET GIT_DIR=%%~dps18 @FOR %%s IN ("!GIT_DIR!") DO @SET GIT_DIR=!GIT_DIR:~0,-1!19 @FOR %%s IN ("!GIT_DIR!") DO @SET GIT_ROOT=%%~dps20 @FOR %%s IN ("!GIT_ROOT!") DO @SET GIT_ROOT=!GIT_ROOT:~0,-1!21 @FOR /D %%s in ("!GIT_ROOT!\usr\bin\ssh-agent.exe") DO @SET SSH_AGENT=%%~s22 @IF NOT EXIST "!SSH_AGENT!" @GOTO ssh-agent-done23 )24 @REM Get the ssh-add executable25 @FOR %%s IN ("!SSH_AGENT!") DO @SET BIN_DIR=%%~dps26 @FOR %%s in ("!BIN_DIR!") DO @SET BIN_DIR=!BIN_DIR:~0,-1!27 @FOR /D %%s in ("!BIN_DIR!\ssh-add.exe") DO @SET SSH_ADD=%%~s28 @IF NOT EXIST "!SSH_ADD!" @GOTO ssh-agent-done29 @REM Check if the agent is running30 @FOR /f "tokens=1-2" %%a IN ('tasklist /fi "imagename eq ssh-agent.exe"') DO @(31 @ECHO %%b | @FINDSTR /r /c:"[0-9][0-9]*" > NUL32 @IF "!ERRORLEVEL!" == "0" @(33 @SET SSH_AGENT_PID=%%b34 ) else @(35 @REM Unset in the case a user kills the agent while a session is open36 @REM needed to remove the old files and prevent a false message37 @SET SSH_AGENT_PID=38 )39 )40 @REM Connect up the current ssh-agent41 @IF [!SSH_AGENT_PID!] == [] @(42 @ECHO Removing old ssh-agent sockets43 @FOR %%s IN (%USERPROFILE%\.ssh\agent\s.*) DO @DEL /q "%%s" 2>nul44 ) ELSE @(45 @ECHO Found ssh-agent at !SSH_AGENT_PID!46 @FOR %%s IN (%USERPROFILE%\.ssh\agent\s.*) DO @(47 @SET SSH_AUTH_SOCK=%%s48 @SET SSH_AUTH_SOCK=!SSH_AUTH_SOCK:%USERPROFILE%=~!49 @SET SSH_AUTH_SOCK=!SSH_AUTH_SOCK:\=/!50 )51 @IF NOT [!SSH_AUTH_SOCK!] == [] @(52 @ECHO Found ssh-agent socket at !SSH_AUTH_SOCK!53 ) ELSE (54 @ECHO Failed to find ssh-agent socket55 @SET SSH_AGENT_PID=56 )57 )58 @REM See if we have the key59 @"!SSH_ADD!" -l 1>NUL 2>NUL60 @SET result=!ERRORLEVEL!61 @IF NOT !result! == 0 @(62 @IF !result! == 2 @(63 @ECHO | @SET /p=Starting ssh-agent:64 @FOR /f "tokens=1-2 delims==;" %%a IN ('"!SSH_AGENT!"') DO @(65 @IF NOT [%%b] == [] @SET %%a=%%b66 )67 @ECHO. done68 )69 @"!SSH_ADD!"70 @ECHO.71 )72)73 74:ssh-agent-done75:failure76 77@ENDLOCAL & @SET "SSH_AUTH_SOCK=%SSH_AUTH_SOCK%" ^78 & @SET "SSH_AGENT_PID=%SSH_AGENT_PID%"79 80@ECHO %cmdcmdline% | @FINDSTR /l "\"\"" >NUL81@IF NOT ERRORLEVEL 1 @(82 @CALL cmd %*83)84 