-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.bat
More file actions
200 lines (176 loc) · 5.26 KB
/
setup.bat
File metadata and controls
200 lines (176 loc) · 5.26 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
@echo off
setlocal enabledelayedexpansion
:: ===================================================================
:: quick-mouse Installer for Windows
:: Supports: winget (preferred), choco (fallback)
:: Auto-refreshes PATH after installing tools
:: ===================================================================
echo Installing quick-mouse...
:: ---------- Clone Repository ----------
if not exist quick-mouse\go.mod (
echo Cloning quick-mouse repository...
git clone https://github.com/DerekCorniello/quick-mouse.git
if errorlevel 1 (
echo [ERROR] Failed to clone repository.
exit /b 1
)
)
cd quick-mouse || (
echo [ERROR] Failed to enter quick-mouse directory.
exit /b 1
)
:: ---------- Install Required Tools ----------
call :install_package go GoLang.Go go
call :install_package nodejs OpenJS.NodeJS node
call :install_package openssl FireDaemon.OpenSSL openssl
:: ---------- Go Backend Build ----------
echo.
echo Installing Go dependencies...
go mod tidy
if errorlevel 1 (
echo [ERROR] Failed to tidy Go modules.
exit /b 1
)
echo Building Go executable...
go build -o quick-mouse.exe
if errorlevel 1 (
echo [ERROR] Failed to build quick-mouse.exe
exit /b 1
)
:: ---------- Client Build ----------
echo.
echo Building client (Node.js)...
if not exist client\package.json (
echo [ERROR] client/package.json not found. Is the repo cloned correctly?
exit /b 1
)
cd client
call npm install
if errorlevel 1 (
echo [ERROR] npm install failed.
exit /b 1
)
call npm run build
if errorlevel 1 (
echo [ERROR] npm run build failed.
exit /b 1
)
cd ..
:: ---------- Certificate Generation ----------
echo.
if not exist certs mkdir certs
:: Check OpenSSL with full path fallback
set "OPENSSL_CMD=openssl"
where openssl >nul 2>nul
if errorlevel 1 (
:: Try common FireDaemon install path
set "FD_PATH=%ProgramFiles%\FireDaemon OpenSSL"
if exist "!FD_PATH!" (
for /d %%d in ("!FD_PATH!\*") do (
if exist "%%d\bin\openssl.exe" (
set "OPENSSL_CMD=%%d\bin\openssl.exe"
set "PATH=!PATH!;%%d\bin"
goto :openssl_found
)
)
)
echo [ERROR] OpenSSL not found in PATH or default install location.
echo Install via: winget install FireDaemon.OpenSSL
exit /b 1
)
:openssl_found
echo Generating TLS certificate for localhost...
"%OPENSSL_CMD%" req -x509 -newkey rsa:4096 ^
-keyout certs\localhost-key.pem ^
-out certs\localhost.pem ^
-days 365 -nodes ^
-subj "/CN=localhost"
if errorlevel 1 (
echo [ERROR] Certificate generation failed.
exit /b 1
)
:: ---------- Success ----------
echo.
echo ========================================
echo Installation completed successfully!
echo ========================================
echo.
echo Executable: quick-mouse.exe
echo Client: client/dist/ (or client/build/)
echo Certs: certs\localhost.pem
echo certs\localhost-key.pem
echo.
echo Run: quick-mouse.exe
echo.
pause
exit /b 0
:: ===================================================================
:: :install_package <name> <winget-id> <check-cmd>
:: Installs package using winget (preferred) or choco (fallback)
:: Auto-refreshes PATH after install
:: ===================================================================
:install_package
set "PKG_NAME=%~1"
set "WINGET_ID=%~2"
set "CHECK_CMD=%~3"
echo Checking for %PKG_NAME%...
where %CHECK_CMD% >nul 2>nul
if not errorlevel 1 (
echo [OK] %PKG_NAME% is already installed.
goto :eof
)
echo [INSTALL] Installing %PKG_NAME%...
:: Try winget
where winget >nul 2>nul
if not errorlevel 1 (
echo Using winget...
winget install --id %WINGET_ID% --silent --accept-package-agreements --accept-source-agreements
if errorlevel 1 (
echo [WARN] winget install failed, trying choco...
goto :try_choco
)
:: Auto-refresh PATH for common tools
if /i "%PKG_NAME%"=="go" (
set "PATH=%PATH%;%ProgramFiles%\Go\bin"
)
if /i "%PKG_NAME%"=="nodejs" (
set "PATH=%PATH%;%ProgramFiles%\nodejs"
)
if /i "%PKG_NAME%"=="openssl" (
call :refresh_openssl_path
)
echo [OK] %PKG_NAME% installed via winget.
goto :eof
)
:try_choco
:: Try Chocolatey
where choco >nul 2>nul
if not errorlevel 1 (
echo Using Chocolatey...
choco install %PKG_NAME% -y
if errorlevel 1 (
echo [ERROR] Failed to install %PKG_NAME% with both winget and choco.
echo Please install manually: https://go.dev/dl/, https://nodejs.org, https://slproweb.com/products/Win32OpenSSL.html
exit /b 1
)
echo [OK] %PKG_NAME% installed via choco.
goto :eof
)
echo [ERROR] Neither winget nor choco is available.
echo Please install %PKG_NAME% manually.
exit /b 1
:: ===================================================================
:: :refresh_openssl_path
:: Finds FireDaemon OpenSSL install and adds to PATH
:: ===================================================================
:refresh_openssl_path
set "FD_BASE=%ProgramFiles%\FireDaemon OpenSSL"
if not exist "!FD_BASE!" goto :eof
for /d %%d in ("!FD_BASE!\*") do (
if exist "%%d\bin\openssl.exe" (
set "PATH=!PATH!;%%d\bin"
echo Added OpenSSL to PATH: %%d\bin
goto :eof
)
)
goto :eof