Running a script to access the Jamf/Downloads folder and install Project Libre

Foster
New Contributor

Hi,

I'm trying to create a policy to push out Project Libre 1.7 to a Mac workstation. There are a couple requirements for the install:

1) Project Libre requires that Java also be installed. We already have a seperate package for java.

2) If Java exists the install will continue and Project Libre will install but the status will report as 'failed' if the Java version installed is > what is in the policy. This happened to me as I manually upgraded java and was at a greater version.

My thought was to write a script (which i'm lousy at) to verify if Java is installed. It would then install both .pkg files from the cache location under JAMF/Downloads. The script looks as follows:

!/bin/bash

#####################################

Variable for the current logged in user name

#####################################

CurrentUser=stat -f "%Su" /dev/console

##################################

Variable for the current Java install path

##################################

JavaFolder="/Library/Application Support/Oracle/java"

#########################

Variable for cached .pkg location

#########################

SoftwareLocation="/Library/Application Support/JAMF/Downloads"

SoftwareLocation="/Library/Application Support/JAMF/Downloads/"

#########################################################################

Check if Java exists before installing Project Libre. If it already exists only

Project Libre will be installed. Otherwise, both packages get installed

#########################################################################

if [ -d "$JavaFolder" ]
then echo " " echo "/Java is already installed. Continuing with the install" echo " "
else sudo installer -pkg "$SoftwareLocation"/Java8Update112.pkg -target /Applications
fi

##################

Install Project Libre .pkg

##################

sudo installer -pkg "$SoftwareLocation"/ProjectLibre-1.7.pkg -target /Applications

The following is the error message in the policy logs. I also get the same error from the terminal. It basically looks like I don't have rights to that directory but I'm not sure how to get around that problem as it looks like Casper has it locked down.

[STEP 1 of 6]
Executing Policy Project Libre-1.7
[STEP 2 of 6]
Caching package Java8Update112.pkg...
Downloading Java8Update112.pkg...
Downloading https://d1yt58bk9i9lao.cloudfront.net/Java8Update112.pkg...
[STEP 3 of 6]
Caching package ProjectLibre-1.7.pkg...
Downloading ProjectLibre-1.7.pkg...
Downloading https://d1yt58bk9i9lao.cloudfront.net/ProjectLibre-1.7.pkg...
[STEP 4 of 6]
Running script Project Libre Script - Check for JavaInstall Project...
Script exit code: 1
Script result: installer: Error the package path specified was invalid: '/Library/Application Support/JAMF/Downloads//Java8Update112.pkg'.<br/>installer: Error the package path specified was invalid: '/Library/Application Support/JAMF/Downloads//ProjectLibre-1.7.pkg'.<br/>
Error running script: return code was 1.
[STEP 5 of 6]
[STEP 6 of 6]

Any assistance would be greatly appreciated. Especially if I'm going about this completely wrong :-)
df62ae663a53464dab98cc657f43d22e

3 REPLIES 3

crigby
New Contributor

@Foster It looks like your script is failing because of the paths to your installers. There's the escape in Application Support and an extra '/' after downloads:

'/Library/Application Support/JAMF/Downloads//Java8Update112.pkg'

I would take a different approach to installing the software that would take out the need to script the install.

  • Use an extension attribute to report whether or not Java is installed, and get the version. Jamf provides a good one as part of their patch reporting functionality:
#!/usr/bin/env bash
#######################################################################################
# Collects information to determine which version of the Java plugin is installed and # 
# then returning that version back if major version (1.X) match what we're searching  # 
# for with SEARCH_FOR_VERSION. Builds the result as 1.X.Y, ignoring the build number, #
# where X is major version and Y is the minor version.                                # 
#######################################################################################
NOT_INSTALLED="Not Installed"
SEARCH_FOR_VERSION="8"
RESULT=""

if [ -f "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Enabled.plist" ] ; then
    RESULT=$( /usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Enabled.plist" CFBundleVersion )
    REPORTED_MAJOR_VERSION=`echo "$RESULT" | awk -F'.' '{print $2}'`
    REPORTED_MINOR_VERSION=`echo "$RESULT" | awk -F'.' '{print $3}'`
    if [ "$REPORTED_MAJOR_VERSION" != "$SEARCH_FOR_VERSION" ] ; then
        RESULT="$NOT_INSTALLED"
    else
        RESULT=1."$REPORTED_MAJOR_VERSION".$REPORTED_MINOR_VERSION
    fi
else
    RESULT="$NOT_INSTALLED"
fi

echo "<result>$RESULT</result>"
  • Create a smart group that includes (or does not include) computers that have correct Java version reported in the extension attribute, and use that group to scope Project Libre. For example, I would scope a policy to install Project Libre to all clients, then exclude clients without the correct version of Java.

Joeborner
New Contributor II

I agree with @Foster , scoping based on Java is the easier option.

As mentioned above you are defining the SoftwareLocation with a trailing /, which is then input again in your script. You need to remove the trailing / when defining the path.

blackholemac
Valued Contributor III

Definitely some great ideas here ...to help you get the right extension attribute for Java and its versions, steal the one JAMF uses for patch management reporting...add it then yourself manually. This will help you get good smart groups to know what you can target rationally.