Reputation: 3285
I've created a SampleApp.app file from XCode 7.1 and converted it to pkg file and signed it using the product build command and it worked fine. But now the problem is, when I install the pkg the app does not start automatically after installation. Do I need to include any other arguments in my command to make this work? Below is the command that I use to create and sign the pkg.
productbuild --component SampleApp.app /Applications SampleApp.pkg
productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg
I've also tried to add a postinstall script but that didnt seem to work, I'm not sure if its the problem with my script or command
pkgbuild --root SampleApp.app --identifier com.companyname.SampleApp --scripts startup.sh --install-location /Applications/SampleApp.app SampleApp.pkg
productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg
My startup.sh file
#!/bin/bash
open -a /Applications/SampleApp.app
exit 0
Upvotes: 5
Views: 9161
Reputation: 7922
For many apps, you don't want to fire them up as sudo/root, so, you'll want to launch it as an ordinary user (e.g the one installing)
su "$USER" -c "open path/to/MyApp.app"
Note, there are many things in pkgbuild
that are either undocumented, archived, or hard to find docs for online, such as $2
, which is the path to the application you're installing.
This means you can also do this...
su "$USER" -c "open $2"
There are other variables as well, such as INSTALLER_TEMP
, which I use in one of my scripts to know if a command line utility my app ships with is being run during install or during normal operation. The variable isn't very useful otherwise.
Bitrot warning... At time of writing this, Google has 4 search results for INSTALLER_TEMP pkgbuild
and GitHub turns up one single result for some savenotes so I feel it important to ask (and answer) and ultimately archive here so that there are secondary copies of these techniques.
Upvotes: 3
Reputation: 1350
As Santanu Karar mentioned in a comment:
- Put a non-extension executable inside a folder and make sure it's must named preinstall or postinstall.
Note: Not postinstall.sh
but postinstall
!
- Apply
chmod 755
andchmod a+x
to the files preinstall and/or postinstall.- No need to mention the script's full path in the pkgBuild command. Point the folder containing postinstall script for the
--scripts
parameter.
As in --scripts "./Scripts/"
and not --scripts "./Scripts/postinstall"
Lastly, it safer to use open "$2/App Name.app/"
in the script, as $2
is the install location, and it's passed to the postinstall script.
Upvotes: 3
Reputation: 21
I had to use sudo
in the postinstall
script to get it to work:
#!/bin/sh
sudo open -a 'appName'
exit 0
Upvotes: 2
Reputation: 32154
ok because OSX is so dumb and stupid, don't use application path instead use app name or bundle id because it seems OSX needs time to figure out that your application is actually an application:
you can open using bundle id:
#!/usr/bin/env bash
open -b 'com.myapp.mac'
exit 0
or open using app name:
#!/usr/bin/env bash
open -a 'MyApp'
exit 0
Upvotes: 0
Reputation: 47169
Usually you would create a postinstall
script, and include it with the --scripts
option.
--scripts scripts-path
The contents of scripts-path is added to the product archive for use by system.run() commands in the distribution. This is valid only for product archives targeted to the OS X Installer application.
So a (very) basic example of postinstall
could launch an app by:
#!/bin/sh
open /path/to/your/app
exit 0
Upvotes: 0