Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create an OS X package from the command line UNIX
How to Programmatically Create a Mac OS X Package (from the command-line or a shell script).

Note that any lines ending with a backslash should be one line; they've been broken here for a narrower display width.
  1. Set up the files you want to package in a folder called dstroot:
    % mkdir ./dstroot
    % mkdir -p ./dstroot/usr/local/bin/ \
       dstroot/usr/local/share/man/man1/
    % install -m 755 myprog ./dstroot/usr/local/bin/
    % install -m 644 myprog.1 \
       ./dstroot/usr/local/share/man/man1/
    
  2. Create a package info file (this has nothing to do with Fink info files). Either copy one from another .pkg to use as a template, or see this pkg info file from osxutils.

  3. Make the package:
    % find dstroot -name .DS_Store -delete
    % sudo chown -R root:staff dstroot
    % package dstroot mypackage-0.1.info -d . -ignoreDSStore
    % rm -f 1
    % install -m 644 README.txt \
       mypackage-0.1.pkg/Contents/Resources/ReadMe.txt
    % install -m 644 LICENSE.txt \ 
       mypackage-0.1.pkg/Contents/Resources/License.txt
    % sudo chown -R root:staff \
       mypackage-0.1.pkg/Contents/Resource
    % tar -h mypackage-0.1.pkg -cf mypackage-0.1.pkg.tar
    % gzip -9 mypackage-0.1.pkg.tar
    
See an example Makefile from the osxutils package which builds a .pkg from the command line at SourceForge.
    •    
  • Currently 2.40 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[29,633 views]  

Create an OS X package from the command line | 8 comments | Create New Account
Click here to return to the 'Create an OS X package from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create an OS X package from the command line
Authored by: wgscott on Jun 23, '03 11:21:32AM

Will this break resource forks? I often use hfstar but can't rely on users to have it.



[ Reply to This | # ]
Create an OS X package from the command line
Authored by: bluehz on Jun 23, '03 01:39:40PM
WOW!!! I am all for CLI stuff and am trying to do everything I can using CLI - but thats incredibly difficult compared to using the PackageMaker that comes with Developer Tools.

For info on using PackageMaker
http://developer.apple.com/techpubs/macosx/Essentials/SystemOverview/InstallIntegrate/chapter_13_section_18.html

You probably have to have Dev registration but its free. If you have downloaded Developer Tools, you are already registered to do that.

I was just learning how to create packages this weekend, and I was surprised how easy it actually is.



[ Reply to This | # ]

Re: Create an OS X package from the command line
Authored by: semios on Jun 23, '03 06:13:56PM

The GUI is great for a one off. But for anything that requires consistency, anything that you do again and again, the CLI is great because it's scriptable. Script it and forget it.



[ Reply to This | # ]
Re: Create an OS X package from the command line
Authored by: Dale Mox on Jun 24, '03 09:19:59AM

That's right!



[ Reply to This | # ]
Create an OS X package from the command line
Authored by: carsten on Jun 23, '03 08:43:06PM

Short answer: Unfortunately, probably not.

Longer answer:
Within an Apple installer pkg, the files to be installed are all stored in the Archive.pax.gz file. So while the pkg itself and its contents are safe to tar up, the pax utility does not support resource forks AFAIK.

Also, I don't know whether the package command-line utility calls pax to do its work or whether the necessary functions are built-in to package along with some kind of added resourcefork support.

There may be a way to hack the pkg after it's been built with package, by manually using the hfspax utility to build a replacement Archive.pax.gz, but would the Installer app honour the resource forks when it's time to install? (hfspax is available in Fink).

If anyone has time to experiment with this, please post your results here.

[ Reply to This | # ]

Create an OS X package from the command line
Authored by: sjk on Jun 23, '03 10:37:43PM
/usr/bin/package is a csh script (yuk!); view it and you'll see it uses pax.

[ Reply to This | # ]
Create an OS X package from the command line
Authored by: GaelicWizard on Jul 17, '03 08:48:45PM

AFAIK, hfstar (and hfspax?) make archives with the resource forks stored in them as somdir/somefile/..namedFork/rsrc so when they come out i *think* that standard tar or pax will un-archive them properly. anyone out there know for sure?


---
Pell



[ Reply to This | # ]
Re: Create an OS X package from the command line
Authored by: semios on Jun 23, '03 06:10:18PM
Awesome! I've been waiting for this kind of information for a while. And yes, PackageMaker is there but this is exactly the kind of stuff you want to automate and forget.

Thank you! You just made my projects much easier.

[ Reply to This | # ]