How to create pkg which installs files to /usr/local
I tried using Whitebox's Packages to create an installer for a LaunchDaemon. The daemon calls a shell script, which itself sources a configuration file.
So what I would like is an installer which installs:
- /Library/LaunchDaemons/my_daemon.plist. (This is not a problem).
- /usr/local/bin/myscript.sh
- /usr/local/etc/myscript.conf
I cannot find how to specify the destination path of /usr/local.
Packages doesn't let me edit the destination of these 2 files, and seems to want to install to "./myscript.sh" and "./myscript.conf", even though it did let me define the absolute destination for the .plist file in /Library/LaunchDaemons.
I guess I could write a postinstall script which creates the directories if needed and copies the files there. But isn't there a better/simpler solution which I am overlooking?
In other words, how can I create a .pkg installer which lets me specify absolute directories for some files, and which creates these directories during the install if needed.
Is a postinstall shell script the only solution, or is there a way to have Packages do things automatically, or is there some other package-creation app which would be more practical for this?
Rather than using a script to create /usr/local and its subfolders, include them as part of the package's payload. That is, create a prototype "local" folder with "bin" and "etc" subfolders, and your script and conf file in them. Set the permissions correctly (root:admin, 755 for all but the conf file, 644 or maybe 664 for that). Then create an installer package that places that whole folder structure in /usr.
Note that if /usr/local (and some subfolders and files) already exist, the installer will simply merge your package's payload with what already exists (i.e. it does exactly what you want).
/usr/local
doesn't exist by default. You have to create it using Terminal in order to use it as a destination path. Open Terminal and enter the following command (triple click it, copy it, and paste it into your prompt). Enter your password when prompted:
sudo mkdir /usr/local/{,bin,etc}; chmod -R 775 /usr/local/; chown -R root:admin /usr/local; exit
The first part makes the directory and sub-folders, the second modifies its permissions, and the third modifies ownership.