Search code examples
macossoftware-distributioninstallation-package

Deploying Software to macOS Endpoints with Command Line Arguments


I have a macho executable for some software that can be installed from the command line by executing installer -unique_key ABC123

I'm trying to package the executable up with the command line arguments so that when it is executed, it will install with the command line arguments.

My goal is to have the software install by simply executing the file without having to supply the command line arguments manually.


Solution

  • Using pkgbuild on the command line, you can archive the mach-o executable in a package, along with scripts to call the mach-o with the command line args.

    For example,

    pkgbuild --root ./bom --scripts ./scripts --version 0.1 --identifier com.companyname.myapp myArchive.pkg
    

    The --root takes a path to a folder called bom, in which you can layout the folder structure of where your mach-o will be deployed. For example, you could have

    ./bom/Applications/myMach-O.app
    

    Installing would copy the myMach-O.app bundle to /Applications

    --scripts is the path to a folder containing scripts. You can use a preinstall script to be called before deployment, or postinstall for after deployment. Therefore, you'd want to use postinstall to call your mach-o executable with the required arguments.

    --version is the version of the package

    --identifier is a unique identifier for the package.

    The final argument to pkgbuild is package output path.

    You can refer to the man pages for pkgbuild for more detailed info and options to building packages.