From 70c61986ad3a7af561d958b34a79a3d24459d542 Mon Sep 17 00:00:00 2001 From: caesay Date: Wed, 6 Jul 2022 13:57:01 +0100 Subject: [PATCH] Run postinstall as current user instead of installer user --- src/Squirrel.CommandLine/OSX/HelperExe.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Squirrel.CommandLine/OSX/HelperExe.cs b/src/Squirrel.CommandLine/OSX/HelperExe.cs index a8ee6e3b9..ab6ab0642 100644 --- a/src/Squirrel.CommandLine/OSX/HelperExe.cs +++ b/src/Squirrel.CommandLine/OSX/HelperExe.cs @@ -75,6 +75,12 @@ public static void CreateInstallerPkg(string appBundlePath, string pkgOutputPath var bundleName = Path.GetFileName(appBundlePath); var tmpBundlePath = Path.Combine(tmpPayload1, bundleName); Utility.CopyFiles(new DirectoryInfo(appBundlePath), new DirectoryInfo(tmpBundlePath)); + + // create postinstall scripts to open app after install + // https://stackoverflow.com/questions/35619036/open-app-after-installation-from-pkg-file-in-mac + var postinstall = Path.Combine(tmpScripts, "postinstall"); + File.WriteAllText(postinstall, $"#!/bin/sh\nsudo -u \"$USER\" open \"$2/{bundleName}/\"\nexit 0"); + PlatformUtil.ChmodFileAsExecutable(postinstall); // generate non-relocatable component pkg. this will be included into a product archive var pkgPlistPath = Path.Combine(tmp, "tmp.plist"); @@ -85,18 +91,13 @@ public static void CreateInstallerPkg(string appBundlePath, string pkgOutputPath string[] args1 = { "--root", tmpPayload1, "--component-plist", pkgPlistPath, + "--scripts", tmpScripts, "--install-location", "/Applications", pkg1Path, }; InvokeAndThrowIfNonZero("pkgbuild", args1, null); - // create postinstall scripts to open app after install - // https://stackoverflow.com/questions/35619036/open-app-after-installation-from-pkg-file-in-mac - var postinstall = Path.Combine(tmpScripts, "postinstall"); - File.WriteAllText(postinstall, $"#!/bin/sh\nopen \"$2/{bundleName}/\"\nexit 0"); - PlatformUtil.ChmodFileAsExecutable(postinstall); - // create product package that installs to home dir var distributionPath = Path.Combine(tmp, "distribution.xml"); InvokeAndThrowIfNonZero("productbuild", new[] { "--synthesize", "--package", pkg1Path, distributionPath }, null); @@ -109,7 +110,6 @@ public static void CreateInstallerPkg(string appBundlePath, string pkgOutputPath List args2 = new() { "--distribution", distributionPath, "--package-path", tmpPayload2, - "--scripts", tmpScripts, pkgOutputPath };