-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstartDocker.bat
More file actions
357 lines (313 loc) · 8.83 KB
/
Copy pathstartDocker.bat
File metadata and controls
357 lines (313 loc) · 8.83 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@echo off
SET "SHARED_VOLUME_NAME=mediaserver-shared-env"
SET "VOLUME_UID=1000"
SET "VOLUME_GID=1000"
SET "ENV_FILE=./.env"
SET "FALLBACK_DEFAULT_DOMAIN=app.test"
echo.
echo ============================================
echo mediaServer Docker Setup
echo ============================================
echo.
SET "IS_CI_MODE=false"
IF /I "%~1"=="--auto-default" (
SET "IS_CI_MODE=true"
call :ColorText "[INFO]" Blue
echo Auto-default mode enabled via command-line argument.
SHIFT /1
) ELSE IF DEFINED CI (
SET "IS_CI_MODE=true"
call :ColorText "[INFO]" Blue
echo Auto-default mode enabled - CI/CD environment detected - CI variable.
) ELSE IF DEFINED GITHUB_ACTIONS (
SET "IS_CI_MODE=true"
call :ColorText "[INFO]" Blue
echo Auto-default mode enabled - CI/CD environment detected - GITHUB_ACTIONS variable.
)
echo.
call :ColorText "[STEP 1/5]" Yellow
echo Verifying required files and folders...
echo.
:: Check for docker-compose.yaml
if not exist docker-compose.yaml (
call :ColorText "[ERROR]" Red
echo Missing 'docker-compose.yaml' file.
echo Please ensure this file is present in the root directory.
pause
goto :end
) else (
call :ColorText "[FOUND]" Green
echo 'docker-compose.yaml' file.
)
echo.
rem --------------------------------------------------
:: Check for .env.docker
if not exist "docker\.env.docker" (
call :ColorText "[ERROR]" Red
echo Missing 'docker/.env.docker' file.
echo Please ensure this file is present in the correct directory.
pause
goto :end
)
:: Create .env if it doesn't exist
if not exist ".env" (
call :ColorText "[INFO]" Blue
echo '.env' file not found. Creating from '.env.docker'...
copy ".\docker\.env.docker" ".\.env"
if errorlevel 1 (
call :ColorText "[ERROR]" Red
echo Failed to create '.env' file.
pause
goto :end
)
call :ColorText "[SUCCESS]" Green
echo '.env' file created.
) else (
call :ColorText "[FOUND]" Green
echo '.env' file.
)
echo.
REM Ensure data directories exists
mkdir data
mkdir data\thumbnails
mkdir data\media
mkdir app
echo.
call :ColorText "[READY]" Green
echo 'data' and 'app' directories are ready.
echo.
:: Ensure logs directory exists
if not exist "logs" (
call :ColorText "[INFO]" Blue
echo Missing 'logs' directory. Creating it...
echo.
mkdir "logs"
mkdir "logs\mediaServer"
mkdir "logs\nginx"
if errorlevel 1 (
call :ColorText "[ERROR]" Red
echo Failed to create 'logs' directory.
pause
goto :end
)
call :ColorText "[SUCCESS]" Green
echo 'logs' directory created.
) else (
call :ColorText "[FOUND]" Green
echo 'logs' directory.
)
echo.
rem --------------------------------------------------
call :ColorText "[STEP 2/5] " Yellow
echo Setting up user config...
echo.
setlocal ENABLEDELAYEDEXPANSION
SET "CURRENT_APP_HOST="
SET "CURRENT_APP_PORT="
IF EXIST "%ENV_FILE%" (
FOR /F "tokens=1* delims==" %%a IN ('findstr /b "APP_HOST=" "%ENV_FILE%"') DO (
SET "CURRENT_APP_HOST=%%b"
)
)
IF EXIST "%ENV_FILE%" (
FOR /F "tokens=1* delims==" %%a IN ('findstr /b "APP_PORT=" "%ENV_FILE%"') DO (
SET "CURRENT_APP_PORT=%%b"
)
)
SET "CURRENT_DOMAIN_DEFAULT=%FALLBACK_DEFAULT_DOMAIN%"
SET "CURRENT_PORT_DEFAULT=8080"
IF NOT "!CURRENT_APP_PORT!"=="" (
REM Remove quotes
SET "TEMP_PORT=!CURRENT_APP_PORT:"=!"
IF NOT "!TEMP_PORT!"=="" (
SET "CURRENT_PORT_DEFAULT=!TEMP_PORT!"
)
)
IF NOT "!CURRENT_APP_HOST!"=="" (
REM Remove quotes
SET "TEMP_DOMAIN_FROM_HOST=!CURRENT_APP_HOST:"=!"
IF NOT "!TEMP_DOMAIN_FROM_HOST!"=="" (
SET "CURRENT_DOMAIN_DEFAULT=!TEMP_DOMAIN_FROM_HOST!"
)
)
ENDLOCAL & (
SET "CURRENT_DOMAIN_DEFAULT=%CURRENT_DOMAIN_DEFAULT%"
SET "CURRENT_PORT_DEFAULT=%CURRENT_PORT_DEFAULT%"
)
REM Ask for domain name, or use default in CI/CD mode
IF "%IS_CI_MODE%"=="true" (
SET "USER_DOMAIN=%CURRENT_DOMAIN_DEFAULT%"
call :ColorText "[INFO] " BLUE
echo Automatically using default domain: %USER_DOMAIN%
) ELSE (
call :ColorText "[CONFIG] " YELLOW
echo "Enter your app domain (URL)..."
echo "Current value: %CURRENT_DOMAIN_DEFAULT% (Press Enter to use this)..."
echo.
set /p USER_DOMAIN="Domain: "
)
echo.
REM Use current default if user input is empty
IF "%USER_DOMAIN%"=="" (
SET "APP_HOST=%CURRENT_DOMAIN_DEFAULT%"
) ELSE (
SET "APP_HOST=%USER_DOMAIN%"
)
REM Use default port if found port is empty
IF "%CURRENT_PORT_DEFAULT%"=="" (
SET "APP_PORT=8080"
) ELSE (
SET "APP_PORT=%CURRENT_PORT_DEFAULT%"
)
call :ColorText "[INFO] " BLUE
echo Setting APP_HOST to: %APP_HOST%
echo.
REM Update APP_HOST in .env file
SET "TEMP_ENV_FILE=%ENV_FILE%.tmp"
(
for /f "tokens=1,* delims=:" %%a in ('findstr /n "^" "%ENV_FILE%"') do (
set "line=%%b"
setlocal ENABLEDELAYEDEXPANSION
if "!line:~0,9!"=="APP_HOST=" (
echo APP_HOST="%APP_HOST%"
) else (
echo(!line!
)
endlocal
)
) > "%TEMP_ENV_FILE%"
IF %ERRORLEVEL% NEQ 0 (
echo.
call :ColorText "[ERROR]" RED
echo Failed to create temporary .env file.
echo Please check script permissions.
pause
goto :end
)
MOVE /Y "%TEMP_ENV_FILE%" "%ENV_FILE%" >nul
IF %ERRORLEVEL% NEQ 0 (
echo.
call :ColorText "[ERROR]" RED
echo Failed to replace original .env file.
echo Please check script permissions.
pause
goto :end
) ELSE (
call :ColorText "[SUCCESS] " GREEN
echo APP_HOST updated in %ENV_FILE%.
)
echo.
call :ColorText "[STEP 3/5] " Yellow
echo Stopping and cleaning up existing mediaServer Docker containers...
echo.
docker compose down
if errorlevel 1 (
echo.
call :ColorText "[ERROR]" Red
echo Failed to bring down Docker containers.
echo Please check your Docker setup and try again.
pause
goto :end
)
echo.
call :ColorText "[SUCCESS]" Green
echo Docker containers stopped and cleaned up.
echo.
rem --------------------------------------------------
echo Docker volumes no longer pruned...
echo.
rem --------------------------------------------------
call :ColorText "[STEP 4/5] " Yellow
echo Pulling latest Docker images...
echo.
docker compose pull
if errorlevel 1 (
echo.
call :ColorText "[ERROR]" Red
echo Failed to pull Docker images.
echo Please check your internet connection and Docker setup.
pause
goto :end
) else (
echo.
call :ColorText "[SUCCESS]" Green
echo Docker images pulled successfully.
echo.
)
call :ColorText "[STEP 5/5] " Yellow
echo Building docker compose...
echo.
call :ColorText "[INFO] " BLUE
echo Checking for shared Docker volume '%SHARED_VOLUME_NAME%'...
docker volume create %SHARED_VOLUME_NAME% >nul 2>&1
docker volume inspect %SHARED_VOLUME_NAME% >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
call :ColorText "[ERROR]" RED
echo.
echo Shared volume '%SHARED_VOLUME_NAME%' could not be created or found.
echo.
pause
goto :end
)
echo.
call :ColorText "[SUCCESS] " GREEN
echo Shared volume '%SHARED_VOLUME_NAME%' ready.
echo.
call :ColorText "[INFO] " BLUE
echo Setting permissions on shared volume '%SHARED_VOLUME_NAME%'...
docker run --rm -v %SHARED_VOLUME_NAME%:/shared alpine sh -c "chown -R %VOLUME_UID%:%VOLUME_GID% /shared"
docker run --rm --user %VOLUME_UID%:%VOLUME_GID% -v %SHARED_VOLUME_NAME%:/shared alpine sh -c "echo initialized > /shared/.init"
IF %ERRORLEVEL% NEQ 0 (
echo.
call :ColorText "[ERROR]" RED
echo Failed to set shared volume permissions.
echo Please check your Docker volume and user/group ID configurations.
pause
goto :end
)
echo.
call :ColorText "[SUCCESS] " GREEN
echo Shared volume permissions set.
echo.
docker compose up -d
if errorlevel 1 (
echo.
call :ColorText "[ERROR]" Red
echo Failed to build docker compose.
echo Please check your configuration.
pause
goto :end
)
echo.
echo ============================================
echo SETUP COMPLETED SUCCESSFULLY!
echo ============================================
echo.
echo Your mediaServer will be available at https://%APP_HOST% or http://%APP_HOST%:%APP_PORT%
echo.
echo To add audio or video to your server, put the files in ./data/media organised by /LIBRARY/FOLDER/VIDEO.mp4
echo.
IF "%APP_HOST%"=="app.test" (
call :ColorText "[WARNING]" Yellow
echo The domain '%APP_HOST%' is not publicly resolvable. You may need to add the following line to your hosts file:
echo.
echo 127.0.0.1 %APP_HOST%
echo.
echo Run the provided powershell script 'add-hosts-entry.ps1' to automate this process
echo.
goto :end
)
:end
set arg0=%0
if [%arg0:~2,1%]==[:] pause
exit /b
REM Function to print colored text
:ColorText
set "text=%~1"
set "color=%~2"
if "%color%"=="" (
echo [ERROR] Color not specified in :ColorText
exit /b 1
)
powershell -NoProfile -Command "Write-Host '%text%' -ForegroundColor %color%"
exit /b 0