-
Notifications
You must be signed in to change notification settings - Fork 31
/
openc3.bat
145 lines (130 loc) · 4.24 KB
/
openc3.bat
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
@echo off
setlocal ENABLEDELAYEDEXPANSION
if "%1" == "" (
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 openc3-cosmos-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.
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=%%
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" == "util" (
FOR /F "tokens=*" %%i in ('findstr /V /B /L /C:# %~dp0.env') do SET %%i
GOTO util
)
GOTO usage
:startup
CALL openc3 build || exit /b
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
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 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
CALL scripts\windows\openc3_setup || exit /b
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 OpenC3
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
: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
@echo Usage: %0 [cli, cliroot, start, stop, cleanup, build, run, dev, test, util] 1>&2
@echo * cli: run a cli command as the default user ('cli help' for more info) 1>&2
@echo * cliroot: run a cli command as the root user ('cli help' for more info) 1>&2
@echo * start: build and run 1>&2
@echo * stop: stop the containers (compose stop) 1>&2
@echo * cleanup [local] [force]: REMOVE volumes / data (compose down -v) 1>&2
@echo * build: build the containers (compose build) 1>&2
@echo * run: run the containers (compose up) 1>&2
@echo * dev: run using compose-dev 1>&2
@echo * test: test openc3 1>&2
@echo * util: various helper commands 1>&2
@echo on