4

How do I get the original *.pkg file directory when install it?

I have created a pkg file, and put it with another file(like test.txt) into a same folder, like ~/Desktop/test

And when install pkg file, I want it to copy the "test.txt" file to ~/Library folder. So I add preinstall/postinstall script into pkg file to copy the "test.txt" file. I try to get the directory use

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

But it will return the tmp directory

/private/tmp/PKInstallSandbox.G5GFI6/Scripts/com.myApp.testApp.pkg.o5k2nE

not the original pkg directory (~/Desktop/test)

Has anybody know how to get the original directory when install?

trent.xu
  • 61
  • 1
  • 1
  • 4
  • why don't you embed the plist with your package? Also plist should be created by your app, not package – CharlesB May 09 '12 at 09:14
  • The plist file may be changed in the later time, it would result in create a new related pkg frequently when plist file changed. BTW: it may not only plist file to be copied. – trent.xu May 09 '12 at 10:02
  • 1
    Have you found a solution for this? – MiuMiu Mar 07 '14 at 07:49

3 Answers3

14

You've created a flat package? Have you tried looking at the parameters passed to the postinstall script?

$0 - Script path
$1 - Package path
$2 - Target location
$3 - Target volume`

Parameter $1 should give you what you're looking for.

Copied from old bundle style format information, but still seems to apply to newer flat packages.

3

This Mac Installers Blog has some useful posts about Packagemaker including details about the usage and solutions to common problems.

Vikram Singh
  • 1,726
  • 1
  • 13
  • 25
2

This:

pkgpath=\`dirname "$PACKAGE_PATH"\`

will give you the path to the package in the variable $pkgpath.

Andrei
  • 3,086
  • 2
  • 19
  • 24
pliniop
  • 21
  • 1