176 lines
7.1 KiB
NSIS
176 lines
7.1 KiB
NSIS
!include "MUI2.nsh"
|
|
!include "LogicLib.nsh"
|
|
|
|
Name "LOGAR Server"
|
|
OutFile "../dist/LOGAR-Server-Setup.exe"
|
|
InstallDir "$PROGRAMFILES64\LOGAR-Server"
|
|
RequestExecutionLevel admin
|
|
|
|
BrandingText "LOGAR Centralized Log Aggregator && Ingestion Hub"
|
|
|
|
VIProductVersion "0.3.4.1"
|
|
VIAddVersionKey "ProductName" "LOGAR Server"
|
|
VIAddVersionKey "CompanyName" "LOGAR"
|
|
VIAddVersionKey "LegalCopyright" "© 2026 LOGAR"
|
|
VIAddVersionKey "FileDescription" "LOGAR Cloud Hub & TCP Ingestion Server Setup"
|
|
VIAddVersionKey "FileVersion" "0.3.4.1"
|
|
VIAddVersionKey "ProductVersion" "0.3.4.1"
|
|
|
|
# --- Visual Graphics & Branding ---
|
|
!define MUI_ICON "assets/logo.ico"
|
|
!define MUI_UNICON "assets/logo.ico"
|
|
!define MUI_HEADERIMAGE
|
|
!define MUI_HEADERIMAGE_RIGHT
|
|
!define MUI_HEADERIMAGE_BITMAP "assets/wizard_header.bmp"
|
|
!define MUI_WELCOMEFINISHPAGE_BITMAP "assets/wizard_sidebar.bmp"
|
|
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "assets/wizard_sidebar.bmp"
|
|
|
|
Var DATADIR
|
|
Var IS_UPDATE
|
|
|
|
# --- UI Pages ---
|
|
!define MUI_ABORTWARNING
|
|
|
|
# Welcome Page
|
|
!define MUI_WELCOMEPAGE_TITLE "Welcome to LOGAR Server Setup"
|
|
!define MUI_WELCOMEPAGE_TEXT "LOGAR provides high-performance encrypted log ingestion, temporal analysis, and mTLS client enrollment.$\r$\n$\r$\nThis wizard will guide you through installing LOGAR Server and configuring it as an automated Windows service."
|
|
!insertmacro MUI_PAGE_WELCOME
|
|
|
|
# Directory Page 1: Installation Directory
|
|
!define MUI_PAGE_HEADER_TEXT "Choose Installation Location"
|
|
!define MUI_PAGE_HEADER_SUBTEXT "Choose the folder in which to install program binaries."
|
|
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUpdate
|
|
!define MUI_DIRECTORYPAGE_VARIABLE $INSTDIR
|
|
!insertmacro MUI_PAGE_DIRECTORY
|
|
|
|
# Directory Page 2: Data Directory
|
|
!define MUI_PAGE_HEADER_TEXT "Choose Data & Storage Location"
|
|
!define MUI_PAGE_HEADER_SUBTEXT "Choose where database, certificates, and configuration files should be stored."
|
|
!define MUI_DIRECTORYPAGE_TEXT_TOP "Choose the folder where LOGAR Server should store its database (logar_state.db), configuration (server_config.json), and mTLS certificates.$\r$\n$\r$\nDefault is recommended for automatic background service access."
|
|
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Data & Storage Folder"
|
|
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUpdate
|
|
!define MUI_DIRECTORYPAGE_VARIABLE $DATADIR
|
|
!insertmacro MUI_PAGE_DIRECTORY
|
|
|
|
# Instfiles Page
|
|
!insertmacro MUI_PAGE_INSTFILES
|
|
|
|
# Finish Page
|
|
!define MUI_FINISHPAGE_TITLE "Installation Complete"
|
|
!define MUI_FINISHPAGE_TEXT "LOGAR Server has been successfully installed and started as a background Windows service.$\r$\n$\r$\nWeb Hub Dashboard: http://localhost:8443$\r$\nTCP Ingestion Port: 9443"
|
|
!insertmacro MUI_PAGE_FINISH
|
|
|
|
# Uninstaller Pages
|
|
!insertmacro MUI_UNPAGE_CONFIRM
|
|
!insertmacro MUI_UNPAGE_INSTFILES
|
|
|
|
!insertmacro MUI_LANGUAGE "English"
|
|
|
|
Function SkipIfUpdate
|
|
${If} $IS_UPDATE == "1"
|
|
Abort
|
|
${EndIf}
|
|
FunctionEnd
|
|
|
|
Function .onInit
|
|
SetShellVarContext all
|
|
StrCpy $DATADIR "$APPDATA\LOGAR-Server"
|
|
StrCpy $IS_UPDATE "0"
|
|
|
|
# 1. Mutual Exclusion Check: Deny installation if LOGAR Client is present
|
|
ReadRegStr $0 HKLM "Software\LOGAR\LOGAR-Client" "DataDir"
|
|
ReadRegStr $1 HKLM "Software\LOGAR\LOGAR-Client" "InstallDir"
|
|
${If} $0 != ""
|
|
${OrIf} $1 != ""
|
|
${OrIf} ${FileExists} "$PROGRAMFILES64\LOGAR\Win_Client.exe"
|
|
${OrIf} ${FileExists} "$PROGRAMFILES\LOGAR\Win_Client.exe"
|
|
MessageBox MB_ICONSTOP|MB_OK "LOGAR Client is already installed on this machine.$\r$\n$\r$\nLOGAR Server cannot be installed on a host where LOGAR Client is present (LOGAR Server already includes built-in local log collection).$\r$\n$\r$\nPlease uninstall LOGAR Client before installing LOGAR Server."
|
|
Abort
|
|
${EndIf}
|
|
|
|
# 2. Existing LOGAR Server Detection for In-Place Update Mode
|
|
ReadRegStr $0 HKLM "Software\LOGAR\LOGAR-Server" "DataDir"
|
|
ReadRegStr $1 HKLM "Software\LOGAR\LOGAR-Server" "InstallDir"
|
|
${If} $0 != ""
|
|
${OrIf} $1 != ""
|
|
${OrIf} ${FileExists} "$INSTDIR\Server.exe"
|
|
StrCpy $IS_UPDATE "1"
|
|
${If} $0 != ""
|
|
StrCpy $DATADIR $0
|
|
${EndIf}
|
|
${If} $1 != ""
|
|
StrCpy $INSTDIR $1
|
|
${EndIf}
|
|
MessageBox MB_ICONINFORMATION|MB_OK "An existing installation of LOGAR Server was detected.$\r$\n$\r$\nSetup will perform an in-place update: program files will be updated while your existing database, configuration (server_config.json), and certificates are preserved."
|
|
${EndIf}
|
|
FunctionEnd
|
|
|
|
Section "Install"
|
|
SetShellVarContext all
|
|
|
|
# Terminate any existing service or running processes before replacing files
|
|
ExecWait 'net stop LOGAR_Server'
|
|
ExecWait 'sc stop LOGAR_Server'
|
|
ExecWait 'taskkill /F /T /IM Server.exe'
|
|
ExecWait 'taskkill /F /T /IM nssm.exe'
|
|
Sleep 500
|
|
|
|
SetOutPath "$INSTDIR"
|
|
File "../dist/Server.exe"
|
|
File "../compilation/nssm.exe"
|
|
File /r "../dist/runtime"
|
|
|
|
CreateDirectory "$DATADIR"
|
|
ExecWait 'icacls "$DATADIR" /grant "*S-1-5-32-545:(OI)(CI)M" /T /Q'
|
|
|
|
# Install and configure service via NSSM
|
|
ExecWait '"$INSTDIR\nssm.exe" install LOGAR_Server "$INSTDIR\Server.exe"'
|
|
ExecWait '"$INSTDIR\nssm.exe" set LOGAR_Server AppDirectory "$INSTDIR"'
|
|
ExecWait '"$INSTDIR\nssm.exe" set LOGAR_Server AppStdout "$DATADIR\server.log"'
|
|
ExecWait '"$INSTDIR\nssm.exe" set LOGAR_Server AppStderr "$DATADIR\server_err.log"'
|
|
ExecWait '"$INSTDIR\nssm.exe" set LOGAR_Server AppParameters "--config $\"$DATADIR\server_config.json$\""'
|
|
ExecWait '"$INSTDIR\nssm.exe" start LOGAR_Server'
|
|
|
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
|
WriteRegStr HKLM "Software\LOGAR\LOGAR-Server" "InstallDir" "$INSTDIR"
|
|
WriteRegStr HKLM "Software\LOGAR\LOGAR-Server" "DataDir" "$DATADIR"
|
|
SectionEnd
|
|
|
|
Section "Uninstall"
|
|
SetShellVarContext all
|
|
ReadRegStr $DATADIR HKLM "Software\LOGAR\LOGAR-Server" "DataDir"
|
|
${If} $DATADIR == ""
|
|
StrCpy $DATADIR "$APPDATA\LOGAR-Server"
|
|
${EndIf}
|
|
|
|
# 1. Stop and remove service
|
|
ExecWait 'net stop LOGAR_Server'
|
|
ExecWait 'sc stop LOGAR_Server'
|
|
${If} ${FileExists} "$INSTDIR\nssm.exe"
|
|
ExecWait '"$INSTDIR\nssm.exe" stop LOGAR_Server'
|
|
ExecWait '"$INSTDIR\nssm.exe" remove LOGAR_Server confirm'
|
|
${EndIf}
|
|
ExecWait 'sc delete LOGAR_Server'
|
|
|
|
# 2. Force terminate any lingering processes
|
|
ExecWait 'taskkill /F /T /IM Server.exe'
|
|
ExecWait 'taskkill /F /T /IM nssm.exe'
|
|
ExecWait `powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Get-CimInstance Win32_Process | Where-Object { $$_.ExecutablePath -like '$INSTDIR\*' } | ForEach-Object { Stop-Process -Id $$_.ProcessId -Force -ErrorAction SilentlyContinue }"`
|
|
Sleep 1200
|
|
|
|
# 3. Clean up all installation and data files
|
|
RMDir /r "$INSTDIR\runtime"
|
|
RMDir /r "$INSTDIR\certs"
|
|
Delete "$INSTDIR\server_config.json"
|
|
Delete "$INSTDIR\logar_state.db"
|
|
Delete "$INSTDIR\logar_state.db-*"
|
|
Delete "$INSTDIR\*.log"
|
|
Delete "$INSTDIR\Server.exe"
|
|
Delete "$INSTDIR\nssm.exe"
|
|
Delete "$INSTDIR\uninstall.exe"
|
|
RMDir /r "$INSTDIR"
|
|
RMDir /r "$DATADIR"
|
|
DeleteRegKey HKLM "Software\LOGAR\LOGAR-Server"
|
|
DeleteRegKey /ifempty HKLM "Software\LOGAR"
|
|
SectionEnd
|