-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows-start.bat
92 lines (77 loc) · 2.99 KB
/
windows-start.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
@echo off
setlocal EnableDelayedExpansion
REM Check if the batch file is running in a Command Prompt window and relaunch it if not
if not "%~1"=="relaunched" (
start cmd /k ""%~f0" relaunched"
exit /b
)
REM Create the C:/SWISH directory if it does not already exist
mkdir "C:/SWISH"
REM Check if C:/SWISH/.env file exists, if not, copy env.example to C:/SWISH/.env
if not exist "C:/SWISH/.env" (
copy "env.example" "C:/SWISH/.env"
echo The .env file has been copied to C:/SWISH/.env from env.example.
)
echo Please edit the .env file to set the required options.
notepad "C:/SWISH/.env"
echo Checking if Docker Desktop is running...
tasklist /FI "IMAGENAME eq Docker Desktop.exe" 2>NUL | find /I /N "Docker Desktop.exe" >NUL
if "%ERRORLEVEL%"=="0" (
echo Docker Desktop is already running.
) else (
echo Starting Docker Desktop...
start "" "C:\Program Files\Docker\Docker\Docker Desktop.exe"
echo Waiting for Docker Desktop to start...
timeout /t 10 /nobreak >NUL 2>&1
:CHECK_DOCKER
tasklist /FI "IMAGENAME eq Docker Desktop.exe" 2>NUL | find /I /N "Docker Desktop.exe" >NUL
if "%ERRORLEVEL%"=="0" (
echo Docker Desktop has started successfully.
) else (
echo Docker Desktop is still not running. Retrying...
timeout /t 5 /nobreak >NUL 2>&1
goto CHECK_DOCKER
)
)
echo Continuing with the rest of the batch script...
REM Pull the briankwest/wirestarter Docker image
docker pull briankwest/wirestarter
REM Check if the container "wirestarter" already exists
docker ps -a --format "{{.Names}}" | findstr /B "wirestarter" > nul
if %ERRORLEVEL% equ 0 (
echo Container "wirestarter" already exists.
set /p USE_EXISTING="Do you want to use the existing container (y/n)? "
echo You selected: '!USE_EXISTING!'
if /I "!USE_EXISTING!"=="y" (
echo Checking if "wirestarter" container is running...
docker ps --format "{{.Names}}" | findstr /B "wirestarter" > nul
if %ERRORLEVEL% neq 0 (
echo Starting the "wirestarter" container...
docker start wirestarter
) else (
echo Container "wirestarter" is already running.
)
goto ExecShell
) else if /I "!USE_EXISTING!"=="n" (
echo Removing the existing "wirestarter" container...
docker rm -f wirestarter
goto CreateNew
) else (
echo Invalid option. Exiting...
pause
exit /b
)
) else (
echo No existing container named "wirestarter". Creating new one...
goto CreateNew
)
:CreateNew
REM Run a new container named "wirestarter" from the pulled image
docker run -it -d --name wirestarter --env-file "C:/SWISH/.env" --volume "C:/SWISH:/workdir" --volume opt:/opt briankwest/wirestarter /start_services.sh || echo "up"
goto ExecShell
:ExecShell
REM Executing a bash shell inside the "wirestarter" container
docker start wirestarter
docker exec -it wirestarter bash
echo Container "wirestarter" is running and a bash shell has been executed inside it.
pause