-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-gba.bat
79 lines (69 loc) · 2.03 KB
/
docker-gba.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
@echo off
setlocal enabledelayedexpansion
set release=stable-gba
set imageBaseName=gtcs2110/cs2110docker-c
set imageName=%imageBaseName%:%release%
set description="Run the CS 2110 C Docker Container: cs2110docker.bat [start|stop|help]"
set action=" "
set "arg=%1"
if not defined arg (
set action=start
goto end_if
)
if /i "%arg%"=="start" (
set action=start
goto end_if
)
if /i "%arg%"=="stop" (
set action=stop
goto end_if
)
if /i "%arg%"=="help" (
echo %description%
exit /b 0
)
set "arg=%2"
if defined arg (
echo Error: unrecognized argument %2
exit /b 1
)
:end_if
docker container ps > nul 2>&1
if "%errorlevel%" neq "0" (
echo ERROR: Docker not found. Ensure that Docker is installed and is running before running this script. Refer to the CS 2110 Docker Guide.
exit /b 1
)
echo Found Docker Installation
if "%action%"=="stop" (
for /f "tokens=3" %%A in ('docker images ^| findstr /c:"gtcs2110/cs2110docker-c"') do set imageId=%%A
for /f "tokens=1" %%i in ('docker ps -qf "ancestor=%imageId%"') do (
set containerId=%%i
echo !containerId!
if !containerId!=="" (
echo No existing CS 2110 containers
) else (
docker stop !containerId!
docker rm -f !containerId!
)
)
echo Successfully stopped all CS 2110 containers
exit /b 0
)
echo Pulling down most recent image of %imageName%
docker pull %imageName%
if "%errorlevel%" neq "0" (
echo ERROR: Unable to pull down the most recent image of %imageName%
exit /b 1
)
set currDir=%cd%
if "%action%"=="start" (
START /B "" java -jar GBAServer.jar
docker run --rm -v "%currDir%:/cs2110/host" --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it "%imageName%"
if "%errorlevel%" == "0" (
echo Successfully launched the CS 2110 Docker Container.
) else (
>&2 echo ERROR: Unable to launch CS 2110 Docker container.
)
wmic process where "name like '%%java%%' and commandline like '%%GBAServer%%'" delete > NUL
exit /b
)