I would start with a tool like Platypus to make your script have all the accoutrements of an App and test to see that things work as expected.
Automator also has a nice GUI for deciding how to handle arguments to a script - and we have several questions here that explore how to pass arguments into and out of an Automator action / applet.
Without more details on how your daemon is designed and how you launch it, I can only pick away at some of the elements to your solution, but since anyone can edit this answer to provide more details (or answer a stand-alone answer) - perhaps this can get the ball rolling to get you a solution.
Short Answer: yes.
Long Answer: Yes, but…a full answer to this question includes a technical answer and a practical concern.
First, the technical answer
You can install a .pkg or .mpkg using this syntax:
sudo installer -verboseR -pkg "/path/to/pkg/foo.mpkg"
If the installer isn't 'signed' properly, you'll need to add -allowUntrusted
sudo installer -allowUntrusted -verboseR -pkg "/path/to/pkg/foo.mpkg"
You may also need to specify where you want it installed, using -target /
(I'm not 100% certain this is required, but it's a good idea):
sudo installer -allowUntrusted -verboseR -pkg "/path/to/pkg/foo.mpkg" -target /
Now, the problem is that sudo
is going to ask you for your administrator password when you try to run installer
. If you want to automate this, you need to tell your Mac not to require your sudo
password when running the installer. To do that, you can add this line to your /etc/sudoers
file:
%admin ALL=NOPASSWD: /usr/sbin/installer
See man visudo
for instructions on editing that file.
Second, the practical concern
If you are the only person who uses your Mac, adding the above line to /etc/sudoers
is not a big deal.
However, if this is a shared Mac, then other people who are in the 'admin' group will be able to run /usr/sbin/installer
without being prompted for their password.
Also, obviously if someone gets into your 'admin' account, they too could, theoretically, cause mischief with /usr/sbin/installer
. Although I am at a loss to think of exactly what they would do, it's a trade-off of security versus convenience.
Third, a github script
I wrote pkginstall.sh to do some nice things like log the process, as well as tell you whether or not you are supposed to reboot after installing the package.
Last but not least: Automate "how?"
As far as how you want to automate the installation, that depends on more specifics of what you are trying to do. You could, for example, make a folder such as ~/Action/AutoInstallPKG/ and tell launchd
to install any .pkg or .mpkg files that are added to that folder, and then move it aside afterwards.
I have been meaning to do something like this for a long time, and so I finally put it together. You can find it at https://github.com/tjluoma/autopkginstall. Installation instructions are included at Github, so I won't repeat them here.
Best Answer
Could you do this with Platypus? I use it to package small executables with a shell script into an install app, which uses the shell script to move executables into the target folder on run. You're still going to have issues with your intended result however as I can't see any way around running a package install without requiring admin access IF the package normally modifies files that require admin permission, but you should be able to put the package, the configuration file, and the install script together into one app using Platypus. End users can then run the app to install the package with your desired configuration.
The setup is really simple, the output is minimal. This is not a program designed to do anything complicated but it is free and has been really useful for distributing self-written script-based apps.