Where do I even begin to debug?
Closed this issue ยท 7 comments
First of all thanks for the simple yet effective utility. I am however struggling to get it to work for me. Perhaps because I have very little understanding of pkgbuild
and productbuild
utilities.
What I am trying to do:-
My installer has no payload and contains only a post-install script. The post-install script does the following:-
- Checks if a certain binary (
mybinary
) is installed on the target machine. - Pulls a couple of config files from a GitHub repo.
- Puts the config files in place with
mybinary
. - Launch the binary as a
launchctl
service.
#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
brew update
fi
which -s mybinary
if [[ $? != 0 ]] ; then
# Install mybinary
brew cask install mybinary
else
cd /var/mybinary
if [[ $? != 0 ]] ; then
echo "mybinary is installed but directory structure not matching"
fi
fi
echo "Creating temp directory..."
install_dir=$(mktemp -d) && cd ${install_dir} && git clone https://github.com/my-repo/mybinary_deps && cd mybinary_deps
echo "Copying dependencies..."
sudo cp * /var/mybinary/
cd /var/mybinary
sudo cp com.mybinary.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/com.mybinary.plist
echo "Post installation process finished"
The post-install script works perfectly as a standalone shell script but when I try to create a package with macos-installer-builder it doesn't. The installer run fine without any error. But it doesn't install the binaries. What am I missing here?
Hi Koba,
Since your post-install script is working when you are running it alone, the issue could be with the running process of the post-install script through the installation process and you can check all the running logs from the following method. You may need to look at these logs to identify the issues.
1. After generating the pkg file, open the .pkg file.
2. Then in the menu bar(App menus) you can open "Installer Log" in the "Window" dropdown. ( or press โL)
3. Now proceed with the installation and you will see the logs and you can start your debugging with it. If you need more details please add debug-logs in the script to debug the process.
Sometimes, permission issues can be observed when you run these bash commands through the installer and you can identify them using these logs. Hope this will help you. ๐
@KosalaHerath Thanks for the tip. I am able to pinpoint the issue but that still doesn't make sense. I'm getting
Sep 29 22:48:32 hxvxt2 installd[80453]: ./postinstall: /tmp/PKInstallSandbox.42j7tU/Scripts/org.mybinary.0.0.4.sDKM7K/postinstall: line 16: brew: command not found
For some reason, brew
is not recognized as a valid command. But when I can verify that it exists and works. I'll probably have a fresh look tomorrow.
Thanks
HI Koba,
This could happen due to the user who runs the installation has no permissions to run the 'brew' command or brew is not on one of the directories listed in your PATH environment variable for that user.
You can check the installation running user (id -un
) in the script and check that the user can run brew in your machine. If it is root user then the following error could have occurred.
Cheers!
I'm running the script and the installer both on the same machine. And there is only one user. Since postinstall wasn't able to locate the command I tried the absolute path in the postscript /usr/local/bin/brew
and that gave me Running homebrew as Root...
error.
Could it be that somewhere on your package build process you might be using sudo
? I had a look at build-macos-x64.sh
but there is't anything that I can spot.
Can you please identify the user adding the following line to the post-install script and check the log:
echo "$USER"
As mentioned here (http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html) your installation post-install script is running under the "root" user. Therefore, you may want to run brew through a different user (you can create a new brew user for that).
Could it be that somewhere on your package build process you might be using sudo? I had a look at build-macos-x64.sh but there is't anything that I can spot.
IMO, build-macos-x64.sh could not modify the installation post-script running user.
This may help you also:
https://apple.stackexchange.com/questions/144159/how-can-i-determine-the-invoking-user-in-an-apple-installer-postinstall-script
Closing since the answer is provided.
Can you please identify the user adding the following line to the post-install script and check the log:
echo "$USER"
As mentioned here (http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html) your installation post-install script is running under the "root" user. Therefore, you may want to run brew through a different user (you can create a new brew user for that).
Could it be that somewhere on your package build process you might be using sudo? I had a look at build-macos-x64.sh but there is't anything that I can spot.
IMO, build-macos-x64.sh could not modify the installation post-script running user.
This may help you also: https://apple.stackexchange.com/questions/144159/how-can-i-determine-the-invoking-user-in-an-apple-installer-postinstall-script
@KosalaHerath any idea what is meant by authorization action here? Is this related to the distribution param:
enable_currentUserHome
enable_localSystem
enable_anywhere
?