File Ownership Modification by productbuild and pkgbuild

2.4k views Asked by At

I am trying to create an installer for a Java app on Mac OS 10.8.4. The app runs fine, and I can install it without a hitch from a zip file. I can create a .pkg installer with either productbuild or pkgbuild. I can also install either of the installer .pkg file successfully, however the app does not run properly due to the fact that both packaging programs change the ownership of a data directory and its subordinate files and subdirectories from user to root. I install this data directory in the Resources directory of the .app bundle, and the first time the program executes, it moves the data directory to /Users/user/Library/Application Support. I tried using the --ownership preserve and --ownership preserve-other options with pkgbuild to no avail. The only way I have been able to install and execute properly is via the zip file, since it leaves file ownership alone. Here is the pkgbuild command I am using:

pkgbuild --ownership preserve --component ./myApp.app ./myApp-installer.pkg

My questions are:

  1. How can I force pkgbuild to honor my --ownership preserve option?

  2. Is it possible to build a separate data-only package with user ownership and destined for the user area and merge it with the executable package via the --synthesize option of pkgbuild? if yes, could someone show me how to build such a data-only package?

1

There are 1 answers

1
Ehsan Enayati On

I know it is quite old, I'll just answer in case someone else needs the answer. What I usually do, is that I have a shell script which creates the .pkg file for me. In that script I set all the file permissions and ownership before packaging. Here is an example:

NAME="PKGFILENAME"

IDENTIFIER="com.pkg.APPNAME"

VERSION="1.0.0"

INSTALL_LOCATION="PATH_TO_WHERE_THE_FILES_SHOULD_BE_COPIED_ON_USERS_MACHINE"
ROOT_LOCATION="PATH_TO_WHERE_FILES_ARE_ON_YOUR_MASCHINE"

# Remove any unwanted .DS_Store files.
find "$ROOT_LOCATION" -name '*.DS_Store' -type f -delete

# put any command for changing the ownership or permissions here
chmod -R +r "$ROOT_LOCATION"

# Build package.
/usr/bin/pkgbuild \
    --root "$ROOT_LOCATION" \
    --install-location "$INSTALL_LOCATION" \
    --identifier "$IDENTIFIER" \
    --version "$VERSION" \
    "$NAME.pkg"

save this something in a file like create-my-package.sh and run this in command line.