Creating a Installpackage for mac
There is an error in the postinstall script. The first line should contain only one hash (#):

#!/usr/bin/env bash


If the .pkg works with installer and Installer.app, then it is a correct package. All other tools are made by third parties and may not support the latest pkg formats and features.

Lacking Permission?

Using sudo in your package script may cause the script to pause forever or instantly fail. How will the sudo command interact with the user to get the super user's credentials?

Remove sudo and make your script test for permission to install before continuing, otherwise print an error and exit:

if [[ $EUID -ne 0 ]]; then
  echo "You must be a root to run this script" 2&gt;&amp;1
  exit 1
fi


It is the responsibility of installer to gain the appropriate authorisation rights and run the package's scripts using those rights. Within your package, specify that it needs administrator rights to ensure this happens.

Logs and Errors

Use the verbose flag with installer to see each step of the installation process and to see errors:

sudo installer -verbose -pkg /Library/Virtualbox.pkg -target /


Apple Package Tools

Installer packages on OS X are typically built with the tools pkgbuild and productbuild. These two Apple tools support pre and post scripts; see the --scripts flag.

AutoPkg

Mac system administrators often use the open source autopkg tool to create packages:


  AutoPkg is an automation framework for OS X software packaging and distribution, oriented towards the tasks one would normally perform manually to prepare third-party software for mass deployment to managed clients.


You may find AutoPkg is a better approach to simplifying the setting up of new Macs.