-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.bat
More file actions
171 lines (151 loc) · 4.86 KB
/
install.bat
File metadata and controls
171 lines (151 loc) · 4.86 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
@echo off
REM Core CLI unified installer (Windows)
REM Served via *.core.help with BunnyCDN edge transformation
REM
REM Usage:
REM curl -fsSL setup.core.help -o install.bat && install.bat # Interactive (default)
REM curl -fsSL ci.core.help -o install.bat && install.bat # CI/CD
REM curl -fsSL dev.core.help -o install.bat && install.bat # Full development
REM curl -fsSL go.core.help -o install.bat && install.bat # Go variant
REM curl -fsSL php.core.help -o install.bat && install.bat # PHP variant
REM curl -fsSL agent.core.help -o install.bat && install.bat # Agent variant
REM
setlocal enabledelayedexpansion
REM === BunnyCDN Edge Variables (transformed at edge based on subdomain) ===
set "MODE={{CORE_MODE}}"
set "VARIANT={{CORE_VARIANT}}"
REM === Fallback for local testing ===
if "!MODE!"=="{{CORE_MODE}}" (
if defined CORE_MODE (set "MODE=!CORE_MODE!") else (set "MODE=setup")
)
if "!VARIANT!"=="{{CORE_VARIANT}}" (
if defined CORE_VARIANT (set "VARIANT=!CORE_VARIANT!") else (set "VARIANT=")
)
REM === Configuration ===
set "VERSION=%~1"
if "%VERSION%"=="" set "VERSION=latest"
set "FORGE=https://forge.lthn.ai"
set "REPO=core/cli"
set "BINARY=core"
set "INSTALL_DIR=%LOCALAPPDATA%\Programs\core"
REM === Resolve Version ===
if "%VERSION%"=="latest" (
for /f "tokens=2 delims=:" %%a in ('curl -fsSL --max-time 10 "%FORGE%/api/v1/repos/%REPO%/releases/latest" ^| findstr "tag_name"') do (
set "VERSION=%%a"
set "VERSION=!VERSION:"=!"
set "VERSION=!VERSION: =!"
set "VERSION=!VERSION:,=!"
)
if "!VERSION!"=="" (
echo ERROR: Failed to fetch latest version
exit /b 1
)
if "!VERSION!"=="latest" (
echo ERROR: Failed to resolve version
exit /b 1
)
)
REM === Create install directory ===
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
REM === Mode dispatch ===
if "%MODE%"=="ci" goto :install_ci
if "%MODE%"=="dev" goto :install_dev
if "%MODE%"=="variant" goto :install_variant
goto :install_setup
:install_setup
echo Installing %BINARY% !VERSION! for Windows...
call :find_archive "" ARCHIVE
if errorlevel 1 exit /b 1
call :download_and_extract
if errorlevel 1 exit /b 1
call :install_binary
if errorlevel 1 exit /b 1
call :verify_install
if errorlevel 1 exit /b 1
goto :done
:install_ci
echo Installing %BINARY% !VERSION! (CI)...
call :find_archive "" ARCHIVE
if errorlevel 1 exit /b 1
call :download_and_extract
if errorlevel 1 exit /b 1
call :install_binary
if errorlevel 1 exit /b 1
%BINARY% --version
if errorlevel 1 exit /b 1
goto :done
:install_dev
echo Installing %BINARY% !VERSION! (full) for Windows...
call :find_archive "" ARCHIVE
if errorlevel 1 exit /b 1
call :download_and_extract
if errorlevel 1 exit /b 1
call :install_binary
if errorlevel 1 exit /b 1
call :verify_install
if errorlevel 1 exit /b 1
echo.
echo Full development variant installed. Available commands:
echo core dev - Multi-repo workflows
echo core build - Cross-platform builds
echo core release - Build and publish releases
goto :done
:install_variant
echo Installing %BINARY% !VERSION! (%VARIANT% variant) for Windows...
call :find_archive "%VARIANT%" ARCHIVE
if errorlevel 1 exit /b 1
call :download_and_extract
if errorlevel 1 exit /b 1
call :install_binary
if errorlevel 1 exit /b 1
call :verify_install
if errorlevel 1 exit /b 1
goto :done
REM === Helper Functions ===
:find_archive
set "_variant=%~1"
set "_result=%~2"
REM Try variant-specific first, then full
if not "%_variant%"=="" (
set "_try=%BINARY%-%_variant%-windows-amd64.zip"
curl -fsSLI --max-time 10 "%FORGE%/%REPO%/releases/download/!VERSION!/!_try!" 2>nul | findstr /r "HTTP/[12].* [23][0-9][0-9]" >nul
if not errorlevel 1 (
set "%_result%=!_try!"
exit /b 0
)
echo Using full variant ^(%_variant% variant not available^)
)
set "%_result%=%BINARY%-windows-amd64.zip"
exit /b 0
:download_and_extract
curl -fsSL --connect-timeout 10 "%FORGE%/%REPO%/releases/download/!VERSION!/!ARCHIVE!" -o "%TEMP%\!ARCHIVE!"
if errorlevel 1 (
echo ERROR: Failed to download !ARCHIVE!
exit /b 1
)
powershell -Command "try { Expand-Archive -Force '%TEMP%\!ARCHIVE!' '%INSTALL_DIR%' } catch { exit 1 }"
if errorlevel 1 (
echo ERROR: Failed to extract archive
del "%TEMP%\!ARCHIVE!" 2>nul
exit /b 1
)
del "%TEMP%\!ARCHIVE!" 2>nul
exit /b 0
:install_binary
REM Add to PATH using PowerShell (avoids setx 1024 char limit)
echo %PATH% | findstr /i /c:"%INSTALL_DIR%" >nul
if errorlevel 1 (
powershell -Command "[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User') + ';%INSTALL_DIR%', 'User')"
set "PATH=%PATH%;%INSTALL_DIR%"
)
exit /b 0
:verify_install
if not exist "%INSTALL_DIR%\%BINARY%.exe" (
echo ERROR: Installation failed - binary not found
exit /b 1
)
"%INSTALL_DIR%\%BINARY%.exe" --version
if errorlevel 1 exit /b 1
exit /b 0
:done
endlocal