-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_windows.bat
More file actions
106 lines (89 loc) · 3.86 KB
/
install_windows.bat
File metadata and controls
106 lines (89 loc) · 3.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
@echo off
setlocal EnableDelayedExpansion
:: ============================================================
:: TSC Bridge — Instalador desatendido para Windows
:: Todo automatico: instala, configura hosts, SSL, firewall,
:: auto-start y abre navegador. Sin intervencion del usuario.
:: ============================================================
set BINARY_NAME=tsc-bridge.exe
set INSTALL_DIR=%LOCALAPPDATA%\tsc-bridge
set CONFIG_DIR=%APPDATA%\tsc-bridge
set CERT_DIR=%CONFIG_DIR%\certs
set STARTUP_DIR=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
set HOSTNAME=myprinter.com
set HOSTS_FILE=%SystemRoot%\System32\drivers\etc\hosts
set SCRIPT_DIR=%~dp0
:: --- Auto-elevate to admin (silently) ---
net session >nul 2>&1
if %errorlevel% neq 0 (
powershell -WindowStyle Hidden -Command "Start-Process cmd -ArgumentList '/c \"%~f0\"' -Verb RunAs -Wait" >nul 2>&1
exit /b
)
:: --- Kill existing instance ---
taskkill /IM %BINARY_NAME% /F >nul 2>&1
timeout /t 1 /nobreak >nul
:: --- Install binary ---
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
if not exist "%CONFIG_DIR%" mkdir "%CONFIG_DIR%"
if exist "%SCRIPT_DIR%%BINARY_NAME%" (
copy /Y "%SCRIPT_DIR%%BINARY_NAME%" "%INSTALL_DIR%\%BINARY_NAME%" >nul
) else (
exit /b 1
)
:: --- Add hostname to hosts file ---
findstr /C:"%HOSTNAME%" "%HOSTS_FILE%" >nul 2>&1
if %errorlevel% neq 0 (
echo 127.0.0.1 %HOSTNAME%>> "%HOSTS_FILE%"
)
:: --- Clean old firewall rules (port 9271/9272 from v2.2.0 and earlier) ---
netsh advfirewall firewall delete rule name="TSC Bridge HTTP" >nul 2>&1
netsh advfirewall firewall delete rule name="TSC Bridge HTTPS" >nul 2>&1
:: --- Add firewall rules (ports 9638 and 9639) ---
netsh advfirewall firewall add rule name="TSC Bridge HTTP" dir=in action=allow protocol=TCP localport=9638 >nul 2>&1
netsh advfirewall firewall add rule name="TSC Bridge HTTPS" dir=in action=allow protocol=TCP localport=9639 >nul 2>&1
:: --- Generate certs: run bridge briefly then kill ---
if not exist "%CERT_DIR%" mkdir "%CERT_DIR%"
del /Q "%CONFIG_DIR%\.browser-opened" >nul 2>&1
start /B "" "%INSTALL_DIR%\%BINARY_NAME%"
timeout /t 4 /nobreak >nul
taskkill /IM %BINARY_NAME% /F >nul 2>&1
timeout /t 1 /nobreak >nul
:: --- Trust CA certificate in Windows cert store ---
set CA_CERT=%CERT_DIR%\ca.pem
if exist "%CA_CERT%" (
certutil -addstore -f "Root" "%CA_CERT%" >nul 2>&1
)
:: --- Remove old startup shortcut before recreating ---
if exist "%STARTUP_DIR%\TSC Bridge.lnk" del "%STARTUP_DIR%\TSC Bridge.lnk" >nul 2>&1
:: --- Create startup shortcut (headless service mode at login, no browser) ---
>"%TEMP%\_tsc_startup.vbs" (
echo Set oWS = WScript.CreateObject^("WScript.Shell"^)
echo sLinkFile = "%STARTUP_DIR%\TSC Bridge.lnk"
echo Set oLink = oWS.CreateShortcut^(sLinkFile^)
echo oLink.TargetPath = "%INSTALL_DIR%\%BINARY_NAME%"
echo oLink.Arguments = "--headless"
echo oLink.WorkingDirectory = "%INSTALL_DIR%"
echo oLink.Description = "TSC Bridge - Servicio de impresion"
echo oLink.WindowStyle = 7
echo oLink.Save
)
cscript //nologo "%TEMP%\_tsc_startup.vbs" >nul 2>&1
del "%TEMP%\_tsc_startup.vbs" >nul 2>&1
:: --- Create desktop shortcut (opens embedded dashboard) ---
set DESKTOP_DIR=%USERPROFILE%\Desktop
>"%TEMP%\_tsc_desktop.vbs" (
echo Set oWS = WScript.CreateObject^("WScript.Shell"^)
echo sLinkFile = "%DESKTOP_DIR%\TSC Bridge.lnk"
echo Set oLink = oWS.CreateShortcut^(sLinkFile^)
echo oLink.TargetPath = "%INSTALL_DIR%\%BINARY_NAME%"
echo oLink.WorkingDirectory = "%INSTALL_DIR%"
echo oLink.Description = "TSC Bridge - Panel de control"
echo oLink.WindowStyle = 1
echo oLink.Save
)
cscript //nologo "%TEMP%\_tsc_desktop.vbs" >nul 2>&1
del "%TEMP%\_tsc_desktop.vbs" >nul 2>&1
:: --- Start the bridge service (headless, stays running in background) ---
start "" "%INSTALL_DIR%\%BINARY_NAME%" --headless
:: Done — no pause, fully unattended
exit /b 0