229 lines
9.5 KiB
Plaintext
229 lines
9.5 KiB
Plaintext
[Setup]
|
|
AppId={{4F3D675E-1E4E-43B6-8C84-B47DE290BE4A}}
|
|
AppName=LOGAR Server
|
|
AppVersion=0.3.5.1
|
|
AppPublisher=LOGAR
|
|
AppPublisherURL=https://logar.eibl.tech
|
|
AppSupportURL=https://logar.eibl.tech
|
|
AppUpdatesURL=https://logar.eibl.tech
|
|
DefaultDirName={autopf}\LOGAR-Server
|
|
UsePreviousAppDir=yes
|
|
OutputDir=..\dist
|
|
OutputBaseFilename=LOGAR-Server-Setup
|
|
PrivilegesRequired=admin
|
|
Compression=lzma
|
|
SolidCompression=yes
|
|
WizardStyle=modern
|
|
SetupIconFile=assets\logo.ico
|
|
WizardImageFile=assets\wizard_sidebar.bmp
|
|
WizardSmallImageFile=assets\wizard_small.bmp
|
|
VersionInfoCompany=LOGAR
|
|
VersionInfoDescription=LOGAR Cloud Hub & TCP Ingestion Server Setup
|
|
VersionInfoVersion=0.3.5.1
|
|
VersionInfoProductName=LOGAR Server
|
|
VersionInfoProductVersion=0.3.5.1
|
|
|
|
[Files]
|
|
Source: "..\dist\Server.exe"; DestDir: "{app}"; Flags: ignoreversion
|
|
Source: "..\compilation\nssm.exe"; DestDir: "{app}"; Flags: ignoreversion
|
|
Source: "..\dist\runtime\*"; DestDir: "{app}\runtime"; Flags: ignoreversion recursesubdirs createallsubdirs
|
|
|
|
[Dirs]
|
|
Name: "{code:GetDataDir}"; Permissions: users-modify
|
|
|
|
[Run]
|
|
Filename: "{app}\nssm.exe"; Parameters: "install LOGAR_Server ""{app}\Server.exe"""; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Server AppDirectory ""{app}"""; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Server AppStdout ""{code:GetDataDir}\server.log"""; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Server AppStderr ""{code:GetDataDir}\server_err.log"""; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Server AppParameters ""--config """"{code:GetDataDir}\server_config.json"""""""; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "start LOGAR_Server"; Flags: runhidden
|
|
|
|
[UninstallRun]
|
|
Filename: "{app}\nssm.exe"; Parameters: "stop LOGAR_Server"; Flags: runhidden
|
|
Filename: "{app}\nssm.exe"; Parameters: "remove LOGAR_Server confirm"; Flags: runhidden
|
|
|
|
[UninstallDelete]
|
|
Type: filesandordirs; Name: "{app}\certs"
|
|
Type: files; Name: "{app}\server_config.json"
|
|
Type: files; Name: "{app}\logar_state.db"
|
|
Type: files; Name: "{app}\logar_state.db-*"
|
|
Type: files; Name: "{app}\*.log"
|
|
Type: filesandordirs; Name: "{app}\runtime"
|
|
Type: filesandordirs; Name: "{app}"
|
|
Type: filesandordirs; Name: "{commonappdata}\LOGAR-Server"
|
|
|
|
[Code]
|
|
var
|
|
DataDirPage: TInputDirWizardPage;
|
|
IsUpdateMode: Boolean;
|
|
ExistingDataDir: String;
|
|
|
|
function InitializeSetup(): Boolean;
|
|
var
|
|
ClientFound: Boolean;
|
|
Val: String;
|
|
begin
|
|
Result := True;
|
|
IsUpdateMode := False;
|
|
ExistingDataDir := '';
|
|
ClientFound := False;
|
|
|
|
// 1. Mutual Exclusion Check: Deny installation if LOGAR Client is already present
|
|
if RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Client') or
|
|
RegValueExists(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Client', 'DataDir') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{9C4A6F1D-8975-476E-8512-4217DE029A88}}_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{9C4A6F1D-8975-476E-8512-4217DE029A88}}_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\LOGAR Client_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\LOGAR Client_is1') or
|
|
FileExists(ExpandConstant('{autopf}\LOGAR\Win_Client.exe')) then
|
|
begin
|
|
ClientFound := True;
|
|
end;
|
|
|
|
if ClientFound then
|
|
begin
|
|
MsgBox('LOGAR Client is already installed on this machine.'#13#10#13#10 +
|
|
'LOGAR Server cannot be installed on a host where LOGAR Client is present (LOGAR Server already includes built-in local log collection).'#13#10#13#10 +
|
|
'Please uninstall LOGAR Client before installing LOGAR Server.',
|
|
mbCriticalError, MB_OK);
|
|
Result := False;
|
|
Exit;
|
|
end;
|
|
|
|
// 2. Existing LOGAR Server Detection for In-Place Update Mode
|
|
if RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{{4F3D675E-1E4E-43B6-8C84-B47DE290BE4A}}_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{4F3D675E-1E4E-43B6-8C84-B47DE290BE4A}}_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\LOGAR Server_is1') or
|
|
RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\LOGAR Server_is1') or
|
|
FileExists(ExpandConstant('{autopf}\LOGAR-Server\Server.exe')) then
|
|
begin
|
|
IsUpdateMode := True;
|
|
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server', 'DataDir', Val) then
|
|
ExistingDataDir := Val;
|
|
|
|
MsgBox('An existing installation of LOGAR Server was detected.'#13#10#13#10 +
|
|
'Setup will perform an in-place update: core binaries will be updated, while your existing configuration (server_config.json), database (logar_state.db), and certificates will be preserved.',
|
|
mbInformation, MB_OK);
|
|
end;
|
|
end;
|
|
|
|
procedure InitializeWizard;
|
|
begin
|
|
DataDirPage := CreateInputDirPage(
|
|
wpSelectDir,
|
|
'Data and Configuration Location',
|
|
'Where should LOGAR Server store its database, certificates, and configuration?',
|
|
'Select the folder where LOGAR Server should store the database (logar_state.db), configuration (server_config.json), and mTLS certificates.'#13#10#13#10 +
|
|
'By default, this is stored in Common AppData (C:\ProgramData\LOGAR-Server), which is accessible to background Windows services.',
|
|
False,
|
|
''
|
|
);
|
|
DataDirPage.Add('Data Directory:');
|
|
if (ExistingDataDir <> '') then
|
|
DataDirPage.Values[0] := ExistingDataDir
|
|
else
|
|
DataDirPage.Values[0] := ExpandConstant('{commonappdata}\LOGAR-Server');
|
|
end;
|
|
|
|
function ShouldSkipPage(PageID: Integer): Boolean;
|
|
begin
|
|
Result := False;
|
|
if IsUpdateMode then
|
|
begin
|
|
if (PageID = wpSelectDir) or (PageID = DataDirPage.ID) then
|
|
Result := True;
|
|
end;
|
|
end;
|
|
|
|
function GetDataDir(Param: String): String;
|
|
begin
|
|
if IsUpdateMode and (ExistingDataDir <> '') then
|
|
begin
|
|
Result := ExistingDataDir;
|
|
Exit;
|
|
end;
|
|
Result := DataDirPage.Values[0];
|
|
if Result = '' then
|
|
Result := ExpandConstant('{commonappdata}\LOGAR-Server');
|
|
end;
|
|
|
|
procedure CurStepChanged(CurStep: TSetupStep);
|
|
var
|
|
ResultCode: Integer;
|
|
begin
|
|
if CurStep = ssInstall then
|
|
begin
|
|
Exec('net.exe', 'stop LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('sc.exe', 'stop LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('taskkill.exe', '/F /T /IM Server.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Sleep(500);
|
|
end
|
|
else if CurStep = ssPostInstall then
|
|
begin
|
|
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server', 'InstallDir', ExpandConstant('{app}'));
|
|
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server', 'DataDir', GetDataDir(''));
|
|
end;
|
|
end;
|
|
|
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
|
var
|
|
CustomDataDir, AppDir, PowerShellCmd: String;
|
|
I, ResultCode: Integer;
|
|
begin
|
|
if CurUninstallStep = usUninstall then
|
|
begin
|
|
AppDir := ExpandConstant('{app}');
|
|
Exec('net.exe', 'stop LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('sc.exe', 'stop LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
if FileExists(AppDir + '\nssm.exe') then
|
|
begin
|
|
Exec(AppDir + '\nssm.exe', 'stop LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec(AppDir + '\nssm.exe', 'remove LOGAR_Server confirm', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
end;
|
|
Exec('sc.exe', 'delete LOGAR_Server', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('taskkill.exe', '/F /T /IM Server.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
PowerShellCmd := '-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "' +
|
|
'Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like ''' + AppDir + '\*'' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }"';
|
|
Exec('powershell.exe', PowerShellCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Sleep(1200);
|
|
end
|
|
else if CurUninstallStep = usPostUninstall then
|
|
begin
|
|
AppDir := ExpandConstant('{app}');
|
|
Exec('taskkill.exe', '/F /T /IM Server.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
|
|
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server', 'DataDir', CustomDataDir) then
|
|
begin
|
|
if (CustomDataDir <> '') and DirExists(CustomDataDir) then
|
|
begin
|
|
for I := 1 to 5 do
|
|
begin
|
|
if DelTree(CustomDataDir, True, True, True) or not DirExists(CustomDataDir) then
|
|
Break;
|
|
Sleep(300);
|
|
end;
|
|
end;
|
|
RegDeleteKeyIncludingSubkeys(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Server');
|
|
end;
|
|
|
|
if (AppDir <> '') and DirExists(AppDir) then
|
|
begin
|
|
for I := 1 to 10 do
|
|
begin
|
|
DeleteFile(AppDir + '\nssm.exe');
|
|
DeleteFile(AppDir + '\Server.exe');
|
|
DelTree(AppDir + '\runtime', True, True, True);
|
|
DelTree(AppDir + '\certs', True, True, True);
|
|
if DelTree(AppDir, True, True, True) or not DirExists(AppDir) then
|
|
Break;
|
|
Sleep(300);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|