Skip to content

Instantly share code, notes, and snippets.

@navono
Created September 28, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navono/d87389881a5fe5f76ea53d6ec094ea70 to your computer and use it in GitHub Desktop.
Save navono/d87389881a5fe5f76ea53d6ec094ea70 to your computer and use it in GitHub Desktop.
setup env with bat
@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions
set dir=%~dp0
set ligGit2Path=%dir%third_party\libgit2
set pkgConfigPath=%dir%third_party\pkg-config
set zlibPath=%dir%third_party\zlib
set KEY_NAME="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
set LIBGIT2_HOME=LIBGIT2_HOME
set PKG_CONFIG_PATH=PKG_CONFIG_PATH
set ZLIB_HOME=ZLIB_HOME
set bin=bin
set include=include
set lib=lib
call :checkEnv %KEY_NAME% %LIBGIT2_HOME% %ligGit2Path% "true"
call :checkEnv %KEY_NAME% %PKG_CONFIG_PATH% %pkgConfigPath% "false"
call :checkEnv %KEY_NAME% %ZLIB_HOME% %zlibPath% "true"
exit /b %errorlevel%
:checkEnv
for /F "usebackq skip=2 tokens=1-4" %%A in (`reg query %1 /v %2 2^>nul`) do (
set valueName=%%A
set valueType=%%B
set valueValue=%%C %%D
)
if defined valueName (
REM @echo Value name = %valueName%
REM @echo Value type = %valueType%
REM @echo Value value = %valueValue%
echo %2 already setup. %valueValue%
) else (
@echo %1 %2 not found, setup
reg add %1 /v %2 /d %3 /f
if "%4"=="true" setx path "%path%;%3\%bin%;%3\%include%;%3\%lib%"
)
exit /b %errorlevel%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment