-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
131 lines (109 loc) · 4.25 KB
/
Copy pathsetup.bat
File metadata and controls
131 lines (109 loc) · 4.25 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
@echo off
setlocal
:: Strip trailing backslash from %~dp0 to avoid escape character issues (\") with quotes
set "BASE_DIR=%~dp0"
if "%BASE_DIR:~-1%"=="\" set "BASE_DIR=%BASE_DIR:~0,-1%"
echo ===================================================
echo ZSecTools - Environment Setup Initialization
echo ===================================================
:: 1. DOWNLOAD AND EXTRACT NODE.JS PORTABLE
if exist "%BASE_DIR%\node-bin\node.exe" (
echo [OK] Node.js Portable is already configured in node-bin.
) else (
echo [INFO] Downloading Node.js v24.18.0...
curl -L "https://nodejs.org/dist/v24.18.0/node-v24.18.0-win-x64.zip" -o "%BASE_DIR%\node.zip"
if errorlevel 1 (
echo [ERROR] Curl failed to download Node.js.
pause
exit /b 1
)
echo [INFO] Extracting Node.js...
tar -xf "%BASE_DIR%\node.zip" -C "%BASE_DIR%"
if errorlevel 1 (
echo [ERROR] Tar failed to extract node.zip.
pause
exit /b 1
)
echo [INFO] Normalizing Node.js directory name...
if exist "%BASE_DIR%\node-bin" rmdir /s /q "%BASE_DIR%\node-bin"
rename "%BASE_DIR%\node-v24.18.0-win-x64" "node-bin"
if errorlevel 1 (
echo [ERROR] Failed to rename node folder to node-bin.
pause
exit /b 1
)
del "%BASE_DIR%\node.zip"
)
:: 2. DOWNLOAD AND EXTRACT POSTGRESQL PORTABLE
if exist "%BASE_DIR%\postgres\bin\pg_ctl.exe" (
echo [OK] PostgreSQL Portable is already configured in postgres.
) else (
echo [INFO] Downloading PostgreSQL Portable v16.3...
curl -L "https://get.enterprisedb.com/postgresql/postgresql-16.3-1-windows-x64-binaries.zip" -o "%BASE_DIR%\postgres.zip"
if errorlevel 1 (
echo [ERROR] Curl failed to download PostgreSQL binaries.
pause
exit /b 1
)
echo [INFO] Extracting PostgreSQL...
tar -xf "%BASE_DIR%\postgres.zip" -C "%BASE_DIR%"
if errorlevel 1 (
echo [ERROR] Tar failed to extract postgres.zip.
pause
exit /b 1
)
echo [INFO] Normalizing PostgreSQL directory name...
if exist "%BASE_DIR%\postgres" rmdir /s /q "%BASE_DIR%\postgres"
if exist "%BASE_DIR%\pgsql" (
rename "%BASE_DIR%\pgsql" "postgres"
) else (
echo [ERROR] Expected directory 'pgsql' was not found after extraction.
pause
exit /b 1
)
del "%BASE_DIR%\postgres.zip"
)
set "PATH=%PATH%;%BASE_DIR%\node-bin"
:: 3. INSTALL BACKEND DEPENDENCIES
echo [INFO] Installing backend dependencies...
cd /d "%BASE_DIR%\backend"
call "%BASE_DIR%\node-bin\npm" install --ignore-scripts
:: 4. INSTALL FRONTEND DEPENDENCIES AND BUILD
echo [INFO] Installing frontend dependencies and building assets...
cd /d "%BASE_DIR%\frontend"
call "%BASE_DIR%\node-bin\npm" install
call "%BASE_DIR%\node-bin\npm" run build
cd /d "%BASE_DIR%"
:: 5. INITIALIZE POSTGRESQL DATABASE TRACK (DEBUGGED BLOCK)
set "PG_DATA=%BASE_DIR%\postgres\data"
set "PG_BIN=%BASE_DIR%\postgres\bin"
if exist "%PG_DATA%\PG_VERSION" (
echo [OK] PostgreSQL cluster is already initialized.
) else (
echo [INFO] Checking Database initialization prerequisites...
:: Automated fallback: If pwfile.txt is missing, we create a temporary one to prevent initdb from crashing
if not exist "%BASE_DIR%\pwfile.txt" (
echo [WARN] pwfile.txt was missing! Generating a default one for setup...
echo apppassword> "%BASE_DIR%\pwfile.txt"
)
if not exist "%PG_DATA%" mkdir "%PG_DATA%"
echo [INFO] Executing initdb.exe core routine...
echo Target Path: "%PG_BIN%\initdb.exe"
:: Run initdb dynamically and capture direct errors without closing window
"%PG_BIN%\initdb.exe" -D "%PG_DATA%" -U appuser -A md5 --pwfile="%BASE_DIR%\pwfile.txt" -E UTF8
if errorlevel 1 (
echo.
echo [CRITICAL ERROR] initdb.exe failed with exit code %errorlevel%.
echo Troubleshooting steps:
echo 1. Ensure your antivirus or OneDrive is not locking the "%BASE_DIR%\postgres" directory.
echo 2. Try running this command prompt as Administrator.
echo.
pause
exit /b 1
)
)
echo ===================================================
echo Setup completed successfully!
echo ===================================================
pause
endlocal