From d869dbf70d7d6445eed57859c19fdf29cf29024e Mon Sep 17 00:00:00 2001
From: jkito <belter@riseup.net>
Date: Sat, 24 Aug 2024 22:33:24 +0530
Subject: [PATCH] installer: name helper launchd service based on app name

this allows us to have multiple branded desktop clients installed
along side each other

earlier installing one would uninstall the previous helper as both
used the same name and label for the launchd daemon
---
 .../qtinstaller/osx-data/post-install.go      | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/branding/templates/qtinstaller/osx-data/post-install.go b/branding/templates/qtinstaller/osx-data/post-install.go
index 9ab03974..5f1afe72 100644
--- a/branding/templates/qtinstaller/osx-data/post-install.go
+++ b/branding/templates/qtinstaller/osx-data/post-install.go
@@ -44,15 +44,13 @@ const (
     <key>ThrottleInterval</key>
     <integer>5</integer>
     <key>Label</key>
-	<string>se.leap.BitmaskHelper</string>
-	<key>Program</key>
+    <string>{{ .Label }}</string>
+    <key>Program</key>
     <string>{{ .Path }}/bitmask-helper</string>
 </dict>
 </plist>`
 
-	plistPath          = "/Library/LaunchDaemons/se.leap.bitmask-helper.plist"
-	helperName         = "bitmask-helper"
-	launchdDaemonLabel = "se.leap.BitmaskHelper"
+	helperName = "bitmask-helper"
 
 	// -action flag values
 	actionPostInstall = "post-install"
@@ -77,6 +75,9 @@ var (
 	installerAction string
 	installerStage  string
 	appName         string
+
+	plistPath          string
+	launchdDaemonLabel string
 )
 
 func init() {
@@ -100,6 +101,13 @@ func main() {
 	if os.Getuid() != 0 {
 		log.Fatal("not running as root")
 	}
+	if appName == "" || installerAction == "" {
+		log.Fatal("-action and -appname flags cannot be empty")
+	}
+
+	plistPath = fmt.Sprintf("/Library/LaunchDaemons/se.leap.helper.%s.plist", appName)
+	launchdDaemonLabel = fmt.Sprintf("se.leap.Helper.%s", appName)
+
 	switch installerAction {
 	case actionPostInstall:
 		if err := setupLogFile(filepath.Join(curdir, "post-install.log")); err != nil {
@@ -250,9 +258,11 @@ func unloadHelperPlist() error {
 func generatePlist() (string, error) {
 
 	appPath := struct {
-		Path string
+		Path  string
+		Label string
 	}{
-		Path: appBundlePath(),
+		Path:  appBundlePath(),
+		Label: launchdDaemonLabel,
 	}
 
 	t, err := template.New("plist").Parse(plistTemplate)
-- 
GitLab