Skip to main content
Question

Script To Install Multiple PKGs

  • April 13, 2016
  • 7 replies
  • 126 views

Forum|alt.badge.img+4

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

ehemmete
Forum|alt.badge.img+5
  • Contributor
  • April 13, 2016

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.


Forum|alt.badge.img+13
  • Honored Contributor
  • April 13, 2016

you could also use installpkg here

install in /usr/local

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

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • April 13, 2016

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


Forum|alt.badge.img+13
  • Honored Contributor
  • April 13, 2016

@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
Forum|alt.badge.img+24
  • Legendary Contributor
  • April 13, 2016

@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!


Forum|alt.badge.img+4
  • Author
  • Contributor
  • April 20, 2016

Thank you very much for your input all.


Forum|alt.badge.img+7
  • Contributor
  • June 8, 2021

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