Skip to content

Commit

Permalink
Feature: separate installer for client and satellite (#103)
Browse files Browse the repository at this point in the history
This PR separates the installer into two different ones (embedded) that allows for non-privileged user installation.
  • Loading branch information
amadeo-alex authored Jun 16, 2024
1 parent bd03bf5 commit c63e485
Show file tree
Hide file tree
Showing 8 changed files with 555 additions and 34 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ jobs:
working-directory: "D:\\a\\HASS.Agent\\HASS.Agent\\src\\HASS.Agent\\HASS.Agent.Satellite.Service"
run: "dotnet publish -c Release -f net6.0-windows10.0.19041.0 -o bin\\Publish-x64\\Release\\ --no-self-contained -r win-x64 -p:Platform=x64"

- name: Compile InnoSetup Installer
- name: Compile InnoSetup Installer - Satellite Service
working-directory: "D:\\a\\HASS.Agent\\HASS.Agent\\src\\HASS.Agent.Installer"
run: |
& "${Env:ProgramFiles(x86)}\\Inno Setup 6\\iscc.exe" InstallerScript-Service.iss
- name: Compile InnoSetup Installer - Client
working-directory: "D:\\a\\HASS.Agent\\HASS.Agent\\src\\HASS.Agent.Installer"
run: |
& "${Env:ProgramFiles(x86)}\\Inno Setup 6\\iscc.exe" InstallerScript.iss
Expand Down
222 changes: 222 additions & 0 deletions src/HASS.Agent.Installer/AfterInstallNotice-Service.rtf

Large diffs are not rendered by default.

218 changes: 218 additions & 0 deletions src/HASS.Agent.Installer/BeforeInstallNotice-Service.rtf

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/HASS.Agent.Installer/InstallerScript-Service.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; Modified to suit HASS.Agent requirements :)

; InnoDependencyInstaller
; Thanks to https://github.com/DomGries/InnoDependencyInstaller for the amazing work!
#define public Dependency_Path_NetCoreCheck "dependencies\"
#include "CodeDependencies.iss"

; Standard installation constants
#define MyAppName "HASS.Agent Satellite Service"
#define MyAppVersion "2.1.0-beta2"
#define MyAppPublisher "HASS.Agent Team"
#define MyAppURL "https://hass-agent.io"
#define MyAppExeName "HASS.Agent.Satellite.Service.exe"
#define ServiceName "hass.agent.svc"
#define ServiceDisplayName "HASS.Agent - Satellite Service"
#define ServiceDescription "Satellite service for HASS.Agent: a Windows based Home Assistant client. This service processes commands and sensors without the requirement of a logged-in user."

