-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-codex.bat
More file actions
251 lines (231 loc) · 8.63 KB
/
install-codex.bat
File metadata and controls
251 lines (231 loc) · 8.63 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
@echo off
setlocal EnableDelayedExpansion
title Codex Desktop for Windows - One-Click Installer
color 0A
echo ============================================
echo Codex Desktop for Windows - Installer
echo ============================================
echo.
:: ============================================
:: [1/8] WINGET
:: ============================================
echo [1/8] Checking winget...
where winget >nul 2>&1
if %errorlevel% neq 0 (
echo winget not found. Attempting to install via PowerShell...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe" 2>nul
where winget >nul 2>&1
if !errorlevel! neq 0 (
echo ERROR: Could not install winget. Please install App Installer from the Microsoft Store.
echo https://apps.microsoft.com/detail/9NBLGGH4NNS1
pause
exit /b 1
)
)
echo winget OK
echo.
:: ============================================
:: [2/8] GIT
:: ============================================
echo [2/8] Checking Git...
where git >nul 2>&1
if %errorlevel% neq 0 (
echo Git not found. Installing via winget...
winget install --id Git.Git -e --source winget --accept-package-agreements --accept-source-agreements --silent
if !errorlevel! neq 0 (
echo ERROR: Failed to install Git.
pause
exit /b 1
)
:: Refresh PATH to pick up new install
set "GIT_DIR=%ProgramFiles%\Git\cmd"
if exist "!GIT_DIR!\git.exe" set "PATH=!GIT_DIR!;!PATH!"
where git >nul 2>&1
if !errorlevel! neq 0 (
echo Git installed but not in PATH. Please restart this script.
pause
exit /b 1
)
)
for /f "tokens=*" %%v in ('git --version') do echo %%v
echo.
:: ============================================
:: [3/8] NODE.JS
:: ============================================
echo [3/8] Checking Node.js...
where node >nul 2>&1
if %errorlevel% neq 0 (
echo Node.js not found. Installing via winget...
winget install --id OpenJS.NodeJS.LTS -e --source winget --accept-package-agreements --accept-source-agreements --silent
if !errorlevel! neq 0 (
echo ERROR: Failed to install Node.js.
pause
exit /b 1
)
:: Refresh PATH
set "NODE_DIR=%ProgramFiles%\nodejs"
if exist "!NODE_DIR!\node.exe" set "PATH=!NODE_DIR!;!PATH!"
where node >nul 2>&1
if !errorlevel! neq 0 (
echo Node.js installed but not in PATH. Please restart this script.
pause
exit /b 1
)
)
for /f "tokens=*" %%v in ('node --version') do echo Node.js %%v
echo.
:: ============================================
:: [4/8] 7-ZIP
:: ============================================
echo [4/8] Checking 7-Zip...
set "SEVENZIP="
where 7z >nul 2>&1
if %errorlevel% equ 0 (
set "SEVENZIP=found"
)
if not defined SEVENZIP (
if exist "%ProgramFiles%\7-Zip\7z.exe" set "SEVENZIP=found"
)
if not defined SEVENZIP (
echo 7-Zip not found. Installing via winget...
winget install --id 7zip.7zip -e --source winget --accept-package-agreements --accept-source-agreements --silent
if !errorlevel! neq 0 (
echo WARNING: winget install failed, run.ps1 will try portable download.
) else (
echo 7-Zip installed.
)
) else (
echo 7-Zip OK
)
echo.
:: ============================================
:: [5/8] CLONE REPO + DOWNLOAD DMG
:: ============================================
cd /d "%~dp0"
set "BASEDIR=%~dp0"
echo [5/8] Setting up repo and downloading DMG...
:: Clone if run.ps1 doesn't exist (user might run bat standalone)
if not exist "%BASEDIR%scripts\run.ps1" (
echo Cloning aidanqm/Codex-Windows...
cd /d "%BASEDIR%.."
git clone https://github.com/aidanqm/Codex-Windows.git Codex-Windows 2>nul
cd /d "%BASEDIR%"
if not exist "%BASEDIR%scripts\run.ps1" (
:: If bat is outside repo, clone into current dir
git clone https://github.com/aidanqm/Codex-Windows.git 2>nul
if exist "%BASEDIR%Codex-Windows\scripts\run.ps1" (
set "BASEDIR=%BASEDIR%Codex-Windows\"
cd /d "!BASEDIR!"
)
)
)
echo Repo ready.
if exist "%BASEDIR%Codex.dmg" (
echo DMG already exists, skipping download.
) else (
echo Downloading Codex.dmg from OpenAI CDN...
curl -L -o "%BASEDIR%Codex.dmg" "https://persistent.oaistatic.com/codex-app-prod/Codex.dmg" --progress-bar
if !errorlevel! neq 0 (
echo ERROR: Failed to download Codex.dmg
pause
exit /b 1
)
echo Download complete.
)
echo.
:: ============================================
:: [6/8] NPM GLOBAL PACKAGES
:: ============================================
echo [6/8] Installing npm packages...
:: Check @electron/asar
call npm.cmd list -g @electron/asar >nul 2>&1
if %errorlevel% neq 0 (
echo Installing @electron/asar...
call npm.cmd install -g @electron/asar
) else (
echo @electron/asar already installed.
)
:: Check @openai/codex - always update to latest for DMG compatibility
echo Installing/updating @openai/codex to latest...
call npm.cmd install -g @openai/codex@latest
echo npm packages ready.
echo.
:: ============================================
:: [7/8] FIND CODEX CLI + PATCH RUN.PS1
:: ============================================
echo [7/8] Patching run.ps1 and locating Codex CLI...
:: Find codex.exe
set "CODEX_EXE="
for /f "tokens=*" %%r in ('npm.cmd root -g 2^>nul') do set "NPM_ROOT=%%r"
if defined NPM_ROOT (
:: v0.101+ layout
if exist "%NPM_ROOT%\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe" (
set "CODEX_EXE=%NPM_ROOT%\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe"
)
:: Older layout fallback
if not defined CODEX_EXE (
if exist "%NPM_ROOT%\@openai\codex\vendor\x86_64-pc-windows-msvc\codex\codex.exe" (
set "CODEX_EXE=%NPM_ROOT%\@openai\codex\vendor\x86_64-pc-windows-msvc\codex\codex.exe"
)
)
:: ARM64 layout
if not defined CODEX_EXE (
if exist "%NPM_ROOT%\@openai\codex\node_modules\@openai\codex-win32-arm64\vendor\aarch64-pc-windows-msvc\codex\codex.exe" (
set "CODEX_EXE=%NPM_ROOT%\@openai\codex\node_modules\@openai\codex-win32-arm64\vendor\aarch64-pc-windows-msvc\codex\codex.exe"
)
)
)
if defined CODEX_EXE (
echo Codex CLI: %CODEX_EXE%
) else (
echo WARNING: Could not locate codex.exe, script will attempt auto-detection.
)
:: Patch run.ps1
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$f = '%BASEDIR%scripts\run.ps1'; " ^
"$c = Get-Content -Raw $f; " ^
"$patched = $false; " ^
"if ($c -match 'Set-StrictMode -Version Latest') { " ^
" $c = $c -replace 'Set-StrictMode -Version Latest', 'Set-StrictMode -Off'; " ^
" $patched = $true " ^
"} " ^
"if ($c -match '& npm ' -and $c -notmatch 'npmCmd') { " ^
" $resolve = \"`n# Resolve .cmd wrappers to avoid PS1 wrapper bugs`n`$npmCmd = (Get-Command npm.cmd -EA SilentlyContinue).Source`nif (-not `$npmCmd) { `$npmCmd = 'npm' }`n\"; " ^
" $c = $c -replace '(Ensure-Command npx)', \"`$1`n$resolve\"; " ^
" $c = $c -replace '& npm ', '& `$npmCmd '; " ^
" $patched = $true " ^
"} " ^
"if ($c -match '& npx --yes @electron/asar' -and $c -notmatch 'asarCmd') { " ^
" $asarBlock = ' `$asarCmd = Get-Command asar -EA SilentlyContinue`n if (`$asarCmd) { & asar extract `$asar `$appDir } else { & npx --yes @electron/asar extract `$asar `$appDir }'; " ^
" $c = $c -replace ' & npx --yes @electron/asar extract \$asar \$appDir', $asarBlock; " ^
" $patched = $true " ^
"} " ^
"if ($patched) { Set-Content -NoNewline -Path $f -Value $c; Write-Host ' Patches applied.' } " ^
"else { Write-Host ' Already patched.' }"
echo.
:: ============================================
:: [8/8] LAUNCH
:: ============================================
echo [8/8] Launching Codex Desktop...
echo ============================================
echo.
if defined CODEX_EXE (
powershell -NoProfile -ExecutionPolicy Bypass -File "%BASEDIR%scripts\run.ps1" -DmgPath "%BASEDIR%Codex.dmg" -CodexCliPath "%CODEX_EXE%"
) else (
powershell -NoProfile -ExecutionPolicy Bypass -File "%BASEDIR%scripts\run.ps1" -DmgPath "%BASEDIR%Codex.dmg"
)
if %errorlevel% neq 0 (
echo.
echo ============================================
echo Codex exited with an error.
echo Check the output above for details.
echo ============================================
pause
exit /b 1
)
echo.
echo ============================================
echo Codex Desktop closed successfully.
echo ============================================
pause