Repository navigation
Expand file tree
/
Copy pathsetup.bat
More file actions
279 lines (253 loc) · 9.92 KB
/
Copy pathsetup.bat
File metadata and controls
279 lines (253 loc) · 9.92 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@echo off
setlocal enabledelayedexpansion
title Freshdesk Dashboard - Server Setup
:: Auto-elevate to admin
net session >nul 2>&1
if %errorlevel% neq 0 (
echo Requesting administrator privileges...
if exist "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" (
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "Start-Process cmd -ArgumentList '/c \"%~f0\"' -Verb RunAs -WorkingDirectory '%~dp0'"
) else (
echo Please right-click setup.bat and select "Run as administrator"
pause
exit /b 1
)
exit /b
)
color 0A
echo ============================================
echo Freshdesk Dashboard - Server Setup
echo ============================================
echo.
:: Get current directory
set "INSTALL_DIR=%~dp0"
set "INSTALL_DIR=%INSTALL_DIR:~0,-1%"
cd /d "%INSTALL_DIR%"
:: 1. Check/Install Python
echo [1/7] Checking Python...
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo Python not found. Downloading installer...
call :download "https://www.python.org/ftp/python/3.13.3/python-3.13.3-amd64.exe" "%TEMP%\python-installer.exe"
if not exist "%TEMP%\python-installer.exe" (
echo.
echo ERROR: Automatic download failed.
echo Please download Python manually:
echo https://www.python.org/downloads/
echo IMPORTANT: Check "Add Python to PATH" during installation
echo Then run setup.bat again.
pause
exit /b 1
)
echo Installing Python silently...
start /wait "" "%TEMP%\python-installer.exe" /quiet InstallAllUsers=1 PrependPath=1 Include_pip=1
del "%TEMP%\python-installer.exe" >nul 2>&1
:: Refresh PATH from registry
for /f "tokens=2*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do set "PATH=%%B"
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v Path 2^>nul') do set "PATH=!PATH!;%%B"
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo ERROR: Python installation failed
echo Please install manually from https://www.python.org/downloads/
echo IMPORTANT: Check "Add Python to PATH" during installation
pause
exit /b 1
)
echo Python installed successfully.
)
for /f "tokens=*" %%i in ('python --version 2^>^&1') do echo Found: %%i
echo.
:: 2. Check/Install Ollama
echo [2/7] Checking Ollama...
where ollama >nul 2>&1
if %errorlevel% neq 0 (
echo Ollama not found. Downloading installer...
call :download "https://ollama.com/download/OllamaSetup.exe" "%TEMP%\OllamaSetup.exe"
if not exist "%TEMP%\OllamaSetup.exe" (
echo.
echo ERROR: Automatic download failed.
echo Please download Ollama manually: https://ollama.com/download
echo Then run setup.bat again.
pause
exit /b 1
)
echo Installing Ollama silently...
start /wait "" "%TEMP%\OllamaSetup.exe" /VERYSILENT /NORESTART
del "%TEMP%\OllamaSetup.exe" >nul 2>&1
echo Ollama installed.
) else (
echo Ollama already installed.
)
echo.
:: 3. Set environment variables (persist across reboots)
echo [3/7] Configuring environment variables...
setx OLLAMA_HOST "0.0.0.0" /M >nul 2>&1
setx OLLAMA_ORIGINS "*" /M >nul 2>&1
set "OLLAMA_HOST=0.0.0.0"
set "OLLAMA_ORIGINS=*"
echo OLLAMA_HOST=0.0.0.0
echo OLLAMA_ORIGINS=*
echo.
:: 4. Install Python dependencies
echo [4/7] Installing Python dependencies...
pip install -r "%INSTALL_DIR%\Sharepoint\requirements.txt" --quiet --no-warn-script-location
echo Dependencies installed.
echo.
:: 5. Pull AI model
echo [5/7] Downloading AI model (qwen3.5:9b ~6GB)...
echo This may take several minutes on first run...
"%LOCALAPPDATA%\Programs\Ollama\ollama.exe" pull qwen3.5:9b
echo.
:: 6. Firewall rules
echo [6/7] Configuring firewall...
netsh advfirewall firewall delete rule name="FreshdeskDashboard-Proxy" >nul 2>&1
netsh advfirewall firewall delete rule name="FreshdeskDashboard-Ollama" >nul 2>&1
netsh advfirewall firewall add rule name="FreshdeskDashboard-Proxy" dir=in action=allow protocol=TCP localport=8080 >nul
netsh advfirewall firewall add rule name="FreshdeskDashboard-Ollama" dir=in action=allow protocol=TCP localport=11434 >nul
echo Port 8080 (proxy) - opened
echo Port 11434 (Ollama) - opened
echo.
:: 7. Configure auto-start on login
echo [7/7] Configuring auto-start...
set "AUTOSTART_OK="
:: Primary: per-user Startup shortcut. Needs no elevation.
set "STARTUP_LNK=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\FreshDeskProMax.lnk"
> "%TEMP%\fd-lnk.vbs" echo Set w=CreateObject("WScript.Shell")
>> "%TEMP%\fd-lnk.vbs" echo Set s=w.CreateShortcut("%STARTUP_LNK%")
>> "%TEMP%\fd-lnk.vbs" echo s.TargetPath="C:\Windows\System32\wscript.exe"
>> "%TEMP%\fd-lnk.vbs" echo s.Arguments="""%INSTALL_DIR%\watchdog.vbs"""
>> "%TEMP%\fd-lnk.vbs" echo s.WorkingDirectory="%INSTALL_DIR%"
>> "%TEMP%\fd-lnk.vbs" echo s.WindowStyle=7
>> "%TEMP%\fd-lnk.vbs" echo s.Save
cscript //nologo "%TEMP%\fd-lnk.vbs" >nul 2>&1
del "%TEMP%\fd-lnk.vbs" >nul 2>&1
if exist "%STARTUP_LNK%" (
set "AUTOSTART_OK=1"
echo Startup shortcut created.
)
:: Secondary: scheduled task. /rl highest needs elevation, so check the exit
:: code and retry unelevated. /f overwrites in place -- deleting first meant a
:: failed create silently left no task at all.
schtasks /create /tn "FreshDeskProMax" /tr "\"%INSTALL_DIR%\start.bat\"" /sc onlogon /rl highest /f >nul 2>&1
if errorlevel 1 (
echo Elevated task creation failed, retrying unelevated...
schtasks /create /tn "FreshDeskProMax" /tr "\"%INSTALL_DIR%\start.bat\"" /sc onlogon /f >nul 2>&1
)
if not errorlevel 1 (
set "AUTOSTART_OK=1"
echo Scheduled task created.
schtasks /delete /tn "FreshdeskDashboard" /f >nul 2>&1
)
if defined AUTOSTART_OK (
echo Auto-start on login configured.
) else (
echo WARNING: could not configure auto-start.
)
echo.
:: Start services now
echo Starting services...
call "%INSTALL_DIR%\start.bat"
echo.
echo ============================================
echo Setup complete!
echo ============================================
echo.
call :spcheck
echo To use the dashboard, open a browser and go to:
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /c:"IPv4"') do (
set "ip=%%a"
set "ip=!ip: =!"
if not "!ip!"=="" echo http://!ip!:8080
)
echo.
echo Other PCs on the network can also access this URL.
echo Services will auto-start when this PC boots.
echo.
echo Opening dashboard in browser...
start "" "http://localhost:8080"
echo.
pause
exit /b
:: ============================================
:: SharePoint configuration check
:: Credentials are deliberately kept out of the installer payload
:: (installer/build-installer.bat aborts the build if it finds them), so a fresh
:: install has no .env and "Generate SharePoint Folder" fails at runtime with
:: "Missing required environment variables". Say so here instead of at first use.
:: Flat gotos rather than nested if/else: parenthesised blocks in batch expand
:: too early and swallow the ^< escapes below.
:: ============================================
:spcheck
if not exist "%INSTALL_DIR%\Sharepoint\.env" goto :spnoenv
if not exist "%INSTALL_DIR%\Sharepoint\token_cache.json" goto :spnoauth
echo SharePoint ticket folders: configured.
echo.
exit /b 0
:spnoenv
echo NOTE: SharePoint ticket folders are not configured yet.
echo The "Generate SharePoint Folder" button will report an error until you:
echo 1. Copy Sharepoint\.env.example to Sharepoint\.env
echo 2. Fill in FRESHDESK_DOMAIN, FRESHDESK_API_KEY, AZURE_CLIENT_ID,
echo AZURE_TENANT_ID and ONEDRIVE_FOLDER_URL
echo 3. Sign in once (see the command below)
echo Then run, replacing ^<ticket_id^> with any real ticket number:
echo python "%INSTALL_DIR%\Sharepoint\create_ticket_folder.py" ^<ticket_id^>
echo.
exit /b 0
:spnoauth
echo NOTE: SharePoint is configured but not signed in to Microsoft yet.
echo The proxy runs hidden and cannot show a sign-in prompt, so run this once,
echo replacing ^<ticket_id^> with any real ticket number:
echo python "%INSTALL_DIR%\Sharepoint\create_ticket_folder.py" ^<ticket_id^>
echo.
exit /b 0
:: ============================================
:: Download function - tries multiple methods
:: Usage: call :download "URL" "FILE"
:: ============================================
:download
set "DL_URL=%~1"
set "DL_FILE=%~2"
if exist "%DL_FILE%" del "%DL_FILE%" >nul 2>&1
:: Method 1: certutil (uses CryptoAPI/Schannel, follows IE TLS settings)
echo Trying certutil...
certutil -urlcache -split -f "%DL_URL%" "%DL_FILE%" >nul 2>&1
if exist "%DL_FILE%" (
echo Download OK.
exit /b 0
)
:: Method 2: PowerShell with TLS 1.2
if exist "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" (
echo Trying PowerShell...
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%DL_URL%', '%DL_FILE%')" >nul 2>&1
if exist "%DL_FILE%" (
echo Download OK.
exit /b 0
)
)
:: Method 3: bitsadmin
echo Trying bitsadmin...
bitsadmin /transfer "FDDownload" /priority high "%DL_URL%" "%DL_FILE%" >nul 2>&1
if exist "%DL_FILE%" (
echo Download OK.
exit /b 0
)
:: Method 4: VBScript (uses WinInet, same TLS as Internet Explorer)
echo Trying VBScript...
echo Set x=CreateObject("MSXML2.XMLHTTP") > "%TEMP%\dl.vbs"
echo x.Open "GET",WScript.Arguments(0),False >> "%TEMP%\dl.vbs"
echo x.Send >> "%TEMP%\dl.vbs"
echo Set s=CreateObject("ADODB.Stream") >> "%TEMP%\dl.vbs"
echo s.Type=1 >> "%TEMP%\dl.vbs"
echo s.Open >> "%TEMP%\dl.vbs"
echo s.Write x.responseBody >> "%TEMP%\dl.vbs"
echo s.SaveToFile WScript.Arguments(1),2 >> "%TEMP%\dl.vbs"
echo s.Close >> "%TEMP%\dl.vbs"
cscript //nologo "%TEMP%\dl.vbs" "%DL_URL%" "%DL_FILE%" >nul 2>&1
del "%TEMP%\dl.vbs" >nul 2>&1
if exist "%DL_FILE%" (
echo Download OK.
exit /b 0
)
echo All download methods failed.
exit /b 1