From 4bf60ee6a5a819bf55422567a514d574eebf81e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Wed, 9 Sep 2020 17:11:00 +0200 Subject: [PATCH 01/11] Add a run wrapper for windows --- .editorconfig | 3 ++ plugin.yaml | 6 ++-- scripts/drivers/sops.sh | 12 ++++--- wrapper/run.cmd | 6 ++++ wrapper/sh.cmd | 70 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 8 deletions(-) create mode 100755 wrapper/run.cmd create mode 100644 wrapper/sh.cmd diff --git a/.editorconfig b/.editorconfig index bc7badc6..2872125f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,9 @@ root = true end_of_line = lf insert_final_newline = true +[*.cmd] +end_of_line = crlf + [*.{sh,bash,bats}] indent_style = space indent_size = 4 diff --git a/plugin.yaml b/plugin.yaml index 55fee033..fe0290df 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -5,10 +5,10 @@ description: |- This plugin provides secrets values encryption for Helm charts secure storing useTunnel: false hooks: - install: "$HELM_PLUGIN_DIR/scripts/install.sh" - update: "$HELM_PLUGIN_DIR/scripts/install.sh" + install: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" + update: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" command: "$HELM_PLUGIN_DIR/scripts/run.sh" platformCommand: - os: windows - command: "sh $HELM_PLUGIN_DIR/scripts/run.sh" + command: "$HELM_PLUGIN_DIR/wrapper/sh.cmd $HELM_PLUGIN_DIR/scripts/run.sh" diff --git a/scripts/drivers/sops.sh b/scripts/drivers/sops.sh index 6522d2d1..6a1bc619 100644 --- a/scripts/drivers/sops.sh +++ b/scripts/drivers/sops.sh @@ -1,5 +1,7 @@ #!/usr/bin/env sh +_SOPS="${HELM_SECRETS_SOPS_BIN:-sops}" + driver_is_file_encrypted() { input="${1}" @@ -12,9 +14,9 @@ driver_encrypt_file() { output="${3}" if [ "${input}" = "${output}" ]; then - sops --encrypt --input-type "${type}" --output-type "${type}" --in-place "${input}" + $_SOPS --encrypt --input-type "${type}" --output-type "${type}" --in-place "${input}" else - sops --encrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}" + $_SOPS --encrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}" fi } @@ -25,9 +27,9 @@ driver_decrypt_file() { output="${3:-}" if [ "${output}" != "" ]; then - sops --decrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}" + $_SOPS --decrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}" else - sops --decrypt --input-type "${type}" --output-type "${type}" "${input}" + $_SOPS --decrypt --input-type "${type}" --output-type "${type}" "${input}" fi } @@ -35,5 +37,5 @@ driver_edit_file() { type="${1}" input="${2}" - sops --input-type yaml --output-type yaml "${input}" + $_SOPS --input-type yaml --output-type yaml "${input}" } diff --git a/wrapper/run.cmd b/wrapper/run.cmd new file mode 100755 index 00000000..c9c2d072 --- /dev/null +++ b/wrapper/run.cmd @@ -0,0 +1,6 @@ +:; exec "$@" # +:; exit $? # + +@echo off +%HELM_PLUGIN_DIR%\wrapper\sh.sh %* +exit /b diff --git a/wrapper/sh.cmd b/wrapper/sh.cmd new file mode 100644 index 00000000..c45dba91 --- /dev/null +++ b/wrapper/sh.cmd @@ -0,0 +1,70 @@ +@setlocal enableextensions enabledelayedexpansion +@echo off + +:: If HELM_SECRETS_WINDOWS_SHELL is provided, use it. +if "%HELM_SECRETS_WINDOWS_SHELL%"!="" GOTO :ENVSH + +:: check for cygwin installation or git for windows is inside %PATH% +sh -c exit >nul 2>&1 + +IF %ERRORLEVEL% EQU 0 GOTO :SH + +:: check for git-bash +C:\Program^ Files\Git\bin\bash.exe -c exit >nul 2>&1 + +IF %ERRORLEVEL% EQU 0 GOTO :GITBASH + +:: check for git-bash (32-bit) +C:\Program^ Files^ (x86)\Git\bin\bash.exe -c exit >nul 2>&1 + +IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32 + +:: check for wsl +wsl sh -c exit >nul 2>&1 + +IF %ERRORLEVEL% EQU 0 GOTO :WSL + +GOTO :NOSHELL + +:ENVSH +%HELM_SECRETS_WINDOWS_SHELL% "%*" +GOTO :EOF + +:SH +sh "'%HELM_PLUGIN_DIR%\scripts\run.sh' %*" +GOTO :EOF + +:GITBASH +C:\Program^ Files\Git\bin\bash.exe "%*" +GOTO :EOF + +:GITBASH32 +C:\Program^ Files^ (x86)\Git\bin\bash.exe "%*" +GOTO :EOF + +:WSL +:: Use WSL, but convert all paths (script + arguments) to wsl paths +SET ARGS= + +:: Loop through all parameters - https://stackoverflow.com/a/34019557/8087167 +:LOOP +if "%1"=="" goto ENDLOOP + +:: CMD output to variable - https://stackoverflow.com/a/6362922/8087167 +FOR /F "tokens=* USEBACKQ" %%F IN (`wsl wslpath "%1"`) DO ( + SET WSLPATH=%%F +) +SET ARGS=%ARGS% %WSLPATH% + +shift +goto LOOP +:ENDLOOP + +wsl bash -x -c "%ARGS%" +GOTO :EOF + +:NOSHELL +:: If no *nix shell found, raise an error. +echo helm-secrets needs a unix shell. Please install WSL, cygwin or Git for Windows. +exit /B 1 +GOTO :EOF From 5392e293b20f6677ff8d2430268f8b71e22eabef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 02:07:06 +0200 Subject: [PATCH 02/11] Update plugin.yaml --- plugin.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugin.yaml b/plugin.yaml index fe0290df..efce7b2c 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "secrets" -version: "3.4.0-master" +version: "3.3.4" usage: "Secrets encryption in Helm for Git storing" description: |- This plugin provides secrets values encryption for Helm charts secure storing @@ -8,7 +8,4 @@ hooks: install: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" update: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" -command: "$HELM_PLUGIN_DIR/scripts/run.sh" -platformCommand: - - os: windows - command: "$HELM_PLUGIN_DIR/wrapper/sh.cmd $HELM_PLUGIN_DIR/scripts/run.sh" +command: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh" From 8f1d4006041a7db3ddd058b99e6b930513be13f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 02:07:30 +0200 Subject: [PATCH 03/11] Update run.cmd --- wrapper/run.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper/run.cmd b/wrapper/run.cmd index c9c2d072..1678465d 100755 --- a/wrapper/run.cmd +++ b/wrapper/run.cmd @@ -2,5 +2,5 @@ :; exit $? # @echo off -%HELM_PLUGIN_DIR%\wrapper\sh.sh %* +%HELM_PLUGIN_DIR%\wrapper\sh.cmd %* exit /b From 8f88cf508c05974dee7324ee10cb2e544662d340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 02:08:09 +0200 Subject: [PATCH 04/11] Update sh.cmd --- wrapper/sh.cmd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wrapper/sh.cmd b/wrapper/sh.cmd index c45dba91..b5de7d32 100644 --- a/wrapper/sh.cmd +++ b/wrapper/sh.cmd @@ -1,21 +1,21 @@ @setlocal enableextensions enabledelayedexpansion -@echo off +@echo on :: If HELM_SECRETS_WINDOWS_SHELL is provided, use it. -if "%HELM_SECRETS_WINDOWS_SHELL%"!="" GOTO :ENVSH +if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH :: check for cygwin installation or git for windows is inside %PATH% -sh -c exit >nul 2>&1 +"sh" -c exit >nul 2>&1 IF %ERRORLEVEL% EQU 0 GOTO :SH :: check for git-bash -C:\Program^ Files\Git\bin\bash.exe -c exit >nul 2>&1 +"%programfiles%\Git\bin\bash.exe" -c exit >nul 2>&1 IF %ERRORLEVEL% EQU 0 GOTO :GITBASH :: check for git-bash (32-bit) -C:\Program^ Files^ (x86)\Git\bin\bash.exe -c exit >nul 2>&1 +"%programfiles(x86)%\Git\bin\bash.exe" -c exit >nul 2>&1 IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32 @@ -27,19 +27,19 @@ IF %ERRORLEVEL% EQU 0 GOTO :WSL GOTO :NOSHELL :ENVSH -%HELM_SECRETS_WINDOWS_SHELL% "%*" +"%HELM_SECRETS_WINDOWS_SHELL%" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :SH -sh "'%HELM_PLUGIN_DIR%\scripts\run.sh' %*" +"sh" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :GITBASH -C:\Program^ Files\Git\bin\bash.exe "%*" +"%programfiles%\Git\bin\bash.exe" -x "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :GITBASH32 -C:\Program^ Files^ (x86)\Git\bin\bash.exe "%*" +"%programfiles(x86)%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :WSL From 8711a69a93b3ee044f41ebbe015d820b4e0f5ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 02:31:11 +0200 Subject: [PATCH 05/11] fix typos --- plugin.yaml | 11 +++++++---- scripts/run.sh | 5 +++++ {wrapper => scripts/wrapper}/run.cmd | 0 {wrapper => scripts/wrapper}/sh.cmd | 8 ++++---- 4 files changed, 16 insertions(+), 8 deletions(-) rename {wrapper => scripts/wrapper}/run.cmd (100%) rename {wrapper => scripts/wrapper}/sh.cmd (96%) diff --git a/plugin.yaml b/plugin.yaml index efce7b2c..cf5a451d 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,11 +1,14 @@ name: "secrets" -version: "3.3.4" +version: "3.4.0-master" usage: "Secrets encryption in Helm for Git storing" description: |- This plugin provides secrets values encryption for Helm charts secure storing useTunnel: false hooks: - install: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" - update: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" + install: "$HELM_PLUGIN_DIR/scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" + update: "$HELM_PLUGIN_DIR/scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh" -command: "$HELM_PLUGIN_DIR/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh" +command: "$HELM_PLUGIN_DIR/scripts/run.sh" +platformCommand: + - os: windows + command: "cmd /c $HELM_PLUGIN_DIR/wrapper/sh.cmd $HELM_PLUGIN_DIR/scripts/run.sh" diff --git a/scripts/run.sh b/scripts/run.sh index 16be25cc..39fc56d5 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -80,6 +80,11 @@ load_secret_driver() { load_secret_driver "$SECRET_DRIVER" +# ./run.sh vs bash run.sh +if [ "$(basename "$0")" != "run.sh" ]; then + shift +fi + while true; do case "${1:-}" in enc) diff --git a/wrapper/run.cmd b/scripts/wrapper/run.cmd similarity index 100% rename from wrapper/run.cmd rename to scripts/wrapper/run.cmd diff --git a/wrapper/sh.cmd b/scripts/wrapper/sh.cmd similarity index 96% rename from wrapper/sh.cmd rename to scripts/wrapper/sh.cmd index b5de7d32..2285823e 100644 --- a/wrapper/sh.cmd +++ b/scripts/wrapper/sh.cmd @@ -1,5 +1,5 @@ @setlocal enableextensions enabledelayedexpansion -@echo on +@echo off :: If HELM_SECRETS_WINDOWS_SHELL is provided, use it. if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH @@ -22,7 +22,7 @@ IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32 :: check for wsl wsl sh -c exit >nul 2>&1 -IF %ERRORLEVEL% EQU 0 GOTO :WSL +IF %ERRORLEVEL% EQU 0 GOTO :WSL GOTO :NOSHELL @@ -45,7 +45,7 @@ GOTO :EOF :WSL :: Use WSL, but convert all paths (script + arguments) to wsl paths SET ARGS= - + :: Loop through all parameters - https://stackoverflow.com/a/34019557/8087167 :LOOP if "%1"=="" goto ENDLOOP @@ -59,7 +59,7 @@ SET ARGS=%ARGS% %WSLPATH% shift goto LOOP :ENDLOOP - + wsl bash -x -c "%ARGS%" GOTO :EOF From ccf6e25571158f0ff0bdc603f1a3d5287837e6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 13:48:25 +0200 Subject: [PATCH 06/11] Update sh.cmd --- scripts/wrapper/sh.cmd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/wrapper/sh.cmd b/scripts/wrapper/sh.cmd index 2285823e..92b6e464 100644 --- a/scripts/wrapper/sh.cmd +++ b/scripts/wrapper/sh.cmd @@ -27,6 +27,8 @@ IF %ERRORLEVEL% EQU 0 GOTO :WSL GOTO :NOSHELL :ENVSH +if "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL + "%HELM_SECRETS_WINDOWS_SHELL%" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF @@ -35,7 +37,7 @@ GOTO :EOF GOTO :EOF :GITBASH -"%programfiles%\Git\bin\bash.exe" -x "%HELM_PLUGIN_DIR%\scripts\run.sh" %* +"%programfiles%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :GITBASH32 @@ -60,7 +62,7 @@ shift goto LOOP :ENDLOOP -wsl bash -x -c "%ARGS%" +wsl bash %ARGS% GOTO :EOF :NOSHELL From f8a14aec34c9b52cb0ba4b07c9279829f7bfb06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 13:48:41 +0200 Subject: [PATCH 07/11] Update run.sh --- scripts/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run.sh b/scripts/run.sh index 39fc56d5..edc80787 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -81,7 +81,7 @@ load_secret_driver() { load_secret_driver "$SECRET_DRIVER" # ./run.sh vs bash run.sh -if [ "$(basename "$0")" != "run.sh" ]; then +if [ "$(basename "$1")" == "run.sh" ]; then shift fi From aa7ad67759b964d2c431602804a0a7fcea2264c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 13:50:05 +0200 Subject: [PATCH 08/11] Update run.sh --- scripts/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run.sh b/scripts/run.sh index edc80787..51cd753e 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -81,7 +81,7 @@ load_secret_driver() { load_secret_driver "$SECRET_DRIVER" # ./run.sh vs bash run.sh -if [ "$(basename "$1")" == "run.sh" ]; then +if [ "$(basename "$1")" = "run.sh" ]; then shift fi From c0a0dede68d47da40e34d429cbefa87b902cf3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 16:21:53 +0200 Subject: [PATCH 09/11] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0a18591..0fe2e1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Allow override sops version on installation +## [Unreleased] + +### Added +- Better lookup for unix shells on Windows (https://github.com/jkroepke/helm-secrets/pull/42) + ## [3.3.4] - 2020-09-09 ### Added From fe0b1926d44089b07ea1446b882c1b30473656ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 16:38:00 +0200 Subject: [PATCH 10/11] fix typos --- scripts/wrapper/run.cmd | 3 +++ scripts/wrapper/sh.cmd | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/scripts/wrapper/run.cmd b/scripts/wrapper/run.cmd index 1678465d..999102dc 100755 --- a/scripts/wrapper/run.cmd +++ b/scripts/wrapper/run.cmd @@ -1,6 +1,9 @@ :; exec "$@" # :; exit $? # +:: .bat bash hybrid script +:: https://stackoverflow.com/a/17623721 + @echo off %HELM_PLUGIN_DIR%\wrapper\sh.cmd %* exit /b diff --git a/scripts/wrapper/sh.cmd b/scripts/wrapper/sh.cmd index 92b6e464..49b40900 100644 --- a/scripts/wrapper/sh.cmd +++ b/scripts/wrapper/sh.cmd @@ -9,15 +9,11 @@ if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH IF %ERRORLEVEL% EQU 0 GOTO :SH -:: check for git-bash -"%programfiles%\Git\bin\bash.exe" -c exit >nul 2>&1 - -IF %ERRORLEVEL% EQU 0 GOTO :GITBASH - -:: check for git-bash (32-bit) -"%programfiles(x86)%\Git\bin\bash.exe" -c exit >nul 2>&1 +:: check git for windows +where.exe git.exe >nul 2>&1 -IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32 +IF %ERRORLEVEL% EQU 0 GOTO :CHECK_GITBASH +:RETURN_GITBASH :: check for wsl wsl sh -c exit >nul 2>&1 @@ -27,7 +23,7 @@ IF %ERRORLEVEL% EQU 0 GOTO :WSL GOTO :NOSHELL :ENVSH -if "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL +IF "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL "%HELM_SECRETS_WINDOWS_SHELL%" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF @@ -36,12 +32,22 @@ GOTO :EOF "sh" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF -:GITBASH -"%programfiles%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* -GOTO :EOF +:CHECK_GITBASH +:: CMD output to variable - https://stackoverflow.com/a/6362922/8087167 +FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe git.exe`) DO ( + SET GIT_FILEPATH=%%F +) + +IF "%GIT_FILEPATH%"=="" GOTO :RETURN_GITBASH + +FOR %%F in ("%GIT_FILEPATH%") DO SET GIT_DIRPATH=%%~dpF + +:: check for git-bash +"%GIT_DIRPATH%\..\bin\bash.exe" -c exit >nul 2>&1 + +IF %ERRORLEVEL% EQU 0 GOTO :RETURN_GITBASH -:GITBASH32 -"%programfiles(x86)%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* +"%GIT_DIRPATH%\..\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF :WSL From 864409445f0840485be9d19cff94b5ff73fb5334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 12 Sep 2020 20:52:04 +0200 Subject: [PATCH 11/11] Update sh.cmd --- scripts/wrapper/sh.cmd | 55 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/scripts/wrapper/sh.cmd b/scripts/wrapper/sh.cmd index 49b40900..99132722 100644 --- a/scripts/wrapper/sh.cmd +++ b/scripts/wrapper/sh.cmd @@ -4,35 +4,68 @@ :: If HELM_SECRETS_WINDOWS_SHELL is provided, use it. if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH + :: check for cygwin installation or git for windows is inside %PATH% "sh" -c exit >nul 2>&1 - IF %ERRORLEVEL% EQU 0 GOTO :SH + +:: check for git-bash +"%programfiles%\Git\bin\bash.exe" -c exit >nul 2>&1 +IF %ERRORLEVEL% EQU 0 GOTO :GITBASH + + +:: check for git-bash (32-bit) +"%programfiles(x86)%\Git\bin\bash.exe" -c exit >nul 2>&1 +IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32 + + :: check git for windows where.exe git.exe >nul 2>&1 - -IF %ERRORLEVEL% EQU 0 GOTO :CHECK_GITBASH +IF %ERRORLEVEL% EQU 0 GOTO :GITBASH_CUSTOM :RETURN_GITBASH + :: check for wsl wsl sh -c exit >nul 2>&1 - IF %ERRORLEVEL% EQU 0 GOTO :WSL GOTO :NOSHELL + + :ENVSH IF "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL "%HELM_SECRETS_WINDOWS_SHELL%" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF + + + :SH "sh" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF -:CHECK_GITBASH + + + +:GITBASH +"%programfiles%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* +GOTO :EOF + + + + + +:GITBASH32 +"%programfiles(x86)%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* +GOTO :EOF + + + + +:GITBASH_CUSTOM :: CMD output to variable - https://stackoverflow.com/a/6362922/8087167 FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe git.exe`) DO ( SET GIT_FILEPATH=%%F @@ -43,13 +76,16 @@ IF "%GIT_FILEPATH%"=="" GOTO :RETURN_GITBASH FOR %%F in ("%GIT_FILEPATH%") DO SET GIT_DIRPATH=%%~dpF :: check for git-bash -"%GIT_DIRPATH%\..\bin\bash.exe" -c exit >nul 2>&1 +"%GIT_DIRPATH%..\bin\bash.exe" -c exit >nul 2>&1 -IF %ERRORLEVEL% EQU 0 GOTO :RETURN_GITBASH +IF %ERRORLEVEL% NEQ 0 GOTO :RETURN_GITBASH -"%GIT_DIRPATH%\..\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* +"%GIT_DIRPATH%..\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %* GOTO :EOF + + + :WSL :: Use WSL, but convert all paths (script + arguments) to wsl paths SET ARGS= @@ -71,6 +107,9 @@ goto LOOP wsl bash %ARGS% GOTO :EOF + + + :NOSHELL :: If no *nix shell found, raise an error. echo helm-secrets needs a unix shell. Please install WSL, cygwin or Git for Windows.