[Setup]
ArchitecturesInstallIn64BitMode=x64
;SetupMutex=Global\HASS.Agent.Setup.Satellite.Mutex,HASS.Agent.Satellite.Setup.Mutex
AppMutex=Global\\HASS.Agent.Service.Mutex
AppId={{4004588E-F411-41C2-ABD8-A898B0A14B93}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={commonpf64}\{#MyAppName}\Service
DisableProgramGroupPage=yes
LicenseFile=..\..\LICENSE.md
InfoBeforeFile=.\BeforeInstallNotice-Service.rtf
InfoAfterFile=.\AfterInstallNotice-Service.rtf
PrivilegesRequired=admin
OutputDir=.\bin
OutputBaseFilename=HASS.Agent.Service.Installer
SetupIconFile=..\HASS.Agent\HASS.Agent.Shared\hassagent.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
CloseApplications=force
CloseApplicationsFilter=*.*
UninstallDisplayIcon={app}\{#MyAppExeName}
UninstallDisplayName={#MyAppName} {#MyAppVersion}

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Files]
; Service files
Source: "..\HASS.Agent\HASS.Agent.Satellite.Service\bin\Publish-x64\Release\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs

[Run]
Filename: "{sys}\sc.exe"; Parameters: "start {#ServiceName}"; Description: "Start Satellite Service"; Flags: postinstall runhidden runascurrentuser

[Registry]
Root: HKLM; Subkey: "SOFTWARE\HASSAgent\SatelliteService"; ValueType: string; ValueName: "InstallPath"; ValueData: "{commonpf64}\{#MyAppName}\Service"; Flags: createvalueifdoesntexist uninsdeletevalue

; Service registration and removal
[Run]
Filename: "{sys}\sc.exe"; Parameters: "create {#ServiceName} binpath= ""{commonpf64}\{#MyAppName}\Service\{#MyAppExeName}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "failure {#ServiceName} reset= 86400 actions= restart/60000/restart/60000//1000"; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "description {#ServiceName} ""{#ServiceDescription}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "config {#ServiceName} DisplayName= ""{#ServiceDisplayName}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "config {#ServiceName} start= auto"; Flags: runhidden
[UninstallRun]
Filename: "{sys}\sc.exe"; Parameters: "stop {#ServiceName}"; RunOnceId: StopService; Flags: runhidden
Filename: "{sys}\timeout.exe"; Parameters: "5"; RunOnceId: Delay1; Flags:runhidden
Filename: "{sys}\sc.exe"; Parameters: "delete {#ServiceName}" ; RunOnceId: DeleteService; Flags: runhidden
Filename: "{sys}\timeout.exe"; Parameters: "5"; RunOnceId: Delay2; Flags:runhidden

[Code]
function InitializeSetup: Boolean;
begin
Dependency_ForceX86 := False;
Dependency_AddDotNet60Desktop;
Result := True;
end;
54 changes: 24 additions & 30 deletions src/HASS.Agent.Installer/InstallerScript.iss
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@

; Standard installation constants
#define MyAppName "HASS.Agent"
#define MyAppVersion "2.1.0-beta1"
#define MyAppVersion "2.1.0-beta2"
#define MyAppPublisher "HASS.Agent Team"
#define MyAppURL "https://hass-agent.io"
#define MyAppExeName "HASS.Agent.exe"
#define MyAppServiceExeName "HASS.Agent.Satellite.Service.exe"
#define ServiceName "hass.agent.svc"
#define ServiceDisplayName "HASS.Agent - Satellite Service"
#define ServiceDescription "Satellite service for HASS.Agent: a Windows based Home Assistant client. This service processes commands and sensors without the requirement of a logged-in user."

[Setup]
ArchitecturesInstallIn64BitMode=x64
SetupMutex=Global\HASS.Agent.Setup.Mutex,HASS.Agent.Setup.Mutex
AppMutex=Global\HASS.Agent.App.Mutex,HASS.Agent.App.Mutex
AppMutex=HASS.Agent.App.Mutex
AppId={{7BBED458-609B-4D13-AD9E-4FF219DF8644}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
Expand All @@ -36,7 +32,7 @@ LicenseFile=..\..\LICENSE.md
InfoBeforeFile=.\BeforeInstallNotice.rtf
InfoAfterFile=.\AfterInstallNotice.rtf
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
PrivilegesRequired=lowest
OutputDir=.\bin
OutputBaseFilename=HASS.Agent.Installer
SetupIconFile=..\HASS.Agent\HASS.Agent.Shared\hassagent.ico
Expand All @@ -57,38 +53,19 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Files]
; Client files
;Source: "..\HASS.Agent\HASS.Agent\bin\Publish-x64\Release\*"; Excludes: "*.pdb"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; Service files
;Source: "..\HASS.Agent\HASS.Agent.Satellite.Service\bin\Publish-x64\Release\*"; Excludes: "*.pdb"; DestDir: "{commonpf64}\{#MyAppName}\Service"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\HASS.Agent\HASS.Agent\bin\Publish-x64\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; Service files
Source: "..\HASS.Agent\HASS.Agent.Satellite.Service\bin\Publish-x64\Release\*"; DestDir: "{commonpf64}\{#MyAppName}\Service"; Flags: ignoreversion recursesubdirs createallsubdirs
; Service installer
Source: ".\bin\HASS.Agent.Service.Installer.exe"; DestDir: "{tmp}"; Flags: ignoreversion

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Parameters: "compat_migrate"; Description: "Try to migrate configuration"; Flags: postinstall skipifsilent runascurrentuser unchecked
Filename: "{sys}\sc.exe"; Parameters: "start {#ServiceName}"; Description: "Start Satellite Service"; Flags: postinstall runhidden runascurrentuser
Filename: "{app}\{#MyAppExeName}"; Parameters: "compat_migrate"; Description: "Try to migrate configuration (administrative permissions required)"; Flags: postinstall skipifsilent runascurrentuser unchecked
Filename: "{tmp}\HASS.Agent.Service.Installer.exe"; Description: "Install Satellite Service (administrative permissions required)"; Flags: postinstall runascurrentuser
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: postinstall skipifsilent nowait

[Registry]
Root: HKLM; Subkey: "SOFTWARE\HASSAgent\SatelliteService"; ValueType: string; ValueName: "InstallPath"; ValueData: "{commonpf64}\{#MyAppName}\Service"; Flags: createvalueifdoesntexist uninsdeletevalue

; Service registration and removal
[Run]
Filename: "{sys}\sc.exe"; Parameters: "create {#ServiceName} binpath= ""{commonpf64}\{#MyAppName}\Service\{#MyAppServiceExeName}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "failure {#ServiceName} reset= 86400 actions= restart/60000/restart/60000//1000"; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "description {#ServiceName} ""{#ServiceDescription}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "config {#ServiceName} DisplayName= ""{#ServiceDisplayName}"""; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "config {#ServiceName} start= auto"; Flags: runhidden
[UninstallRun]
Filename: "{sys}\sc.exe"; Parameters: "stop {#ServiceName}"; RunOnceId: StopService; Flags: runhidden
Filename: "{sys}\sc.exe"; Parameters: "delete {#ServiceName}" ; RunOnceId: DeleteService; Flags: runhidden
; Additional delay for the service to be uninstalled
Filename: "{sys}\timeout.exe"; Parameters: "5"; Flags:runhidden

[Code]
function InitializeSetup: Boolean;
begin
Expand Down Expand Up @@ -118,3 +95,20 @@ begin
Result := True;
end
end;
procedure CurUninstallStepChanged (CurUninstallStep: TUninstallStep);
var
mres : integer;
serviceUninstallerPath : String;
ResultCode : integer;
begin
case CurUninstallStep of
usPostUninstall:
begin
mres := MsgBox('Do you want to uninstall the Satellite Service? (administrative permissions required)', mbConfirmation, MB_YESNO or MB_DEFBUTTON2)
if mres = IDYES then
RegQueryStringValue(HKLM, 'SOFTWARE\HASSAgent\SatelliteService', 'InstallPath', serviceUninstallerPath);
Exec(serviceUninstallerPath + '\unins000.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
end;
end;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UserSecretsId>dotnet-HASSAgentSatelliteService-6E4FA50A-3AC9-4E66-8671-9FAB92372154</UserSecretsId>
<PlatformTarget>x64</PlatformTarget>
<Platforms>x64;x86</Platforms>
<Version>2.1.0-beta1</Version>
<Version>2.1.0-beta2</Version>
<Company>HASS.Agent Team</Company>
<Product>HASS.Agent Satellite Service</Product>
<AssemblyName>HASS.Agent.Satellite.Service</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion src/HASS.Agent/HASS.Agent.Shared/HASS.Agent.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/hass-agent/HASS.Agent</RepositoryUrl>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Version>2.1.0-beta1</Version>
<Version>2.1.0-beta2</Version>
<PackageIcon>logo_128.png</PackageIcon>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<ApplicationIcon>hassagent.ico</ApplicationIcon>
Expand Down
2 changes: 1 addition & 1 deletion src/HASS.Agent/HASS.Agent/HASS.Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PlatformTarget>x64</PlatformTarget>
<Platforms>x64;x86</Platforms>
<DebugType>full</DebugType>
<Version>2.1.0-beta1</Version>
<Version>2.1.0-beta2</Version>
<Company>HASS.Agent Team</Company>
<Authors>HASS.Agent Team</Authors>
<Description>Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more. </Description>
Expand Down

0 comments on commit c63e485

Please sign in to comment.