forked from enjin/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.bat
193 lines (175 loc) · 6.2 KB
/
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
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
@echo off
setlocal enabledelayedexpansion
goto :MAIN
:: Function to check if the APP_URL is set and prompt the user if not
:check_has_app_url
:: Check if APP_URL is already set
set "APP_URL="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"APP_URL=" configs\core\.env') do (
set "APP_URL=%%i"
)
:: If not set, prompt the user
if "%APP_URL%"=="" (
echo For a few things to work, we need to know your platform URL
set /p APP_URL="Please input the URL: (e.g. http://127.0.0.1:8000) "
if "%APP_URL%"=="" (
set "APP_URL=http://127.0.0.1:8000"
)
powershell -Command "(Get-Content 'configs\core\.env') | ForEach-Object {$_ -replace '\bAPP_URL=.*', 'APP_URL=!APP_URL!'} | Set-Content 'configs\core\.env'"
)
goto :EOF
:: Function to generate a new basic auth token and set it in the .env file
:generate_basic_token
:: Generate a new basic auth token
set "BASIC_TOKEN="
for /l %%i in (1,1,64) do (
set /a "rand=!random! %% 16"
for %%x in (!rand!) do (
set "hexDigit=0123456789ABCDEF"
for /f %%d in ("!hexDigit:~%%x,1!") do (
set "BASIC_TOKEN=!BASIC_TOKEN!%%d"
)
)
)
echo Done, your basic static token is: !BASIC_TOKEN!
:: Replace the BASIC_AUTH_TOKEN in the .env file
powershell -Command "(Get-Content 'configs\core\.env') | ForEach-Object {$_ -replace '\bBASIC_AUTH_TOKEN=.*', 'BASIC_AUTH_TOKEN=!BASIC_TOKEN!'} | Set-Content 'configs\core\.env'"
powershell -Command "(Get-Content 'configs\daemon\.env') | ForEach-Object {$_ -replace '\bPLATFORM_KEY=.*', 'PLATFORM_KEY=!BASIC_TOKEN!'} | Set-Content 'configs\daemon\.env'"
goto :EOF
:: Function to check if the BASIC_AUTH_TOKEN is set and prompt the user if not
:check_has_basic_token
:: Check if BASIC_AUTH_TOKEN is already set
set "AUTH_TOKEN="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"BASIC_AUTH_TOKEN=" configs\core\.env') do (
set "AUTH_TOKEN=%%i"
)
:: If not set, prompt the user
if "%AUTH_TOKEN%"=="" (
echo We also use a static token to protect your platform from unauthorized access
set /p generate_token="Your BASIC_AUTH_TOKEN is not set, do you want to generate one? (y/n) "
if /i "!generate_token!"=="n" (
echo Please set BASIC_AUTH_TOKEN in configs\core\.env and run this script again
exit /b 1
) else (
call :generate_basic_token
)
)
goto :EOF
:: Function to generate a daemon password and set it in the .env file
:generate_daemon_password
:: Generate a new daemon password
set "WALLET_PASSWORD="
for /l %%i in (1,1,64) do (
set /a "rand=!random! %% 16"
for %%x in (!rand!) do (
set "hexDigit=0123456789ABCDEF"
for /f %%d in ("!hexDigit:~%%x,1!") do (
set "WALLET_PASSWORD=!WALLET_PASSWORD!%%d"
)
)
)
echo Done, your daemon password is: !WALLET_PASSWORD!
:: Replace the KEY_PASS in the .env file
powershell -Command "(Get-Content 'configs\daemon\.env') | ForEach-Object {$_ -replace '\bKEY_PASS=.*', 'KEY_PASS=!WALLET_PASSWORD!'} | Set-Content 'configs\daemon\.env'"
goto :EOF
:: Function to check if the KEY_PASS is set and prompt the user if not
:check_has_daemon_password
:: Check if KEY_PASS is already set
set "KEY_PASS="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"KEY_PASS=" configs\daemon\.env') do (
set "KEY_PASS=%%i"
)
:: If not set, prompt the user
if "%KEY_PASS%"=="" (
echo Finally, we also use a password to protect your wallet daemon
set /p generate_daemon="Your KEY_PASS is not set, do you want to generate one? (y/n) "
if /i "!generate_daemon!"=="n" (
echo Please set KEY_PASS in configs\daemon\.env and run this script again
exit /b 1
) else (
call :generate_daemon_password
)
)
goto :EOF
:: Function to get the wallet daemon address
:get_daemon_address
:: Check if DAEMON_ACCOUNT is already set
set "DAEMON_ACCOUNT="
for /f "tokens=2 delims==" %%i in ('findstr /r /c:"DAEMON_ACCOUNT=" configs\core\.env') do (
set "DAEMON_ACCOUNT=%%i"
)
:: If not set, get the address
if "%DAEMON_ACCOUNT%"=="" (
echo Let's get your wallet daemon address, please wait...
(docker compose up -d daemon)
for /f "delims=" %%a in ('docker compose logs daemon 2^>^&1 ^| findstr /r /c:"Efinity:"') do (
for %%w in (%%a) do set "WALLET_ADDRESS=%%w"
)
echo Your wallet daemon address is: !WALLET_ADDRESS!
powershell -Command "(Get-Content 'configs\core\.env') | ForEach-Object {$_ -replace '\bDAEMON_ACCOUNT=.*', 'DAEMON_ACCOUNT=!WALLET_ADDRESS!'} | Set-Content 'configs\core\.env'"
) else (
echo Your wallet daemon address is: %DAEMON_ACCOUNT%
)
goto :EOF
:: Function to check if Docker is installed
:check_docker_is_installed
where docker >nul 2>nul
if %errorlevel% neq 0 (
echo Please install Docker and run this script again
exit /b 1
)
goto :EOF
:: Function to check if Docker Compose is installed
:check_compose_is_installed
docker compose --version >nul 2>nul
if %errorlevel% neq 0 (
echo Please install Docker Compose and run this script again
exit /b 1
)
goto :EOF
:: Function to check if Docker is running
:check_docker_is_running
docker ps >nul 2>nul
if %errorlevel% neq 0 (
echo Please start Docker and run this script again
exit /b 1
)
goto :EOF
:: Function to check if OpenSSL is installed
:check_openssl_is_installed
where openssl >nul 2>nul
if %errorlevel% neq 0 (
echo Please install OpenSSL and run this script again
exit /b 1
)
goto :EOF
:: Function to check if Git is installed
:check_git_is_installed
where git >nul 2>nul
if %errorlevel% neq 0 (
echo Please install Git and run this script again
exit /b 1
)
goto :EOF
:MAIN
echo Welcome to Enjin Platform, this script will help you start it up
call :check_git_is_installed
:: Initialize Git submodules
git submodule update --init
call :check_has_app_url
call :check_has_basic_token
call :check_has_daemon_password
:: Build the daemon container
docker compose build daemon
call :get_daemon_address
:: Prompt the user to start platform services
set /p start_services=Do you want to start all platform services? (y/n)
if /i "%start_services%"=="y" (
docker compose build
docker compose up -d
echo Your Enjin Platform is now running, please visit: http://127.0.0.1:8000
) else (
docker compose down
echo Please run this script again when you are ready
exit /b 1
)