-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.bat
More file actions
178 lines (149 loc) · 5.17 KB
/
Copy pathinstall.bat
File metadata and controls
178 lines (149 loc) · 5.17 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
@echo off
chcp 65001 >nul 2>&1
setlocal EnableDelayedExpansion
:: ================================================
:: Shield CLI - Windows One-Click Installer
:: Double-click to install Shield as a service
:: and open the Web UI in your browser.
:: ================================================
title Shield CLI Installer
:: ----------------------------
:: Step 1: Request Admin rights
:: ----------------------------
net session >nul 2>&1
if %errorLevel% neq 0 (
echo [Shield CLI] Requesting administrator privileges...
powershell -Command "Start-Process cmd -ArgumentList '/c \"\"%~f0\"\"' -Verb RunAs"
exit /b
)
:: ----------------------------
:: Step 2: Configuration
:: ----------------------------
set "REPO=fengyily/shield-cli"
set "INSTALL_DIR=%ProgramFiles%\ShieldCLI"
set "BINARY=shield.exe"
set "PORT=8181"
echo.
echo ============================================
echo Shield CLI - One-Click Installer
echo ============================================
echo.
:: ----------------------------
:: Step 3: Detect Architecture
:: ----------------------------
set "ARCH=amd64"
if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" set "ARCH=arm64"
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" (
if /i "%PROCESSOR_ARCHITEW6432%"=="" (
echo [ERROR] 32-bit Windows is not supported.
echo Please use a 64-bit version of Windows.
echo.
pause
exit /b 1
)
)
:: WoW64: 32-bit cmd on 64-bit OS
if /i "%PROCESSOR_ARCHITEW6432%"=="AMD64" set "ARCH=amd64"
if /i "%PROCESSOR_ARCHITEW6432%"=="ARM64" set "ARCH=arm64"
echo Architecture: windows/%ARCH%
echo.
:: ----------------------------
:: Step 4: Get latest version
:: ----------------------------
echo [1/5] Fetching latest version...
for /f "delims=" %%V in ('powershell -NoProfile -Command "(Invoke-RestMethod -Uri 'https://api.github.com/repos/%REPO%/releases/latest').tag_name -replace '^v',''"') do set "VERSION=%%V"
if "%VERSION%"=="" (
echo.
echo [ERROR] Failed to fetch latest version.
echo Please check your network connection.
echo.
pause
exit /b 1
)
echo Latest version: v%VERSION%
:: ----------------------------
:: Step 5: Download
:: ----------------------------
set "FILENAME=shield-windows-%ARCH%.zip"
set "URL=https://github.com/%REPO%/releases/download/v%VERSION%/%FILENAME%"
set "TMPDIR=%TEMP%\shield-install-%RANDOM%"
mkdir "%TMPDIR%" >nul 2>&1
echo [2/5] Downloading Shield CLI v%VERSION%...
powershell -NoProfile -Command ^
"$ProgressPreference='SilentlyContinue'; " ^
"try { Invoke-WebRequest -Uri '%URL%' -OutFile '%TMPDIR%\%FILENAME%' -UseBasicParsing } " ^
"catch { " ^
" Write-Host ''; " ^
" Write-Host ' [INFO] GitHub download slow? Trying China mirror...'; " ^
" $mirrorUrl = 'https://mirror.ghproxy.com/%URL%'; " ^
" try { Invoke-WebRequest -Uri $mirrorUrl -OutFile '%TMPDIR%\%FILENAME%' -UseBasicParsing } " ^
" catch { Write-Host ' [ERROR] Download failed.'; exit 1 } " ^
"}"
if not exist "%TMPDIR%\%FILENAME%" (
echo.
echo [ERROR] Download failed.
echo URL: %URL%
echo.
rd /s /q "%TMPDIR%" >nul 2>&1
pause
exit /b 1
)
:: ----------------------------
:: Step 6: Extract
:: ----------------------------
echo [3/5] Extracting...
powershell -NoProfile -Command "Expand-Archive -Path '%TMPDIR%\%FILENAME%' -DestinationPath '%TMPDIR%\extracted' -Force"
:: ----------------------------
:: Step 7: Install binary
:: ----------------------------
echo [4/5] Installing to %INSTALL_DIR%...
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
copy /y "%TMPDIR%\extracted\%BINARY%" "%INSTALL_DIR%\%BINARY%" >nul
:: Add to system PATH
powershell -NoProfile -Command ^
"$path = [Environment]::GetEnvironmentVariable('Path','Machine'); " ^
"if ($path -notlike '*%INSTALL_DIR%*') { " ^
" [Environment]::SetEnvironmentVariable('Path', \"$path;%INSTALL_DIR%\", 'Machine'); " ^
" Write-Host ' Added to system PATH' " ^
"}"
:: Cleanup temp files
rd /s /q "%TMPDIR%" >nul 2>&1
:: ----------------------------
:: Step 8: Install as service
:: ----------------------------
echo [5/5] Installing system service...
:: Stop and remove existing service if present
sc query ShieldCLI >nul 2>&1 && (
sc stop ShieldCLI >nul 2>&1
timeout /t 2 /nobreak >nul
sc delete ShieldCLI >nul 2>&1
timeout /t 1 /nobreak >nul
)
"%INSTALL_DIR%\%BINARY%" install --port %PORT%
if %errorLevel% neq 0 (
echo.
echo [WARNING] Service installation had issues.
echo You can manually run: shield install --port %PORT%
echo.
)
:: ----------------------------
:: Step 9: Open browser
:: ----------------------------
echo.
echo ============================================
echo Shield CLI v%VERSION% installed!
echo ============================================
echo.
echo Web UI: http://localhost:%PORT%
echo Binary: %INSTALL_DIR%\%BINARY%
echo.
echo Commands:
echo shield start - Start Web UI
echo shield install - Install as service
echo shield uninstall - Remove service
echo shield --help - More options
echo.
:: Open Web UI in default browser
start "" "http://localhost:%PORT%"
echo Press any key to close this window...
pause >nul