Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Run postinstall as current user instead of installer user
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Jul 6, 2022
1 parent 24c5748 commit 70c6198
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Squirrel.CommandLine/OSX/HelperExe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -109,7 +110,6 @@ public static void CreateInstallerPkg(string appBundlePath, string pkgOutputPath
List<string> args2 = new() {
"--distribution", distributionPath,
"--package-path", tmpPayload2,
"--scripts", tmpScripts,
pkgOutputPath
};

Expand Down

0 comments on commit 70c6198

Please sign in to comment.