A Casper/jamf pro EA for package versions

Not all packages are .apps

By default casper will allow you to take an inventory of any .app applicatiosn installed into the /Applications folder.

But what if the package doesn’t install there and you need to check the version?

pkgutil –pkgs

A tool that is used to check what is installed on the machine is pkgutil. One switch for this lists all the installed packages by name, pkgutil –pkgs.

Running this will list every installed package, use grep to narrow the list down like this;

screen-shot-2016-12-29-at-14-20-47

pkgutil –pkg-info

Having obtained the name, or pkg ID, of the application we want to get the version  from the pkgutil –pkg-info switch allows us to return the recorded info for the package;

Using the outlook example;

pkgutil --pkg-info com.microsoft.package.Microsoft_Outlook.app

will return;

screen-shot-2016-12-29-at-14-29-59

The finished EA

The finished EA extracts the version info from this and returns it to the jamf server;

#!/bin/bash

# EA to find the installed version of a specified package
# reads the info direct from the pkg installed DB
# set the packagename as the pkgName variable
pkgName="com.somesoftware.aclient.package.pkg"


# read the info, strip off the version: string and remove any spaces for consistency
result=$(pkgutil --pkg-info $pkgName | grep version | awk -F: '{print $2}' | sed s'/ //')

#echo $result

# check that a value has been returned, if not set a default
if [ "$result" = "" ]; then
	result="NotInstalled"
fi

# send value to JSS
echo "$result"

This EA is usable for any pkg that I tested it with, all that is required is to find out the correct pkgName before hand.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s