Script To Install Multiple PKGs

Jae
New Contributor III

Hello,

I know I can create this as a policy but can anyone tell me how to go about scripting multiple pkgs to run? I remember doing this at JAMF training but I do not remember the steps/ scripts involved.

7 REPLIES 7

ehemmete
New Contributor II

You can use the installer command and loop through your packages.

sudo installer -pkg <path to package> -target <path to target, normally />

One of those lines for each package.

Nix4Life
Valued Contributor

you could also use installpkg here

install in /usr/local

/usr/local/installpkg  /path/to/directory/of/packages/*

mm2270
Legendary Contributor III

Kind of basic and crude, but something like this:

#!/bin/bash

while read PKG; do
    installer -pkg "$PKG" -tgt / -verbose
done < <(find /path/to/packages -name *.pkg -o -name *.mpkg)

That should locate any installers (.pkg or .mpkg files) in the directory and run each one thru command line installer. The above does no error checking, so if any of them fail to install, I'm not sure how it would be reported. Hence why I threw in the -verbose flag so hopefully you'd get some output to tell you that.

You'd need to specify the /path/to/packages in the script, either hardcoded, or as a variable, or even passed as a parameter to the script, like in $4

Nix4Life
Valued Contributor

@mm2270 Good point. Just assumed logging would go to jamf log or system log, better to not assume. Also kudos on app-packager,it's one of my latest go to tools

Larry

mm2270
Legendary Contributor III

@LSinNY Actually, I wasn't referring to your post, I was referring to mine :) My script doesn't do any error checking as I literally just threw it together before I posted.
I haven't actually looked at installpkg, mostly because I wasn't aware it was there. Thanks for pointing it out. I plan on taking a look at it at some point. And glad you're making use of App Packager!

Jae
New Contributor III

Thank you very much for your input all.

killer23d
Contributor

For those who still need this, I have revised the code:

#!/bin/bash
for pkg in $( ls /path/to/*.pkg ); do
    echo "Installing $pkg"
    installer -pkg $pkg -target /
done