-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathopenc3.bat
More file actions
315 lines (296 loc) · 10.9 KB
/
openc3.bat
File metadata and controls
315 lines (296 loc) · 10.9 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM Detect if this is a development (build) environment or runtime environment
REM by checking for compose-build.yaml
set OPENC3_DEVEL=0
if exist "%~dp0compose-build.yaml" (
set OPENC3_DEVEL=1
)
REM Detect if this is enterprise by checking for enterprise-specific services
set OPENC3_ENTERPRISE=0
if exist "%~dp0compose-build.yaml" (
findstr /C:"openc3-enterprise-gem" "%~dp0compose-build.yaml" >nul 2>&1
if !ERRORLEVEL! == 0 (
set OPENC3_ENTERPRISE=1
)
)
if !OPENC3_ENTERPRISE! == 0 (
if exist "%~dp0compose.yaml" (
findstr /C:"openc3-metrics" "%~dp0compose.yaml" >nul 2>&1
if !ERRORLEVEL! == 0 (
set OPENC3_ENTERPRISE=1
)
)
)
REM Set display name based on enterprise flag
if "%OPENC3_ENTERPRISE%" == "1" (
set COSMOS_NAME=COSMOS Enterprise
) else (
set COSMOS_NAME=COSMOS Core
)
if "%1" == "" (
GOTO usage
)
if "%1" == "--help" (
GOTO usage
)
if "%1" == "-h" (
GOTO usage
)
if "%1" == "cli" (
REM tokens=* means process the full line
REM findstr /V = print lines that don't match, /B beginning of line, /L literal search string, /C:# match #
FOR /F "tokens=*" %%i in ('findstr /V /B /L /C:# %~dp0.env') do SET %%i
set params=%*
call set params=%%params:*%1=%%
REM Start (and remove when done --rm) the cmd-tlm-api container with the current working directory
REM mapped as volume (-v) /openc3/local and container working directory (-w) also set to /openc3/local.
REM This allows tools running in the container to have a consistent path to the current working directory.
REM Run the command "ruby /openc3/bin/openc3cli" with all parameters ignoring the first.
REM Note: The service name is always openc3-cosmos-cmd-tlm-api; compose.yaml pulls the correct image
REM (enterprise or non-enterprise) based on environment variables.
if "%OPENC3_ENTERPRISE%" == "1" (
docker compose -f %~dp0compose.yaml run -it --rm -v %cd%:/openc3/local -w /openc3/local -e OPENC3_API_USER=!OPENC3_API_USER! -e OPENC3_API_PASSWORD=!OPENC3_API_PASSWORD! --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli !params!
) else (
docker compose -f %~dp0compose.yaml run -it --rm -v %cd%:/openc3/local -w /openc3/local -e OPENC3_API_PASSWORD=!OPENC3_API_PASSWORD! --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli !params!
)
GOTO :EOF
)
if "%1" == "cliroot" (
FOR /F "tokens=*" %%i in ('findstr /V /B /L /C:# %~dp0.env') do SET %%i
set params=%*
call set params=%%params:*%1=%%
REM Note: The service name is always openc3-cosmos-cmd-tlm-api; compose.yaml pulls the correct image
REM (enterprise or non-enterprise) based on environment variables.
if "%OPENC3_ENTERPRISE%" == "1" (
docker compose -f %~dp0compose.yaml run -it --rm --user=root -v %cd%:/openc3/local -w /openc3/local -e OPENC3_API_USER=!OPENC3_API_USER! -e OPENC3_API_PASSWORD=!OPENC3_API_PASSWORD! --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli !params!
) else (
docker compose -f %~dp0compose.yaml run -it --rm --user=root -v %cd%:/openc3/local -w /openc3/local -e OPENC3_API_PASSWORD=!OPENC3_API_PASSWORD! --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli !params!
)
GOTO :EOF
)
if "%1" == "start" (
GOTO startup
)
if "%1" == "stop" (
GOTO stop
)
if "%1" == "cleanup" (
GOTO cleanup
)
if "%1" == "build" (
GOTO build
)
if "%1" == "run" (
GOTO run
)
if "%1" == "dev" (
GOTO dev
)
if "%1" == "test" (
GOTO test
)
if "%1" == "upgrade" (
GOTO upgrade
)
if "%1" == "util" (
FOR /F "tokens=*" %%i in ('findstr /V /B /L /C:# %~dp0.env') do SET %%i
GOTO util
)
GOTO usage
:startup
if "%OPENC3_DEVEL%" == "1" (
CALL openc3 build || exit /b
docker compose -f compose.yaml up -d
) else (
docker compose -f compose.yaml up -d
)
@echo off
GOTO :EOF
:stop
docker compose stop openc3-operator
docker compose stop openc3-cosmos-script-runner-api
docker compose stop openc3-cosmos-cmd-tlm-api
if "%OPENC3_ENTERPRISE%" == "1" (
docker compose stop openc3-metrics
)
timeout /t 5 /nobreak
docker compose -f compose.yaml down -t 30
@echo off
GOTO :EOF
:cleanup
if "%2" == "force" (
goto :cleanup_y
)
if "%3" == "force" (
goto :cleanup_y
)
:try_cleanup
set /P c=Are you sure? Cleanup removes ALL docker volumes and all %COSMOS_NAME% data! [Y/N]?
if /I "!c!" EQU "Y" goto :cleanup_y
if /I "!c!" EQU "N" goto :EOF
goto :try_cleanup
:cleanup_y
docker compose -f compose.yaml down -t 30 -v
if "%2" == "local" (
FOR /d %%a IN (%~dp0plugins\DEFAULT\*) DO RD /S /Q "%%a"
FOR %%a IN (%~dp0plugins\DEFAULT\*) DO IF /i NOT "%%~nxa"=="README.md" DEL "%%a"
)
@echo off
GOTO :EOF
:build
if "%OPENC3_DEVEL%" == "0" (
@echo Error: 'build' command is only available in development environments 1>&2
@echo This appears to be a runtime-only installation. 1>&2
exit /b 1
)
CALL scripts\windows\openc3_setup || exit /b
if "%OPENC3_ENTERPRISE%" == "1" (
docker compose -f compose.yaml -f compose-build.yaml build openc3-enterprise-gem || exit /b
) else (
docker compose -f compose.yaml -f compose-build.yaml build openc3-ruby || exit /b
docker compose -f compose.yaml -f compose-build.yaml build openc3-base || exit /b
docker compose -f compose.yaml -f compose-build.yaml build openc3-node || exit /b
)
docker compose -f compose.yaml -f compose-build.yaml build || exit /b
@echo off
GOTO :EOF
:run
docker compose -f compose.yaml up -d
@echo off
GOTO :EOF
:dev
docker compose -f compose.yaml -f compose-dev.yaml up -d
@echo off
GOTO :EOF
:test
REM Building COSMOS
CALL scripts\windows\openc3_setup || exit /b
docker compose -f compose.yaml -f compose-build.yaml build
set args=%*
call set args=%%args:*%1=%%
REM Running tests
CALL scripts\windows\openc3_test %args% || exit /b
@echo off
GOTO :EOF
:upgrade
if "%OPENC3_DEVEL%" == "1" (
@echo Error: 'upgrade' command is only available in runtime environments 1>&2
@echo This appears to be a development installation. 1>&2
exit /b 1
)
REM Send the remaining arguments to openc3_upgrade
set args=%*
call set args=%%args:*%1=%%
CALL scripts\windows\openc3_upgrade %args% || exit /b
GOTO :EOF
:util
REM Send the remaining arguments to openc3_util
set args=%*
call set args=%%args:*%1=%%
CALL scripts\windows\openc3_util %args% || exit /b
@echo off
GOTO :EOF
:usage
if "%OPENC3_DEVEL%" == "1" (
if "%OPENC3_ENTERPRISE%" == "1" (
@echo OpenC3 COSMOS - Command and Control System (Enterprise Development Installation) 1>&2
) else (
@echo OpenC3 COSMOS - Command and Control System (Development Installation) 1>&2
)
) else (
if "%OPENC3_ENTERPRISE%" == "1" (
@echo OpenC3 COSMOS - Command and Control System (Enterprise Runtime-Only Installation) 1>&2
) else (
@echo OpenC3 COSMOS - Command and Control System (Runtime-Only Installation) 1>&2
)
)
@echo Usage: %0 COMMAND [OPTIONS] 1>&2
@echo. 1>&2
@echo DESCRIPTION: 1>&2
@echo %COSMOS_NAME% is a command and control system for embedded systems. This script 1>&2
if "%OPENC3_DEVEL%" == "1" (
@echo provides a convenient interface for building, running, testing, and managing 1>&2
@echo %COSMOS_NAME% in Docker containers. 1>&2
@echo. 1>&2
if "%OPENC3_ENTERPRISE%" == "1" (
@echo This is an ENTERPRISE DEVELOPMENT installation with source code and build capabilities. 1>&2
) else (
@echo This is a DEVELOPMENT installation with source code and build capabilities. 1>&2
)
) else (
@echo provides a convenient interface for running, testing, and managing 1>&2
@echo %COSMOS_NAME% in Docker containers. 1>&2
@echo. 1>&2
if "%OPENC3_ENTERPRISE%" == "1" (
@echo This is an ENTERPRISE RUNTIME-ONLY installation using pre-built images. 1>&2
) else (
@echo This is a RUNTIME-ONLY installation using pre-built images. 1>&2
)
)
@echo. 1>&2
@echo COMMON COMMANDS: 1>&2
if "%OPENC3_DEVEL%" == "1" (
@echo start Build and run %COSMOS_NAME% (equivalent to: build + run) 1>&2
@echo This is the typical command to get %COSMOS_NAME% running. 1>&2
@echo. 1>&2
) else (
@echo run Start %COSMOS_NAME% containers 1>&2
@echo Access at: http://localhost:2900 1>&2
@echo. 1>&2
)
@echo stop Stop all running %COSMOS_NAME% containers gracefully 1>&2
@echo Allows containers to shutdown cleanly. 1>&2
@echo. 1>&2
@echo cli [COMMAND] Run %COSMOS_NAME% CLI commands in a container 1>&2
@echo Use 'cli help' for available commands 1>&2
@echo Examples: 1>&2
@echo %0 cli generate plugin MyPlugin 1>&2
@echo %0 cli validate myplugin.gem 1>&2
@echo. 1>&2
@echo cliroot [COMMAND] Run %COSMOS_NAME% CLI commands as root user 1>&2
@echo For operations requiring root privileges 1>&2
@echo. 1>&2
if "%OPENC3_DEVEL%" == "1" (
@echo DEVELOPMENT COMMANDS: 1>&2
@echo build Build all %COSMOS_NAME% Docker containers from source 1>&2
@echo Required before first run or after code changes. 1>&2
@echo. 1>&2
@echo run Start %COSMOS_NAME% containers in detached mode 1>&2
@echo Access at: http://localhost:2900 1>&2
@echo. 1>&2
@echo dev Start %COSMOS_NAME% containers in development mode 1>&2
@echo Uses compose-dev.yaml for development. 1>&2
@echo. 1>&2
)
@echo test [COMMAND] Run test suites (rspec, playwright) 1>&2
@echo Use '%0 test' to see available test commands. 1>&2
@echo. 1>&2
@echo util [COMMAND] Utility commands (encode, hash, etc.) 1>&2
@echo Use '%0 util' to see available utilities. 1>&2
@echo. 1>&2
if "%OPENC3_DEVEL%" == "0" (
@echo upgrade Upgrade %COSMOS_NAME% to latest version 1>&2
@echo Downloads and installs latest release. 1>&2
@echo. 1>&2
)
@echo CLEANUP: 1>&2
@echo cleanup [OPTIONS] Remove Docker volumes and data 1>&2
@echo WARNING: This deletes all %COSMOS_NAME% data! 1>&2
@echo Options: 1>&2
@echo local - Also remove local plugin files 1>&2
@echo force - Skip confirmation prompt 1>&2
@echo. 1>&2
@echo GETTING STARTED: 1>&2
@echo 1. First time setup: %0 start 1>&2
@echo 2. Access %COSMOS_NAME%: http://localhost:2900 1>&2
@echo 3. Stop when done: %0 stop 1>&2
@echo 4. Remove everything: %0 cleanup 1>&2
@echo. 1>&2
@echo MORE INFORMATION: 1>&2
@echo Documentation: https://docs.openc3.com 1>&2
@echo. 1>&2
@echo OPTIONS: 1>&2
@echo -h, --help Show this help message 1>&2
@echo. 1>&2
@echo on