-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathrun.cmd
executable file
·293 lines (221 loc) · 7.04 KB
/
run.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
@echo off
SETLOCAL DisableDelayedExpansion
IF DEFINED HELM_DEBUG (
IF "%HELM_DEBUG%"=="1" (
@echo on
)
IF "%HELM_DEBUG%"=="true" (
@echo on
)
)
SET SCRIPT_DIR=%~dp0
SET SCRIPT_DIR=%SCRIPT_DIR:~0,-1%
FOR %%F in ("%SCRIPT_DIR%") do SET PLUGIN_DIR=%%~dpF
SET RUNSH=%PLUGIN_DIR%run.sh
IF NOT DEFINED SOPS_GPG_EXEC (
where /q gpg.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
FOR /F "tokens=* USEBACKQ" %%F IN (`where gpg.exe`) DO (
SET SOPS_GPG_EXEC=%%F
)
)
)
:: Some environment name it gpg2.exe
IF NOT DEFINED SOPS_GPG_EXEC (
where /q gpg2.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
FOR /F "tokens=* USEBACKQ" %%F IN (`where gpg.exe`) DO (
SET SOPS_GPG_EXEC=%%F
)
)
)
:: If HELM_SECRETS_WINDOWS_SHELL is provided, use it.
if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH
:: check for git-bash
"%programfiles%\Git\bin\bash.exe" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :GITBASH
:: check for bash via scoop
"%userprofile%\scoop\shims\bash.exe" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :SCOOP_BASH
:: check for sh via scoop
"%userprofile%\scoop\shims\sh.exe" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :SCOOP_SH
:: check for git-bash via scoop
"%userprofile%\scoop\shims\git-bash.exe" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :SCOOP_GITBASH
:: check for git-bash (32-bit)
"%programfiles(x86)%\Git\bin\bash.exe" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :GITBASH32
:: check git for windows
where.exe git.exe >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :GITBASH_CUSTOM
:RETURN_GITBASH
:: check for wsl
wsl bash -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :WSL
:: check for cygwin installation or git for windows is inside %PATH%
"sh" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :SH
:: check for cygwin installation or git for windows is inside %PATH%
"bash" -c exit >nul 2>&1
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 GOTO :BASH
GOTO :NOSHELL
:ENVSH
IF "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL
"%HELM_SECRETS_WINDOWS_SHELL%" "%RUNSH%" %*
exit /b %errorlevel%
:SH
"sh" "%RUNSH%" %*
exit /b %errorlevel%
:BASH
"bash" "%RUNSH%" %*
exit /b %errorlevel%
:GITBASH
"%programfiles%\Git\bin\bash.exe" "%RUNSH%" %*
exit /b %errorlevel%
:GITBASH32
"%programfiles(x86)%\Git\bin\bash.exe" "%RUNSH%" %*
exit /b %errorlevel%
:SCOOP_BASH
"%userprofile%\scoop\shims\bash.exe" "%RUNSH%" %*
exit /b %errorlevel%
:SCOOP_SH
"%userprofile%\scoop\shims\sh.exe" "%RUNSH%" %*
exit /b %errorlevel%
:SCOOP_GITBASH
"%userprofile%\scoop\shims\git-bash.exe" "%RUNSH%" %*
exit /b %errorlevel%
: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
)
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 1 GOTO :RETURN_GITBASH
"%GIT_DIRPATH%..\bin\bash.exe" "%RUNSH%" %*
exit /b %ERRORLEVEL%
:WSL
:: WSL needs .exe suffix for windows binary. Define path only if exists in windows PATH
IF NOT DEFINED HELM_BIN (
IF NOT DEFINED HELM_SECRETS_HELM_PATH (
where /q helm.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
SET HELM_SECRETS_HELM_PATH=helm.exe
)
)
)
IF NOT DEFINED HELM_SECRETS_SOPS_PATH (
where /q sops.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
SET HELM_SECRETS_SOPS_PATH=sops.exe
)
)
IF NOT DEFINED HELM_SECRETS_VALS_PATH (
where /q vals.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
SET HELM_SECRETS_VALS_PATH=vals.exe
)
)
IF NOT DEFINED HELM_SECRETS_CURL_PATH (
where /q curl.exe
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 (
SET HELM_SECRETS_CURL_PATH=curl.exe
)
)
:: https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
SET WSLENV=SOPS_AGE_KEY:SOPS_AGE_KEY_FILE:%WSLENV%
IF DEFINED HELM_SECRETS_DEC_SUFFIX (
SET WSLENV=HELM_SECRETS_DEC_SUFFIX:%WSLENV%
)
IF DEFINED HELM_SECRETS_DEC_PREFIX (
SET WSLENV=HELM_SECRETS_DEC_PREFIX:%WSLENV%
)
IF DEFINED HELM_SECRETS_QUIET (
SET WSLENV=HELM_SECRETS_QUIET:%WSLENV%
)
IF DEFINED HELM_SECRETS_BACKEND (
SET WSLENV=HELM_SECRETS_BACKEND:%WSLENV%
)
IF DEFINED HELM_SECRETS_BACKEND_ARGS (
SET WSLENV=HELM_SECRETS_BACKEND_ARGS:%WSLENV%
)
IF DEFINED HELM_SECRETS_ALLOWED_BACKENDS (
SET WSLENV=HELM_SECRETS_ALLOWED_BACKENDS:%WSLENV%
)
IF DEFINED HELM_SECRETS_DEC_DIR (
SET WSLENV=HELM_SECRETS_DEC_DIR:%WSLENV%
)
IF DEFINED HELM_SECRETS_URL_VARIABLE_EXPANSION (
SET WSLENV=HELM_SECRETS_URL_VARIABLE_EXPANSION:%WSLENV%
)
IF DEFINED HELM_DEBUG (
SET WSLENV=HELM_DEBUG:%WSLENV%
)
IF DEFINED HELM_SECRETS_IGNORE_MISSING_VALUES (
SET WSLENV=HELM_SECRETS_IGNORE_MISSING_VALUES:%WSLENV%
)
IF DEFINED HELM_SECRETS_EVALUATE_TEMPLATES (
SET WSLENV=HELM_SECRETS_EVALUATE_TEMPLATES:%WSLENV%
)
IF DEFINED HELM_SECRETS_EVALUATE_TEMPLATES_DECODE_SECRETS (
SET WSLENV=HELM_SECRETS_EVALUATE_TEMPLATES_DECODE_SECRETS:%WSLENV%
)
IF NOT DEFINED HELM_BIN GOTO END_HELM_BIN
IF "x%HELM_BIN:\=%"=="x%HELM_BIN%" (
SET WSLENV=HELM_BIN:%WSLENV%
) else (
SET WSLENV=HELM_BIN/p:%WSLENV%
)
:END_HELM_BIN
IF NOT DEFINED HELM_PLUGIN_DIR GOTO END_HELM_PLUGIN_DIR
IF "x%HELM_PLUGIN_DIR:\=%"=="x%HELM_PLUGIN_DIR%" (
SET WSLENV=HELM_PLUGIN_DIR:%WSLENV%
) else (
SET WSLENV=HELM_PLUGIN_DIR/p:%WSLENV%
)
:END_HELM_PLUGIN_DIR
IF NOT DEFINED HELM_SECRETS_HELM_PATH GOTO END_HELM_SECRETS_HELM_PATH
IF "x%HELM_SECRETS_HELM_PATH:\=%"=="x%HELM_SECRETS_HELM_PATH%" (
SET WSLENV=HELM_SECRETS_HELM_PATH:%WSLENV%
) else (
SET WSLENV=HELM_SECRETS_HELM_PATH/p:%WSLENV%
)
:END_HELM_SECRETS_HELM_PATH
IF NOT DEFINED HELM_SECRETS_SOPS_PATH GOTO END_HELM_SECRETS_SOPS_PATH
IF "x%HELM_SECRETS_SOPS_PATH:\=%"=="x%HELM_SECRETS_SOPS_PATH%" (
SET WSLENV=HELM_SECRETS_SOPS_PATH:%WSLENV%
) else (
SET WSLENV=HELM_SECRETS_SOPS_PATH/p:%WSLENV%
)
:END_HELM_SECRETS_SOPS_PATH
IF NOT DEFINED HELM_SECRETS_VALS_PATH GOTO END_HELM_SECRETS_VALS_PATH
IF "x%HELM_SECRETS_VALS_PATH:\=%"=="x%HELM_SECRETS_VALS_PATH%" (
SET WSLENV=HELM_SECRETS_VALS_PATH:%WSLENV%
) else (
SET WSLENV=HELM_SECRETS_VALS_PATH/p:%WSLENV%
)
:END_HELM_SECRETS_VALS_PATH
IF NOT DEFINED HELM_SECRETS_CURL_PATH GOTO END_HELM_SECRETS_CURL_PATH
IF "x%HELM_SECRETS_CURL_PATH:\=%"=="x%HELM_SECRETS_CURL_PATH%" (
SET WSLENV=HELM_SECRETS_CURL_PATH:%WSLENV%
) else (
SET WSLENV=HELM_SECRETS_CURL_PATH/p:%WSLENV%
)
:END_HELM_SECRETS_CURL_PATH
SET HELM_SECRET_WSL_INTEROP=1
SET WSLENV=HELM_SECRET_WSL_INTEROP:%WSLENV%
IF NOT "x%RUNSH:\=%"=="x%RUNSH%" (
:: CMD output to variable - https://stackoverflow.com/a/6362922/8087167
FOR /F "tokens=* USEBACKQ" %%F IN (`wsl wslpath "%RUNSH:\=/%"`) DO (
SET RUNSH="%%F"
)
)
wsl bash %RUNSH% %*
exit /b %ERRORLEVEL%
: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